Added delay to auto announces on start

This commit is contained in:
Mark Qvist 2021-12-11 19:20:34 +01:00
parent 9824a8f7ea
commit b86c811bde
2 changed files with 19 additions and 3 deletions

View File

@ -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)

View File

@ -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