refactor(net): unify closed incoming session handling (#600)

This commit is contained in:
Matthias Seitz
2022-12-24 12:38:21 +01:00
committed by GitHub
parent 43008b7b07
commit 5affa67805
6 changed files with 145 additions and 52 deletions

View File

@ -47,21 +47,28 @@ impl BanList {
evicted
}
/// Removes all entries that should no longer be banned.
pub fn evict(&mut self, now: Instant) {
self.banned_ips.retain(|_, until| {
/// Removes all ip addresses that are no longer banned.
pub fn evict_ips(&mut self, now: Instant) -> Vec<IpAddr> {
let mut evicted = Vec::new();
self.banned_ips.retain(|peer, until| {
if let Some(until) = until {
return *until > now
if now > *until {
evicted.push(*peer);
return false
}
}
true
});
evicted
}
self.banned_peers.retain(|_, until| {
if let Some(until) = until {
return *until > now
}
true
});
/// Removes all entries that should no longer be banned.
///
/// Returns the evicted entries.
pub fn evict(&mut self, now: Instant) -> (Vec<IpAddr>, Vec<PeerId>) {
let ips = self.evict_ips(now);
let peers = self.evict_peers(now);
(ips, peers)
}
/// Returns true if either the given peer id _or_ ip address is banned.