Struct KBucketsTable

Source
pub struct KBucketsTable<TNodeId, TVal: Eq> { /* private fields */ }
Expand description

A KBucketsTable represents a Kademlia routing table.

Implementations§

Source§

impl<TNodeId, TVal> KBucketsTable<TNodeId, TVal>
where TNodeId: Clone, TVal: Eq,

Source

pub fn new( local_key: Key<TNodeId>, pending_timeout: Duration, max_incoming_per_bucket: usize, table_filter: Option<Box<dyn Filter<TVal>>>, bucket_filter: Option<Box<dyn Filter<TVal>>>, ) -> Self

Creates a new, empty Kademlia routing table with entries partitioned into buckets as per the Kademlia protocol.

The given pending_timeout specifies the duration after creation of a PendingEntry after which it becomes eligible for insertion into a full bucket, replacing the least-recently (dis)connected node.

A filter can be applied that limits entries into a bucket based on the buckets contents. Entries that fail the filter, will not be inserted.

Source

pub fn update_node_status( &mut self, key: &Key<TNodeId>, state: ConnectionState, direction: Option<ConnectionDirection>, ) -> UpdateResult

Source

pub fn update_node( &mut self, key: &Key<TNodeId>, value: TVal, state: Option<ConnectionState>, ) -> UpdateResult

Updates a node’s value if it exists in the table.

Optionally the connection state can be modified.

Source

pub fn insert_or_update( &mut self, key: &Key<TNodeId>, value: TVal, status: NodeStatus, ) -> InsertResult<TNodeId>

Source

pub fn remove(&mut self, key: &Key<TNodeId>) -> bool

Removes a node from the routing table. Returns true of the node existed.

Source

pub fn entry<'a>( &'a mut self, key: &'a Key<TNodeId>, ) -> Entry<'a, TNodeId, TVal>

Returns an Entry for the given key, representing the state of the entry in the routing table. NOTE: This must be used with caution. Modifying values manually can bypass the internal table filters and ingoing/outgoing limits.

Source

pub fn iter(&mut self) -> impl Iterator<Item = EntryRefView<'_, TNodeId, TVal>>

Returns an iterator over all the entries in the routing table.

Source

pub fn buckets_iter(&self) -> impl Iterator<Item = &KBucket<TNodeId, TVal>>

Returns an iterator over all the buckets in the routing table

Source

pub fn iter_ref(&self) -> impl Iterator<Item = EntryRefView<'_, TNodeId, TVal>>

Returns an iterator over all the entries in the routing table. Does not add pending node to kbucket to get an iterator which takes a mutable reference instead of a reference.

Source

pub fn take_applied_pending(&mut self) -> Option<AppliedPending<TNodeId, TVal>>

Consumes the next applied pending entry, if any.

When an entry is attempted to be inserted and the respective bucket is full, it may be recorded as pending insertion after a timeout, see InsertResult::Pending.

If the oldest currently disconnected entry in the respective bucket does not change its status until the timeout of pending entry expires, it is evicted and the pending entry inserted instead. These insertions of pending entries happens lazily, whenever the KBucketsTable is accessed, and the corresponding buckets are updated accordingly. The fact that a pending entry was applied is recorded in the KBucketsTable in the form of AppliedPending results, which must be consumed by calling this function.

Source

pub fn nodes_by_distances( &mut self, log2_distances: &[u64], max_nodes: usize, ) -> Vec<EntryRefView<'_, TNodeId, TVal>>

Returns an iterator over the keys that are contained in a kbucket, specified by a log2 distance.

Source

pub fn closest_keys<'a, T>( &'a mut self, target: &'a Key<T>, ) -> impl Iterator<Item = Key<TNodeId>> + 'a
where T: Clone,

Returns an iterator over the keys closest to target, ordered by increasing distance.

Source

pub fn closest_values<'a, T>( &'a mut self, target: &'a Key<T>, ) -> impl Iterator<Item = ClosestValue<TNodeId, TVal>> + 'a
where T: Clone, TVal: Clone,

Returns an iterator over the keys closest to target, ordered by increasing distance.

Source

pub fn closest_values_predicate<'a, T, F>( &'a mut self, target: &'a Key<T>, predicate: F, ) -> impl Iterator<Item = PredicateValue<TNodeId, TVal>> + 'a
where T: Clone, F: Fn(&TVal) -> bool + 'a, TVal: Clone,

Returns an iterator over the keys closest to target, ordered by increasing distance specifying which keys agree with a value predicate.

Source

pub fn get_bucket(&self, key: &Key<TNodeId>) -> Option<&KBucket<TNodeId, TVal>>

Returns a reference to a bucket given the key. Returns None if bucket does not exist.

Source

pub fn get_index(&self, key: &Key<TNodeId>) -> Option<usize>

Returns a bucket index given the key. Returns None if bucket index does not exist.

Trait Implementations§

Source§

impl<TNodeId: Clone, TVal: Clone + Eq> Clone for KBucketsTable<TNodeId, TVal>

Source§

fn clone(&self) -> KBucketsTable<TNodeId, TVal>

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<TNodeId, TVal> Freeze for KBucketsTable<TNodeId, TVal>
where TNodeId: Freeze,

§

impl<TNodeId, TVal> !RefUnwindSafe for KBucketsTable<TNodeId, TVal>

§

impl<TNodeId, TVal> Send for KBucketsTable<TNodeId, TVal>
where TNodeId: Send, TVal: Send,

§

impl<TNodeId, TVal> Sync for KBucketsTable<TNodeId, TVal>
where TNodeId: Sync, TVal: Sync,

§

impl<TNodeId, TVal> Unpin for KBucketsTable<TNodeId, TVal>
where TNodeId: Unpin, TVal: Unpin,

§

impl<TNodeId, TVal> !UnwindSafe for KBucketsTable<TNodeId, TVal>

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
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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