Expand description
DHT-aware content routing table with geographic/latency affinity scoring.
This module implements a ContentRoutingTable that maps CID strings to
ordered lists of provider RoutingEntry records. Entries are ranked by
an affinity score that combines observed latency, recent activity and
remaining TTL so that the best provider is always returned first.
§Design
- Lock granularity – a single
RwLock<HashMap<…>>wrapping all entries keeps the implementation simple while still allowing concurrent reads. Writes (add / remove / evict) are short-lived. - Capacity enforcement – when the per-CID provider list reaches
max_providers_per_cid, a new entry is rejected withRoutingError::CapacityExceeded. - Affinity scoring – see
RoutingEntry::affinity_scorefor the exact formula.
§Example
use ipfrs_network::routing_table::{ContentRoutingTable, RoutingEntry};
use std::time::{Duration, Instant};
let table = ContentRoutingTable::new("local-peer".to_string(), 20);
let entry = RoutingEntry::new("peer-1".to_string(), vec!["/ip4/1.2.3.4/tcp/4001".to_string()]);
table.add_provider("QmFoo", entry).unwrap();
assert_eq!(table.provider_count(), 1);Structs§
- Content
Routing Table - DHT-aware content routing table with per-CID provider lists and affinity scoring.
- Routing
Entry - A single provider record held inside the routing table.
- Routing
Table Stats - Summary statistics for a
ContentRoutingTable.
Enums§
- Routing
Error - Errors produced by
ContentRoutingTableoperations.
Constants§
- DEFAULT_
ENTRY_ TTL - Default TTL for a routing entry (24 hours).
- DEFAULT_
MAX_ PROVIDERS - Default maximum number of providers recorded per CID.