pub struct MeshHealthMonitor { /* private fields */ }Expand description
Monitors GossipSub mesh health and manages graft/prune decisions.
The monitor tracks a per-topic peer count relative to the D_low / D_high thresholds defined in the GossipSub specification and implements a backoff-aware heal scheduler so that repeated failed graft attempts do not flood the network.
Implementations§
Source§impl MeshHealthMonitor
impl MeshHealthMonitor
Sourcepub fn new(d_low: usize, d_high: usize) -> Self
pub fn new(d_low: usize, d_high: usize) -> Self
Create a new monitor with the given D_low and D_high thresholds.
The heal interval defaults to 30 seconds.
Sourcepub fn with_heal_interval(self, secs: u64) -> Self
pub fn with_heal_interval(self, secs: u64) -> Self
Create a monitor with an explicit heal interval.
Sourcepub fn heal_interval_secs(&self) -> u64
pub fn heal_interval_secs(&self) -> u64
Return the heal interval in seconds.
Sourcepub fn heal_attempts(&self) -> u64
pub fn heal_attempts(&self) -> u64
Return the number of heal attempts recorded so far.
Sourcepub fn is_mesh_underpeered(&self, topic_peer_count: usize) -> bool
pub fn is_mesh_underpeered(&self, topic_peer_count: usize) -> bool
Return true when the given peer count is below D_low.
Sourcepub fn is_mesh_overloaded(&self, topic_peer_count: usize) -> bool
pub fn is_mesh_overloaded(&self, topic_peer_count: usize) -> bool
Return true when the given peer count exceeds D_high.
Sourcepub fn health_status(&self, mesh_size: usize) -> MeshHealthStatus
pub fn health_status(&self, mesh_size: usize) -> MeshHealthStatus
Summarise mesh health given the current peer count.
Sourcepub fn suggest_grafts(
&self,
gossip_peers: &[String],
mesh_peers: &[String],
) -> Vec<String>
pub fn suggest_grafts( &self, gossip_peers: &[String], mesh_peers: &[String], ) -> Vec<String>
Suggest peers to graft from the gossip peer cache when the mesh is sparse.
Returns peer IDs that are in gossip_peers but not in
mesh_peers. The result is bounded to at most D_high - mesh_size
candidates so callers never receive more grafts than needed.
Sourcepub fn record_heal_attempt(&mut self)
pub fn record_heal_attempt(&mut self)
Record that a heal attempt was made right now.
After calling this should_attempt_heal will return false until
the configured heal interval has elapsed.
Sourcepub fn should_attempt_heal(&self) -> bool
pub fn should_attempt_heal(&self) -> bool
Return true when sufficient time has passed since the last heal
attempt (or no attempt has ever been made) so that a new heal should
be tried.
Auto Trait Implementations§
impl Freeze for MeshHealthMonitor
impl RefUnwindSafe for MeshHealthMonitor
impl Send for MeshHealthMonitor
impl Sync for MeshHealthMonitor
impl Unpin for MeshHealthMonitor
impl UnsafeUnpin for MeshHealthMonitor
impl UnwindSafe for MeshHealthMonitor
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