[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [sbws/maint-1.1] chg: stem, scanner: Change args initializing controller
commit 80f379ac5f12078ca358d7645beee5f4278acd95
Author: juga0 <juga@xxxxxxxxxx>
Date: Wed Dec 16 15:39:31 2020 +0000
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.
---
sbws/core/scanner.py | 3 +--
sbws/util/stem.py | 30 +++++++++++-------------------
2 files changed, 12 insertions(+), 21 deletions(-)
diff --git a/sbws/core/scanner.py b/sbws/core/scanner.py
index 5e6cac3..bcbeb47 100644
--- a/sbws/core/scanner.py
+++ b/sbws/core/scanner.py
@@ -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)
else:
diff --git a/sbws/util/stem.py b/sbws/util/stem.py
index 746fa88..169acda 100644
--- a/sbws/util/stem.py
+++ b/sbws/util/stem.py
@@ -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)
else:
- 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):
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits