Package org.bitcoinj.core
Class PeerAddress
java.lang.Object
org.bitcoinj.core.Message
org.bitcoinj.core.ChildMessage
org.bitcoinj.core.PeerAddress
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
ConstructorDescriptionPeerAddress
(NetworkParameters params, byte[] payload, int offset, Message parent, MessageSerializer serializer) Construct a peer address from a serialized payload.PeerAddress
(NetworkParameters params, String hostname, int port) Constructs a peer address from a stringified hostname+port.PeerAddress
(NetworkParameters params, InetAddress addr) Constructs a peer address from the given IP address.PeerAddress
(NetworkParameters params, InetAddress addr, int port) Constructs a peer address from the given IP address and port.PeerAddress
(NetworkParameters params, InetAddress addr, int port, BigInteger services) Constructs a peer address from the given IP address, port and services.PeerAddress
(NetworkParameters params, InetAddress addr, int port, BigInteger services, MessageSerializer serializer) Construct a peer address from a memorized or hardcoded address.PeerAddress
(NetworkParameters params, InetSocketAddress addr) Constructs a peer address from anInetSocketAddress
. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
bitcoinSerializeToStream
(OutputStream stream) Serializes this message to the provided stream.boolean
getAddr()
int
getPort()
long
getTime()
int
hashCode()
static PeerAddress
localhost
(NetworkParameters params) protected void
parse()
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 Details
-
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, InetAddress addr, int port, BigInteger services, MessageSerializer serializer) Construct a peer address from a memorized or hardcoded address. -
PeerAddress
Constructs a peer address from the given IP address, port and services. Version number is default for the given parameters. -
PeerAddress
Constructs a peer address from the given IP address and port. Version number is default for the given parameters. -
PeerAddress
Constructs a peer address from the given IP address. Port and version number are default for the given parameters. -
PeerAddress
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
Constructs a peer address from a stringified hostname+port. Use this if you want to connect to a Tor .onion address.
-
-
Method Details
-
localhost
-
bitcoinSerializeToStream
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:
IOException
-
parse
- Specified by:
parse
in classMessage
- Throws:
ProtocolException
-
getHostname
-
getAddr
-
getSocketAddress
-
getPort
public int getPort() -
getServices
-
getTime
public long getTime() -
toString
-
equals
-
hashCode
public int hashCode() -
toSocketAddress
-