Skip to main content

RoutingTable

Struct RoutingTable 

Source
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

Source

pub fn new(key: [u8; 32]) -> Self

Creates a new RoutingTable

Source

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.

Source

pub fn contains_key(&self, key: &[u8; 32]) -> bool

Check if the table contains the given key.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn remove_entry(&self, key: &[u8; 32])

Removes an entry with the given key from the routing table, if it exists.

Source

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.

Source

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.

Source

pub fn random_entry(&self, entry_flag: u16) -> Option<Entry>

Returns a random entry from the routing table.

Source

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).

Source

fn bucket_index(&self, key: &[u8; 32]) -> Option<usize>

Trait Implementations§

Source§

impl Debug for RoutingTable

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more