diff options
author | Ivan Alejandro <ivanalejandro0@gmail.com> | 2014-03-10 17:29:52 -0300 |
---|---|---|
committer | Ivan Alejandro <ivanalejandro0@gmail.com> | 2014-03-13 13:22:14 -0300 |
commit | d724a65ca08d5b1c16da1f2ce3fd0b50bd519dec (patch) | |
tree | 5ddf4da7e0a7507cd8b747d2e38dc643a4aea6d6 /src/leap | |
parent | 614c090eaeeb96f709ca840069ca5425dfc8f4d3 (diff) |
Check for DNS resolution after connecting EIP.
[Closes #5301]
Diffstat (limited to 'src/leap')
-rw-r--r-- | src/leap/bitmask/gui/mainwindow.py | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/src/leap/bitmask/gui/mainwindow.py b/src/leap/bitmask/gui/mainwindow.py index 7cec4831..758bff4e 100644 --- a/src/leap/bitmask/gui/mainwindow.py +++ b/src/leap/bitmask/gui/mainwindow.py @@ -18,13 +18,14 @@ Main window for Bitmask. """ import logging +import socket from threading import Condition from datetime import datetime from PySide import QtCore, QtGui from zope.proxy import ProxyBase, setProxiedObject -from twisted.internet import threads +from twisted.internet import reactor, threads from twisted.internet.defer import CancelledError from leap.bitmask import __version__ as VERSION @@ -1456,6 +1457,55 @@ class MainWindow(QtGui.QMainWindow): """ self._eip_connection.qtsigs.connected_signal.emit() + # check for connectivity + provider_config = self._get_best_provider_config() + domain = provider_config.get_domain() + self._check_name_resolution(domain) + + def _check_name_resolution(self, domain): + """ + Check if we can resolve the given domain name. + + :param domain: the domain to check. + :type domain: str + """ + def do_check(): + """ + Try to resolve the domain name. + """ + socket.gethostbyname(domain.encode('idna')) + + def check_err(failure): + """ + Errback handler for `do_check`. + + :param failure: the failure that triggered the errback. + :type failure: twisted.python.failure.Failure + """ + logger.error(repr(failure)) + logger.error("Can't resolve hostname.") + + msg = self.tr( + "The server at {0} can't be found, because the DNS lookup " + "failed. DNS is the network service that translates a " + "website's name to its Internet address. Either your computer " + "is having trouble connecting to the network, or you are " + "missing some helper files that are needed to securely use " + "DNS while {1} is active. To install these helper files, quit " + "this application and start it again." + ).format(domain, self._eip_name) + + show_err = lambda: QtGui.QMessageBox.critical( + self, self.tr("Connection Error"), msg) + reactor.callLater(0, show_err) + + # python 2.7.4 raises socket.error + # python 2.7.5 raises socket.gaierror + failure.trap(socket.gaierror, socket.error) + + d = threads.deferToThread(do_check) + d.addErrback(check_err) + def _try_autostart_eip(self): """ Tries to autostart EIP |