Package org.bitcoinj.core
Class PeerAddress
java.lang.Object
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.
Instances of this class are not safe for use by multiple threads.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
getAddr()
static InetAddress
getByAddress
(byte[] addrBytes) int
getMessageSize
(int protocolVariant) Return the size of the serialized message, using a given protocol variant.int
getPort()
long
getTime()
Deprecated.int
hashCode()
static PeerAddress
inet
(InetAddress addr, int port, Services services, Instant time) Constructs a peer address from the given IP address, port, services and time.static PeerAddress
inet
(InetSocketAddress addr, Services services, Instant time) Constructs a peer address from the given IP address, port, services and time.static PeerAddress
localhost
(NetworkParameters params) static byte[]
mapIntoIPv6
(byte[] ip) Map given IPv4 address into IPv6 space.static PeerAddress
read
(ByteBuffer payload, int protocolVariant) Deserialize this peer address from a given payload, using a given protocol variant.byte[]
serialize
(int protocolVariant) Allocates a byte array and writes this peer address into it, using a given protocol variant.static PeerAddress
simple
(InetAddress addr, int port) Constructs a simple peer address from the given IP address and port, but without services.static PeerAddress
simple
(InetSocketAddress addr) Constructs a simple peer address from the given socket address, but without services.time()
Gets the time that the node was last seen as connected to the network.toString()
write
(ByteBuffer buf, int protocolVariant) Write this peer address into the given buffer, using a given protocol variant.
-
Method Details
-
simple
Constructs a simple peer address from the given IP address and port, but without services. The time is set to current time.- Parameters:
addr
- ip address of peerport
- port the peer is listening on- Returns:
- simple peer address
-
simple
Constructs a simple peer address from the given socket address, but without services. The time is set to current time.- Parameters:
addr
- ip address and port of peer- Returns:
- simple peer address
-
inet
Constructs a peer address from the given IP address, port, services and time. Such addresses are used for `addr` and `addrv2` messages of types IPv4 and IPv6.- Parameters:
addr
- ip address of the peerport
- port the peer is listening onservices
- node services the peer is providingtime
- last-seen time of the peer
-
inet
Constructs a peer address from the given IP address, port, services and time. Such addresses are used for `addr` and `addrv2` messages of types IPv4 and IPv6.- Parameters:
addr
- ip address and port of the peerservices
- node services the peer is providingtime
- last-seen time of the peer
-
read
public static PeerAddress read(ByteBuffer payload, int protocolVariant) throws BufferUnderflowException, ProtocolException Deserialize this peer address from a given payload, using a given protocol variant. The variant can be 1 (AddressV1Message
) or 2 (AddressV2Message
).- Parameters:
payload
- payload to deserialize fromprotocolVariant
- variant of protocol to use for parsing- Returns:
- read message
- Throws:
BufferUnderflowException
- if the read message extends beyond the remaining bytes of the payloadProtocolException
-
localhost
-
write
Write this peer address into the given buffer, using a given protocol variant. The variant can be 1 (AddressV1Message
) or 2 (AddressV2Message
)..- Parameters:
buf
- buffer to write intoprotocolVariant
- variant of protocol used- Returns:
- the buffer
- Throws:
BufferOverflowException
- if the peer addressdoesn't fit the remaining buffer
-
serialize
public byte[] serialize(int protocolVariant) Allocates a byte array and writes this peer address into it, using a given protocol variant. The variant can be 1 (AddressV1Message
) or 2 (AddressV2Message
).- Parameters:
protocolVariant
- variant of protocol used- Returns:
- byte array containing the peer address
-
getMessageSize
public int getMessageSize(int protocolVariant) Return the size of the serialized message, using a given protocol variant. The variant can be 1 (AddressV1Message
) or 2 (AddressV2Message
).. Note that if the message was deserialized from a payload, this size can differ from the size of the original payload.- Parameters:
protocolVariant
- variant of protocol used- Returns:
- size of the serialized message in bytes
-
getByAddress
-
mapIntoIPv6
public static byte[] mapIntoIPv6(byte[] ip) Map given IPv4 address into IPv6 space.- Parameters:
ip
- IPv4 to map into IPv6 space- Returns:
- mapped IP
-
getHostname
-
getAddr
-
getSocketAddress
-
getPort
public int getPort() -
getServices
-
time
Gets the time that the node was last seen as connected to the network.- Returns:
- time that the node was last seen
-
getTime
Deprecated.usetime()
-
toString
-
equals
-
hashCode
public int hashCode() -
toSocketAddress
-
time()