mirror of
https://github.com/liamcottle/reticulum-meshchat.git
synced 2026-04-28 00:20:48 +00:00
add timeout for establishing link for downloads
This commit is contained in:
parent
1522c3a73c
commit
5ace093e04
1 changed files with 13 additions and 2 deletions
15
web.py
15
web.py
|
|
@ -1246,7 +1246,7 @@ class NomadnetDownloader:
|
|||
self.on_progress_update = on_progress_update
|
||||
|
||||
# setup link to destination and request download
|
||||
async def download(self, path_lookup_timeout: int = 15):
|
||||
async def download(self, path_lookup_timeout: int = 15, link_establishment_timeout: int = 15):
|
||||
|
||||
# determine when to timeout
|
||||
timeout_after_seconds = time.time() + path_lookup_timeout
|
||||
|
|
@ -1277,7 +1277,18 @@ class NomadnetDownloader:
|
|||
)
|
||||
|
||||
# create link to destination
|
||||
RNS.Link(destination, established_callback=self.link_established)
|
||||
link = RNS.Link(destination, established_callback=self.link_established)
|
||||
|
||||
# determine when to timeout
|
||||
timeout_after_seconds = time.time() + link_establishment_timeout
|
||||
|
||||
# wait until we have established a link, or give up after the configured timeout
|
||||
while link.status is not RNS.Link.ACTIVE and time.time() < timeout_after_seconds:
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
# if we still haven't established a link, bail out
|
||||
if link.status is not RNS.Link.ACTIVE:
|
||||
self.on_download_failure("Could not establish link to destination.")
|
||||
|
||||
# link to destination was established, we should now request the download
|
||||
def link_established(self, link):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue