public final class PeerAddress extends Object implements Comparable<PeerAddress>, Serializable
20 bytes - Number160
2 bytes - Header
- 1 byte options: IPv6, firewalled UDP, firewalled TCP
- 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 int |
MAX_RELAYS |
static int |
MAX_SIZE |
static int |
MIN_SIZE |
| Constructor and Description |
|---|
PeerAddress(byte[] me)
Creates a new peeraddress, 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, InetAddress, int, int, boolean, boolean, 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, boolean, boolean, PeerSocketAddress[]). |
PeerAddress(Number160 id,
PeerSocketAddress peerSocketAddress,
boolean firewalledTCP,
boolean firewalledUDP,
boolean isRelayed,
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, boolean, boolean, PeerSocketAddress[]). |
| 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 firewalledTCP status.
|
PeerAddress |
changeFirewalledUDP(boolean firewalledUDP)
Create a new PeerAddress and change the firewallUDP status.
|
PeerAddress |
changePeerId(Number160 peerId)
Create a new PeerAddress and change the peer id.
|
PeerAddress |
changePeerSocketAddress(PeerSocketAddress peerSocketAddress) |
PeerAddress |
changePeerSocketAddresses(PeerSocketAddress[] peerSocketAddresses) |
PeerAddress |
changePorts(int tcpPort,
int udpPort)
Create a new PeerAddress and change the TCP and UDP ports.
|
int |
compareTo(PeerAddress nodeAddress) |
InetSocketAddress |
createSocketTCP()
Returns the socket address.
|
InetSocketAddress |
createSocketUDP()
Returns the socket address.
|
boolean |
equals(Object obj) |
InetAddress |
getInetAddress()
Returns the address or null if no address set.
|
byte |
getOptions() |
Number160 |
getPeerId()
The id of the peer.
|
PeerSocketAddress[] |
getPeerSocketAddresses() |
byte |
getRelays() |
int |
hashCode() |
boolean |
isFirewalledTCP() |
boolean |
isFirewalledUDP() |
boolean |
isIPv4() |
boolean |
isIPv6() |
boolean |
isRelayed() |
int |
offset()
When deserializing, we need to know how much we deserialized from the constructor call.
|
PeerSocketAddress |
peerSocketAddress() |
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 int MAX_RELAYS
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, 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 used as a relaypeerSocketAddresses - the relay peerspublic PeerAddress(Number160 peerId, InetAddress inetAddress, int tcpPort, int udpPort)
#PeerAddress(Number160, InetAddress, int, int, boolean, boolean, PeerSocketAddress[]).peerId - The id of the peerinetAddress - The inetAddress of the peer, how to reach this peertcpPort - The TCP port how to reach the peerudpPort - The UDP port how to reach the peerpublic PeerAddress(Number160 id, String address, int tcpPort, int udpPort) throws UnknownHostException
#PeerAddress(Number160, InetAddress, int, int, boolean, boolean, PeerSocketAddress[]).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)
#PeerAddress(Number160, InetAddress, int, int, boolean, boolean, PeerSocketAddress[]).id - The id of the peerinetSocketAddress - The socket address of the peer, how to reach this peer. Both UPD and TCP will be set to the same portpublic 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 - Set optionspublic 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 getInetAddress()
public InetSocketAddress createSocketTCP()
public InetSocketAddress createSocketUDP()
public Number160 getPeerId()
public byte getOptions()
public byte getRelays()
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 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(PeerSocketAddress[] peerSocketAddresses)
public PeerAddress changePeerSocketAddress(PeerSocketAddress peerSocketAddress)
public PeerSocketAddress[] getPeerSocketAddresses()
public static int size(int header)
header - The header is in the lower 16 bitspublic 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 what type it isCopyright © 2014. All rights reserved.