removed netcheck comm timer

This commit is contained in:
Kevin Froman 2020-11-18 22:16:37 -06:00
parent a775f3b26d
commit 59330149e1
2 changed files with 12 additions and 10 deletions

View File

@ -52,7 +52,8 @@ config.reload()
class OnionrCommunicatorDaemon: class OnionrCommunicatorDaemon:
def __init__(self, shared_state, developmentMode=None): def __init__(self, shared_state, developmentMode=None):
if developmentMode is None: if developmentMode is None:
developmentMode = config.get('general.dev_mode', False) developmentMode = config.get(
'general.dev_mode', False)
# configure logger and stuff # configure logger and stuff
self.config = config self.config = config
@ -139,9 +140,7 @@ class OnionrCommunicatorDaemon:
if config.get('transports.tor', True): if config.get('transports.tor', True):
# Timer to check for connectivity, # Timer to check for connectivity,
# through Tor to various high-profile onion services # through Tor to various high-profile onion services
OnionrCommunicatorTimers( add_onionr_thread(netcheck.net_check, [shared_state], 500, 60)
self, netcheck.net_check, 500,
my_args=[self], max_threads=1)
# Announce the public API server transport address # Announce the public API server transport address
# to other nodes if security level allows # to other nodes if security level allows

View File

@ -30,14 +30,16 @@ if TYPE_CHECKING:
""" """
def net_check(comm_inst): def net_check(shared_state):
"""Check if we are connected to the internet. """Check if we are connected to the internet.
or not when we can't connect to any peers or not when we can't connect to any peers
""" """
# for detecting if we have received incoming connections recently # for detecting if we have received incoming connections recently
rec = False rec = False
kv: "DeadSimpleKV" = comm_inst.shared_state.get_by_string("DeadSimpleKV") kv: "DeadSimpleKV" = shared_state.get_by_string("DeadSimpleKV")
proxy_port = shared_state.get_by_string("NetController").socksPort
if len(kv.get('onlinePeers')) == 0: if len(kv.get('onlinePeers')) == 0:
try: try:
if (epoch.get_epoch() - int(localcommand.local_command if (epoch.get_epoch() - int(localcommand.local_command
@ -46,16 +48,17 @@ def net_check(comm_inst):
rec = True rec = True
except ValueError: except ValueError:
pass pass
if not rec and not netutils.check_network(torPort=comm_inst.proxyPort): if not rec and not netutils.check_network(torPort=proxy_port):
if not kv.get('shutdown'): if not kv.get('shutdown'):
if not comm_inst.config.get('general.offline_mode', False): if not shared_state.get_by_string(
"OnionrCommunicatorDaemon").config.get(
'general.offline_mode', False):
logger.warn('Network check failed, are you connected to ' + logger.warn('Network check failed, are you connected to ' +
'the Internet, and is Tor working? ' + 'the Internet, and is Tor working? ' +
'This is usually temporary, but bugs and censorship can cause this to persist, in which case you should report it to beardog [at] mailbox.org', # noqa 'This is usually temporary, but bugs and censorship can cause this to persist, in which case you should report it to beardog [at] mailbox.org', # noqa
terminal=True) terminal=True)
restarttor.restart(comm_inst.shared_state) restarttor.restart(shared_state)
kv.put('offlinePeers', []) kv.put('offlinePeers', [])
kv.put('isOnline', False) kv.put('isOnline', False)
else: else:
kv.put('isOnline', True) kv.put('isOnline', True)
comm_inst.decrementThreadCount('net_check')