Moved cooldownPeer to KV to further reduce coupling
This commit is contained in:
parent
dde10b7005
commit
fad5e8547e
@ -70,6 +70,7 @@ class OnionrCommunicatorDaemon:
|
|||||||
self.kv.put('newPeers', [])
|
self.kv.put('newPeers', [])
|
||||||
self.kv.put('dbTimestamps', {})
|
self.kv.put('dbTimestamps', {})
|
||||||
self.kv.put('blocksToUpload', [])
|
self.kv.put('blocksToUpload', [])
|
||||||
|
self.kv.put('cooldownPeer', {})
|
||||||
|
|
||||||
if config.get('general.offline_mode', False):
|
if config.get('general.offline_mode', False):
|
||||||
self.isOnline = False
|
self.isOnline = False
|
||||||
@ -88,7 +89,6 @@ class OnionrCommunicatorDaemon:
|
|||||||
self.delay = 1
|
self.delay = 1
|
||||||
|
|
||||||
# lists of connected peers and peers we know we can't reach currently
|
# lists of connected peers and peers we know we can't reach currently
|
||||||
self.cooldownPeer = {}
|
|
||||||
self.connectTimes = {}
|
self.connectTimes = {}
|
||||||
# list of peer's profiles (onionrpeers.PeerProfile instances)
|
# list of peer's profiles (onionrpeers.PeerProfile instances)
|
||||||
self.peerProfiles = []
|
self.peerProfiles = []
|
||||||
|
@ -76,7 +76,7 @@ def connect_new_peer_to_communicator(comm_inst, peer='', useBootstrap=False):
|
|||||||
"""
|
"""
|
||||||
if len(address) == 0 or address in tried \
|
if len(address) == 0 or address in tried \
|
||||||
or address in kv.get('onlinePeers') \
|
or address in kv.get('onlinePeers') \
|
||||||
or address in comm_inst.cooldownPeer:
|
or address in kv.get('cooldownPeer'):
|
||||||
continue
|
continue
|
||||||
if kv.get('shutdown'):
|
if kv.get('shutdown'):
|
||||||
return
|
return
|
||||||
|
@ -36,10 +36,10 @@ def cooldown_peer(comm_inst):
|
|||||||
tempConnectTimes = dict(comm_inst.connectTimes)
|
tempConnectTimes = dict(comm_inst.connectTimes)
|
||||||
|
|
||||||
# Remove peers from cooldown that have been there long enough
|
# Remove peers from cooldown that have been there long enough
|
||||||
tempCooldown = dict(comm_inst.cooldownPeer)
|
tempCooldown = dict(kv.get('cooldownPeer'))
|
||||||
for peer in tempCooldown:
|
for peer in tempCooldown:
|
||||||
if (epoch.get_epoch() - tempCooldown[peer]) >= cooldown_time:
|
if (epoch.get_epoch() - tempCooldown[peer]) >= cooldown_time:
|
||||||
del comm_inst.cooldownPeer[peer]
|
del kv.get('cooldownPeer')[peer]
|
||||||
|
|
||||||
# Cool down a peer, if we have max connections alive for long enough
|
# Cool down a peer, if we have max connections alive for long enough
|
||||||
if online_peer_amount >= config.get('peers.max_connect', 10, save=True):
|
if online_peer_amount >= config.get('peers.max_connect', 10, save=True):
|
||||||
@ -56,6 +56,6 @@ def cooldown_peer(comm_inst):
|
|||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
onlinepeers.remove_online_peer(comm_inst, to_cool)
|
onlinepeers.remove_online_peer(comm_inst, to_cool)
|
||||||
comm_inst.cooldownPeer[to_cool] = epoch.get_epoch()
|
kv.get('cooldownPeer')[to_cool] = epoch.get_epoch()
|
||||||
|
|
||||||
comm_inst.decrementThreadCount('cooldown_peer')
|
comm_inst.decrementThreadCount('cooldown_peer')
|
||||||
|
Loading…
Reference in New Issue
Block a user