tor: add comments, let it pick its own control port

This commit is contained in:
Brian Warner 2016-03-24 08:29:23 -07:00
parent 618706681a
commit 589226f076

View File

@ -93,6 +93,8 @@ class TorManager:
_start_unix = self._timing.add_event("tor unix") _start_unix = self._timing.add_event("tor unix")
try: try:
connection = (self._reactor, "/var/run/tor/control") connection = (self._reactor, "/var/run/tor/control")
# add build_state=False to get back a Protocol object instead
# of a State object
state = yield txtorcon.build_tor_connection(connection) state = yield txtorcon.build_tor_connection(connection)
self._tor_protocol = state.protocol self._tor_protocol = state.protocol
except (ValueError, ConnectError): except (ValueError, ConnectError):
@ -125,8 +127,8 @@ class TorManager:
datadir = tempfile.mkdtemp() datadir = tempfile.mkdtemp()
config.DataDirectory = datadir config.DataDirectory = datadir
config.ControlPort = allocate_tcp_port() # defaults to 9052 #config.ControlPort = allocate_tcp_port() # defaults to 9052
print("setting config.ControlPort to", config.ControlPort) #print("setting config.ControlPort to", config.ControlPort)
config.SocksPort = allocate_tcp_port() config.SocksPort = allocate_tcp_port()
self._tor_socks_port = config.SocksPort self._tor_socks_port = config.SocksPort
print("setting config.SocksPort to", config.SocksPort) print("setting config.SocksPort to", config.SocksPort)
@ -152,7 +154,7 @@ class TorManager:
except ValueError: except ValueError:
return False # non-numeric, let Tor try it return False # non-numeric, let Tor try it
if a.version != 4: if a.version != 4:
return True # IPv6 gets ignoredn return True # IPv6 gets ignored
if (a.is_loopback or a.is_multicast or a.is_private or a.is_reserved if (a.is_loopback or a.is_multicast or a.is_private or a.is_reserved
or a.is_unspecified): or a.is_unspecified):
return True # too weird, don't connect return True # too weird, don't connect