Expand description
Sharded DHT routing table that distributes peers across multiple shards based on XOR-distance partitioning, enabling parallel lookups and reduced contention under high peer churn.
§Design overview
NodeId([u8; 32])— 256-bit node identifier. Shard assignment usesnode_id.0[0] % num_shardsso that the bit-prefix distribution matches the Kademlia bucket model while keeping O(1) assignment.RoutingTableShardingstores oneHashMap<NodeId, RoutingEntry>per shard and never needs a global lock for single-shard operations.- Eviction is pluggable via
EvictionPolicy— choose the least-recently- seen node, the highest-RTT node, or a deterministic pseudo-random node (xorshift64 seeded at construction time).
§Example
use ipfrs_network::routing_table_sharding::{
EvictionPolicy, NodeId as RtsNodeId, RoutingEntry as RtsRoutingEntry,
RoutingTableSharding, ShardConfig,
};
let cfg = ShardConfig::default();
let mut table = RoutingTableSharding::new(cfg);
let id = RtsNodeId([1u8; 32]);
let entry = RtsRoutingEntry {
node_id: id.clone(),
addr: "127.0.0.1:4001".to_string(),
last_seen: 1_000,
rtt_ms: 10,
shard: table.shard_for(&id),
};
let evicted = table.insert(entry, 1_000);
assert!(!evicted);
assert_eq!(table.total_entries(), 1);Structs§
- NodeId
- 256-bit node identifier used for XOR-distance routing.
- Routing
Entry - A single peer record stored inside a shard.
- Routing
Table Sharding - Sharded DHT routing table.
- Shard
Config - Configuration for
RoutingTableSharding. - ShardId
- Index of a shard in
[0, num_shards). - Shard
Stats - Per-shard statistics snapshot.
Enums§
- Eviction
Policy - Strategy used to select the victim when a shard is full.