p2p: ignore last connection attempt when there is not enough outbound peers
This commit is contained in:
@@ -194,7 +194,8 @@ fn monitor_peers(peers: Arc<p2p::Peers>, config: p2p::P2PConfig, tx: mpsc::Sende
|
||||
return;
|
||||
}
|
||||
|
||||
if !peers.enough_outbound_peers() {
|
||||
let enough_outbound = peers.enough_outbound_peers();
|
||||
if !enough_outbound {
|
||||
// loop over connected peers that can provide peer lists
|
||||
// ask them for their list of peers
|
||||
let mut connected_peers: Vec<PeerAddr> = vec![];
|
||||
@@ -239,7 +240,7 @@ fn monitor_peers(peers: Arc<p2p::Peers>, config: p2p::P2PConfig, tx: mpsc::Sende
|
||||
.iter()
|
||||
.filter(|p| {
|
||||
peers.get_connected_peer(p.addr).is_none()
|
||||
&& Utc::now().timestamp() - p.last_attempt >= max_attempt_delay
|
||||
&& (enough_outbound && Utc::now().timestamp() - p.last_attempt >= max_attempt_delay)
|
||||
})
|
||||
.choose_multiple(&mut thread_rng(), max_peer_attempts / 2)
|
||||
{
|
||||
@@ -268,7 +269,7 @@ fn monitor_peers(peers: Arc<p2p::Peers>, config: p2p::P2PConfig, tx: mpsc::Sende
|
||||
// check min 32 (max 128, if there are no healthy and unknown) random defunct peers no more often than 1 hour per peer.
|
||||
for dp in defuncts
|
||||
.iter()
|
||||
.filter(|p| Utc::now().timestamp() - p.last_attempt >= max_attempt_delay)
|
||||
.filter(|p| enough_outbound && Utc::now().timestamp() - p.last_attempt >= max_attempt_delay)
|
||||
.choose_multiple(&mut thread_rng(), max_peer_attempts - new_peers.len())
|
||||
{
|
||||
new_peers.push(&dp.addr);
|
||||
|
||||
Reference in New Issue
Block a user