Package org.klomp.snark.dht
Class NodeInfo
java.lang.Object
net.i2p.data.SimpleDataStructure
org.klomp.snark.dht.NodeInfo
- All Implemented Interfaces:
DataStructure
-
Field Summary
Fields inherited from class net.i2p.data.SimpleDataStructure
_data
-
Constructor Summary
ConstructorDescriptionNodeInfo
(byte[] compactInfo, int offset) No Destination yet availableCreate from persistent storage string.NodeInfo
(Destination dest, int port) With a fake NID used for pingsNodeInfo
(NID nID, Destination dest, int port) Use this if we have the full destinationNo Destination yet available -
Method Summary
Modifier and TypeMethodDescriptionCalculate the SHA256 value of this object (useful for a few scenarios)boolean
Warning - this returns true for two different classes with the same size and same data, e.g.static NID
generateNID
(Hash h, int p, RandomSource random) Generate a secure NID that matches the Hash and port.getHash()
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 structurevoid
setDestination
(Destination dest) This can come in later but the hash must match.To persistent storage string.toString()
Methods inherited from class net.i2p.data.SimpleDataStructure
fromBase64, fromByteArray, getData, read, readBytes, setData, toBase64, toByteArray, writeBytes
-
Field Details
-
LENGTH
public static final int LENGTH- See Also:
-
-
Constructor Details
-
NodeInfo
With a fake NID used for pings -
NodeInfo
Use this if we have the full destination- Throws:
IllegalArgumentException
-
NodeInfo
No Destination yet available- Throws:
IllegalArgumentException
-
NodeInfo
public NodeInfo(byte[] compactInfo, int offset) No Destination yet available- Parameters:
compactInfo
- 20 byte node ID, 32 byte destHash, 2 byte portoffset
- starting at this offset in compactInfo- Throws:
IllegalArgumentException
ArrayIndexOutOfBoundsException
-
NodeInfo
Create from persistent storage string. Format: NID:Hash:Destination:port First 3 in base 64; Destination may be empty string
-
-
Method Details
-
generateNID
Generate a secure NID that matches the Hash and port. Rules: First 4 bytes must match Hash. Next 2 bytes must match Hash ^ port. Remaining bytes may be random.- Throws:
IllegalArgumentException
-
length
public int length()Description copied from class:SimpleDataStructure
The legal length of the byte array in this data structure- Specified by:
length
in classSimpleDataStructure
-
getNID
-
getDestination
- Returns:
- may be null if we don't have it
-
getHash
-
calculateHash
Description copied from interface:DataStructure
Calculate the SHA256 value of this object (useful for a few scenarios)- Specified by:
calculateHash
in interfaceDataStructure
- Overrides:
calculateHash
in classSimpleDataStructure
- Returns:
- the SHA256 hash of the byte array, or null if the data is null
-
setDestination
This can come in later but the hash must match.- Throws:
IllegalArgumentException
- if hash of dest doesn't match previous hash
-
getPort
public int getPort() -
lastSeen
public long lastSeen() -
hashCode
public int hashCode()Description copied from class:SimpleDataStructure
We assume the data has enough randomness in it, so use the first 4 bytes for speed. If this is not the case, override in the extending class.- Overrides:
hashCode
in classSimpleDataStructure
-
equals
Description copied from class:SimpleDataStructure
Warning - this returns true for two different classes with the same size and same data, e.g. SessionKey and SessionTag, but you wouldn't put them in the same Set, would you?- Overrides:
equals
in classSimpleDataStructure
-
toString
- Overrides:
toString
in classSimpleDataStructure
-
toPersistentString
To persistent storage string. Format: NID:Hash:Destination:port First 3 in base 64; Destination may be empty string
-