@@ -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