pub struct PeerDiscoveryManager {
pub peers: HashMap<String, DiscoveredPeer>,
pub max_dial_attempts: u32,
pub stats: DiscoveryStats,
}Expand description
Manages multiple peer discovery mechanisms and deduplicates discovered peers.
Fields§
§peers: HashMap<String, DiscoveredPeer>Map from peer_id to its discovery record.
max_dial_attempts: u32Maximum number of dial attempts before a peer is considered permanently unreachable.
stats: DiscoveryStatsRunning statistics.
Implementations§
Source§impl PeerDiscoveryManager
impl PeerDiscoveryManager
Sourcepub fn new(max_dial_attempts: u32) -> Self
pub fn new(max_dial_attempts: u32) -> Self
Create a new manager with the given dial-attempt limit.
Sourcepub fn add_peer(&mut self, peer: DiscoveredPeer) -> bool
pub fn add_peer(&mut self, peer: DiscoveredPeer) -> bool
Attempt to register a newly discovered peer.
Returns true when the peer was inserted (first time seen).
Returns false when the peer was already known; stats.duplicates_skipped is
incremented in that case.
Sourcepub fn record_dial_result(&mut self, peer_id: &str, success: bool)
pub fn record_dial_result(&mut self, peer_id: &str, success: bool)
Record the outcome of a dial attempt for the given peer.
Increments dial_attempts, updates last_dial_result, and bumps the
appropriate aggregate counter. If peer_id is unknown this is a no-op.
Sourcepub fn candidates_to_dial(&self) -> Vec<&DiscoveredPeer>
pub fn candidates_to_dial(&self) -> Vec<&DiscoveredPeer>
Return all peers that should still be dialed, sorted by ascending dial_attempts.
A peer is a candidate when should_retry(max_dial_attempts) is true.
Sourcepub fn connected_peers(&self) -> Vec<&DiscoveredPeer>
pub fn connected_peers(&self) -> Vec<&DiscoveredPeer>
Return all peers whose last dial was successful.
Sourcepub fn failed_peers(&self) -> Vec<&DiscoveredPeer>
pub fn failed_peers(&self) -> Vec<&DiscoveredPeer>
Return all peers that have exhausted their dial budget without success.
Sourcepub fn peers_by_source(&self, source: DiscoverySource) -> Vec<&DiscoveredPeer>
pub fn peers_by_source(&self, source: DiscoverySource) -> Vec<&DiscoveredPeer>
Return all peers discovered via a specific source.
Sourcepub fn remove_peer(&mut self, peer_id: &str) -> bool
pub fn remove_peer(&mut self, peer_id: &str) -> bool
Remove a peer from the manager.
Returns true if the peer was present and has been removed, false otherwise.
Sourcepub fn stats(&self) -> &DiscoveryStats
pub fn stats(&self) -> &DiscoveryStats
Borrow the current discovery statistics.
Sourcepub fn merge_addresses(&mut self, peer_id: &str, new_addrs: &[String])
pub fn merge_addresses(&mut self, peer_id: &str, new_addrs: &[String])
Merge additional addresses into a known peer’s address list.
Any address already recorded for that peer is silently skipped.
If peer_id is unknown this is a no-op.
Auto Trait Implementations§
impl Freeze for PeerDiscoveryManager
impl RefUnwindSafe for PeerDiscoveryManager
impl Send for PeerDiscoveryManager
impl Sync for PeerDiscoveryManager
impl Unpin for PeerDiscoveryManager
impl UnsafeUnpin for PeerDiscoveryManager
impl UnwindSafe for PeerDiscoveryManager
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> 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