Skip to main content

Module key

Module key 

Source
Expand description

The 256-bit Kademlia keyspace: Key, XOR Distance, and the maps from a PeerId and a ContentId into it.

Kademlia organizes both nodes and content in a single 256-bit metric space and measures closeness by the XOR of two keys interpreted as a big-endian integer (Maymounkov & Mazières, 2002). This module is the pure, network-free core of that metric:

  • A node’s key is its peer_id verbatim — peer_id = SHA-256(TLS SPKI DER) is already a uniform 256-bit value (Key::from_peer_id), so the DHT node id IS the peer id.
  • A content key is the SHA-256 of the content id’s canonical bytes (ContentId::to_key), which lands DIG content (store / capsule / root / resource) in the same 256-bit space so find_node(key) and find_providers(content_key) share one lookup.

Distance is XOR; the routing table’s bucket index for a key is 255 - leading_zeros of the distance from this node — the standard Kademlia longest-common-prefix bucketing.

Structs§

Distance
The XOR distance between two Keys — a point in the same 256-bit space, ordered as a big-endian unsigned integer (smaller = closer).
Key
A point in the 256-bit Kademlia keyspace — 32 big-endian bytes.