pub struct PeerConnectionTracker {
pub peers: HashMap<String, PeerConnectionInfo>,
pub event_log: VecDeque<ConnectionEvent>,
pub stats: TrackerStats,
}Expand description
Tracks the lifecycle of all peer connections with per-peer statistics.
Fields§
§peers: HashMap<String, PeerConnectionInfo>Per-peer connection info, keyed by peer ID.
event_log: VecDeque<ConnectionEvent>Bounded ring-buffer of recent events (last MAX_EVENT_LOG).
stats: TrackerStatsAggregated statistics across all events.
Implementations§
Source§impl PeerConnectionTracker
impl PeerConnectionTracker
Sourcepub fn record_event(&mut self, event: ConnectionEvent)
pub fn record_event(&mut self, event: ConnectionEvent)
Record a ConnectionEvent, updating per-peer state and the event log.
Sourcepub fn connected_peers(&self) -> Vec<&PeerConnectionInfo>
pub fn connected_peers(&self) -> Vec<&PeerConnectionInfo>
Return references to all peers currently in the Connected state.
Sourcepub fn peer_info(&self, peer_id: &str) -> Option<&PeerConnectionInfo>
pub fn peer_info(&self, peer_id: &str) -> Option<&PeerConnectionInfo>
Look up a single peer by ID.
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 registry entirely.
Returns true if the peer was present, false otherwise.
Sourcepub fn unreliable_peers(&self, threshold: f64) -> Vec<&PeerConnectionInfo>
pub fn unreliable_peers(&self, threshold: f64) -> Vec<&PeerConnectionInfo>
Return peers whose reliability() is strictly below threshold.
Sourcepub fn top_peers_by_uptime(
&self,
n: usize,
now_secs: u64,
) -> Vec<&PeerConnectionInfo>
pub fn top_peers_by_uptime( &self, n: usize, now_secs: u64, ) -> Vec<&PeerConnectionInfo>
Return the top-n peers sorted by uptime_secs(now_secs) in descending order.
Sourcepub fn stats(&self) -> &TrackerStats
pub fn stats(&self) -> &TrackerStats
Return a reference to the current aggregated statistics.
Sourcepub fn recent_events(&self, count: usize) -> Vec<&ConnectionEvent>
pub fn recent_events(&self, count: usize) -> Vec<&ConnectionEvent>
Return the last count events from the event log.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PeerConnectionTracker
impl RefUnwindSafe for PeerConnectionTracker
impl Send for PeerConnectionTracker
impl Sync for PeerConnectionTracker
impl Unpin for PeerConnectionTracker
impl UnsafeUnpin for PeerConnectionTracker
impl UnwindSafe for PeerConnectionTracker
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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