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_idverbatim —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 sofind_node(key)andfind_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.