mirror of
https://github.com/markqvist/Reticulum.git
synced 2026-01-07 19:45:43 -05:00
Added await_path method to transport API
This commit is contained in:
parent
5e4d32c4c0
commit
5de4e24a9f
1 changed files with 18 additions and 0 deletions
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue