From ab79ee2a043b03781e63479cf0a24d02f0441c42 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Thu, 20 Oct 2016 01:46:48 +0200 Subject: [PATCH] Proxy error handling - UI will now display notifications in the status bar if the connection to the proxy itself is broken. This should give better feedback to people who are unfamiliar with tor and misconfigured it - The proxy error handling in the background was slightly improved as well --- src/class_outgoingSynSender.py | 19 ++++++++++++++----- src/helper_bootstrap.py | 7 ++++--- src/socks/__init__.py | 11 ++++++++--- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/class_outgoingSynSender.py b/src/class_outgoingSynSender.py index f61129a2..3814c9d8 100644 --- a/src/class_outgoingSynSender.py +++ b/src/class_outgoingSynSender.py @@ -203,7 +203,16 @@ class outgoingSynSender(threading.Thread, StoppableThread): logger.debug(str(self) + ' connected to ' + str(peer) + ' during an outgoing attempt.') except socks.GeneralProxyError as err: - if shared.verbose >= 2: + if err[0][0] in [7, 8, 9]: + logger.error('Error communicating with proxy: %s', str(err)) + shared.UISignalQueue.put(( + 'updateStatusBar', + tr._translate( + "MainWindow", "Problem communicating with proxy: %1. Please check your network settings.").arg(str(err[0][1])) + )) + self.stop.wait(1) + continue + elif shared.verbose >= 2: logger.debug('Could NOT connect to ' + str(peer) + ' during outgoing attempt. ' + str(err)) deletedPeer = None @@ -227,13 +236,13 @@ class outgoingSynSender(threading.Thread, StoppableThread): except socks.Socks5AuthError as err: shared.UISignalQueue.put(( 'updateStatusBar', tr._translate( - "MainWindow", "SOCKS5 Authentication problem: %1").arg(str(err)))) + "MainWindow", "SOCKS5 Authentication problem: %1. Please check your SOCKS5 settings").arg(str(err)))) except socks.Socks5Error as err: - if err[0] in [3, 4, 5, 6]: + if err[0][0] in [3, 4, 5, 6]: # this is a more bening "error": host unreachable, network unreachable, connection refused, TTL expired - logger.debug('SOCKS5 error. ' + str(err)) + logger.debug('SOCKS5 error: %s', str(err)) else: - logger.error('SOCKS5 error. ' + str(err)) + logger.error('SOCKS5 error: %s', str(err)) except socks.Socks4Error as err: logger.error('Socks4Error: ' + str(err)) except socket.error as err: diff --git a/src/helper_bootstrap.py b/src/helper_bootstrap.py index e14e932c..82f5b5bc 100644 --- a/src/helper_bootstrap.py +++ b/src/helper_bootstrap.py @@ -85,9 +85,10 @@ def dns(): sock.close() except: logger.error("SOCKS DNS resolving failed", exc_info=True) - if ip is not None: - logger.info ('Adding ' + ip + ' to knownNodes based on SOCKS DNS bootstrap method') - shared.knownNodes[1][shared.Peer(ip, port)] = time.time() + else: + if ip is not None: + logger.info ('Adding ' + ip + ' to knownNodes based on SOCKS DNS bootstrap method') + shared.knownNodes[1][shared.Peer(ip, port)] = time.time() else: logger.info('DNS bootstrap skipped because the proxy type does not support DNS resolution.') diff --git a/src/socks/__init__.py b/src/socks/__init__.py index 2bd03f48..ca1336b9 100644 --- a/src/socks/__init__.py +++ b/src/socks/__init__.py @@ -64,7 +64,10 @@ _generalerrors = ("success", "not available", "bad proxy type", "bad input", - "timed out") + "timed out", + "network unreachable", + "connection refused", + "host unreachable") _socks5errors = ("succeeded", "general SOCKS server failure", @@ -404,9 +407,11 @@ class socksocket(socket.socket): _orgsocket.connect(self, (self.__proxy[1], portnum)) except socket.error as e: if e[0] == 101: - raise Socks5Error((3, _socks5errors[3])) + raise GeneralProxyError((7, _generalerrors[7])) if e[0] == 111: - raise Socks5Error((5, _socks5errors[5])) + raise GeneralProxyError((8, _generalerrors[8])) + if e[0] == 113: + raise GeneralProxyError((9, _generalerrors[9])) raise self.__negotiatesocks5() self.__connectsocks5(destpair[0], destpair[1])