pub struct PeerReputationTracker { /* private fields */ }Expand description
Thread-safe tracker that maintains per-peer reputation scores and exposes
aggregate statistics via AtomicU64 counters.
§Thread Safety
All mutating operations acquire the internal RwLock<HashMap> write lock,
while read-only queries acquire only the read lock. The aggregate stats are
updated via relaxed atomic stores so they never block readers.
Implementations§
Source§impl PeerReputationTracker
impl PeerReputationTracker
Sourcepub fn record_event(&self, peer_id: &str, event: PeerReputationEvent)
pub fn record_event(&self, peer_id: &str, event: PeerReputationEvent)
Records an event for the given peer.
If the peer is unknown a new record initialised to score 0 is created
automatically. The function also updates total_bans / total_unbans
counters when the event crosses the ban threshold.
Sourcepub fn get_score(&self, peer_id: &str) -> f64
pub fn get_score(&self, peer_id: &str) -> f64
Returns the current score for peer_id, or 0.0 if the peer is unknown.
Sourcepub fn get_tier(&self, peer_id: &str) -> PeerTier
pub fn get_tier(&self, peer_id: &str) -> PeerTier
Returns the PeerTier for peer_id.
Unknown peers are treated as having a score of 0 (PeerTier::Neutral).
Sourcepub fn is_banned(&self, peer_id: &str) -> bool
pub fn is_banned(&self, peer_id: &str) -> bool
Returns true when the peer is banned (score <= -50).
Sourcepub fn banned_peers(&self) -> Vec<String>
pub fn banned_peers(&self) -> Vec<String>
Returns the peer IDs of all currently-banned peers.
Sourcepub fn trusted_peers(&self) -> Vec<String>
pub fn trusted_peers(&self) -> Vec<String>
Returns the peer IDs of all currently-trusted peers (score >= 50).
Sourcepub fn top_peers(&self, n: usize) -> Vec<(String, f64)>
pub fn top_peers(&self, n: usize) -> Vec<(String, f64)>
Returns the top n peers by score (descending), as (peer_id, score) pairs.
Sourcepub fn apply_decay(&self, elapsed: Duration)
pub fn apply_decay(&self, elapsed: Duration)
Applies time-based score decay to every tracked peer.
Sourcepub fn remove_peer(&self, peer_id: &str)
pub fn remove_peer(&self, peer_id: &str)
Removes the reputation record for peer_id. Does nothing if the peer
is unknown.
Sourcepub fn peer_count(&self) -> usize
pub fn peer_count(&self) -> usize
Returns the total number of peers currently being tracked.
Sourcepub fn stats(&self) -> &PeerReputationStats
pub fn stats(&self) -> &PeerReputationStats
Returns a reference to the aggregate statistics.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for PeerReputationTracker
impl RefUnwindSafe for PeerReputationTracker
impl Send for PeerReputationTracker
impl Sync for PeerReputationTracker
impl Unpin for PeerReputationTracker
impl UnsafeUnpin for PeerReputationTracker
impl UnwindSafe for PeerReputationTracker
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