[−][src]Struct libp2p_kad::kbucket::KBucketsTable
A KBucketsTable
represents a Kademlia routing table.
Implementations
impl<TKey, TVal> KBucketsTable<TKey, TVal> where
TKey: Clone + AsRef<KeyBytes>,
TVal: Clone,
[src]
TKey: Clone + AsRef<KeyBytes>,
TVal: Clone,
pub fn new(local_key: TKey, pending_timeout: Duration) -> Self
[src]
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.
pub fn local_key(&self) -> &TKey
[src]
Returns the local key.
pub fn entry<'a>(&'a mut self, key: &'a TKey) -> Entry<'a, TKey, TVal>
[src]
Returns an Entry
for the given key, representing the state of the entry
in the routing table.
pub fn iter<'a>(
&'a mut self
) -> impl Iterator<Item = KBucketRef<'a, TKey, TVal>> + 'a
[src]
&'a mut self
) -> impl Iterator<Item = KBucketRef<'a, TKey, TVal>> + 'a
Returns an iterator over all buckets.
The buckets are ordered by proximity to the local_key
, i.e. the first
bucket is the closest bucket (containing at most one key).
pub fn bucket<K>(&mut self, key: &K) -> Option<KBucketRef<'_, TKey, TVal>> where
K: AsRef<KeyBytes>,
[src]
K: AsRef<KeyBytes>,
Returns the bucket for the distance to the given key.
Returns None
if the given key refers to the local key.
pub fn take_applied_pending(&mut self) -> Option<AppliedPending<TKey, TVal>>
[src]
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.
pub fn closest_keys<'a, T>(
&'a mut self,
target: &'a T
) -> impl Iterator<Item = TKey> + 'a where
T: Clone + AsRef<KeyBytes>,
[src]
&'a mut self,
target: &'a T
) -> impl Iterator<Item = TKey> + 'a where
T: Clone + AsRef<KeyBytes>,
Returns an iterator over the keys closest to target
, ordered by
increasing distance.
pub fn closest<'a, T>(
&'a mut self,
target: &'a T
) -> impl Iterator<Item = EntryView<TKey, TVal>> + 'a where
T: Clone + AsRef<KeyBytes>,
TVal: Clone,
[src]
&'a mut self,
target: &'a T
) -> impl Iterator<Item = EntryView<TKey, TVal>> + 'a where
T: Clone + AsRef<KeyBytes>,
TVal: Clone,
Returns an iterator over the nodes closest to the target
key, ordered by
increasing distance.
pub fn count_nodes_between<T>(&mut self, target: &T) -> usize where
T: AsRef<KeyBytes>,
[src]
T: AsRef<KeyBytes>,
Counts the number of nodes between the local node and the node
closest to target
.
The number of nodes between the local node and the target are calculated by backtracking from the target towards the local key.
Trait Implementations
impl<TKey: Clone, TVal: Clone> Clone for KBucketsTable<TKey, TVal>
[src]
fn clone(&self) -> KBucketsTable<TKey, TVal>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<TKey: Debug, TVal: Debug> Debug for KBucketsTable<TKey, TVal>
[src]
Auto Trait Implementations
impl<TKey, TVal> RefUnwindSafe for KBucketsTable<TKey, TVal> where
TKey: RefUnwindSafe,
TVal: RefUnwindSafe,
TKey: RefUnwindSafe,
TVal: RefUnwindSafe,
impl<TKey, TVal> Send for KBucketsTable<TKey, TVal> where
TKey: Send,
TVal: Send,
TKey: Send,
TVal: Send,
impl<TKey, TVal> Sync for KBucketsTable<TKey, TVal> where
TKey: Sync,
TVal: Sync,
TKey: Sync,
TVal: Sync,
impl<TKey, TVal> Unpin for KBucketsTable<TKey, TVal> where
TKey: Unpin,
TVal: Unpin,
TKey: Unpin,
TVal: Unpin,
impl<TKey, TVal> UnwindSafe for KBucketsTable<TKey, TVal> where
TKey: UnwindSafe,
TVal: UnwindSafe,
TKey: UnwindSafe,
TVal: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,