Skip to content

Commit 229db60

Browse files
committed
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.
1 parent 9265235 commit 229db60

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed

src/bitmessageqt/settings.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,11 @@ def accept(self):
358358
if proxytype_index > 2: # last literal proxytype in ui
359359
start_proxyconfig()
360360

361+
onionOnly_deprecated = BMConfigParser().safeGetBoolean(
362+
"bitmessagesettings", "onionservicesonly")
363+
onionOnly = BMConfigParser().safeGet(
364+
"bitmessagesettings", "onlynet") == "onion"
365+
onionOnly = onionOnly or onionOnly_deprecated
361366
self.config.set('bitmessagesettings', 'socksauthentication', str(
362367
self.checkBoxAuthentication.isChecked()))
363368
self.config.set('bitmessagesettings', 'sockshostname', str(
@@ -371,10 +376,20 @@ def accept(self):
371376
self.config.set('bitmessagesettings', 'sockslisten', str(
372377
self.checkBoxSocksListen.isChecked()))
373378
if self.checkBoxOnionOnly.isChecked() \
374-
and not self.config.safeGetBoolean('bitmessagesettings', 'onionservicesonly'):
379+
and not onionOnly:
375380
self.net_restart_needed = True
376-
self.config.set('bitmessagesettings', 'onionservicesonly', str(
377-
self.checkBoxOnionOnly.isChecked()))
381+
if self.checkBoxOnionOnly.isChecked():
382+
self.config.set('bitmessagesettings', 'onlynet', 'onion')
383+
else:
384+
try:
385+
return self.config.remove_option('bitmessagesettings', 'onlynet')
386+
except ConfigParser.NoOptionError:
387+
pass
388+
#remove deprecated onionservicesonly option if it exists:
389+
try:
390+
return self.config.remove_option('bitmessagesettings', 'onionservicesonly')
391+
except ConfigParser.NoOptionError:
392+
pass
378393
try:
379394
# Rounding to integers just for aesthetics
380395
self.config.set('bitmessagesettings', 'maxdownloadrate', str(

src/network/connectionchooser.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ def chooseConnection(stream):
3131
"""Returns an appropriate connection"""
3232
haveOnion = BMConfigParser().safeGet(
3333
"bitmessagesettings", "socksproxytype")[0:5] == 'SOCKS'
34-
onionOnly = BMConfigParser().safeGetBoolean(
34+
onionOnly_deprecated = BMConfigParser().safeGetBoolean(
3535
"bitmessagesettings", "onionservicesonly")
36+
onionOnly = BMConfigParser().safeGet(
37+
"bitmessagesettings", "onlynet") == "onion"
38+
onionOnly = onionOnly or onionOnly_deprecated
3639
try:
3740
retval = portCheckerQueue.get(False)
3841
portCheckerQueue.task_done()

src/tests/core.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,7 @@ def test_bootstrap_tor(self):
194194
start_proxyconfig()
195195
self._check_bootstrap()
196196

197-
@unittest.skipUnless(stem_version, 'No stem, skipping tor dependent test')
198-
def test_onionservicesonly(self): # this should start after bootstrap
199-
"""
200-
set onionservicesonly, wait for 3 connections and check them all
201-
are onions
202-
"""
203-
BMConfigParser().set('bitmessagesettings', 'socksproxytype', 'SOCKS5')
204-
BMConfigParser().set('bitmessagesettings', 'onionservicesonly', 'true')
197+
def _check_exclusively_onion_networking(self):
205198
self._initiate_bootstrap()
206199
BMConfigParser().remove_option('bitmessagesettings', 'dontconnect')
207200
for _ in range(360):
@@ -218,6 +211,25 @@ def test_onionservicesonly(self): # this should start after bootstrap
218211
% peer.host)
219212
self.fail('Failed to connect to at least 3 nodes within 360 sec')
220213

214+
@unittest.skipUnless(stem_version, 'No stem, skipping tor dependent test')
215+
def test_onionservicesonly(self): # this should start after bootstrap
216+
"""
217+
set onionservicesonly (deprecated), wait for 3 connections and check
218+
that all are onions
219+
"""
220+
BMConfigParser().set('bitmessagesettings', 'socksproxytype', 'SOCKS5')
221+
BMConfigParser().set('bitmessagesettings', 'onionservicesonly', 'true')
222+
self._check_exclusively_onion_networking()
223+
224+
@unittest.skipUnless(stem_version, 'No stem, skipping tor dependent test')
225+
def test_onlynetonion(self): # this should start after bootstrap
226+
"""
227+
set onlynet=onion, wait for 3 connections and check that all are onions
228+
"""
229+
BMConfigParser().set('bitmessagesettings', 'socksproxytype', 'SOCKS5')
230+
BMConfigParser().set('bitmessagesettings', 'onlynet', 'onion')
231+
self._check_exclusively_onion_networking()
232+
221233
@staticmethod
222234
def _decode_msg(data, pattern):
223235
proto = BMProto()

0 commit comments

Comments
 (0)