[Pkg-privacy-commits] [onionshare] 148/256: Make UpdateChecker use signals and slots to communicate tor status messages. And make the latest version http request differentiate between automatic requests and forced requests

Ulrike Uhlig ulrike at moszumanska.debian.org
Fri May 26 12:53:30 UTC 2017


This is an automated email from the git hooks/post-receive script.

ulrike pushed a commit to branch master
in repository onionshare.

commit da70c71d8a593f765df0251c40b5844454ee6aa8
Author: Micah Lee <micah at micahflee.com>
Date:   Mon Apr 17 13:03:16 2017 -0700

    Make UpdateChecker use signals and slots to communicate tor status messages. And make the latest version http request differentiate between automatic requests and forced requests
---
 onionshare_gui/settings_dialog.py | 20 +++++++++-----------
 onionshare_gui/update_checker.py  | 36 +++++++++++++++++++++++++++---------
 2 files changed, 36 insertions(+), 20 deletions(-)

diff --git a/onionshare_gui/settings_dialog.py b/onionshare_gui/settings_dialog.py
index 1b1e2bf..b5ae4f4 100644
--- a/onionshare_gui/settings_dialog.py
+++ b/onionshare_gui/settings_dialog.py
@@ -347,7 +347,7 @@ class SettingsDialog(QtWidgets.QDialog):
             if settings.get('connection_type') == 'bundled':
                 self.tor_status.show()
                 self._disable_buttons()
-                bundled_tor_func = self._bundled_tor_func
+                bundled_tor_func = self._tor_status_update
             else:
                 bundled_tor_func = None
 
@@ -372,14 +372,6 @@ class SettingsDialog(QtWidgets.QDialog):
         settings = Settings()
         settings.load()
 
-        # Show Tor connection status if connection type is bundled tor
-        if settings.get('connection_type') == 'bundled':
-            self.tor_status.show()
-            self._disable_buttons()
-            bundled_tor_func = self._bundled_tor_func
-        else:
-            bundled_tor_func = None
-
         # Check for updates
         def update_available(update_url, installed_version, latest_version):
             Alert(strings._("update_available", True).format(update_url, installed_version, latest_version))
@@ -390,8 +382,14 @@ class SettingsDialog(QtWidgets.QDialog):
         u.update_available.connect(update_available)
         u.update_not_available.connect(update_not_available)
 
+        # Show Tor connection status if connection type is bundled tor
+        if settings.get('connection_type') == 'bundled':
+            self.tor_status.show()
+            self._disable_buttons()
+            u.tor_status_update.connect(self._tor_status_update)
+
         try:
-            u.check(force=True, bundled_tor_func=bundled_tor_func)
+            u.check(force=True)
         except UpdateCheckerTorError:
             Alert(strings._('update_error_tor', True), QtWidgets.QMessageBox.Warning)
         except UpdateCheckerSOCKSHTTPError:
@@ -466,7 +464,7 @@ class SettingsDialog(QtWidgets.QDialog):
             last_checked = strings._('gui_settings_autoupdate_timestamp_never', True)
         self.autoupdate_timestamp.setText(strings._('gui_settings_autoupdate_timestamp', True).format(last_checked))
 
-    def _bundled_tor_func(self, message):
+    def _tor_status_update(self, message):
         self.tor_status.setText('<strong>{}</strong><br>{}'.format(strings._('connecting_to_tor', True), message))
         self.qtapp.processEvents()
         if 'Done' in message:
diff --git a/onionshare_gui/update_checker.py b/onionshare_gui/update_checker.py
index 16a0f44..0511ada 100644
--- a/onionshare_gui/update_checker.py
+++ b/onionshare_gui/update_checker.py
@@ -56,17 +56,23 @@ class UpdateChecker(QtCore.QObject):
     """
     update_available = QtCore.pyqtSignal(str, str, str)
     update_not_available = QtCore.pyqtSignal()
+    tor_status_update = QtCore.pyqtSignal(str)
 
     def __init__(self):
         super(UpdateChecker, self).__init__()
 
-    def check(self, force=False, bundled_tor_func=None):
+    def check(self, force=False):
         # Load the settings
         settings = Settings()
         settings.load()
 
-        # See if it's been 1 day since the last check, and if so set force to True
-        if not force:
+        # If force=True, then definitely check
+        if force:
+            check_for_updates = True
+        else:
+            check_for_updates = False
+
+            # See if it's been 1 day since the last check
             autoupdate_timestamp = settings.get('autoupdate_timestamp')
             if autoupdate_timestamp:
                 last_checked = datetime.datetime.fromtimestamp(autoupdate_timestamp)
@@ -74,20 +80,29 @@ class UpdateChecker(QtCore.QObject):
 
                 one_day = datetime.timedelta(days=1)
                 if now - last_checked > one_day:
-                    force = True
+                    check_for_updates = True
             else:
-                force = True
+                check_for_updates = True
 
         # Check for updates
-        if force:
+        if check_for_updates:
             # Create an Onion object, for checking for updates over tor
             try:
-                onion = Onion(settings=settings, bundled_tor_func=bundled_tor_func)
+                onion = Onion(settings=settings, bundled_tor_func=self._bundled_tor_func)
             except:
                 raise UpdateCheckerTorError
 
             # Download the latest-version file over Tor
             try:
+                # User agent string includes OnionShare version and platform
+                user_agent = 'OnionShare {}, {}'.format(helpers.get_version(), platform.system())
+
+                # If the update is forced, add '?force=1' to the URL, to more
+                # accurately measure daily users
+                path = '/latest-version.txt'
+                if force:
+                    path += '?force=1'
+
                 (socks_address, socks_port) = onion.get_tor_socks_port()
                 socks.set_default_proxy(socks.SOCKS5, socks_address, socks_port)
 
@@ -95,9 +110,9 @@ class UpdateChecker(QtCore.QObject):
                 s.settimeout(15) # 15 second timeout
                 s.connect(('elx57ue5uyfplgva.onion', 80))
 
-                http_request = 'GET /latest-version.txt HTTP/1.0\r\n'
+                http_request = 'GET {} HTTP/1.0\r\n'.format(path)
                 http_request += 'Host: elx57ue5uyfplgva.onion\r\n'
-                http_request += 'User-Agent: OnionShare {}, {}\r\n'.format(helpers.get_version(), platform.system())
+                http_request += 'User-Agent: {}\r\n'.format(user_agent)
                 http_request += '\r\n'
                 s.sendall(http_request.encode('utf-8'))
 
@@ -130,6 +145,9 @@ class UpdateChecker(QtCore.QObject):
             # No updates are available
             self.update_not_available.emit()
 
+    def _bundled_tor_func(self, message):
+        self.tor_status_update.emit(message)
+
 class UpdateThread(QtCore.QThread):
     def __init__(self):
         super(UpdateThread, self).__init__()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/onionshare.git



More information about the Pkg-privacy-commits mailing list