class TokenKey extends SHA1Hash
This class generates a unique key for indexing tokens by combining the requesting node's ID with the torrent's info hash. The XOR operation creates a deterministic key that can be reproduced when the same node and torrent combination is used, enabling efficient token lookup and validation.
Token indexing is crucial for DHT security as it ensures that tokens are bound to both the requesting node and the specific torrent. This prevents token replay attacks where a malicious peer might try to use a token intended for one torrent on another, or use another node's token.
The resulting SHA1 hash provides a fixed-size key suitable for use in hash maps and other data structures for efficient token storage and retrieval.
HASH_LENGTH_data| Constructor and Description |
|---|
TokenKey(NID nID,
InfoHash ih)
Creates a new token key by combining a node ID with an info hash.
|
calculateHash, equals, fromBase64, fromByteArray, getData, read, toBase64, toByteArray, toString, writeBytespublic TokenKey(NID nID, InfoHash ih)
The key is generated by XOR-ing the raw bytes of the node ID and info hash, then computing the SHA1 hash of the result. This creates a unique, deterministic identifier for the (node, torrent) pair.
This method ensures that tokens are properly scoped to both the requesting node and the specific torrent, preventing cross-use of tokens and enhancing DHT security.
nID - the node ID of the requesting peerih - the info hash of the torrent