Commit 80f379ac authored by juga's avatar juga
Browse files

chg: stem, scanner: Change args initializing controller

to check whether the external control port configuration is set.
There is no need to assert all argument options nor to return the error.
parent 553f4a8f
......@@ -679,8 +679,7 @@ def run_speedtest(args, conf):
global rd, pool, controller
controller, _ = stem_utils.init_controller(
path=conf.getpath('tor', 'control_socket'))
controller = stem_utils.init_controller(conf)
if not controller:
controller = stem_utils.launch_tor(conf)
......@@ -60,27 +60,19 @@ def remove_event_listener(controller, func):
log.exception("Exception trying to remove event %s", e)
def init_controller(port=None, path=None, set_custom_stream_settings=True):
# NOTE: we do not currently support a control port even though the rest of
# this function will pretend like port could be set.
assert port is None
# make sure only one is set
assert port is not None or path is not None
assert not (port is not None and path is not None)
# and for the one that is set, make sure it is likely valid
assert port is None or isinstance(port, int)
assert path is None or isinstance(path, str)
def init_controller(conf):
c = None
if port:
c = _init_controller_port(port)
if not c:
return None, 'Unable to reach tor on control port'
# If the external control port is set, use it to initialize the controller.
control_port = conf['tor']['external_control_port']
if control_port:
control_port = int(control_port)
# If it can not connect, the program will exit here
c = _init_controller_port(control_port)
c = _init_controller_socket(path)
if not c:
return None, 'Unable to reach tor on control socket'
assert c is not None
return c, ''
c = _init_controller_socket(
socket=conf.getpath('tor', 'control_socket')
return c
def is_bootstrapped(c):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment