pub struct RoutingTable { /* private fields */ }Expand description
Kademlia routing table.
Implementations§
Source§impl RoutingTable
impl RoutingTable
Sourcepub fn new_with_config(own_id: Id20, restrict_ips: bool) -> Self
pub fn new_with_config(own_id: Id20, restrict_ips: bool) -> Self
Create a new routing table with IP restriction setting.
Sourcepub fn with_config(own_id: Id20, restrict_ips: bool, max_nodes: usize) -> Self
pub fn with_config(own_id: Id20, restrict_ips: bool, max_nodes: usize) -> Self
Create a new routing table with full configuration.
Sourcepub fn bucket_count(&self) -> usize
pub fn bucket_count(&self) -> usize
Number of buckets.
Sourcepub fn insert(&mut self, id: Id20, addr: SocketAddr) -> bool
pub fn insert(&mut self, id: Id20, addr: SocketAddr) -> bool
Insert or update a node. Returns true if the node was added/updated.
Sourcepub fn remove(&mut self, id: &Id20) -> bool
pub fn remove(&mut self, id: &Id20) -> bool
Remove a node by ID. Returns true if it was present.
Sourcepub fn mark_failed(&mut self, id: &Id20)
pub fn mark_failed(&mut self, id: &Id20)
Increment a node’s fail count.
Sourcepub fn closest(&self, target: &Id20, count: usize) -> Vec<RoutingNode>
pub fn closest(&self, target: &Id20, count: usize) -> Vec<RoutingNode>
Return the count closest nodes to target, sorted by XOR distance.
Sourcepub fn stale_buckets(&self, max_age: Duration) -> Vec<usize>
pub fn stale_buckets(&self, max_age: Duration) -> Vec<usize>
Return bucket indices that haven’t been refreshed recently.
M175 BUG FIX: same shape as RoutingNode::status — Instant::now() - max_age
panics if max_age exceeds process uptime. Compares elapsed time forward
instead.
Sourcepub fn random_id_in_bucket(&self, bucket_idx: usize) -> Id20
pub fn random_id_in_bucket(&self, bucket_idx: usize) -> Id20
Generate a random ID that falls within the given bucket index. Useful for refreshing stale buckets.
Sourcepub fn all_nodes(&self) -> Vec<(Id20, SocketAddr)>
pub fn all_nodes(&self) -> Vec<(Id20, SocketAddr)>
Return all nodes in the routing table as (id, addr) pairs.
Sourcepub fn get(&self, id: &Id20) -> Option<&RoutingNode>
pub fn get(&self, id: &Id20) -> Option<&RoutingNode>
Get a reference to a node by ID.
Sourcepub fn get_mut(&mut self, id: &Id20) -> Option<&mut RoutingNode>
pub fn get_mut(&mut self, id: &Id20) -> Option<&mut RoutingNode>
Get a mutable reference to a node by ID.
Sourcepub fn mark_response(&mut self, id: &Id20)
pub fn mark_response(&mut self, id: &Id20)
Record a successful response from a node, resetting its fail count.
Sourcepub fn mark_query(&mut self, id: &Id20)
pub fn mark_query(&mut self, id: &Id20)
Record an incoming query from a node.
Sourcepub fn mark_all_questionable(&mut self)
pub fn mark_all_questionable(&mut self)
Mark all nodes in the routing table as Questionable (M97).
Called when saved-state verification fails — loaded nodes may be stale.
Setting last_response = None and last_query = None makes nodes
Questionable (never responded, never queried). fail_count = 0 ensures
they are Questionable rather than Bad.
Sourcepub fn questionable_nodes(&self) -> Vec<(Id20, SocketAddr)>
pub fn questionable_nodes(&self) -> Vec<(Id20, SocketAddr)>
Return all nodes whose status is Questionable.
Trait Implementations§
Source§impl Clone for RoutingTable
impl Clone for RoutingTable
Source§fn clone(&self) -> RoutingTable
fn clone(&self) -> RoutingTable
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more