From 80c0262f9a9348f4ea4f3f6d2e3c313d00b0a6de Mon Sep 17 00:00:00 2001 From: juga0 Date: Tue, 6 Feb 2018 20:08:47 +0000 Subject: [PATCH 1/2] Change tor config before is launched to don't get error about options that can't be changed once it's launched. --- bwscanner/attacher.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/bwscanner/attacher.py b/bwscanner/attacher.py index 798df59..20cc02c 100644 --- a/bwscanner/attacher.py +++ b/bwscanner/attacher.py @@ -54,9 +54,16 @@ def connect_to_tor(launch_tor, circuit_build_timeout, tor_dir=None, control_port if tor_overrides: tor_options.update(tor_overrides) + tor_config = txtorcon.TorConfig() + + # Update Tor config options from dictionary + for key, value in tor_options.items(): + setattr(tor_config, key, value) + if launch_tor: log.info("Spawning a new Tor instance.") - tor = yield txtorcon.launch(reactor, data_directory=tor_dir) + tor = yield txtorcon.launch(reactor, data_directory=tor_dir, + _tor_config=tor_config) else: log.info("Trying to connect to a running Tor instance.") if control_port: @@ -64,19 +71,14 @@ def connect_to_tor(launch_tor, circuit_build_timeout, tor_dir=None, control_port else: endpoint = None tor = yield txtorcon.connect(reactor, endpoint) + # TODO: check whether CONF_CHANGED will happen here or not because + # we get the state later + tor.config = tor_config + tor.config.save() - # Get Tor state first to avoid a race conditions where CONF_CHANGED - # messages are received while Txtorcon is reading the consensus. - tor_state = yield tor.create_state() - - # Get current TorConfig object - tor_config = yield tor.get_config() wait_for_consensus = options_need_new_consensus(tor_config, tor_options) - # Update Tor config options from dictionary - for key, value in tor_options.items(): - setattr(tor_config, key, value) - yield tor_config.save() # Send updated options to Tor + tor_state = yield tor.create_state() if wait_for_consensus: yield wait_for_newconsensus(tor_state) From b9ad1a510d9746496a196c17aad02d6c815129f7 Mon Sep 17 00:00:00 2001 From: juga0 Date: Thu, 22 Mar 2018 15:24:52 +0000 Subject: [PATCH 2/2] Get tor config and update it when connecting to tor --- bwscanner/attacher.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/bwscanner/attacher.py b/bwscanner/attacher.py index 20cc02c..8fda574 100644 --- a/bwscanner/attacher.py +++ b/bwscanner/attacher.py @@ -54,14 +54,15 @@ def connect_to_tor(launch_tor, circuit_build_timeout, tor_dir=None, control_port if tor_overrides: tor_options.update(tor_overrides) - tor_config = txtorcon.TorConfig() - - # Update Tor config options from dictionary - for key, value in tor_options.items(): - setattr(tor_config, key, value) - if launch_tor: log.info("Spawning a new Tor instance.") + # Create new TorConfig object + tor_config = txtorcon.TorConfig() + # Update tor config options from dictionary + for key, value in tor_options.items(): + setattr(tor_config, key, value) + # Launch tor with config, in order to don't get CONF_CHANGED when + # updating options that can't be changed while tor is running. tor = yield txtorcon.launch(reactor, data_directory=tor_dir, _tor_config=tor_config) else: @@ -71,10 +72,16 @@ def connect_to_tor(launch_tor, circuit_build_timeout, tor_dir=None, control_port else: endpoint = None tor = yield txtorcon.connect(reactor, endpoint) + # Get current tor config and update it with our options # TODO: check whether CONF_CHANGED will happen here or not because - # we get the state later - tor.config = tor_config - tor.config.save() + # FIXME: check that this is the recommended way to change config for + # a running tor, and whether the following is also possible + # tor._config = tor_config + # tor._config.save() + tor_config = yield tor.get_config() + for key, value in tor_options.items(): + setattr(tor_config, key, value) + yield tor_config.save() # Send updated options to Tor wait_for_consensus = options_need_new_consensus(tor_config, tor_options)