class NodeInfo extends SimpleDataStructure
This class encapsulates all essential information about a DHT node including its Node ID (NID), destination hash, port, and optionally the full I2P destination. It serves as the primary data structure stored in DHTNodes for routing table management and node discovery operations.
Data structure components:
- NID: 20-byte node identifier used for Kademlia distance calculations
- Hash: 32-byte destination hash for I2P routing
- Port: 2-byte network port for DHT communication
- Destination: Optional full I2P destination (may be added later)
The compact representation (54 bytes) is immutable and contains NID, hash, and port. This compact format is used for network transmission and efficient storage. The full destination may be added later when available, enabling direct communication with the node.
Design considerations:
- DHT exchanges often use only hashes initially, with destinations added later
- Compact format enables efficient network transmission and storage
- Immutable core data ensures consistency in routing operations
- Optional destination allows progressive information discovery
| Modifier and Type | Field and Description |
|---|---|
static int | LENGTHSerialized length in bytes (NID + Hash + 2). |
_data| Constructor and Description |
|---|
NodeInfo(byte[] compactInfo,
int offset)No Destination yet available. |
NodeInfo(Destination dest,
int port)With a fake NID used for pings |
NodeInfo(NID nID,
Destination dest,
int port)Use this if we have the full destination. |
NodeInfo(NID nID,
Hash hash,
int port)No Destination yet available. |
NodeInfo(String s)Create from persistent storage string. |
| Modifier and Type | Method and Description |
|---|---|
Hash | calculateHash()calculateHash. |
boolean | equals(Object o)equals. |
static NID | generateNID(Hash h,
int p,
RandomSource random)Generate a secure NID that matches the Hash and port. |
Destination | getDestination() |
Hash | getHash() |
NID | getNID() |
int | getPort() |
int | hashCode()We assume the data has enough randomness in it, so use the first 4 bytes for speed. |
long | lastSeen() |
int | length()The legal length of the byte array in this data structure. |
void | setDestination(Destination dest)This can come in later but the hash must match. |
String | toPersistentString()To persistent storage string. |
String | toString()toString. |
fromBase64, fromByteArray, getData, read, readBytes, setData, toBase64, toByteArray, writeBytespublic static final int LENGTH
public NodeInfo(byte[] compactInfo,
int offset)compactInfo - 20 byte node ID, 32 byte destHash, 2 byte portoffset - starting at this offset in compactInfoIllegalArgumentException - if port is invalidArrayIndexOutOfBoundsException - if compactInfo is too shortpublic NodeInfo(Destination dest, int port)
public NodeInfo(NID nID, Destination dest, int port)
nID - the node identifierdest - the full I2P destinationport - the DHT query portIllegalArgumentException - if the NID does not match the destination hashpublic NodeInfo(NID nID, Hash hash, int port)
nID - the node identifierhash - the destination hashport - the DHT query portIllegalArgumentException - if the NID does not match the hash or port is invalidpublic NodeInfo(String s) throws DataFormatException
s - the persistent storage stringDataFormatException - if the string format is invalidIllegalArgumentException - if the NID does not match the hashpublic Hash calculateHash()
calculateHash in interface DataStructurecalculateHash in class SimpleDataStructurepublic boolean equals(Object o)
equals in class SimpleDataStructureo - the object to comparepublic static NID generateNID(Hash h, int p, RandomSource random)
h - the destination hashp - the port numberrandom - the randompublic Destination getDestination()
public Hash getHash()
public NID getNID()
public int getPort()
public int hashCode()
SimpleDataStructurehashCode in class SimpleDataStructurepublic long lastSeen()
public int length()
SimpleDataStructurelength in class SimpleDataStructurepublic void setDestination(Destination dest) throws IllegalArgumentException
IllegalArgumentException - if hash of dest doesn't match previous hashpublic String toPersistentString()
public String toString()
toString in class SimpleDataStructure