From 5de4e24a9f8eec9f615bb3dd7edeb5a808461ccd Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Thu, 1 Jan 2026 21:37:56 +0100 Subject: [PATCH] Added await_path method to transport API --- RNS/Transport.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/RNS/Transport.py b/RNS/Transport.py index 870bfec..df11ec5 100755 --- a/RNS/Transport.py +++ b/RNS/Transport.py @@ -163,6 +163,7 @@ class Transport: inbound_announce_lock = Lock() interface_announcer = None discovery_handler = None + blackhole_updater = None traffic_rxb = 0 traffic_txb = 0 @@ -2466,6 +2467,23 @@ class Transport: return False + @staticmethod + def await_path(destination_hash, timeout=None, on_interface=None): + """ + Requests a path to the destination from the network and + blocks until the path is available, or the timeout is reached. + + :param destination_hash: A destination hash as *bytes*. + :param timeout: An optional timeout in seconds. + :param on_interface: If specified, the path request will only be sent on this interface. In normal use, Reticulum handles this automatically, and this parameter should not be used. + :returns: *True* if a path to the destination is found, otherwise *False*. + """ + timeout = time.time()+(timeout if timeout else Transport.PATH_REQUEST_TIMEOUT) + if Transport.has_path(destination_hash): return True + else: Transport.request_path(destination_hash, on_interface=on_interface) + while not Transport.has_path(destination_hash) and time.time() < timeout: time.sleep(0.05) + return Transport.has_path(destination_hash) + @staticmethod def request_path(destination_hash, on_interface=None, tag=None, recursive=False): """