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 untrusted user: 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)."))
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()))

View File

@ -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))

View File

@ -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((

View File

@ -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):

View File

@ -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()