Moved communicator shutdown over to KV model for more decoupling
This commit is contained in:
parent
0460d3380f
commit
0e4e7bb050
8 changed files with 30 additions and 22 deletions
|
@ -33,6 +33,7 @@ def connect_new_peer_to_communicator(comm_inst, peer='', useBootstrap=False):
|
|||
config = comm_inst.config
|
||||
retData = False
|
||||
tried = comm_inst.offlinePeers
|
||||
kv: "DeadSimpleKV" = comm_inst.shared_state.get_by_string("DeadSimpleKV")
|
||||
transports = gettransports.get()
|
||||
if peer != '':
|
||||
if stringvalidators.validate_transport(peer):
|
||||
|
@ -77,7 +78,7 @@ def connect_new_peer_to_communicator(comm_inst, peer='', useBootstrap=False):
|
|||
or address in comm_inst.onlinePeers \
|
||||
or address in comm_inst.cooldownPeer:
|
||||
continue
|
||||
if comm_inst.shutdown:
|
||||
if kv.get('shutdown'):
|
||||
return
|
||||
# Ping a peer,
|
||||
ret = peeraction.peer_action(comm_inst, address, 'ping')
|
||||
|
|
|
@ -63,7 +63,7 @@ def download_blocks_from_communicator(comm_inst: "OnionrCommunicatorDaemon"):
|
|||
if not shoulddownload.should_download(comm_inst, blockHash):
|
||||
continue
|
||||
|
||||
if comm_inst.shutdown or not comm_inst.isOnline or \
|
||||
if kv.get('shutdown') or not comm_inst.isOnline or \
|
||||
storage_counter.is_full():
|
||||
# Exit loop if shutting down or offline, or disk allocation reached
|
||||
break
|
||||
|
@ -84,7 +84,7 @@ def download_blocks_from_communicator(comm_inst: "OnionrCommunicatorDaemon"):
|
|||
blockPeers = onionrcrypto.cryptoutils.random_shuffle(blockPeers)
|
||||
peerUsed = blockPeers.pop(0)
|
||||
|
||||
if not comm_inst.shutdown and peerUsed.strip() != '':
|
||||
if not kv.get('shutdown') and peerUsed.strip() != '':
|
||||
logger.info(
|
||||
f"Attempting to download %s from {peerUsed}..." % (blockHash[:12],))
|
||||
content = peeraction.peer_action(
|
||||
|
|
|
@ -32,6 +32,7 @@ def net_check(comm_inst):
|
|||
"""
|
||||
# for detecting if we have received incoming connections recently
|
||||
rec = False
|
||||
kv: "DeadSimpleKV" = comm_inst.shared_state.get_by_string("DeadSimpleKV")
|
||||
if len(comm_inst.onlinePeers) == 0:
|
||||
try:
|
||||
if (epoch.get_epoch() - int(localcommand.local_command
|
||||
|
@ -41,7 +42,7 @@ def net_check(comm_inst):
|
|||
except ValueError:
|
||||
pass
|
||||
if not rec and not netutils.checkNetwork(torPort=comm_inst.proxyPort):
|
||||
if not comm_inst.shutdown:
|
||||
if not kv.get('shutdown'):
|
||||
if not comm_inst.config.get('general.offline_mode', False):
|
||||
logger.warn('Network check failed, are you connected to ' +
|
||||
'the Internet, and is Tor working? ' +
|
||||
|
|
|
@ -13,6 +13,7 @@ import logger
|
|||
from typing import TYPE_CHECKING
|
||||
from typing import Callable, NewType, Iterable
|
||||
if TYPE_CHECKING:
|
||||
from deadsimplekv import DeadSimpleKV
|
||||
from communicator import OnionrCommunicatorDaemon
|
||||
"""
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
|
@ -47,6 +48,8 @@ class OnionrCommunicatorTimers:
|
|||
self.daemon_inst = daemon_inst
|
||||
self.max_threads = max_threads
|
||||
self.args = my_args
|
||||
self.kv: "DeadSimpleKV" = daemon_inst.shared_state.get_by_string(
|
||||
"DeadSimpleKV")
|
||||
|
||||
self.daemon_inst.timers.append(self)
|
||||
self.count = 0
|
||||
|
@ -60,7 +63,7 @@ class OnionrCommunicatorTimers:
|
|||
self.daemon_inst.threadCounts[self.timer_function.__name__] = 0
|
||||
|
||||
# execute timer's func, if we are not missing *required* online peer
|
||||
if self.count == self.frequency and not self.daemon_inst.shutdown:
|
||||
if self.count == self.frequency and not self.kv.get('shutdown'):
|
||||
try:
|
||||
if self.requires_peer and \
|
||||
len(self.daemon_inst.onlinePeers) == 0:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue