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.
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 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 buckets(&self) -> Vec<Bucket>
pub fn buckets(&self) -> Vec<Bucket>
Returns an iterator of entries. FIXME: TODO: avoid cloning the data
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.
fn bucket_index(&self, key: &[u8; 32]) -> Option<usize>
Sourcefn subnet_restricted(&self, idx: usize, entry: &Entry) -> bool
fn subnet_restricted(&self, idx: usize, entry: &Entry) -> bool
This function iterate through the routing table and counts how many entries in the same subnet as the given Entry are already present.
If the number of matching entries in the same bucket exceeds a threshold (MAX_MATCHED_SUBNET_IN_BUCKET), or if the total count of matching entries in the entire table exceeds a threshold (MAX_MATCHED_SUBNET_IN_TABLE), the addition of the Entry is considered restricted and returns true.