pub struct KBucket {
pub entries: Vec<BucketEntry>,
pub replacement_cache: VecDeque<BucketEntry>,
pub max_size: usize,
}Expand description
A single Kademlia k-bucket.
Entries are stored in LRU order: index 0 is the least-recently-seen node,
index len-1 is the most-recently-seen node. When the bucket is full a
newly observed node goes into replacement_cache rather than the bucket.
Fields§
§entries: Vec<BucketEntry>Active entries, ordered from least-recently-seen (front) to most-recently-seen (back).
replacement_cache: VecDeque<BucketEntry>Candidates waiting to replace evicted entries (FIFO).
max_size: usizeMaximum number of active entries.
Implementations§
Source§impl KBucket
impl KBucket
Sourcepub fn add(&mut self, entry: BucketEntry)
pub fn add(&mut self, entry: BucketEntry)
Insert or refresh a node in the bucket.
- If the node already exists in active entries → move to tail (LRU update).
- Else if the bucket is not full → append to tail.
- Else if the node is in the replacement cache → update it there.
- Else → push to the back of the replacement cache (bounded by
DEFAULT_REPLACEMENT_CACHE_SIZE).
Sourcepub fn remove(&mut self, node_id: &NodeId) -> bool
pub fn remove(&mut self, node_id: &NodeId) -> bool
Remove the node with the given ID from active entries.
If a replacement candidate exists in the cache it is promoted.
Returns true if the node was found and removed.
Sourcepub fn mark_failed(&mut self, node_id: &NodeId, now: u64) -> bool
pub fn mark_failed(&mut self, node_id: &NodeId, now: u64) -> bool
Increment the failure counter for a node.
Returns true if the node was evicted due to too many failures.
Sourcepub fn update_rtt(&mut self, node_id: &NodeId, rtt_ms: u64, now: u64)
pub fn update_rtt(&mut self, node_id: &NodeId, rtt_ms: u64, now: u64)
Update the RTT and last-seen timestamp for a node.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for KBucket
impl RefUnwindSafe for KBucket
impl Send for KBucket
impl Sync for KBucket
impl Unpin for KBucket
impl UnsafeUnpin for KBucket
impl UnwindSafe for KBucket
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more