Expand description
Kademlia-style XOR-metric routing table manager for P2P overlay networks.
Implements a full 256-bucket Kademlia routing table where each bucket stores
at most k entries (default 20) sorted by last-seen time. A replacement
cache holds candidates that were not admitted because the bucket was full.
§Design highlights
NodeId([u8; 32])— 256-bit node identifier (SHA-256 hash of public key).BucketEntry— information about a known remote node.KBucket— a single k-bucket with a replacement cache (VecDeque).RoutingTableManager— 256 k-buckets indexed by the leading-zero-bit count ofXOR(local_id, target_id).
§Thread safety
RoutingTableManager is not Sync by design; callers that need shared
access should wrap it in parking_lot::RwLock or tokio::sync::RwLock.
§Example
use ipfrs_network::routing_table_manager::{NodeId, RoutingTableManager};
let local = NodeId([0u8; 32]);
let mut rtm = RoutingTableManager::new(local, 20, 3);
let mut target_bytes = [0u8; 32];
target_bytes[0] = 0x80; // distance bucket 0
let target = NodeId(target_bytes);
rtm.add_node(target, "127.0.0.1:4001".to_string(), 5, 1000);
assert_eq!(rtm.total_nodes(), 1);Structs§
- Bucket
Entry - Metadata stored for every known remote node.
- KBucket
- A single Kademlia k-bucket.
- NodeId
- 256-bit node identifier, typically the SHA-256 hash of a public key.
- Routing
Table Manager - Kademlia-style XOR-metric routing table manager.
- Routing
Table Stats - Aggregate statistics for the routing table.
Constants§
- DEFAULT_
ALPHA - Default alpha concurrency parameter.
- DEFAULT_
K - Default k-bucket size (standard Kademlia value).
- DEFAULT_
REPLACEMENT_ CACHE_ SIZE - Maximum number of entries kept in a bucket’s replacement cache.
Functions§
- bucket_
index - Return the index of the k-bucket for
targetrelative tolocal. - xor_
distance - Compute the 256-bit XOR distance between two node IDs.