Skip to content

Commit 4b163ce

Browse files
apollo_network: added misconduct score AddAssign docs (#8951)
1 parent f02c4c7 commit 4b163ce

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

crates/apollo_network/src/misconduct_score.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
/// ```
124142
impl 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
}

0 commit comments

Comments
 (0)