1- import sys
2-
1+ import txtorcon
32from twisted .internet import defer , reactor , endpoints
43from txtorcon .interface import CircuitListenerMixin , IStreamAttacher , StreamListenerMixin
5- import txtorcon
6- from txtorcon import TorState , launch_tor
7- from txtorcon .util import available_tcp_port
84from zope .interface import implementer
95
106from bwscanner .logger import log
@@ -112,28 +108,6 @@ def stream_closed(self, *args, **kw):
112108 self .circ .close (ifUnused = True )
113109
114110
115- def start_tor (config ):
116- """
117- Launches tor with random TCP ports chosen for SocksPort and ControlPort,
118- and other options specified by a txtorcon.torconfig.TorConfig instance.
119-
120- Returns a deferred that calls back with a txtorcon.torstate.TorState
121- instance.
122- """
123- def get_random_tor_ports ():
124- d2 = available_tcp_port (reactor )
125- d2 .addCallback (lambda port : config .__setattr__ ('SocksPort' , port ))
126- d2 .addCallback (lambda _ : available_tcp_port (reactor ))
127- d2 .addCallback (lambda port : config .__setattr__ ('ControlPort' , port ))
128- return d2
129-
130- def launch_and_get_state (ignore ):
131- d2 = launch_tor (config , reactor , stdout = sys .stdout )
132- d2 .addCallback (lambda tpp : TorState (tpp .tor_protocol ).post_bootstrap )
133- return d2
134- return get_random_tor_ports ().addCallback (launch_and_get_state )
135-
136-
137111def options_need_new_consensus (tor_config , new_options ):
138112 """
139113 Check if we need to wait for a new consensus after updating
@@ -160,21 +134,6 @@ def got_newconsensus(event):
160134 return got_consensus
161135
162136
163- def setconf_singleport_exit (tor ):
164- port = available_tcp_port (reactor )
165-
166- def add_single_port_exit (port ):
167- tor .protocol .set_conf ('PublishServerDescriptor' , '0' ,
168- 'PortForwarding' , '1' ,
169- 'AssumeReachable' , '1' ,
170- 'ClientRejectInternalAddresses' , '0' ,
171- 'OrPort' , 'auto' ,
172- 'ExitPolicyRejectPrivate' , '0' ,
173- 'ExitPolicy' , 'accept 127.0.0.1:{}, reject *:*' .format (port ))
174- return port .addCallback (add_single_port_exit ).addCallback (
175- lambda ign : tor .routers [tor .protocol .get_info ("fingerprint" )])
176-
177-
178137@defer .inlineCallbacks
179138def connect_to_tor (launch_tor , circuit_build_timeout , control_port = None ,
180139 tor_overrides = None ):
0 commit comments