File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
crates/apollo_network/src Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -121,9 +121,28 @@ impl MisconductScore {
121121 }
122122}
123123
124+ /// Implementation of `AddAssign` for accumulating misconduct scores.
125+ ///
126+ /// This allows multiple misconduct incidents to be accumulated for a peer.
127+ /// The score is clamped to the maximum malicious threshold to prevent overflow.
128+ ///
129+ /// # Examples
130+ ///
131+ /// ```rust
132+ /// use apollo_network::misconduct_score::MisconductScore;
133+ ///
134+ /// let mut peer_score = MisconductScore::NEUTRAL;
135+ /// peer_score += MisconductScore::new(0.3); // First violation
136+ /// peer_score += MisconductScore::new(0.5); // Second violation
137+ /// peer_score += MisconductScore::new(0.8); // Third violation
138+ ///
139+ /// // Score is clamped to maximum malicious level
140+ /// assert!(peer_score.is_malicious());
141+ /// ```
124142impl AddAssign for MisconductScore {
125143 fn add_assign ( & mut self , rhs : Self ) {
126144 self . score += rhs. score ;
145+ // Clamp to maximum malicious score to prevent overflow
127146 if * self > Self :: MALICIOUS {
128147 * self = Self :: MALICIOUS ;
129148 }
You can’t perform that action at this time.
0 commit comments