Skip to content

Commit b41f0bd

Browse files
committed
p2p: ignore last connection attempt when there is not enough outbound peers
1 parent ab90750 commit b41f0bd

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

servers/src/grin/seed.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ fn monitor_peers(peers: Arc<p2p::Peers>, config: p2p::P2PConfig, tx: mpsc::Sende
194194
return;
195195
}
196196

197-
if !peers.enough_outbound_peers() {
197+
let enough_outbound = peers.enough_outbound_peers();
198+
if !enough_outbound {
198199
// loop over connected peers that can provide peer lists
199200
// ask them for their list of peers
200201
let mut connected_peers: Vec<PeerAddr> = vec![];
@@ -239,7 +240,7 @@ fn monitor_peers(peers: Arc<p2p::Peers>, config: p2p::P2PConfig, tx: mpsc::Sende
239240
.iter()
240241
.filter(|p| {
241242
peers.get_connected_peer(p.addr).is_none()
242-
&& Utc::now().timestamp() - p.last_attempt >= max_attempt_delay
243+
&& (enough_outbound && Utc::now().timestamp() - p.last_attempt >= max_attempt_delay)
243244
})
244245
.choose_multiple(&mut thread_rng(), max_peer_attempts / 2)
245246
{
@@ -268,7 +269,7 @@ fn monitor_peers(peers: Arc<p2p::Peers>, config: p2p::P2PConfig, tx: mpsc::Sende
268269
// check min 32 (max 128, if there are no healthy and unknown) random defunct peers no more often than 1 hour per peer.
269270
for dp in defuncts
270271
.iter()
271-
.filter(|p| Utc::now().timestamp() - p.last_attempt >= max_attempt_delay)
272+
.filter(|p| enough_outbound && Utc::now().timestamp() - p.last_attempt >= max_attempt_delay)
272273
.choose_multiple(&mut thread_rng(), max_peer_attempts - new_peers.len())
273274
{
274275
new_peers.push(&dp.addr);

0 commit comments

Comments
 (0)