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

Commit d2db0c4

Browse files
aagbsnDonnchaC
authored andcommitted
Wait for a NEWCONSENSUS after set_conf
Thanks to meejah for the example code. TODO: refactor to only do this if we need to (apparently when toggling UseMicroDescriptors)
1 parent fac2166 commit d2db0c4

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

bwscanner/attacher.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,24 @@ def launch_and_get_state(ignore):
134134
return get_random_tor_ports().addCallback(launch_and_get_state)
135135

136136

137+
def update_tor_config(tor, config):
138+
"""
139+
Update the Tor config from a dict of config key: value pairs.
140+
"""
141+
config_pairs = [(key, value) for key, value in config.items()]
142+
d = tor.protocol.set_conf(*itertools.chain.from_iterable(config_pairs))
143+
#XXX Only follow this path if we are changing config options that
144+
# require a wait for NEWCONSENSUS
145+
def wait_for_newconsensus(_):
146+
got_consensus = defer.Deferred()
147+
def got_newconsensus(evt):
148+
got_consensus.callback(tor)
149+
tor.protocol.remove_event_listener('NEWCONSENSUS', got_newconsensus)
150+
tor.protocol.add_event_listener('NEWCONSENSUS', got_newconsensus)
151+
return got_consensus
152+
return d.addCallback(wait_for_newconsensus)
153+
154+
137155
def setconf_singleport_exit(tor):
138156
port = available_tcp_port(reactor)
139157

0 commit comments

Comments
 (0)