diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 008647ab..91d62564 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -2364,6 +2364,7 @@ class MyForm(settingsmixin.SMainWindow): "MainWindow", "Bitmessage will use your proxy from now on but you may want to manually restart Bitmessage now to close existing connections (if any).")) if BMConfigParser().get('bitmessagesettings', 'socksproxytype')[0:5] == 'SOCKS' and self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5] != 'SOCKS': self.statusBar().clearMessage() + state.resetNetworkProtocolAvailability() # just in case we changed something in the network connectivity if self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5] == 'SOCKS': BMConfigParser().set('bitmessagesettings', 'socksproxytype', str( self.settingsDialogInstance.ui.comboBoxProxyType.currentText())) diff --git a/src/class_outgoingSynSender.py b/src/class_outgoingSynSender.py index b2e0f984..ef63d770 100644 --- a/src/class_outgoingSynSender.py +++ b/src/class_outgoingSynSender.py @@ -255,15 +255,15 @@ class outgoingSynSender(threading.Thread, StoppableThread): else: logger.error('SOCKS5 error: %s', str(err)) if err[0][0] == 4 or err[0][0] == 2: - state.networkProtocolLastFailed['IPv6'] = time.time() + state.networkProtocolAvailability[protocol.networkType(peer.host)] = False except socks.Socks4Error as err: logger.error('Socks4Error: ' + str(err)) except socket.error as err: if BMConfigParser().get('bitmessagesettings', 'socksproxytype')[0:5] == 'SOCKS': logger.error('Bitmessage MIGHT be having trouble connecting to the SOCKS server. ' + str(err)) else: - if ":" in peer.host and err[0] == errno.ENETUNREACH: - state.networkProtocolLastFailed['IPv6'] = time.time() + if err[0] == errno.ENETUNREACH: + state.networkProtocolAvailability[protocol.networkType(peer.host)] = False if shared.verbose >= 1: logger.debug('Could NOT connect to ' + str(peer) + 'during outgoing attempt. ' + str(err)) diff --git a/src/class_receiveDataThread.py b/src/class_receiveDataThread.py index 396b9b8c..5dac4b19 100644 --- a/src/class_receiveDataThread.py +++ b/src/class_receiveDataThread.py @@ -333,6 +333,9 @@ class receiveDataThread(threading.Thread): 'The length of sendDataQueues is now: ' + str(len(state.sendDataQueues)) + "\n" + \ 'broadcasting addr from within connectionFullyEstablished function.') + if self.initiatedConnection: + state.networkProtocolAvailability[protocol.networkType(self.peer.host)] = True + # Let all of our peers know about this new node. dataToSend = (int(time.time()), self.streamNumber, 1, self.peer.host, self.remoteNodeIncomingPort) protocol.broadcastToSendDataQueues(( diff --git a/src/protocol.py b/src/protocol.py index da0cd3aa..ae04740b 100644 --- a/src/protocol.py +++ b/src/protocol.py @@ -67,6 +67,14 @@ def encodeHost(host): else: return socket.inet_pton(socket.AF_INET6, host) +def networkType(host): + if host.find('.onion') > -1: + return 'onion' + elif host.find(':') == -1: + return 'IPv4' + else: + return 'IPv6' + # checks def haveSSL(server = False): diff --git a/src/state.py b/src/state.py index 9e546b51..f8af54c7 100644 --- a/src/state.py +++ b/src/state.py @@ -10,8 +10,8 @@ extPort = None # for Tor hidden service socksIP = None -# Network protocols last check failed -networkProtocolLastFailed = {'IPv4': 0, 'IPv6': 0, 'onion': 0} +# Network protocols availability, initialised below +networkProtocolAvailability = None appdata = '' #holds the location of the application data storage directory @@ -28,3 +28,9 @@ appdata = '' #holds the location of the application data storage directory trustedPeer = None Peer = collections.namedtuple('Peer', ['host', 'port']) + +def resetNetworkProtocolAvailability(): + global networkProtocolAvailability + networkProtocolAvailability = {'IPv4': None, 'IPv6': None, 'onion': None} + +resetNetworkProtocolAvailability()