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

@ -5,7 +5,7 @@ get online peers in a communicator instance
import time
from typing import TYPE_CHECKING
from etc import humanreadabletime
from etc.humanreadabletime import human_readable_time
import logger
if TYPE_CHECKING:
from deadsimplekv import DeadSimpleKV
@ -41,9 +41,8 @@ def get_online_peers(comm_inst: 'OnionrCommunicatorDaemon'):
needed = max_peers - len(kv.get('onlinePeers'))
last_seen = 'never'
if not isinstance(comm_inst.lastNodeSeen, type(None)):
last_seen = humanreadabletime.human_readable_time(
comm_inst.lastNodeSeen)
if not isinstance(kv.get('lastNodeSeen'), type(None)):
last_seen = human_readable_time(kv.get('lastNodeSeen'))
for _ in range(needed):
if len(kv.get('onlinePeers')) == 0:
@ -62,5 +61,5 @@ def get_online_peers(comm_inst: 'OnionrCommunicatorDaemon'):
except RecursionError:
pass
else:
comm_inst.lastNodeSeen = time.time()
kv.put('lastNodeSeen', time.time())
comm_inst.decrementThreadCount('get_online_peers')

View file

@ -26,7 +26,7 @@ def remove_online_peer(comm_inst, peer):
"""Remove an online peer."""
kv: "DeadSimpleKV" = comm_inst.shared_state.get_by_string("DeadSimpleKV")
try:
del comm_inst.connectTimes[peer]
del kv.get('connectTimes')[peer]
except KeyError:
pass
try: