Added await_path method to transport API

This commit is contained in:
Mark Qvist 2026-01-01 21:37:56 +01:00
parent 5e4d32c4c0
commit 5de4e24a9f

View file

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