public final class PeerAddress extends Object implements Comparable<PeerAddress>, Serializable
20 bytes - Number160
2 bytes - Header
- 1 byte options: IPv6, firewalled UDP, firewalled TCP, is relayed
- 1 byte relays:
- first 3 bits: number of relays (max 5.)
- second 5 bits: if the 5 relays are IPv6 (bit set) or not (no bit set)
2 bytes - TCP port
2 bytes - UDP port
4 or 16 bytes - Inet Address
0-5 relays:
- 2 bytes - TCP port
- 2 bytes - UDP port
- 4 or 16 bytes - Inet Address
| Modifier and Type | Field and Description |
|---|---|
static Collection<PeerSocketAddress> |
EMPTY_PEER_SOCKET_ADDRESSES |
static int |
MAX_SIZE |
static int |
MIN_SIZE |
| Constructor and Description |
|---|
PeerAddress(byte[] me)
Creates a peer address, where the byte array has to be in the rigth format and in the right size.
|
PeerAddress(byte[] me,
int initialOffset)
Creates a PeerAddress from a continuous byte array.
|
PeerAddress(io.netty.buffer.ByteBuf channelBuffer)
Creates a PeerAddress from a Netty ByteBuf.
|
PeerAddress(Number160 id)
If you only need to know the id.
|
PeerAddress(Number160 id,
InetAddress address)
If you only need to know the id and InetAddress.
|
PeerAddress(Number160 peerId,
InetAddress inetAddress,
int tcpPort,
int udpPort)
Facade for PeerAddress(Number160, PeerSocketAddress, boolean, boolean, boolean, Collection-PeerSocketAddress>).
|
PeerAddress(Number160 id,
InetAddress inetAddress,
int tcpPort,
int udpPort,
int options)
Facade for
#PeerAddress(Number160, InetAddress, int, int, boolean, boolean, PeerSocketAddress[]). |
PeerAddress(Number160 id,
InetSocketAddress inetSocketAddress)
Facade for PeerAddress(Number160, InetAddress, int, int).
|
PeerAddress(Number160 id,
PeerSocketAddress peerSocketAddress,
boolean firewalledTCP,
boolean firewalledUDP,
boolean isRelayed,
boolean isSlow,
boolean portForwarding,
Collection<PeerSocketAddress> peerSocketAddresses)
Creates a PeerAddress if all the values are known.
|
PeerAddress(Number160 id,
String address,
int tcpPort,
int udpPort)
Facade for PeerAddress(Number160, InetAddress, int, int).
|
| Modifier and Type | Method and Description |
|---|---|
PeerAddress |
changeAddress(InetAddress inetAddress)
Create a new PeerAddress and change the InetAddress.
|
PeerAddress |
changeFirewalledTCP(boolean firewalledTCP)
Create a new PeerAddress and change the firewall TCP status.
|
PeerAddress |
changeFirewalledUDP(boolean firewalledUDP)
Create a new PeerAddress and change the firewall UDP status.
|
PeerAddress |
changePeerId(Number160 peerId)
Create a new PeerAddress and change the peer id.
|
PeerAddress |
changePeerSocketAddress(PeerSocketAddress peerSocketAddress) |
PeerAddress |
changePeerSocketAddresses(Collection<PeerSocketAddress> peerSocketAddresses) |
PeerAddress |
changePortForwarding(boolean portForwarding) |
PeerAddress |
changePorts(int tcpPort,
int udpPort)
Create a new PeerAddress and change the TCP and UDP ports.
|
PeerAddress |
changeRelayed(boolean isRelayed)
Create a new PeerAddress and change the relayed status.
|
PeerAddress |
changeSlow(boolean isSlow)
Create a new PeerAddress and change the slow status
|
int |
compareTo(PeerAddress nodeAddress) |
InetSocketAddress |
createSocketTCP()
Creates and returns the socket address using the TCP port.
|
InetSocketAddress |
createSocketUDP()
Creates and returns the socket address using the UDP port.
|
InetSocketAddress |
createSocketUDP(int port) |
boolean |
equals(Object obj) |
int |
hashCode() |
InetAddress |
inetAddress()
Returns the address or null if no address set.
|
PeerSocketAddress |
internalPeerSocketAddress() |
PeerAddress |
internalPeerSocketAddress(PeerSocketAddress internalPeerSocketAddress) |
boolean |
isFirewalledTCP() |
boolean |
isFirewalledUDP() |
boolean |
isIPv4() |
boolean |
isIPv6() |
boolean |
isPortForwarding() |
boolean |
isRelayed() |
boolean |
isSlow() |
int |
offset()
When deserializing, we need to know how much we deserialized from the constructor call.
|
byte |
options() |
Number160 |
peerId()
The id of the peer.
|
PeerSocketAddress |
peerSocketAddress() |
Collection<PeerSocketAddress> |
peerSocketAddresses() |
byte |
relays() |
int |
relaySize() |
int |
size() |
static int |
size(int header)
Calculates the size based on the two header bytes.
|
static int |
size(int options,
int relays)
Calculates the size based on the two header bytes.
|
int |
tcpPort() |
byte[] |
toByteArray()
Serializes to a new array with the proper size.
|
int |
toByteArray(byte[] me,
int offset)
Serializes to an existing array.
|
String |
toString() |
int |
udpPort() |
public static final int MAX_SIZE
public static final int MIN_SIZE
public static final Collection<PeerSocketAddress> EMPTY_PEER_SOCKET_ADDRESSES
public PeerAddress(byte[] me)
me - The serialized arraypublic PeerAddress(byte[] me,
int initialOffset)
me - The serialized arrayinitialOffset - the offset, where to startpublic PeerAddress(io.netty.buffer.ByteBuf channelBuffer)
channelBuffer - The channel buffer to read frompublic PeerAddress(Number160 id)
id - The id of the peerpublic PeerAddress(Number160 id, InetAddress address)
id - The id of the peeraddress - The InetAddress of the peerpublic PeerAddress(Number160 id, PeerSocketAddress peerSocketAddress, boolean firewalledTCP, boolean firewalledUDP, boolean isRelayed, boolean isSlow, boolean portForwarding, Collection<PeerSocketAddress> peerSocketAddresses)
id - The id of the peerpeerSocketAddress - The peer socket address including both ports UDP and TCPfirewalledUDP - Indicates if peer is not reachable via UDPfirewalledTCP - Indicates if peer is not reachable via TCPisRelay - Indicates if peer is used as a relayisSlow - Indicates if a peer is slowpeerSocketAddresses - the relay peerspublic PeerAddress(Number160 peerId, InetAddress inetAddress, int tcpPort, int udpPort)
peerId - The id of the peerinetAddress - The internet address of the peertcpPort - The TCP port of the peerudpPort - The UDP port of the peerpublic PeerAddress(Number160 id, InetAddress inetAddress, int tcpPort, int udpPort, int options)
#PeerAddress(Number160, InetAddress, int, int, boolean, boolean, PeerSocketAddress[]).id - The id of the peerinetAddress - The address of the peer, how to reach this peertcpPort - The TCP port how to reach the peerudpPort - The UDP port how to reach the peeroptions - The options for the created PeerAddress.public PeerAddress(Number160 id, String address, int tcpPort, int udpPort) throws UnknownHostException
id - The id of the peeraddress - The address of the peer, how to reach this peertcpPort - The TCP port how to reach the peerudpPort - The UDP port how to reach the peerUnknownHostException - If no IP address for the host could be found, or if a scope_id was specified for a global IPv6
address.public PeerAddress(Number160 id, InetSocketAddress inetSocketAddress)
id - The id of the peerinetSocketAddress - The socket address of the peer, how to reach this peer. Both TCP and UDP will be set to the same portpublic int offset()
public int size()
public byte[] toByteArray()
public int toByteArray(byte[] me,
int offset)
me - The array where the result should be storedoffset - The offset where to start to save the result in the byte arraypublic PeerSocketAddress peerSocketAddress()
public InetAddress inetAddress()
public InetSocketAddress createSocketTCP()
public InetSocketAddress createSocketUDP()
public InetSocketAddress createSocketUDP(int port)
public Number160 peerId()
public byte options()
public byte relays()
public int compareTo(PeerAddress nodeAddress)
compareTo in interface Comparable<PeerAddress>public int udpPort()
public int tcpPort()
public boolean isFirewalledUDP()
public boolean isFirewalledTCP()
public boolean isIPv6()
public boolean isIPv4()
public boolean isRelayed()
public boolean isSlow()
public boolean isPortForwarding()
public PeerAddress changeRelayed(boolean isRelayed)
isRelayed - the new relay statuspublic PeerAddress changeSlow(boolean isSlow)
isSlow - the new statuspublic PeerAddress changePortForwarding(boolean portForwarding)
public PeerAddress changeFirewalledUDP(boolean firewalledUDP)
firewalledUDP - the new statuspublic PeerAddress changeFirewalledTCP(boolean firewalledTCP)
firewalledTCP - the new statuspublic PeerAddress changePorts(int tcpPort, int udpPort)
tcpPort - The new TCP portudpPort - The new UDP portpublic PeerAddress changeAddress(InetAddress inetAddress)
inetAddress - The new InetAddresspublic PeerAddress changePeerId(Number160 peerId)
peerId - the new peer idpublic PeerAddress changePeerSocketAddresses(Collection<PeerSocketAddress> peerSocketAddresses)
public PeerAddress changePeerSocketAddress(PeerSocketAddress peerSocketAddress)
public Collection<PeerSocketAddress> peerSocketAddresses()
public static int size(int header)
header - The header in the lower 16 bits of this integer.public static int size(int options,
int relays)
options - The option tells us if the inet address is IPv4 or IPv6relays - The relays tells us how many relays we have and of what type they are.public int relaySize()
public PeerSocketAddress internalPeerSocketAddress()
public PeerAddress internalPeerSocketAddress(PeerSocketAddress internalPeerSocketAddress)
Copyright © 2014. All rights reserved.