pub struct RoutingTable {
key: [u8; 32],
buckets: RwLock<Vec<Bucket>>,
}Expand description
This is a modified version of the Kademlia Distributed Hash Table (DHT). https://en.wikipedia.org/wiki/Kademlia
Fields§
§key: [u8; 32]§buckets: RwLock<Vec<Bucket>>Implementations§
Source§impl RoutingTable
impl RoutingTable
Sourcepub fn add_entry(&self, entry: Entry) -> AddEntryResult
pub fn add_entry(&self, entry: Entry) -> AddEntryResult
Adds a new entry to the table and returns a result indicating success, failure, or restrictions.
Takes the write lock once and performs all checks inside it to avoid TOCTOU between contains_key / subnet_restricted / add.
Sourcepub fn contains_key(&self, key: &[u8; 32]) -> bool
pub fn contains_key(&self, key: &[u8; 32]) -> bool
Check if the table contains the given key.
Sourcepub fn update_entry(&self, key: &[u8; 32], entry_flag: u16)
pub fn update_entry(&self, key: &[u8; 32], entry_flag: u16)
Updates the status of an entry in the routing table identified by the given key.
If the key is not found, no action is taken.
Sourcepub fn bucket_indexes(&self, target_key: &[u8; 32]) -> Vec<usize>
pub fn bucket_indexes(&self, target_key: &[u8; 32]) -> Vec<usize>
Returns a list of bucket indexes that are closest to the given target key.
Sourcepub fn closest_entries(
&self,
target_key: &[u8; 32],
max_entries: usize,
) -> Vec<Entry>
pub fn closest_entries( &self, target_key: &[u8; 32], max_entries: usize, ) -> Vec<Entry>
Returns a list of the closest entries to the given target key, limited by max_entries.
Sourcepub fn closest_entries_filtered(
&self,
target_key: &[u8; 32],
max_entries: usize,
mine: &Bloom,
) -> Vec<Entry>
pub fn closest_entries_filtered( &self, target_key: &[u8; 32], max_entries: usize, mine: &Bloom, ) -> Vec<Entry>
Same as closest_entries, but skips entries whose bloom does
not satisfy mine. The peer’s bloom must cover mine.mandatory
and (when non-empty) intersect mine.optional.
Sourcepub fn entries_with_item(&self, item: &[u8]) -> Vec<Entry>
pub fn entries_with_item(&self, item: &[u8]) -> Vec<Entry>
Returns all entries whose advertised bloom may contain item.
Skips unreachable / unstable entries. False positives are
possible per bloom semantics.
Sourcepub fn remove_entry(&self, key: &[u8; 32])
pub fn remove_entry(&self, key: &[u8; 32])
Removes an entry with the given key from the routing table, if it exists.
Sourcepub fn has_discovery_ip(&self, ip: &IpAddr) -> bool
pub fn has_discovery_ip(&self, ip: &IpAddr) -> bool
Returns true if any entry has a discovery address with the given IP. Used by the refresh listen loop to drop pings from unknown sources.
Sourcepub fn refresh_candidates(&self, per_bucket: usize) -> Vec<BucketEntry>
pub fn refresh_candidates(&self, per_bucket: usize) -> Vec<BucketEntry>
Returns up to per_bucket entries from each bucket, skipping
connected and incompatible ones. Used by the refresh service.
Sourcepub fn random_entry(&self, entry_flag: u16) -> Option<Entry>
pub fn random_entry(&self, entry_flag: u16) -> Option<Entry>
Returns a random entry from the routing table.
Sourcepub fn random_entry_filtered(
&self,
entry_flag: u16,
mine: &Bloom,
) -> Option<Entry>
pub fn random_entry_filtered( &self, entry_flag: u16, mine: &Bloom, ) -> Option<Entry>
Same as random_entry, but only returns entries whose bloom
satisfies mine (covers mandatory, intersects optional when set).