mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
feat(net): temporarily ban bad peers (#492)
* feat(net): temporarily ban bad peers * use half duration interval * Update crates/net/network/src/peers/manager.rs Co-authored-by: Bjerg <onbjerg@users.noreply.github.com> * fix bad test Co-authored-by: Bjerg <onbjerg@users.noreply.github.com>
This commit is contained in:
@ -32,6 +32,21 @@ impl BanList {
|
||||
Self { banned_ips, banned_peers }
|
||||
}
|
||||
|
||||
/// Removes all peers that are no longer banned.
|
||||
pub fn evict_peers(&mut self, now: Instant) -> Vec<PeerId> {
|
||||
let mut evicted = Vec::new();
|
||||
self.banned_peers.retain(|peer, until| {
|
||||
if let Some(until) = until {
|
||||
if now > *until {
|
||||
evicted.push(*peer);
|
||||
return false
|
||||
}
|
||||
}
|
||||
true
|
||||
});
|
||||
evicted
|
||||
}
|
||||
|
||||
/// Removes all entries that should no longer be banned.
|
||||
pub fn evict(&mut self, now: Instant) {
|
||||
self.banned_ips.retain(|_, until| {
|
||||
|
||||
Reference in New Issue
Block a user