Skip to main content

PeerScoringService

Struct PeerScoringService 

Source
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>

Source

pub fn new( storage: S, score_deltas: HashMap<ScoreEvent, i64>, config: ScoringConfig, ) -> Self

Trait Implementations§

Source§

impl<S: PeerScoreStorage> PeerScoringPlugin for PeerScoringService<S>

Source§

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])

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>

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>

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 more
Source§

fn snapshot(&self) -> ScoreSnapshot

Sparse snapshot of non-default scores for ConversationSync send.
Source§

fn score_for(&self, member_id: &[u8]) -> Option<i64>

Source§

fn members_below_threshold(&self) -> Vec<Vec<u8>>

Source§

fn all_members_with_scores(&self) -> Vec<(Vec<u8>, i64)>

Source§

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)

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

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)

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>

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Classify for T

Source§

type Classified = T

Source§

fn classify(self) -> T

Source§

impl<T> Declassify for T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more