Skip to content
This repository was archived by the owner on Mar 2, 2022. It is now read-only.

Commit 8c627db

Browse files
committed
Allow Tor options to be passed to connect_to_tor
1 parent 4b28cfd commit 8c627db

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

bwscanner/attacher.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ def add_single_port_exit(port):
150150

151151

152152
@defer.inlineCallbacks
153-
def connect_to_tor(launch_tor, circuit_build_timeout, control_port=9051):
153+
def connect_to_tor(launch_tor, circuit_build_timeout, control_port=None,
154+
tor_overrides=None):
154155
"""
155156
Launch or connect to a Tor instance
156157
@@ -167,16 +168,20 @@ def connect_to_tor(launch_tor, circuit_build_timeout, control_port=9051):
167168
'FetchDirInfoExtraEarly': 1,
168169
}
169170

171+
if tor_overrides:
172+
tor_options.update(tor_overrides)
173+
170174
if launch_tor:
171175
log.info("Spawning a new Tor instance.")
172176
# TODO: Pass in data_dir directory so consensus can be cached
173177
tor = yield txtorcon.launch(reactor)
174178
else:
175179
log.info("Trying to connect to a running Tor instance.")
176-
tor = yield txtorcon.connect(
177-
reactor,
178-
endpoints.TCP4ClientEndpoint(reactor, "localhost", control_port)
179-
)
180+
if control_port:
181+
endpoint = endpoints.TCP4ClientEndpoint(reactor, "localhost", control_port)
182+
else:
183+
endpoint = None
184+
tor = yield txtorcon.connect(reactor, endpoint)
180185

181186
# Get Tor state first to avoid a race conditions where CONF_CHANGED
182187
# messages are received while Txtorcon is reading the consensus.

test/template.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@ class TorTestCase(unittest.TestCase):
1414
def setUp(self):
1515
self.tor_state = yield connect_to_tor(
1616
launch_tor=False,
17+
control_port=int(os.environ.get('CHUTNEY_CONTROL_PORT')),
1718
circuit_build_timeout=30,
18-
control_port=int(os.environ.get('CHUTNEY_CONTROL_PORT')))
19+
# XXX: Avoid switching to regular descriptors in tests.
20+
# There is a race condition where the tests can
21+
# start running while the new consensus is still
22+
# being fetched and loaded by Txtorcon.
23+
#
24+
# We should find a solution for this race.
25+
tor_overrides={'UseMicroDescriptors': 1},
26+
)
1927

2028
self.attacher = SOCKSClientStreamAttacher(self.tor_state)
2129
yield self.tor_state.set_attacher(self.attacher, reactor)

0 commit comments

Comments
 (0)