pub struct PeerDiscoveryManager {
pub config: DiscoveryConfig,
/* private fields */
}Expand description
Multi-strategy peer discovery manager.
Maintains a scored, deduplicated pool of PeerCandidates, drives the
connection lifecycle, and provides ranked candidate selection with
configurable backoff and stale eviction.
Fields§
§config: DiscoveryConfigConfiguration.
Implementations§
Source§impl PeerDiscoveryManager
impl PeerDiscoveryManager
Sourcepub fn new(config: DiscoveryConfig) -> Self
pub fn new(config: DiscoveryConfig) -> Self
Create a new manager with the given configuration.
Sourcepub fn add_candidate(&mut self, candidate: PeerCandidate) -> bool
pub fn add_candidate(&mut self, candidate: PeerCandidate) -> bool
Add or update a candidate.
- If the peer is already tracked, the new addresses are merged
(deduplicated) into the existing record and
trueis returned. - If the candidate pool is at
max_candidates, the lowest-scoring non-connected candidate is evicted first. If no eviction is possible (all slots are connected)falseis returned. - Otherwise the candidate is inserted and
trueis returned.
Sourcepub fn record_outcome(
&mut self,
peer_id: &str,
outcome: ConnectOutcome,
now: u64,
) -> bool
pub fn record_outcome( &mut self, peer_id: &str, outcome: ConnectOutcome, now: u64, ) -> bool
Record the outcome of a connection attempt.
Updates connect_score, attempted, connected, and counters.
Returns false when the peer is not found.
Sourcepub fn mark_disconnected(&mut self, peer_id: &str) -> bool
pub fn mark_disconnected(&mut self, peer_id: &str) -> bool
Mark a peer as disconnected.
The peer remains in the candidate pool with a slightly reduced score so
it can be re-tried later. Returns false when the peer is not found.
Sourcepub fn candidates_to_try(&self, n: usize, now: u64) -> Vec<&PeerCandidate>
pub fn candidates_to_try(&self, n: usize, now: u64) -> Vec<&PeerCandidate>
Return up to n candidates that should be tried next.
Eligible candidates are those that:
- Are not currently connected.
- Have
last_attempt == Noneorlast_attemptis at leastretry_backoff_msbeforenow.
Results are sorted by connect_score descending.
Sourcepub fn evict_stale(&mut self, now: u64) -> usize
pub fn evict_stale(&mut self, now: u64) -> usize
Evict non-connected candidates that are considered stale.
A candidate is stale when both:
discovered_at < now - stale_threshold_mslast_attempt < now - stale_threshold_msorlast_attempt == None
Returns the number of evicted candidates.
Sourcepub fn connected_peers(&self) -> Vec<&PeerCandidate>
pub fn connected_peers(&self) -> Vec<&PeerCandidate>
All currently connected peer candidates.
Sourcepub fn peer_count(&self) -> usize
pub fn peer_count(&self) -> usize
Total number of tracked candidates.
Sourcepub fn connected_count(&self) -> usize
pub fn connected_count(&self) -> usize
Number of currently connected peers.
Sourcepub fn best_candidate(&self) -> Option<&PeerCandidate>
pub fn best_candidate(&self) -> Option<&PeerCandidate>
The highest-scoring candidate that is not currently connected.
Sourcepub fn candidates_by_method(
&self,
method: &DiscoveryMethod,
) -> Vec<&PeerCandidate>
pub fn candidates_by_method( &self, method: &DiscoveryMethod, ) -> Vec<&PeerCandidate>
All candidates discovered via the given method.
Sourcepub fn stats(&self) -> DiscoveryStats
pub fn stats(&self) -> DiscoveryStats
A statistics snapshot covering the current pool state.
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