Skip to main content

Module routing_table_sharding

Module routing_table_sharding 

Source
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 uses node_id.0[0] % num_shards so that the bit-prefix distribution matches the Kademlia bucket model while keeping O(1) assignment.
  • RoutingTableSharding stores one HashMap<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.
RoutingEntry
A single peer record stored inside a shard.
RoutingTableSharding
Sharded DHT routing table.
ShardConfig
Configuration for RoutingTableSharding.
ShardId
Index of a shard in [0, num_shards).
ShardStats
Per-shard statistics snapshot.

Enums§

EvictionPolicy
Strategy used to select the victim when a shard is full.