Peer manager cfg (#2766)

## Issue Addressed
I've done this change in a couple of WIPs already so I might as well submit it on its own. This changes no functionality but reduces coupling in a 0.0001%. It also helps new people who need to work in the peer manager to better understand what it actually needs from the outside

## Proposed Changes

Add a config to the peer manager
This commit is contained in:
Divma
2021-11-03 23:44:44 +00:00
parent 7502970a7d
commit a683e0296a
6 changed files with 98 additions and 65 deletions

View File

@@ -52,7 +52,7 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
Self {
log: log.clone(),
disconnected_peers: 0,
banned_peers_count: BannedPeersCount::new(),
banned_peers_count: BannedPeersCount::default(),
peers,
}
}
@@ -923,7 +923,7 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
"banned_peers > MAX_BANNED_PEERS despite no banned peers in db!"
);
// reset banned_peers this will also exit the loop
self.banned_peers_count = BannedPeersCount::new();
self.banned_peers_count = BannedPeersCount::default();
None
} {
debug!(self.log, "Removing old banned peer"; "peer_id" => %to_drop);
@@ -1087,6 +1087,7 @@ impl BanResult {
}
}
#[derive(Default)]
pub struct BannedPeersCount {
/// The number of banned peers in the database.
banned_peers: usize,
@@ -1132,13 +1133,6 @@ impl BannedPeersCount {
.get(ip)
.map_or(false, |count| *count > BANNED_PEERS_PER_IP_THRESHOLD)
}
pub fn new() -> Self {
BannedPeersCount {
banned_peers: 0,
banned_peers_per_ip: HashMap::new(),
}
}
}
#[cfg(test)]