From b86c811bde94f367e1fe062519ee48d7e0e10b1c Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sat, 11 Dec 2021 19:20:34 +0100 Subject: [PATCH] Added delay to auto announces on start --- nomadnet/Node.py | 11 +++++++++-- nomadnet/NomadNetworkApp.py | 11 ++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/nomadnet/Node.py b/nomadnet/Node.py index ab10139..9a0ffd5 100644 --- a/nomadnet/Node.py +++ b/nomadnet/Node.py @@ -7,13 +7,14 @@ import RNS.vendor.umsgpack as msgpack class Node: JOB_INTERVAL = 5 + START_ANNOUNCE_DELAY = 6 def __init__(self, app): RNS.log("Nomad Network Node starting...", RNS.LOG_VERBOSE) self.app = app self.identity = self.app.identity self.destination = RNS.Destination(self.identity, RNS.Destination.IN, RNS.Destination.SINGLE, "nomadnetwork", "node") - self.last_announce = None + self.last_announce = time.time() self.announce_interval = self.app.node_announce_interval self.job_interval = Node.JOB_INTERVAL self.should_run_jobs = True @@ -29,7 +30,13 @@ class Node: RNS.log("Node \""+self.name+"\" ready for incoming connections on "+RNS.prettyhexrep(self.destination.hash), RNS.LOG_VERBOSE) if self.app.node_announce_at_start: - self.announce() + def delayed_announce(): + time.sleep(Node.START_ANNOUNCE_DELAY) + self.announce() + + da_thread = threading.Thread(target=delayed_announce) + da_thread.setDaemon(True) + da_thread.start() job_thread = threading.Thread(target=self.__jobs) job_thread.setDaemon(True) diff --git a/nomadnet/NomadNetworkApp.py b/nomadnet/NomadNetworkApp.py index c8630a7..7753a45 100644 --- a/nomadnet/NomadNetworkApp.py +++ b/nomadnet/NomadNetworkApp.py @@ -3,6 +3,7 @@ import io import sys import time import atexit +import threading import traceback import contextlib @@ -23,6 +24,8 @@ class NomadNetworkApp: configdir = os.path.expanduser("~")+"/.nomadnetwork" + START_ANNOUNCE_DELAY = 3 + def exit_handler(self): RNS.log("Nomad Network Client exit handler executing...", RNS.LOG_VERBOSE) RNS.log("Saving directory...", RNS.LOG_VERBOSE) @@ -208,7 +211,13 @@ class NomadNetworkApp: self.autoselect_propagation_node() if self.peer_announce_at_start: - self.announce_now() + def delayed_announce(): + time.sleep(NomadNetworkApp.START_ANNOUNCE_DELAY) + self.announce_now() + + da_thread = threading.Thread(target=delayed_announce) + da_thread.setDaemon(True) + da_thread.start() atexit.register(self.exit_handler) sys.excepthook = self.exception_handler