v0.5.18: onion helpers, download robustness, Tor-aware messages
This commit is contained in:
@@ -1156,6 +1156,19 @@ class BalWindow:
|
|||||||
f"len={len(resp) if hasattr(resp, '__len__') else 'n/a'}"
|
f"len={len(resp) if hasattr(resp, '__len__') else 'n/a'}"
|
||||||
)
|
)
|
||||||
if resp:
|
if resp:
|
||||||
|
# Robustness: the server is expected to return a dict of
|
||||||
|
# {url: info}. If it returns anything else (a raw string
|
||||||
|
# error page, a list, etc. - more likely over Tor when a
|
||||||
|
# server misbehaves), do NOT use it: that would later crash
|
||||||
|
# on `self.willexecutors.update(result)`. Treat it as an
|
||||||
|
# empty/failed response and try the next candidate.
|
||||||
|
if not isinstance(resp, dict):
|
||||||
|
_logger.warning(
|
||||||
|
f"fetch_will_executors_list: {url} -> unexpected "
|
||||||
|
f"response type {type(resp).__name__}, ignoring"
|
||||||
|
)
|
||||||
|
last_error = "invalid response format"
|
||||||
|
continue
|
||||||
result = resp
|
result = resp
|
||||||
# Tor gating: if Electrum is NOT connected through Tor, drop
|
# Tor gating: if Electrum is NOT connected through Tor, drop
|
||||||
# the .onion servers entirely - they are unreachable without
|
# the .onion servers entirely - they are unreachable without
|
||||||
@@ -1164,6 +1177,11 @@ class BalWindow:
|
|||||||
for w in list(result.keys()):
|
for w in list(result.keys()):
|
||||||
if w in ("status", "url"):
|
if w in ("status", "url"):
|
||||||
continue
|
continue
|
||||||
|
# Defensive: each entry must be a dict too; skip anything
|
||||||
|
# malformed rather than crashing downstream.
|
||||||
|
if not isinstance(result.get(w), dict):
|
||||||
|
del result[w]
|
||||||
|
continue
|
||||||
if not tor_on and is_onion_url(w):
|
if not tor_on and is_onion_url(w):
|
||||||
del result[w]
|
del result[w]
|
||||||
continue
|
continue
|
||||||
@@ -1199,6 +1217,16 @@ class BalWindow:
|
|||||||
"and try again."
|
"and try again."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Shown when the download fails while Electrum is connected through Tor:
|
||||||
|
# the most common cause is a slow Tor connection, so guide the user
|
||||||
|
# accordingly instead of the generic message above.
|
||||||
|
DOWNLOAD_FAILED_TOR_MESSAGE = (
|
||||||
|
"Could not download the will-executors list over Tor.\n\n"
|
||||||
|
"Electrum is connected through Tor and the connection is taking too "
|
||||||
|
"long. Your Tor connection may be slow. Please try again, or use a VPN "
|
||||||
|
"(or temporarily disable Tor) for a faster connection."
|
||||||
|
)
|
||||||
|
|
||||||
def download_list(self, willexecutors, fn_on_success, fn_on_failure=None):
|
def download_list(self, willexecutors, fn_on_success, fn_on_failure=None):
|
||||||
if fn_on_failure is None:
|
if fn_on_failure is None:
|
||||||
fn_on_failure = log_error
|
fn_on_failure = log_error
|
||||||
@@ -1243,9 +1271,18 @@ class BalWindow:
|
|||||||
stop_heartbeat.set()
|
stop_heartbeat.set()
|
||||||
|
|
||||||
def on_success(result):
|
def on_success(result):
|
||||||
if result:
|
# Defensive: only merge a proper dict (see fetch_will_executors_list).
|
||||||
|
# A non-dict here would raise "dictionary update sequence element..."
|
||||||
|
if isinstance(result, dict) and result:
|
||||||
self.willexecutors.update(result)
|
self.willexecutors.update(result)
|
||||||
fn_on_success(result)
|
fn_on_success(result)
|
||||||
|
else:
|
||||||
|
# Tor-aware failure message: a download failure/timeout while
|
||||||
|
# Electrum is connected through Tor is most often a slow Tor
|
||||||
|
# connection, so point the user to that (try again / VPN /
|
||||||
|
# disable Tor). Otherwise keep the generic connection message.
|
||||||
|
if is_tor_active():
|
||||||
|
self.show_warning(_(self.DOWNLOAD_FAILED_TOR_MESSAGE))
|
||||||
else:
|
else:
|
||||||
self.show_warning(_(self.DOWNLOAD_FAILED_MESSAGE))
|
self.show_warning(_(self.DOWNLOAD_FAILED_MESSAGE))
|
||||||
|
|
||||||
@@ -1277,6 +1314,11 @@ class BalWindow:
|
|||||||
f"No active will-executor found for the "
|
f"No active will-executor found for the "
|
||||||
f"{err.chain} network."
|
f"{err.chain} network."
|
||||||
))
|
))
|
||||||
|
else:
|
||||||
|
# Tor-aware: a generic failure/timeout while on Tor is most
|
||||||
|
# likely a slow Tor connection.
|
||||||
|
if is_tor_active():
|
||||||
|
self.show_warning(_(self.DOWNLOAD_FAILED_TOR_MESSAGE))
|
||||||
else:
|
else:
|
||||||
self.show_warning(_(self.DOWNLOAD_FAILED_MESSAGE))
|
self.show_warning(_(self.DOWNLOAD_FAILED_MESSAGE))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user