From 7b168b7041bdbd82609af6a316ed73362e5ff7b4 Mon Sep 17 00:00:00 2001 From: George McCandless <5fk7echy8@riseup.net> Date: Mon, 7 Dec 2020 22:54:44 +0000 Subject: [PATCH] Closes #1538. Changes 'onionservicesonly=true' to 'onlynet=onion'. Old-style 'onionservicesonly' is deprecated but still accepted. The configuration option will be upgraded upon the first GUI settings update. --- src/bitmessageqt/settings.py | 21 ++++++++++++++++++--- src/network/connectionchooser.py | 5 ++++- src/tests/core.py | 28 ++++++++++++++++++++-------- 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src/bitmessageqt/settings.py b/src/bitmessageqt/settings.py index f1c1a11f..6c3eee27 100644 --- a/src/bitmessageqt/settings.py +++ b/src/bitmessageqt/settings.py @@ -358,6 +358,11 @@ class SettingsDialog(QtGui.QDialog): if proxytype_index > 2: # last literal proxytype in ui start_proxyconfig() + onionOnly_deprecated = BMConfigParser().safeGetBoolean( + "bitmessagesettings", "onionservicesonly") + onionOnly = BMConfigParser().safeGet( + "bitmessagesettings", "onlynet") == "onion" + onionOnly = onionOnly or onionOnly_deprecated self.config.set('bitmessagesettings', 'socksauthentication', str( self.checkBoxAuthentication.isChecked())) self.config.set('bitmessagesettings', 'sockshostname', str( @@ -371,10 +376,20 @@ class SettingsDialog(QtGui.QDialog): self.config.set('bitmessagesettings', 'sockslisten', str( self.checkBoxSocksListen.isChecked())) if self.checkBoxOnionOnly.isChecked() \ - and not self.config.safeGetBoolean('bitmessagesettings', 'onionservicesonly'): + and not onionOnly: self.net_restart_needed = True - self.config.set('bitmessagesettings', 'onionservicesonly', str( - self.checkBoxOnionOnly.isChecked())) + if self.checkBoxOnionOnly.isChecked(): + self.config.set('bitmessagesettings', 'onlynet', 'onion') + else: + try: + return self.config.remove_option('bitmessagesettings', 'onlynet') + except ConfigParser.NoOptionError: + pass + # Remove deprecated onionservicesonly option if it exists: + try: + return self.config.remove_option('bitmessagesettings', 'onionservicesonly') + except ConfigParser.NoOptionError: + pass try: # Rounding to integers just for aesthetics self.config.set('bitmessagesettings', 'maxdownloadrate', str( diff --git a/src/network/connectionchooser.py b/src/network/connectionchooser.py index badd98b7..c3a11616 100644 --- a/src/network/connectionchooser.py +++ b/src/network/connectionchooser.py @@ -31,8 +31,11 @@ def chooseConnection(stream): """Returns an appropriate connection""" haveOnion = BMConfigParser().safeGet( "bitmessagesettings", "socksproxytype")[0:5] == 'SOCKS' - onionOnly = BMConfigParser().safeGetBoolean( + onionOnly_deprecated = BMConfigParser().safeGetBoolean( "bitmessagesettings", "onionservicesonly") + onionOnly = BMConfigParser().safeGet( + "bitmessagesettings", "onlynet") == "onion" + onionOnly = onionOnly or onionOnly_deprecated try: retval = portCheckerQueue.get(False) portCheckerQueue.task_done() diff --git a/src/tests/core.py b/src/tests/core.py index 3d8ac983..711e0e1a 100644 --- a/src/tests/core.py +++ b/src/tests/core.py @@ -194,14 +194,7 @@ class TestCore(unittest.TestCase): start_proxyconfig() self._check_bootstrap() - @unittest.skipUnless(stem_version, 'No stem, skipping tor dependent test') - def test_onionservicesonly(self): # this should start after bootstrap - """ - set onionservicesonly, wait for 3 connections and check them all - are onions - """ - BMConfigParser().set('bitmessagesettings', 'socksproxytype', 'SOCKS5') - BMConfigParser().set('bitmessagesettings', 'onionservicesonly', 'true') + def _check_exclusively_onion_networking(self): self._initiate_bootstrap() BMConfigParser().remove_option('bitmessagesettings', 'dontconnect') for _ in range(360): @@ -218,6 +211,25 @@ class TestCore(unittest.TestCase): % peer.host) self.fail('Failed to connect to at least 3 nodes within 360 sec') + @unittest.skipUnless(stem_version, 'No stem, skipping tor dependent test') + def test_onionservicesonly(self): # this should start after bootstrap + """ + set onionservicesonly (deprecated), wait for 3 connections and check + that all are onions + """ + BMConfigParser().set('bitmessagesettings', 'socksproxytype', 'SOCKS5') + BMConfigParser().set('bitmessagesettings', 'onionservicesonly', 'true') + self._check_exclusively_onion_networking() + + @unittest.skipUnless(stem_version, 'No stem, skipping tor dependent test') + def test_onlynetonion(self): # this should start after bootstrap + """ + set onlynet=onion, wait for 3 connections and check that all are onions + """ + BMConfigParser().set('bitmessagesettings', 'socksproxytype', 'SOCKS5') + BMConfigParser().set('bitmessagesettings', 'onlynet', 'onion') + self._check_exclusively_onion_networking() + @staticmethod def _decode_msg(data, pattern): proto = BMProto()