Moved all communicator ext vars to KV

This commit is contained in:
Kevin 2020-07-29 03:57:06 -05:00
parent 080f33bf1f
commit f28d469e56
7 changed files with 34 additions and 35 deletions

View file

@ -90,15 +90,15 @@ def connect_new_peer_to_communicator(comm_inst, peer='', useBootstrap=False):
if address not in kv.get('onlinePeers'):
logger.info('Connected to ' + address, terminal=True)
kv.get('onlinePeers').append(address)
comm_inst.connectTimes[address] = epoch.get_epoch()
kv.get('connectTimes')[address] = epoch.get_epoch()
retData = address
# add peer to profile list if they're not in it
for profile in comm_inst.peerProfiles:
for profile in kv.get('peerProfiles'):
if profile.address == address:
break
else:
comm_inst.peerProfiles.append(
kv.get('peerProfiles').append(
onionrpeers.PeerProfiles(address))
break
else:

View file

@ -33,7 +33,7 @@ def cooldown_peer(comm_inst):
minTime = 300
cooldown_time = 600
to_cool = ''
tempConnectTimes = dict(comm_inst.connectTimes)
tempConnectTimes = dict(kv.get('connectTimes'))
# Remove peers from cooldown that have been there long enough
tempCooldown = dict(kv.get('cooldownPeer'))

View file

@ -88,7 +88,7 @@ class BlockUploadSessionManager:
kv: "DeadSimpleKV" = comm_inst.shared_state.get_by_string(
"DeadSimpleKV")
sessions_to_delete = []
if comm_inst.getUptime() < 120:
if kv.get('startTime') < 120:
return
onlinePeerCount = len(kv.get('onlinePeers'))
@ -105,7 +105,8 @@ class BlockUploadSessionManager:
# Clean sessions if they have uploaded to enough online peers
if sess.total_success_count <= 0:
continue
if (sess.total_success_count / onlinePeerCount) >= onionrvalues.MIN_BLOCK_UPLOAD_PEER_PERCENT:
if (sess.total_success_count / onlinePeerCount) >= \
onionrvalues.MIN_BLOCK_UPLOAD_PEER_PERCENT:
sessions_to_delete.append(sess)
for sess in sessions_to_delete:
try: