pub struct PeerScoringService<S: PeerScoreStorage> { /* private fields */ }Expand description
Per-conversation, per-member score tracker. Reference PeerScoringPlugin
implementation. One instance per conversation; threshold travels with
ScoringConfig. Storage is abstracted via PeerScoreStorage so
app-layer backends (in-memory, on-disk, …) plug in without touching
this protocol logic.
Implementations§
Source§impl<S: PeerScoreStorage> PeerScoringService<S>
impl<S: PeerScoreStorage> PeerScoringService<S>
pub fn new( storage: S, score_deltas: HashMap<ScoreEvent, i64>, config: ScoringConfig, ) -> Self
Trait Implementations§
Source§impl<S: PeerScoreStorage> PeerScoringPlugin for PeerScoringService<S>
impl<S: PeerScoreStorage> PeerScoringPlugin for PeerScoringService<S>
Source§fn add_member(&mut self, member_id: &[u8]) -> Vec<PeerScoringEvent>
fn add_member(&mut self, member_id: &[u8]) -> Vec<PeerScoringEvent>
Start tracking a member at the plug-in’s default score. Read more
Source§fn remove_member(&mut self, member_id: &[u8])
fn remove_member(&mut self, member_id: &[u8])
Stop tracking a member. Emits no events — removal is a membership
change, not a score event. Idempotent: a no-op on an untracked
member.
Source§fn apply_op(&mut self, op: &ScoreOp) -> Vec<PeerScoringEvent>
fn apply_op(&mut self, op: &ScoreOp) -> Vec<PeerScoringEvent>
Apply a single
ScoreOp. Untracked members are no-ops (no
event, no auto-tracking — coordinators must call Self::add_member
before applying ops). Returns events only when the op causes a
threshold cross; repeated ops on a member already at-or-below
threshold do not re-emit.Source§fn apply_snapshot(&mut self, snapshot: &ScoreSnapshot) -> Vec<PeerScoringEvent>
fn apply_snapshot(&mut self, snapshot: &ScoreSnapshot) -> Vec<PeerScoringEvent>
Apply a snapshot of absolute scores (ConversationSync bootstrap).
Unknown members are auto-tracked at the snapshot value — unlike
Self::apply_op, which ignores them — because a snapshot may
arrive before the MLS membership view catches up. Read moreSource§fn snapshot(&self) -> ScoreSnapshot
fn snapshot(&self) -> ScoreSnapshot
Sparse snapshot of non-default scores for ConversationSync send.
fn score_for(&self, member_id: &[u8]) -> Option<i64>
fn members_below_threshold(&self) -> Vec<Vec<u8>>
fn all_members_with_scores(&self) -> Vec<(Vec<u8>, i64)>
Source§fn threshold(&self) -> i64
fn threshold(&self) -> i64
Current removal threshold. Coordinator reads this when building
ConversationSync so joiners adopt the same value.Source§fn set_threshold(&mut self, threshold: i64)
fn set_threshold(&mut self, threshold: i64)
Update the threshold in place. Emits NO events — even though a
tightened threshold can re-classify members from above to
at-or-below, the plug-in does not retroactively scan and emit.
Event-driven coordinators MUST re-scan
Self::members_below_threshold after a set_threshold call,
or arrange for a subsequent apply that surfaces the affected
members through normal cross-detection.Source§fn default_score(&self) -> i64
fn default_score(&self) -> i64
Starting score for a newly tracked member. Called by
Self::add_member and on apply_snapshot for unknown identities.Source§fn set_default_score(&mut self, score: i64)
fn set_default_score(&mut self, score: i64)
Update the starting score in place. Applies to future
Self::add_member calls; does not retroactively rescore
already-tracked members.Source§fn apply_ops(&mut self, ops: &[ScoreOp]) -> Vec<PeerScoringEvent>
fn apply_ops(&mut self, ops: &[ScoreOp]) -> Vec<PeerScoringEvent>
Apply a batch of
ScoreOps. Returns the concatenated events
for every op in input order. A member crossing threshold twice
in one batch (down then up, say) yields two events in that order.
Default impl chains Self::apply_op; override for batched-write
storage where the round-trip cost dominates.Auto Trait Implementations§
impl<S> Freeze for PeerScoringService<S>where
S: Freeze,
impl<S> RefUnwindSafe for PeerScoringService<S>where
S: RefUnwindSafe,
impl<S> Send for PeerScoringService<S>where
S: Send,
impl<S> Sync for PeerScoringService<S>where
S: Sync,
impl<S> Unpin for PeerScoringService<S>where
S: Unpin,
impl<S> UnsafeUnpin for PeerScoringService<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for PeerScoringService<S>where
S: UnwindSafe,
Blanket Implementations§
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
Source§impl<T> Declassify for T
impl<T> Declassify for T
type Declassified = T
fn declassify(self) -> T
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