Skip to main content

Module routing_table

Module routing_table 

Source
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 with RoutingError::CapacityExceeded.
  • Affinity scoring – see RoutingEntry::affinity_score for 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§

ContentRoutingTable
DHT-aware content routing table with per-CID provider lists and affinity scoring.
RoutingEntry
A single provider record held inside the routing table.
RoutingTableStats
Summary statistics for a ContentRoutingTable.

Enums§

RoutingError
Errors produced by ContentRoutingTable operations.

Constants§

DEFAULT_ENTRY_TTL
Default TTL for a routing entry (24 hours).
DEFAULT_MAX_PROVIDERS
Default maximum number of providers recorded per CID.