pub struct PeerBehaviorClassifier {
pub profiles: HashMap<String, BehaviorProfile>,
}Expand description
Classifies peers into behavioral categories based on recorded signals.
§Example
use ipfrs_network::behavior_classifier::{PeerBehaviorClassifier, BehaviorSignal};
let mut classifier = PeerBehaviorClassifier::new();
classifier.record_signal("peer-1", BehaviorSignal::FastResponder);
classifier.record_signal("peer-1", BehaviorSignal::FastResponder);
let classified = classifier.classify("peer-1");
assert!(classified.contains(&BehaviorSignal::FastResponder));Fields§
§profiles: HashMap<String, BehaviorProfile>Profiles keyed by peer_id.
Implementations§
Source§impl PeerBehaviorClassifier
impl PeerBehaviorClassifier
Sourcepub fn record_signal(&mut self, peer_id: &str, signal: BehaviorSignal)
pub fn record_signal(&mut self, peer_id: &str, signal: BehaviorSignal)
Records a behavioral signal for a peer.
If no profile exists for peer_id, one is created automatically.
Duplicates are allowed — signal frequency is meaningful.
Sourcepub fn classify(&self, peer_id: &str) -> Vec<BehaviorSignal>
pub fn classify(&self, peer_id: &str) -> Vec<BehaviorSignal>
Returns the “consistent” signals for a peer — those appearing more than once in the recorded history.
The returned Vec contains each qualifying signal exactly once, sorted
by declaration order (discriminant index).
Returns an empty Vec for unknown peers.
Sourcepub fn peers_with_signal(&self, signal: &BehaviorSignal) -> Vec<&str>
pub fn peers_with_signal(&self, signal: &BehaviorSignal) -> Vec<&str>
Returns peer IDs where classify() includes the given signal, sorted
alphabetically.
Sourcepub fn remove_peer(&mut self, peer_id: &str) -> bool
pub fn remove_peer(&mut self, peer_id: &str) -> bool
Removes a peer profile. Returns true if the peer existed.
Sourcepub fn stats(&self) -> ClassifierStats
pub fn stats(&self) -> ClassifierStats
Returns aggregate statistics across all tracked peers.
Sourcepub fn profile(&self, peer_id: &str) -> Option<&BehaviorProfile>
pub fn profile(&self, peer_id: &str) -> Option<&BehaviorProfile>
Returns an immutable reference to a peer’s profile, or None if
unknown.
Trait Implementations§
Source§impl Debug for PeerBehaviorClassifier
impl Debug for PeerBehaviorClassifier
Source§impl Default for PeerBehaviorClassifier
impl Default for PeerBehaviorClassifier
Source§fn default() -> PeerBehaviorClassifier
fn default() -> PeerBehaviorClassifier
Auto Trait Implementations§
impl Freeze for PeerBehaviorClassifier
impl RefUnwindSafe for PeerBehaviorClassifier
impl Send for PeerBehaviorClassifier
impl Sync for PeerBehaviorClassifier
impl Unpin for PeerBehaviorClassifier
impl UnsafeUnpin for PeerBehaviorClassifier
impl UnwindSafe for PeerBehaviorClassifier
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