From ab458531e8db577941d5053d6bb0c700e50d60ed Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Thu, 19 Oct 2017 09:16:29 +0200 Subject: [PATCH] Changes in SOCKS and onion handling in connectionchooser - onion addresses have a priority of 1 when SOCKS is on - don't connect to private/loopback addresses when SOCKS is on --- src/network/connectionchooser.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/network/connectionchooser.py b/src/network/connectionchooser.py index ee2a8b40..819dfeb1 100644 --- a/src/network/connectionchooser.py +++ b/src/network/connectionchooser.py @@ -3,6 +3,7 @@ import random from bmconfigparser import BMConfigParser import knownnodes +import protocol from queues import portCheckerQueue import state @@ -38,8 +39,15 @@ def chooseConnection(stream): except TypeError: print "Error in %s" % (peer) rating = 0 - if haveOnion and peer.host.endswith('.onion') and rating > 0: - rating *= 10 + if haveOnion: + # onion addresses have a higher priority when SOCKS + if peer.host.endswith('.onion') and rating > 0: + rating = 1 + else: + encodedAddr = protocol.encodeHost(peer.host) + # don't connect to local IPs when using SOCKS + if not protocol.checkIPAddress(encodedAddr, False): + continue if rating > 1: rating = 1 try: