Package org.bitcoinj.core
Class PeerAddress
- java.lang.Object
-
- org.bitcoinj.core.Message
-
- org.bitcoinj.core.ChildMessage
-
- org.bitcoinj.core.PeerAddress
-
public class PeerAddress extends ChildMessage
A PeerAddress holds an IP address and port number representing the network location of a peer in the Bitcoin P2P network. It exists primarily for serialization purposes.
This class abuses the protocol version contained in its serializer. It can only contain 0 (format within
VersionMessage
), 1 (AddressV1Message
) or 2 (AddressV2Message
).Instances of this class are not safe for use by multiple threads.
-
-
Field Summary
-
Fields inherited from class org.bitcoinj.core.ChildMessage
parent
-
Fields inherited from class org.bitcoinj.core.Message
cursor, length, MAX_SIZE, offset, params, payload, recached, serializer, UNKNOWN_LENGTH
-
-
Constructor Summary
Constructors Constructor Description PeerAddress(NetworkParameters params, byte[] payload, int offset, Message parent, MessageSerializer serializer)
Construct a peer address from a serialized payload.PeerAddress(NetworkParameters params, java.lang.String hostname, int port)
Constructs a peer address from a stringified hostname+port.PeerAddress(NetworkParameters params, java.net.InetAddress addr)
Constructs a peer address from the given IP address.PeerAddress(NetworkParameters params, java.net.InetAddress addr, int port)
Constructs a peer address from the given IP address and port.PeerAddress(NetworkParameters params, java.net.InetAddress addr, int port, java.math.BigInteger services)
Constructs a peer address from the given IP address, port and services.PeerAddress(NetworkParameters params, java.net.InetAddress addr, int port, java.math.BigInteger services, MessageSerializer serializer)
Construct a peer address from a memorized or hardcoded address.PeerAddress(NetworkParameters params, java.net.InetSocketAddress addr)
Constructs a peer address from anInetSocketAddress
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
bitcoinSerializeToStream(java.io.OutputStream stream)
Serializes this message to the provided stream.boolean
equals(java.lang.Object o)
java.net.InetAddress
getAddr()
java.lang.String
getHostname()
int
getPort()
java.math.BigInteger
getServices()
java.net.InetSocketAddress
getSocketAddress()
long
getTime()
int
hashCode()
static PeerAddress
localhost(NetworkParameters params)
protected void
parse()
java.net.InetSocketAddress
toSocketAddress()
java.lang.String
toString()
-
Methods inherited from class org.bitcoinj.core.ChildMessage
adjustLength, adjustLength, setParent, unCache
-
Methods inherited from class org.bitcoinj.core.Message
bitcoinSerialize, bitcoinSerialize, getHash, getMessageSize, getParams, hasMoreBytes, isCached, isRecached, readByte, readByteArray, readBytes, readHash, readInt64, readStr, readUint32, readUint64, readVarInt, readVarInt, setSerializer, unsafeBitcoinSerialize
-
-
-
-
Constructor Detail
-
PeerAddress
public PeerAddress(NetworkParameters params, byte[] payload, int offset, Message parent, MessageSerializer serializer) throws ProtocolException
Construct a peer address from a serialized payload.- Parameters:
params
- NetworkParameters object.payload
- Bitcoin protocol formatted byte array containing message content.offset
- The location of the first payload byte within the array.serializer
- the serializer to use for this message.- Throws:
ProtocolException
-
PeerAddress
public PeerAddress(NetworkParameters params, java.net.InetAddress addr, int port, java.math.BigInteger services, MessageSerializer serializer)
Construct a peer address from a memorized or hardcoded address.
-
PeerAddress
public PeerAddress(NetworkParameters params, java.net.InetAddress addr, int port, java.math.BigInteger services)
Constructs a peer address from the given IP address, port and services. Version number is default for the given parameters.
-
PeerAddress
public PeerAddress(NetworkParameters params, java.net.InetAddress addr, int port)
Constructs a peer address from the given IP address and port. Version number is default for the given parameters.
-
PeerAddress
public PeerAddress(NetworkParameters params, java.net.InetAddress addr)
Constructs a peer address from the given IP address. Port and version number are default for the given parameters.
-
PeerAddress
public PeerAddress(NetworkParameters params, java.net.InetSocketAddress addr)
Constructs a peer address from anInetSocketAddress
. An InetSocketAddress can take in as parameters an InetAddress or a String hostname. If you want to connect to a .onion, set the hostname to the .onion address.
-
PeerAddress
public PeerAddress(NetworkParameters params, java.lang.String hostname, int port)
Constructs a peer address from a stringified hostname+port. Use this if you want to connect to a Tor .onion address.
-
-
Method Detail
-
localhost
public static PeerAddress localhost(NetworkParameters params)
-
bitcoinSerializeToStream
protected void bitcoinSerializeToStream(java.io.OutputStream stream) throws java.io.IOException
Description copied from class:Message
Serializes this message to the provided stream. If you just want the raw bytes use bitcoinSerialize().- Overrides:
bitcoinSerializeToStream
in classMessage
- Throws:
java.io.IOException
-
parse
protected void parse() throws ProtocolException
- Specified by:
parse
in classMessage
- Throws:
ProtocolException
-
getHostname
public java.lang.String getHostname()
-
getAddr
public java.net.InetAddress getAddr()
-
getSocketAddress
public java.net.InetSocketAddress getSocketAddress()
-
getPort
public int getPort()
-
getServices
public java.math.BigInteger getServices()
-
getTime
public long getTime()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toSocketAddress
public java.net.InetSocketAddress toSocketAddress()
-
-