summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2014-03-13 14:15:31 -0300
committerTomás Touceda <chiiph@leap.se>2014-03-13 14:15:31 -0300
commitfa6ac24e679b0263efd2eb89ba53eeccd9ebb4d1 (patch)
tree5ddf4da7e0a7507cd8b747d2e38dc643a4aea6d6
parent614c090eaeeb96f709ca840069ca5425dfc8f4d3 (diff)
parentd724a65ca08d5b1c16da1f2ce3fd0b50bd519dec (diff)
Merge remote-tracking branch 'refs/remotes/ivan/feature/check-for-dns-resolution' into develop
-rw-r--r--changes/feature_check-for-dns-resolution1
-rw-r--r--src/leap/bitmask/gui/mainwindow.py52
2 files changed, 52 insertions, 1 deletions
diff --git a/changes/feature_check-for-dns-resolution b/changes/feature_check-for-dns-resolution
new file mode 100644
index 00000000..f0e2bf3e
--- /dev/null
+++ b/changes/feature_check-for-dns-resolution
@@ -0,0 +1 @@
+- After connecting EIP check for DNS resolution and warn the user on error. Closes #5301.
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