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

Commit ccddac6

Browse files
committed
Change tor config before is launched
to don't get error about options that can't be changed once it's launched.
1 parent 44d2dc1 commit ccddac6

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

bwscanner/attacher.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,30 +156,33 @@ def connect_to_tor(launch_tor, circuit_build_timeout, control_port=None,
156156
if tor_overrides:
157157
tor_options.update(tor_overrides)
158158

159+
tor_config = txtorcon.TorConfig()
160+
161+
# Update Tor config options from dictionary
162+
for key, value in tor_options.items():
163+
setattr(tor_config, key, value)
164+
159165
if launch_tor:
160166
log.info("Spawning a new Tor instance.")
161167
# TODO: Pass in data_dir directory so consensus can be cached
162-
tor = yield txtorcon.launch(reactor)
168+
# Launch tor with config, in order to don't get CONF_CHANGED when
169+
# updating options that can't be changed while tor is running.
170+
tor = yield txtorcon.launch(reactor, _tor_config=tor_config)
163171
else:
164172
log.info("Trying to connect to a running Tor instance.")
165173
if control_port:
166174
endpoint = endpoints.TCP4ClientEndpoint(reactor, "localhost", control_port)
167175
else:
168176
endpoint = None
169177
tor = yield txtorcon.connect(reactor, endpoint)
178+
# TODO: check whether CONF_CHANGED will happen here or not because
179+
# we get the state later
180+
tor.config = tor_config
181+
tor.config.save()
170182

171-
# Get Tor state first to avoid a race conditions where CONF_CHANGED
172-
# messages are received while Txtorcon is reading the consensus.
173-
tor_state = yield tor.create_state()
174-
175-
# Get current TorConfig object
176-
tor_config = yield tor.get_config()
177183
wait_for_consensus = options_need_new_consensus(tor_config, tor_options)
178184

179-
# Update Tor config options from dictionary
180-
for key, value in tor_options.items():
181-
setattr(tor_config, key, value)
182-
yield tor_config.save() # Send updated options to Tor
185+
tor_state = yield tor.create_state()
183186

184187
if wait_for_consensus:
185188
yield wait_for_newconsensus(tor_state)

0 commit comments

Comments
 (0)