pub struct PeerReputationManager { /* private fields */ }Expand description
Manages long-term reputation scores for a set of remote peers.
Scores are keyed by an opaque peer-ID string and are automatically
created at the neutral value of 0.5 on the first event.
Implementations§
Source§impl PeerReputationManager
impl PeerReputationManager
Sourcepub fn new(config: PrReputationConfig) -> Self
pub fn new(config: PrReputationConfig) -> Self
Creates a new manager with the supplied configuration.
Sourcepub fn record_event(&mut self, peer_id: &str, event: PrReputationEvent)
pub fn record_event(&mut self, peer_id: &str, event: PrReputationEvent)
Records a behavioural event for peer_id.
If the peer is not yet tracked it is inserted with the neutral score of
0.5 before the event is applied. The resulting score is always clamped
to [0.0, 1.0].
Sourcepub fn decay_all(&mut self)
pub fn decay_all(&mut self)
Nudges every tracked peer’s score one step toward 0.5 by decay_rate.
Sourcepub fn score(&self, peer_id: &str) -> Option<&PrReputationScore>
pub fn score(&self, peer_id: &str) -> Option<&PrReputationScore>
Returns the current score for peer_id, or None if unknown.
Sourcepub fn trusted_peers(&self) -> Vec<&str>
pub fn trusted_peers(&self) -> Vec<&str>
Returns the IDs of all trusted peers, sorted by score descending.
Sourcepub fn banned_peers(&self) -> Vec<&str>
pub fn banned_peers(&self) -> Vec<&str>
Returns the IDs of all banned peers (order is unspecified).
Sourcepub fn remove_peer(&mut self, peer_id: &str) -> bool
pub fn remove_peer(&mut self, peer_id: &str) -> bool
Removes a peer from the tracker.
Returns true if the peer was present, false otherwise.
Sourcepub fn stats(&self) -> PrReputationStats
pub fn stats(&self) -> PrReputationStats
Computes aggregate statistics over all currently tracked peers.
Auto Trait Implementations§
impl Freeze for PeerReputationManager
impl RefUnwindSafe for PeerReputationManager
impl Send for PeerReputationManager
impl Sync for PeerReputationManager
impl Unpin for PeerReputationManager
impl UnsafeUnpin for PeerReputationManager
impl UnwindSafe for PeerReputationManager
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