pub struct PeerChurnManager {
pub lifetimes: HashMap<String, PeerLifetime>,
pub events: Vec<ChurnEvent>,
pub config: ChurnManagerConfig,
}Expand description
Manages peer join/leave events, computes churn rate over sliding windows, and provides stability scores for DHT and routing decisions.
Fields§
§lifetimes: HashMap<String, PeerLifetime>Per-peer lifetime records, keyed by peer ID.
events: Vec<ChurnEvent>All events recorded in chronological order.
config: ChurnManagerConfigConfiguration governing window size and stability threshold.
Implementations§
Source§impl PeerChurnManager
impl PeerChurnManager
Sourcepub fn new(config: ChurnManagerConfig) -> Self
pub fn new(config: ChurnManagerConfig) -> Self
Creates a new PeerChurnManager with the given configuration.
Sourcepub fn record_event(&mut self, event: ChurnEvent)
pub fn record_event(&mut self, event: ChurnEvent)
Records a churn event and updates internal state accordingly.
Joined: Creates (or replaces, if the peer was previously offline) aPeerLifetimerecord.Left: If the peer is currently online, marks the peer as offline by settingleft_tick. If the peer is unknown or already offline, this is a no-op beyond storing the event.
Sourcepub fn current_window(&self, current_tick: u64) -> ChurnWindow
pub fn current_window(&self, current_tick: u64) -> ChurnWindow
Builds the current sliding window ending at current_tick.
The window spans [current_tick - window_size_ticks, current_tick]
(saturating at 0), and counts join and leave events within that range.
Sourcepub fn stability_score(&self, current_tick: u64) -> f64
pub fn stability_score(&self, current_tick: u64) -> f64
Computes a stability score in [0.0, 1.0].
1.0 means no churn; 0.0 means maximum churn (rate ≥ 1.0).
Sourcepub fn online_peers(&self) -> Vec<&str>
pub fn online_peers(&self) -> Vec<&str>
Returns the peer IDs of all currently online peers, sorted alphabetically.
Sourcepub fn peer_lifetime(&self, peer_id: &str) -> Option<&PeerLifetime>
pub fn peer_lifetime(&self, peer_id: &str) -> Option<&PeerLifetime>
Returns a reference to the PeerLifetime for a given peer ID, if any.
Sourcepub fn stats(&self, current_tick: u64) -> ChurnStats
pub fn stats(&self, current_tick: u64) -> ChurnStats
Computes aggregated ChurnStats at the given tick.
Auto Trait Implementations§
impl Freeze for PeerChurnManager
impl RefUnwindSafe for PeerChurnManager
impl Send for PeerChurnManager
impl Sync for PeerChurnManager
impl Unpin for PeerChurnManager
impl UnsafeUnpin for PeerChurnManager
impl UnwindSafe for PeerChurnManager
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