maintain preferred peer connections (#3435)
This commit is contained in:
+12
-5
@@ -416,7 +416,12 @@ impl Peers {
|
||||
/// Iterate over the peer list and prune all peers we have
|
||||
/// lost connection to or have been deemed problematic.
|
||||
/// Also avoid connected peer count getting too high.
|
||||
pub fn clean_peers(&self, max_inbound_count: usize, max_outbound_count: usize) {
|
||||
pub fn clean_peers(
|
||||
&self,
|
||||
max_inbound_count: usize,
|
||||
max_outbound_count: usize,
|
||||
preferred_peers: &[PeerAddr],
|
||||
) {
|
||||
let mut rm = vec![];
|
||||
|
||||
// build a list of peers to be cleaned up
|
||||
@@ -464,12 +469,13 @@ impl Peers {
|
||||
let excess_outgoing_count =
|
||||
(self.peer_outbound_count() as usize).saturating_sub(max_outbound_count);
|
||||
if excess_outgoing_count > 0 {
|
||||
let mut addrs = self
|
||||
let mut addrs: Vec<_> = self
|
||||
.outgoing_connected_peers()
|
||||
.iter()
|
||||
.filter(|x| !preferred_peers.contains(&x.info.addr))
|
||||
.take(excess_outgoing_count)
|
||||
.map(|x| x.info.addr)
|
||||
.collect::<Vec<_>>();
|
||||
.collect();
|
||||
rm.append(&mut addrs);
|
||||
}
|
||||
|
||||
@@ -477,12 +483,13 @@ impl Peers {
|
||||
let excess_incoming_count =
|
||||
(self.peer_inbound_count() as usize).saturating_sub(max_inbound_count);
|
||||
if excess_incoming_count > 0 {
|
||||
let mut addrs = self
|
||||
let mut addrs: Vec<_> = self
|
||||
.incoming_connected_peers()
|
||||
.iter()
|
||||
.filter(|x| !preferred_peers.contains(&x.info.addr))
|
||||
.take(excess_incoming_count)
|
||||
.map(|x| x.info.addr)
|
||||
.collect::<Vec<_>>();
|
||||
.collect();
|
||||
rm.append(&mut addrs);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user