pub struct PeerScoreTracker {
pub scores: HashMap<String, PeerScore>,
pub params: ScoreParameter,
}Expand description
Central tracker that maintains PeerScore entries for every known peer
and exposes mesh-management queries.
Fields§
§scores: HashMap<String, PeerScore>Map from peer ID string to per-peer score state.
params: ScoreParameterGlobal scoring parameters.
Implementations§
Source§impl PeerScoreTracker
impl PeerScoreTracker
Sourcepub fn new(params: ScoreParameter) -> Self
pub fn new(params: ScoreParameter) -> Self
Create a new tracker with the given scoring parameters.
Sourcepub fn get_or_create(&mut self, peer_id: &str) -> &mut PeerScore
pub fn get_or_create(&mut self, peer_id: &str) -> &mut PeerScore
Return a mutable reference to the PeerScore for peer_id,
inserting a default entry if it does not yet exist.
Sourcepub fn composite_score(&self, peer_id: &str) -> f64
pub fn composite_score(&self, peer_id: &str) -> f64
Return the composite score for peer_id, or 0.0 if unknown.
Sourcepub fn banned_peers(&self) -> Vec<String>
pub fn banned_peers(&self) -> Vec<String>
Return all peer IDs whose composite score is below the ban threshold.
Sourcepub fn greylisted_peers(&self) -> Vec<String>
pub fn greylisted_peers(&self) -> Vec<String>
Return all peer IDs whose composite score is below the graylist threshold but at or above the ban threshold.
Sourcepub fn best_peers(&self, n: usize) -> Vec<String>
pub fn best_peers(&self, n: usize) -> Vec<String>
Return the top-n peer IDs sorted by composite score (descending).
Sourcepub fn apply_decay_all(&mut self)
pub fn apply_decay_all(&mut self)
Trigger a decay pass on every tracked peer.
Sourcepub fn prune_peers(&mut self, ids: &[&str])
pub fn prune_peers(&mut self, ids: &[&str])
Remove the listed peer IDs from the tracker.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PeerScoreTracker
impl RefUnwindSafe for PeerScoreTracker
impl Send for PeerScoreTracker
impl Sync for PeerScoreTracker
impl Unpin for PeerScoreTracker
impl UnsafeUnpin for PeerScoreTracker
impl UnwindSafe for PeerScoreTracker
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