From fdbafa4929cb9969e8f2ea3b256eb4bd9f99a7a7 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Fri, 6 Jun 2014 12:10:08 -0300 Subject: Move quit callback to mainwindow. --- src/leap/bitmask/gui/mainwindow.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src/leap/bitmask/gui/mainwindow.py') diff --git a/src/leap/bitmask/gui/mainwindow.py b/src/leap/bitmask/gui/mainwindow.py index c61b7dc9..71885a78 100644 --- a/src/leap/bitmask/gui/mainwindow.py +++ b/src/leap/bitmask/gui/mainwindow.py @@ -39,6 +39,7 @@ from leap.bitmask.gui.mail_status import MailStatusWidget from leap.bitmask.gui.preferenceswindow import PreferencesWindow from leap.bitmask.gui.systray import SysTray from leap.bitmask.gui.wizard import Wizard +from leap.bitmask.gui import twisted_main from leap.bitmask.platform_init import IS_WIN, IS_MAC, IS_LINUX from leap.bitmask.platform_init.initializers import init_platform @@ -91,14 +92,10 @@ class MainWindow(QtGui.QMainWindow): # We give the services some time to a halt before forcing quit. SERVICES_STOP_TIMEOUT = 20 - def __init__(self, quit_callback, bypass_checks=False, start_hidden=False): + def __init__(self, bypass_checks=False, start_hidden=False): """ Constructor for the client main window - :param quit_callback: Function to be called when closing - the application. - :type quit_callback: callable - :param bypass_checks: Set to true if the app should bypass first round of checks for CA certificates at bootstrap :type bypass_checks: bool @@ -117,7 +114,6 @@ class MainWindow(QtGui.QMainWindow): reqcbk=lambda req, resp: None) # make rpc call async # end register leap events #################################### - self._quit_callback = quit_callback self._updates_content = "" # setup UI @@ -1817,4 +1813,4 @@ class MainWindow(QtGui.QMainWindow): self._backend.stop() self.close() - reactor.callLater(1, self._quit_callback) + reactor.callLater(1, twisted_main.quit) -- cgit v1.2.3 From e2e79a5efcbd2f8047cc18968d827f8cb66570d1 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Mon, 9 Jun 2014 12:45:42 -0300 Subject: Move dns check to the backend. --- src/leap/bitmask/gui/mainwindow.py | 73 ++++++++++++-------------------------- 1 file changed, 22 insertions(+), 51 deletions(-) (limited to 'src/leap/bitmask/gui/mainwindow.py') diff --git a/src/leap/bitmask/gui/mainwindow.py b/src/leap/bitmask/gui/mainwindow.py index 885cb792..266158c5 100644 --- a/src/leap/bitmask/gui/mainwindow.py +++ b/src/leap/bitmask/gui/mainwindow.py @@ -18,12 +18,11 @@ Main window for Bitmask. """ import logging -import socket from datetime import datetime from PySide import QtCore, QtGui -from twisted.internet import reactor, threads +from twisted.internet import reactor from leap.bitmask import __version__ as VERSION from leap.bitmask import __version_hash__ as VERSION_HASH @@ -403,6 +402,8 @@ class MainWindow(QtGui.QMainWindow): sig.eip_can_start.connect(self._backend_can_start_eip) sig.eip_cannot_start.connect(self._backend_cannot_start_eip) + sig.eip_dns_error.connect(self._eip_dns_error) + # ================================================================== # Soledad signals @@ -1461,55 +1462,25 @@ class MainWindow(QtGui.QMainWindow): self._already_started_eip = True # check for connectivity - # we might want to leave a little time here... - self._check_name_resolution(domain) - - def _check_name_resolution(self, domain): - # FIXME this has to be moved to backend !!! - # Should move to netchecks module. - # and separate qt from reactor... - """ - 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_conductor.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) + self._backend.eip_check_dns(domain) + + @QtCore.Slot() + def _eip_dns_error(self): + """ + Trigger this if we don't have a working DNS resolver. + """ + domain = self._login_widget.get_selected_provider() + 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_conductor.eip_name) + + QtGui.QMessageBox.critical(self, self.tr("Connection Error"), msg) def _try_autostart_eip(self): """ -- cgit v1.2.3 From adf42939117ec0a303fd2e50881e3f5dd38ceb78 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Mon, 9 Jun 2014 17:53:06 -0300 Subject: Replace twisted's callLater with Qt's singleShot. Note: we use an alias for singleShot called QtDelayedCall. --- src/leap/bitmask/gui/mainwindow.py | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'src/leap/bitmask/gui/mainwindow.py') diff --git a/src/leap/bitmask/gui/mainwindow.py b/src/leap/bitmask/gui/mainwindow.py index 266158c5..03c29d0e 100644 --- a/src/leap/bitmask/gui/mainwindow.py +++ b/src/leap/bitmask/gui/mainwindow.py @@ -22,7 +22,6 @@ import logging from datetime import datetime from PySide import QtCore, QtGui -from twisted.internet import reactor from leap.bitmask import __version__ as VERSION from leap.bitmask import __version_hash__ as VERSION_HASH @@ -176,8 +175,8 @@ class MainWindow(QtGui.QMainWindow): # Set used to track the services being stopped and need wait. self._services_being_stopped = {} - # timeout object used to trigger quit - self._quit_timeout_callater = None + # used to know if we are in the final steps of quitting + self._finally_quitting = False self._backend_connected_signals = [] self._backend_connect() @@ -898,7 +897,7 @@ class MainWindow(QtGui.QMainWindow): self.tr('Hello!'), self.tr('Bitmask has started in the tray.')) # we wait for the systray to be ready - reactor.callLater(1, hello) + QtDelayedCall(1, hello) @QtCore.Slot(int) def _tray_activated(self, reason=None): @@ -1739,8 +1738,7 @@ class MainWindow(QtGui.QMainWindow): # call final quit when all the services are stopped self.all_services_stopped.connect(self.final_quit) # or if we reach the timeout - self._quit_timeout_callater = reactor.callLater( - self.SERVICES_STOP_TIMEOUT, self.final_quit) + QtDelayedCall(self.SERVICES_STOP_TIMEOUT, self.final_quit) @QtCore.Slot() def _remove_service(self, service): @@ -1766,16 +1764,13 @@ class MainWindow(QtGui.QMainWindow): """ logger.debug('Final quit...') - try: - # disconnect signal if we get here due a timeout. - self.all_services_stopped.disconnect(self.final_quit) - except RuntimeError: - pass # Signal was not connected + # We can reach here because all the services are stopped or because a + # timeout was triggered. Since we want to run this only once, we exit + # if this is called twice. + if self._finally_quitting: + return - # Cancel timeout to avoid being called if we reached here through the - # signal - if self._quit_timeout_callater.active(): - self._quit_timeout_callater.cancel() + self._finally_quitting = True # Remove lockfiles on a clean shutdown. logger.debug('Cleaning pidfiles') @@ -1785,4 +1780,4 @@ class MainWindow(QtGui.QMainWindow): self._backend.stop() self.close() - reactor.callLater(1, twisted_main.quit) + QtDelayedCall(1, twisted_main.quit) -- cgit v1.2.3 From 418621eba5739c4de2dabc91b0927e4f1a188dc9 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Wed, 18 Jun 2014 14:32:16 -0300 Subject: Move backend to its own namespace. --- src/leap/bitmask/gui/mainwindow.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/leap/bitmask/gui/mainwindow.py') diff --git a/src/leap/bitmask/gui/mainwindow.py b/src/leap/bitmask/gui/mainwindow.py index 03c29d0e..11b9acf1 100644 --- a/src/leap/bitmask/gui/mainwindow.py +++ b/src/leap/bitmask/gui/mainwindow.py @@ -42,7 +42,7 @@ from leap.bitmask.gui import twisted_main from leap.bitmask.platform_init import IS_WIN, IS_MAC, IS_LINUX from leap.bitmask.platform_init.initializers import init_platform -from leap.bitmask import backend +from leap.bitmask.backend import leapbackend from leap.bitmask.services.eip import conductor as eip_conductor from leap.bitmask.services.mail import conductor as mail_conductor @@ -118,7 +118,7 @@ class MainWindow(QtGui.QMainWindow): self.ui = Ui_MainWindow() self.ui.setupUi(self) self.menuBar().setNativeMenuBar(not IS_LINUX) - self._backend = backend.Backend(bypass_checks) + self._backend = leapbackend.Backend(bypass_checks) self._backend.start() self._settings = LeapSettings() -- cgit v1.2.3 From 243cb6a282085414188d351aca547965191a32a2 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Mon, 23 Jun 2014 14:41:14 -0300 Subject: Fix wait time. Use milliseconds instead of seconds. On the twisted_main.quit() we use 1/10 of a second since is enough wait. --- src/leap/bitmask/gui/mainwindow.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/leap/bitmask/gui/mainwindow.py') diff --git a/src/leap/bitmask/gui/mainwindow.py b/src/leap/bitmask/gui/mainwindow.py index 11b9acf1..5feaf610 100644 --- a/src/leap/bitmask/gui/mainwindow.py +++ b/src/leap/bitmask/gui/mainwindow.py @@ -88,7 +88,7 @@ class MainWindow(QtGui.QMainWindow): EIP_START_TIMEOUT = 60000 # in milliseconds # We give the services some time to a halt before forcing quit. - SERVICES_STOP_TIMEOUT = 20 + SERVICES_STOP_TIMEOUT = 20000 # in milliseconds def __init__(self, bypass_checks=False, start_hidden=False): """ @@ -897,7 +897,7 @@ class MainWindow(QtGui.QMainWindow): self.tr('Hello!'), self.tr('Bitmask has started in the tray.')) # we wait for the systray to be ready - QtDelayedCall(1, hello) + QtDelayedCall(1000, hello) @QtCore.Slot(int) def _tray_activated(self, reason=None): @@ -1780,4 +1780,4 @@ class MainWindow(QtGui.QMainWindow): self._backend.stop() self.close() - QtDelayedCall(1, twisted_main.quit) + QtDelayedCall(100, twisted_main.quit) -- cgit v1.2.3 From 4b52040da3750096b73fd3d5b790c2494ef18b0b Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Thu, 12 Jun 2014 15:11:25 -0300 Subject: Use a dict instead of an object to ease serialization. --- src/leap/bitmask/gui/mainwindow.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/leap/bitmask/gui/mainwindow.py') diff --git a/src/leap/bitmask/gui/mainwindow.py b/src/leap/bitmask/gui/mainwindow.py index 5feaf610..9e0e78bc 100644 --- a/src/leap/bitmask/gui/mainwindow.py +++ b/src/leap/bitmask/gui/mainwindow.py @@ -549,7 +549,7 @@ class MainWindow(QtGui.QMainWindow): details = self._provider_details mx_provided = False if details is not None: - mx_provided = MX_SERVICE in details.services + mx_provided = MX_SERVICE in details['services'] # XXX: handle differently not logged in user? akm = AdvancedKeyManagement(self, mx_provided, logged_user, @@ -569,7 +569,7 @@ class MainWindow(QtGui.QMainWindow): domain = self._login_widget.get_selected_provider() mx_provided = False if self._provider_details is not None: - mx_provided = MX_SERVICE in self._provider_details.services + mx_provided = MX_SERVICE in self._provider_details['services'] preferences = PreferencesWindow(self, user, domain, self._backend, self._soledad_started, mx_provided) @@ -1267,7 +1267,7 @@ class MainWindow(QtGui.QMainWindow): sig.soledad_bootstrap_failed.connect(lambda: btn_enabled(True)) sig.soledad_bootstrap_finished.connect(lambda: btn_enabled(True)) - if not MX_SERVICE in self._provider_details.services: + if not MX_SERVICE in self._provider_details['services']: self._set_mx_visible(False) def _start_eip_bootstrap(self): @@ -1310,7 +1310,7 @@ class MainWindow(QtGui.QMainWindow): Set the details for the just downloaded provider. :param details: the details of the provider. - :type details: ProviderConfigLight + :type details: dict """ self._provider_details = details @@ -1327,7 +1327,7 @@ class MainWindow(QtGui.QMainWindow): mx_enabled = MX_SERVICE in enabled_services mx_provided = False if self._provider_details is not None: - mx_provided = MX_SERVICE in self._provider_details.services + mx_provided = MX_SERVICE in self._provider_details['services'] return mx_enabled and mx_provided @@ -1344,7 +1344,7 @@ class MainWindow(QtGui.QMainWindow): eip_enabled = EIP_SERVICE in enabled_services eip_provided = False if self._provider_details is not None: - eip_provided = EIP_SERVICE in self._provider_details.services + eip_provided = EIP_SERVICE in self._provider_details['services'] return eip_enabled and eip_provided -- cgit v1.2.3 From 9689c961743c3ccecd54c8010ce5e2e5cf1ec940 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Thu, 26 Jun 2014 11:35:55 -0500 Subject: disable eip if helper files not installed --- src/leap/bitmask/gui/mainwindow.py | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'src/leap/bitmask/gui/mainwindow.py') diff --git a/src/leap/bitmask/gui/mainwindow.py b/src/leap/bitmask/gui/mainwindow.py index 9e0e78bc..53a7d95a 100644 --- a/src/leap/bitmask/gui/mainwindow.py +++ b/src/leap/bitmask/gui/mainwindow.py @@ -41,6 +41,7 @@ from leap.bitmask.gui import twisted_main from leap.bitmask.platform_init import IS_WIN, IS_MAC, IS_LINUX from leap.bitmask.platform_init.initializers import init_platform +from leap.bitmask.platform_init.initializers import init_signals from leap.bitmask.backend import leapbackend @@ -146,6 +147,9 @@ class MainWindow(QtGui.QMainWindow): self._settings, self._backend) self._eip_status = EIPStatusWidget(self, self._eip_conductor) + init_signals.eip_missing_helpers.connect( + self._disable_eip_missing_helpers) + self.ui.eipLayout.addWidget(self._eip_status) self._eip_conductor.add_eip_widget(self._eip_status) @@ -662,6 +666,16 @@ class MainWindow(QtGui.QMainWindow): self._eip_status.disable_eip_start() self._eip_status.set_eip_status(self.tr("Disabled")) + @QtCore.Slot() + def _disable_eip_missing_helpers(self): + """ + TRIGGERS: + init_signals.missing_helpers + + Set the missing_helpers flag, so we can disable EIP. + """ + self._eip_status.missing_helpers = True + @QtCore.Slot() def _show_eip_preferences(self): """ @@ -1509,7 +1523,13 @@ class MainWindow(QtGui.QMainWindow): else: should_start = self._provides_eip_and_enabled() - if should_start and not self._already_started_eip: + missing_helpers = self._eip_status.missing_helpers + already_started = self._already_started_eip + can_start = (should_start + and not already_started + and not missing_helpers) + + if can_start: if self._eip_status.is_cold_start: self._backend.tear_fw_down() # XXX this should be handled by the state machine. @@ -1529,12 +1549,16 @@ class MainWindow(QtGui.QMainWindow): else: if not self._already_started_eip: if EIP_SERVICE in self._enabled_services: - self._eip_status.set_eip_status( - self.tr("Not supported"), - error=True) + if missing_helpers: + msg = self.tr( + "Disabled: missing helper files") + else: + msg = self.tr("Not supported"), + self._eip_status.set_eip_status(msg, error=True) else: + msg = self.tr("Disabled") self._eip_status.disable_eip_start() - self._eip_status.set_eip_status(self.tr("Disabled")) + self._eip_status.set_eip_status(msg) # eip will not start, so we start soledad anyway self._maybe_run_soledad_setup_checks() -- cgit v1.2.3