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.
This commit is contained in:
George McCandless 2020-12-07 22:54:44 +00:00
parent 9265235053
commit 7b168b7041
No known key found for this signature in database
GPG Key ID: 62B9F5A4802A74BD
3 changed files with 42 additions and 12 deletions

View File

@ -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(

View File

@ -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()

View File

@ -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()