commit ab127347de4e42127c39123f4a8d947310294d76 Author: Ana Custura ana@netstat.org.uk Date: Sat May 30 02:04:22 2020 +0100
Simplifies measurement function parameters
Signed-off-by: Philipp Winter phw@nymity.ch --- onionperf/measurement.py | 18 +++++++++--------- onionperf/onionperf | 3 ++- 2 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/onionperf/measurement.py b/onionperf/measurement.py index cffcae1..a2fca69 100644 --- a/onionperf/measurement.py +++ b/onionperf/measurement.py @@ -161,7 +161,7 @@ def logrotate_thread_task(writables, tgen_writable, torctl_writable, docroot, ni
class Measurement(object):
- def __init__(self, tor_bin_path, tgen_bin_path, datadir_path, privatedir_path, nickname, oneshot, additional_client_conf=None, torclient_conf_file=None, torserver_conf_file=None): + def __init__(self, tor_bin_path, tgen_bin_path, datadir_path, privatedir_path, nickname, oneshot, additional_client_conf=None, torclient_conf_file=None, torserver_conf_file=None, single_onion=False): self.tor_bin_path = tor_bin_path self.tgen_bin_path = tgen_bin_path self.datadir_path = datadir_path @@ -176,8 +176,9 @@ class Measurement(object): self.additional_client_conf = additional_client_conf self.torclient_conf_file = torclient_conf_file self.torserver_conf_file = torserver_conf_file + self.single_onion = single_onion
- def run(self, do_onion=True, do_inet=True, single_onion=False, client_tgen_listen_port=58888, client_tgen_connect_ip='0.0.0.0', client_tgen_connect_port=8080, client_tor_ctl_port=59050, client_tor_socks_port=59000, + def run(self, do_onion=True, do_inet=True, client_tgen_listen_port=58888, client_tgen_connect_ip='0.0.0.0', client_tgen_connect_port=8080, client_tor_ctl_port=59050, client_tor_socks_port=59000, server_tgen_listen_port=8080, server_tor_ctl_port=59051, server_tor_socks_port=59001): ''' only `server_tgen_listen_port` are "public" and need to be opened on the firewall. @@ -218,11 +219,10 @@ class Measurement(object): logging.info("Onion Service private keys will be placed in {0}".format(self.privatedir_path)) # one must not have an open socks port when running a single # onion service. see tor's man page for more information. - if single_onion: + if self.single_onion: server_tor_socks_port = 0 tor_writable, torctl_writable = self.__start_tor_server(server_tor_ctl_port, server_tor_socks_port, - single_onion, {client_tgen_connect_port:server_tgen_listen_port}) general_writables.append(tor_writable) general_writables.append(torctl_writable) @@ -351,7 +351,7 @@ class Measurement(object):
return tgen_writable
- def create_tor_config(self, control_port, socks_port, tor_datadir, name, single_onion): + def create_tor_config(self, control_port, socks_port, tor_datadir, name): """ This function generates a tor configuration based on a default template. This template is appended to any tor configuration inherited @@ -418,16 +418,16 @@ WarnUnsafeSocks 0\nSafeLogging 0\nMaxCircuitDirtiness 60 seconds\nDataDirectory def __start_tor_client(self, control_port, socks_port): return self.__start_tor("client", control_port, socks_port)
- def __start_tor_server(self, control_port, socks_port, single_onion, hs_port_mapping): - return self.__start_tor("server", control_port, socks_port, single_onion, hs_port_mapping) + def __start_tor_server(self, control_port, socks_port, hs_port_mapping): + return self.__start_tor("server", control_port, socks_port, hs_port_mapping)
- def __start_tor(self, name, control_port, socks_port, single_onion=False, hs_port_mapping=None): + def __start_tor(self, name, control_port, socks_port, hs_port_mapping=None): logging.info("Starting Tor {0} process with ControlPort={1}, SocksPort={2}...".format(name, control_port, socks_port)) tor_datadir = "{0}/tor-{1}".format(self.datadir_path, name) key_path_v3 = "{0}/os_key_v3".format(self.privatedir_path)
if not os.path.exists(tor_datadir): os.makedirs(tor_datadir) - tor_config = self.create_tor_config(control_port,socks_port,tor_datadir,name,single_onion) + tor_config = self.create_tor_config(control_port,socks_port,tor_datadir,name)
tor_logpath = "{0}/onionperf.tor.log".format(tor_datadir) tor_writable = util.FileWritable(tor_logpath) diff --git a/onionperf/onionperf b/onionperf/onionperf index 3b80eff..d811e7b 100755 --- a/onionperf/onionperf +++ b/onionperf/onionperf @@ -352,7 +352,8 @@ def measure(args): args.oneshot, args.additional_client_conf, args.torclient_conf_file, - args.torserver_conf_file) + args.torserver_conf_file, + args.single_onion)
meas.run(do_onion=not args.inet_only, do_inet=not args.onion_only,