From 4c69b376b2a7ef8cf5771ab62034428a7cf77a2a Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Fri, 21 Aug 2026 22:20:00 +0200 Subject: [PATCH] Added adaptive timeouts to utilities, by Zenith --- RNS/Utilities/rncp.py | 6 ++++-- RNS/Utilities/rnpath.py | 3 ++- RNS/Utilities/rnprobe.py | 4 ++-- RNS/Utilities/rnx.py | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/RNS/Utilities/rncp.py b/RNS/Utilities/rncp.py index 3fa84e26..151a5723 100644 --- a/RNS/Utilities/rncp.py +++ b/RNS/Utilities/rncp.py @@ -401,7 +401,7 @@ def fetch(configdir, identitypath = None, verbosity = 0, quietness = 0, destinat i = 0 syms = "⢄⢂⢁⡁⡈⡐⡠" - estab_timeout = time.time()+timeout + estab_timeout = time.time()+max(timeout, reticulum.get_medium_path_timeout()) while not RNS.Transport.has_path(destination_hash) and time.time() < estab_timeout: if not silent: time.sleep(0.1) @@ -431,6 +431,7 @@ def fetch(configdir, identitypath = None, verbosity = 0, quietness = 0, destinat ) link = RNS.Link(listener_destination) + estab_timeout = max(estab_timeout, time.time()+link.establishment_timeout) while link.status != RNS.Link.ACTIVE and time.time() < estab_timeout: if not silent: time.sleep(0.1) @@ -656,7 +657,7 @@ def send(configdir, identitypath = None, verbosity = 0, quietness = 0, destinati i = 0 syms = "⢄⢂⢁⡁⡈⡐⡠" - estab_timeout = time.time()+timeout + estab_timeout = time.time()+max(timeout, reticulum.get_medium_path_timeout()) while not RNS.Transport.has_path(destination_hash) and time.time() < estab_timeout: if not silent: time.sleep(0.1) @@ -686,6 +687,7 @@ def send(configdir, identitypath = None, verbosity = 0, quietness = 0, destinati ) link = RNS.Link(receiver_destination) + estab_timeout = max(estab_timeout, time.time()+link.establishment_timeout) while link.status != RNS.Link.ACTIVE and time.time() < estab_timeout: if not silent: time.sleep(0.1) diff --git a/RNS/Utilities/rnpath.py b/RNS/Utilities/rnpath.py index 5b0a30db..3f65a691 100644 --- a/RNS/Utilities/rnpath.py +++ b/RNS/Utilities/rnpath.py @@ -42,6 +42,7 @@ remote_link = None output_rst_str = "\r \r" def connect_remote(destination_hash, auth_identity, timeout, no_output = False, purpose="management"): global remote_link, reticulum + timeout = max(timeout, reticulum.get_medium_path_timeout()) if not RNS.Transport.has_path(destination_hash): if not no_output: print("Path to "+RNS.prettyhexrep(destination_hash)+" requested", end=" ") @@ -451,7 +452,7 @@ def program_setup(configdir, table, rates, drop, destination_hexhash, verbosity, i = 0 syms = "⢄⢂⢁⡁⡈⡐⡠" - limit = time.time()+timeout + limit = time.time()+max(timeout, reticulum.get_medium_path_timeout()) while not RNS.Transport.has_path(destination_hash) and time.time() _timeout: @@ -131,7 +131,7 @@ def program_setup(configdir, destination_hexhash, size=None, full_name = None, v print("\rSent probe "+str(sent)+" ("+str(size)+" bytes) to "+RNS.prettyhexrep(destination_hash)+more+" ", end=" ") - _timeout = time.time() + (timeout or DEFAULT_TIMEOUT+reticulum.get_first_hop_timeout(destination_hash)) + _timeout = time.time() + (timeout or max(DEFAULT_TIMEOUT+reticulum.get_first_hop_timeout(destination_hash), reticulum.get_medium_path_timeout())) i = 0 while receipt.status == RNS.PacketReceipt.SENT and not time.time() > _timeout: time.sleep(0.1) diff --git a/RNS/Utilities/rnx.py b/RNS/Utilities/rnx.py index 0be8219b..4bfcf83b 100644 --- a/RNS/Utilities/rnx.py +++ b/RNS/Utilities/rnx.py @@ -347,7 +347,7 @@ def execute(configdir, identitypath = None, verbosity = 0, quietness = 0, detail if not RNS.Transport.has_path(destination_hash): RNS.Transport.request_path(destination_hash) - if not spin(until=lambda: RNS.Transport.has_path(destination_hash), msg="Path to "+RNS.prettyhexrep(destination_hash)+" requested", timeout=timeout): + if not spin(until=lambda: RNS.Transport.has_path(destination_hash), msg="Path to "+RNS.prettyhexrep(destination_hash)+" requested", timeout=max(timeout, reticulum.get_medium_path_timeout())): print("Path not found") exit(242) @@ -365,7 +365,7 @@ def execute(configdir, identitypath = None, verbosity = 0, quietness = 0, detail link = RNS.Link(listener_destination) link.did_identify = False - if not spin(until=lambda: link.status == RNS.Link.ACTIVE, msg="Establishing link with "+RNS.prettyhexrep(destination_hash), timeout=timeout): + if not spin(until=lambda: link.status == RNS.Link.ACTIVE, msg="Establishing link with "+RNS.prettyhexrep(destination_hash), timeout=max(timeout, link.establishment_timeout)): print("Could not establish link with "+RNS.prettyhexrep(destination_hash)) exit(243)