Skip to content

Commit 1879717

Browse files
committed
bootstrap: Respect 'onlynet=onion' and, when a trusted peer is set, connect only to that trusted peer.
1 parent 229db60 commit 1879717

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/network/connectionpool.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ def __init__(self):
5151
BMConfigParser().safeGetInt(
5252
"bitmessagesettings", "maxuploadrate")
5353
)
54+
onionOnly_deprecated = BMConfigParser().safeGetBoolean(
55+
"bitmessagesettings", "onionservicesonly")
56+
onionOnly = BMConfigParser().safeGet(
57+
"bitmessagesettings", "onlynet") == "onion"
58+
59+
self.onionOnly = onionOnly or onionOnly_deprecated
5460
self.outboundConnections = {}
5561
self.inboundConnections = {}
5662
self.listeningSockets = {}
@@ -205,30 +211,40 @@ def startUDPSocket(self, bind=None):
205211

206212
def startBootstrappers(self):
207213
"""Run the process of resolving bootstrap hostnames"""
214+
onion_seed = 'quzwelsuziwqgpt2.onion' #FIXME onion bootstrap server is down
208215
proxy_type = BMConfigParser().safeGet(
209216
'bitmessagesettings', 'socksproxytype')
210217
# A plugins may be added here
211218
hostname = None
219+
port = 8444
220+
212221
if not proxy_type or proxy_type == 'none':
213222
connection_base = TCPConnection
214223
elif proxy_type == 'SOCKS5':
215224
connection_base = Socks5BMConnection
216-
hostname = helper_random.randomchoice([
217-
'quzwelsuziwqgpt2.onion', None
218-
])
219225
elif proxy_type == 'SOCKS4a':
220226
connection_base = Socks4aBMConnection # FIXME: I cannot test
221227
else:
222228
# This should never happen because socksproxytype setting
223229
# is handled in bitmessagemain before starting the connectionpool
224230
return
225231

226-
bootstrapper = bootstrap(connection_base)
227-
if not hostname:
232+
if self.trustedPeer is not None:
233+
hostname = self.trustedPeer.host
234+
port = self.trustedPeer.port
235+
elif proxy_type == "SOCKS5" or self.onionOnly:
236+
if self.onionOnly:
237+
hostname = onion_seed
238+
else:
239+
hostname = helper_random.randomchoice([
240+
onion_seed, None
241+
])
242+
243+
if hostname is None:
228244
port = helper_random.randomchoice([8080, 8444])
229245
hostname = 'bootstrap%s.bitmessage.org' % port
230-
else:
231-
port = 8444
246+
247+
bootstrapper = bootstrap(connection_base)
232248
self.addConnection(bootstrapper(hostname, port))
233249

234250
def loop(self): # pylint: disable=too-many-branches,too-many-statements

0 commit comments

Comments
 (0)