pub struct NeighborMap { /* private fields */ }Expand description
Thread-safe map of discovered gossip peers with automatic staleness expiry.
Tracks which peers are actively participating in a gossip topic. A background
cleanup task removes peers whose last_seen exceeds the expiration timeout.
This handles the case where a peer crashes silently without sending
NeighborDown.
Implementations§
Source§impl NeighborMap
impl NeighborMap
Sourcepub fn new(expiration_timeout: Duration) -> Self
pub fn new(expiration_timeout: Duration) -> Self
Create a new neighbor map and spawn a background cleanup task.
The cleanup task runs every expiration_timeout / 3 and removes
peers not seen within the timeout.
Sourcepub fn new_without_cleanup(expiration_timeout: Duration) -> Self
pub fn new_without_cleanup(expiration_timeout: Duration) -> Self
Create a neighbor map without automatic cleanup (for testing).
Sourcepub fn touch(&self, node_id: PublicKey, name: Option<&str>)
pub fn touch(&self, node_id: PublicKey, name: Option<&str>)
Record a peer as seen, resetting its staleness timer.
Sourcepub fn mark_disconnected(&self, node_id: &PublicKey)
pub fn mark_disconnected(&self, node_id: &PublicKey)
Mark a peer as disconnected (without removing it).
Sourcepub fn remove(&self, node_id: &PublicKey) -> Option<PeerInfo>
pub fn remove(&self, node_id: &PublicKey) -> Option<PeerInfo>
Remove a peer (e.g. on explicit NeighborDown).
Sourcepub fn list_connected(&self) -> Vec<PeerInfo>
pub fn list_connected(&self) -> Vec<PeerInfo>
List all non-expired, currently connected peers.
Sourcepub const fn inner(&self) -> &Arc<DashMap<PublicKey, PeerInfo>> ⓘ
pub const fn inner(&self) -> &Arc<DashMap<PublicKey, PeerInfo>> ⓘ
Return a reference to the underlying peer map.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Trait Implementations§
Source§impl Clone for NeighborMap
impl Clone for NeighborMap
Source§fn clone(&self) -> NeighborMap
fn clone(&self) -> NeighborMap
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for NeighborMap
impl !UnwindSafe for NeighborMap
impl Freeze for NeighborMap
impl Send for NeighborMap
impl Sync for NeighborMap
impl Unpin for NeighborMap
impl UnsafeUnpin for NeighborMap
Blanket Implementations§
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