use std::collections::HashMap;
use crate::PeerSocketAddr;
pub(super) const FIND_RESPONSE_STALL_THRESHOLD: usize = 3;
#[derive(Default)]
pub(super) struct FindResponseStallTracker {
counts: HashMap<PeerSocketAddr, usize>,
}
impl FindResponseStallTracker {
pub(super) fn new() -> Self {
Self::default()
}
pub(super) fn record_stall(&mut self, addr: PeerSocketAddr) -> bool {
let count = self.counts.entry(addr).or_default();
*count += 1;
if *count >= FIND_RESPONSE_STALL_THRESHOLD {
self.counts.remove(&addr);
true
} else {
false
}
}
pub(super) fn clear(&mut self, addr: PeerSocketAddr) {
self.counts.remove(&addr);
}
}
#[cfg(test)]
mod tests;