Keep track of network protocol status

This commit is contained in:
Peter Šurda 2017-01-12 19:18:56 +01:00
parent 810e50a040
commit ff8deebf60
Signed by: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
5 changed files with 23 additions and 5 deletions

View File

@ -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).")) "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': if BMConfigParser().get('bitmessagesettings', 'socksproxytype')[0:5] == 'SOCKS' and self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5] != 'SOCKS':
self.statusBar().clearMessage() self.statusBar().clearMessage()
state.resetNetworkProtocolAvailability() # just in case we changed something in the network connectivity
if self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5] == 'SOCKS': if self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5] == 'SOCKS':
BMConfigParser().set('bitmessagesettings', 'socksproxytype', str( BMConfigParser().set('bitmessagesettings', 'socksproxytype', str(
self.settingsDialogInstance.ui.comboBoxProxyType.currentText())) self.settingsDialogInstance.ui.comboBoxProxyType.currentText()))

View File

@ -255,15 +255,15 @@ class outgoingSynSender(threading.Thread, StoppableThread):
else: else:
logger.error('SOCKS5 error: %s', str(err)) logger.error('SOCKS5 error: %s', str(err))
if err[0][0] == 4 or err[0][0] == 2: 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: except socks.Socks4Error as err:
logger.error('Socks4Error: ' + str(err)) logger.error('Socks4Error: ' + str(err))
except socket.error as err: except socket.error as err:
if BMConfigParser().get('bitmessagesettings', 'socksproxytype')[0:5] == 'SOCKS': if BMConfigParser().get('bitmessagesettings', 'socksproxytype')[0:5] == 'SOCKS':
logger.error('Bitmessage MIGHT be having trouble connecting to the SOCKS server. ' + str(err)) logger.error('Bitmessage MIGHT be having trouble connecting to the SOCKS server. ' + str(err))
else: else:
if ":" in peer.host and err[0] == errno.ENETUNREACH: if err[0] == errno.ENETUNREACH:
state.networkProtocolLastFailed['IPv6'] = time.time() state.networkProtocolAvailability[protocol.networkType(peer.host)] = False
if shared.verbose >= 1: if shared.verbose >= 1:
logger.debug('Could NOT connect to ' + str(peer) + 'during outgoing attempt. ' + str(err)) logger.debug('Could NOT connect to ' + str(peer) + 'during outgoing attempt. ' + str(err))

View File

@ -333,6 +333,9 @@ class receiveDataThread(threading.Thread):
'The length of sendDataQueues is now: ' + str(len(state.sendDataQueues)) + "\n" + \ 'The length of sendDataQueues is now: ' + str(len(state.sendDataQueues)) + "\n" + \
'broadcasting addr from within connectionFullyEstablished function.') '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. # Let all of our peers know about this new node.
dataToSend = (int(time.time()), self.streamNumber, 1, self.peer.host, self.remoteNodeIncomingPort) dataToSend = (int(time.time()), self.streamNumber, 1, self.peer.host, self.remoteNodeIncomingPort)
protocol.broadcastToSendDataQueues(( protocol.broadcastToSendDataQueues((

View File

@ -67,6 +67,14 @@ def encodeHost(host):
else: else:
return socket.inet_pton(socket.AF_INET6, host) 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 # checks
def haveSSL(server = False): def haveSSL(server = False):

View File

@ -10,8 +10,8 @@ extPort = None
# for Tor hidden service # for Tor hidden service
socksIP = None socksIP = None
# Network protocols last check failed # Network protocols availability, initialised below
networkProtocolLastFailed = {'IPv4': 0, 'IPv6': 0, 'onion': 0} networkProtocolAvailability = None
appdata = '' #holds the location of the application data storage directory 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 trustedPeer = None
Peer = collections.namedtuple('Peer', ['host', 'port']) Peer = collections.namedtuple('Peer', ['host', 'port'])
def resetNetworkProtocolAvailability():
global networkProtocolAvailability
networkProtocolAvailability = {'IPv4': None, 'IPv6': None, 'onion': None}
resetNetworkProtocolAvailability()