From 27f94cfb0401edbf632070fd782246971040a75d Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Wed, 1 Mar 2017 20:20:30 +0900 Subject: [PATCH] Take up to 2 peers randomly from each bucket Bumped up from 1. Restore STALE_SECS to 1 day --- server/peers.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/server/peers.py b/server/peers.py index 8eb8501..3022cec 100644 --- a/server/peers.py +++ b/server/peers.py @@ -25,7 +25,7 @@ import server.version as version PEERS_FILE = 'peers' PEER_GOOD, PEER_STALE, PEER_NEVER, PEER_BAD = range(4) -STALE_SECS = 3600 * 4 # 86400 +STALE_SECS = 24 * 3600 WAKEUP_SECS = 300 @@ -330,14 +330,16 @@ class PeerManager(util.LoggedClass): peers = set(myself for myself in self.myselves if myself.last_connect > cutoff) - # Bucket the clearnet peers and select one from each + # Bucket the clearnet peers and select up to two from each buckets = defaultdict(list) for peer in recent: if peer.is_tor: onion_peers.append(peer) else: buckets[peer.bucket()].append(peer) - peers.update(random.choice(bpeers) for bpeers in buckets.values()) + for bucket_peers in buckets.values(): + random.shuffle(bucket_peers) + peers.update(bucket_peers[:2]) # Add up to 20% onion peers (but up to 10 is OK anyway) onion_peers = onion_peers or self.onion_peers