pub struct RoutingTableManager {
pub buckets: Vec<KBucket>,
pub local_id: NodeId,
pub k: usize,
pub alpha: usize,
}Expand description
Kademlia-style XOR-metric routing table manager.
Manages 256 k-buckets (one per bit of the 256-bit node-ID space). Bucket
i holds nodes whose XOR distance to the local node starts with exactly
i leading zero bits.
§Parameters
k— maximum number of active entries per bucket (default: 20).alpha— concurrency factor for parallel lookups (default: 3; stored but not used internally — callers read it when launching lookups).
Fields§
§buckets: Vec<KBucket>The 256 k-buckets.
local_id: NodeIdThis node’s own identifier.
k: usizeMaximum entries per bucket.
alpha: usizeLookup concurrency parameter.
Implementations§
Source§impl RoutingTableManager
impl RoutingTableManager
Sourcepub fn new(local_id: NodeId, k: usize, alpha: usize) -> Self
pub fn new(local_id: NodeId, k: usize, alpha: usize) -> Self
Create a new routing table manager.
§Arguments
local_id— this node’s 256-bit identifier.k— k-bucket size (useDEFAULT_Kfor the standard Kademlia value).alpha— concurrency factor (useDEFAULT_ALPHAfor the standard value).
Sourcepub fn with_defaults(local_id: NodeId) -> Self
pub fn with_defaults(local_id: NodeId) -> Self
Create a routing table manager with default parameters (k=20, alpha=3).
Sourcepub fn add_node(
&mut self,
node_id: NodeId,
address: String,
rtt_ms: u64,
now: u64,
)
pub fn add_node( &mut self, node_id: NodeId, address: String, rtt_ms: u64, now: u64, )
Insert or refresh a node in the routing table.
- If the node already appears in its bucket → LRU update (move to tail).
- If the bucket is not full → append.
- If the bucket is full → put into the replacement cache.
Silently ignores attempts to add the local node itself.
Sourcepub fn remove_node(&mut self, node_id: &NodeId) -> bool
pub fn remove_node(&mut self, node_id: &NodeId) -> bool
Remove a node from the routing table.
If the node was in a bucket’s active list a replacement from the cache is promoted automatically.
Returns true if the node was found in an active bucket.
Sourcepub fn mark_failed(&mut self, node_id: &NodeId, now: u64)
pub fn mark_failed(&mut self, node_id: &NodeId, now: u64)
Record a failed query for a node.
After MAX_FAILED_QUERIES (3) consecutive failures the node is evicted
and a replacement is promoted from the cache.
Sourcepub fn update_rtt(&mut self, node_id: &NodeId, rtt_ms: u64, now: u64)
pub fn update_rtt(&mut self, node_id: &NodeId, rtt_ms: u64, now: u64)
Update the RTT observation and last-seen timestamp for a node.
Sourcepub fn find_closest(&self, target: &NodeId, count: usize) -> Vec<BucketEntry>
pub fn find_closest(&self, target: &NodeId, count: usize) -> Vec<BucketEntry>
Return up to count entries closest to target measured by XOR distance.
The result is sorted ascending by XOR distance (closest first).
Sourcepub fn bucket_sizes(&self) -> Vec<usize>
pub fn bucket_sizes(&self) -> Vec<usize>
Return the number of active entries in each of the 256 buckets.
Sourcepub fn total_nodes(&self) -> usize
pub fn total_nodes(&self) -> usize
Return the total number of active entries across all buckets.
Sourcepub fn stats(&self) -> RoutingTableStats
pub fn stats(&self) -> RoutingTableStats
Compute aggregate statistics for the routing table.
Sourcepub fn bucket_index_for(&self, target: &NodeId) -> usize
pub fn bucket_index_for(&self, target: &NodeId) -> usize
Return the k-bucket index for a given target node ID.
Sourcepub fn iter_entries(&self) -> impl Iterator<Item = &BucketEntry>
pub fn iter_entries(&self) -> impl Iterator<Item = &BucketEntry>
Iterate over all active BucketEntry records.
Auto Trait Implementations§
impl Freeze for RoutingTableManager
impl RefUnwindSafe for RoutingTableManager
impl Send for RoutingTableManager
impl Sync for RoutingTableManager
impl Unpin for RoutingTableManager
impl UnsafeUnpin for RoutingTableManager
impl UnwindSafe for RoutingTableManager
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more