commit e9fd47d95db102b3a7ace36fa412e18d182c5fa4 Author: Karsten Loesing karsten.loesing@gmx.net Date: Tue Jun 16 21:30:07 2020 +0200
Measure static guard nodes.
Add --drop-guards parameter to use and drop guards after a given number of hours.
Implements #33399. --- onionperf/measurement.py | 7 ++++--- onionperf/monitor.py | 18 +++++++++++++----- onionperf/onionperf | 9 ++++++++- 3 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/onionperf/measurement.py b/onionperf/measurement.py index 4a58bc4..899b277 100644 --- a/onionperf/measurement.py +++ b/onionperf/measurement.py @@ -172,7 +172,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, single_onion=False): + 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, drop_guards_interval_hours=None): self.tor_bin_path = tor_bin_path self.tgen_bin_path = tgen_bin_path self.datadir_path = datadir_path @@ -188,6 +188,7 @@ class Measurement(object): self.torclient_conf_file = torclient_conf_file self.torserver_conf_file = torserver_conf_file self.single_onion = single_onion + self.drop_guards_interval_hours = drop_guards_interval_hours
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): @@ -388,7 +389,7 @@ WarnUnsafeSocks 0\nSafeLogging 0\nMaxCircuitDirtiness 60 seconds\nDataDirectory tor_config = tor_config + f.read() if name == "client" and self.additional_client_conf: tor_config += self.additional_client_conf - if not 'UseEntryGuards' in tor_config and not 'UseBridges' in tor_config: + if not 'UseEntryGuards' in tor_config and not 'UseBridges' in tor_config and self.drop_guards_interval_hours == 0: tor_config += "UseEntryGuards 0\n" if name == "server" and self.single_onion: tor_config += "HiddenServiceSingleHopMode 1\nHiddenServiceNonAnonymousMode 1\n" @@ -467,7 +468,7 @@ WarnUnsafeSocks 0\nSafeLogging 0\nMaxCircuitDirtiness 60 seconds\nDataDirectory
torctl_events = [e for e in monitor.get_supported_torctl_events() if e not in ['DEBUG', 'INFO', 'NOTICE', 'WARN', 'ERR']] newnym_interval_seconds = 300 - torctl_args = (control_port, torctl_writable, torctl_events, newnym_interval_seconds, self.done_event) + torctl_args = (control_port, torctl_writable, torctl_events, newnym_interval_seconds, self.drop_guards_interval_hours, self.done_event) torctl_helper = threading.Thread(target=monitor.tor_monitor_run, name="torctl_{0}_helper".format(name), args=torctl_args) torctl_helper.start() self.threads.append(torctl_helper) diff --git a/onionperf/monitor.py b/onionperf/monitor.py index 5387bff..ac6fea9 100644 --- a/onionperf/monitor.py +++ b/onionperf/monitor.py @@ -22,7 +22,7 @@ class TorMonitor(object): self.writable = writable self.events = events
- def run(self, newnym_interval_seconds=None, done_ev=None): + def run(self, newnym_interval_seconds=None, drop_guards_interval_hours=0, done_ev=None): with Controller.from_port(port=self.tor_ctl_port) as torctl: torctl.authenticate()
@@ -54,6 +54,10 @@ class TorMonitor(object): # let stem run its threads and log all of the events, until user interrupts try: interval_count = 0 + if newnym_interval_seconds is not None: + next_newnym = newnym_interval_seconds + if drop_guards_interval_hours > 0: + next_drop_guards = drop_guards_interval_hours * 3600 while done_ev is None or not done_ev.is_set(): # if self.filepath != '-' and os.path.exists(self.filepath): # with open(self.filepath, 'rb') as sizef: @@ -61,9 +65,13 @@ class TorMonitor(object): # logging.info(msg) sleep(1) interval_count += 1 - if newnym_interval_seconds is not None and interval_count >= newnym_interval_seconds: - interval_count = 0 + if newnym_interval_seconds is not None and interval_count >= next_newnym: + next_newnym += newnym_interval_seconds torctl.signal(Signal.NEWNYM) + if drop_guards_interval_hours > 0 and interval_count >= next_drop_guards: + next_drop_guards += drop_guards_interval_hours * 3600 + torctl.drop_guards() + except KeyboardInterrupt: pass # the user hit ctrl+c
@@ -79,6 +87,6 @@ class TorMonitor(object): unix_ts = (utcnow - epoch).total_seconds() writable.write("{0} {1:.02f} {2}".format(now.strftime("%Y-%m-%d %H:%M:%S"), unix_ts, msg))
-def tor_monitor_run(tor_ctl_port, writable, events, newnym_interval_seconds, done_ev): +def tor_monitor_run(tor_ctl_port, writable, events, newnym_interval_seconds, drop_guards_interval_hours, done_ev): torctl_monitor = TorMonitor(tor_ctl_port, writable, events) - torctl_monitor.run(newnym_interval_seconds=newnym_interval_seconds, done_ev=done_ev) + torctl_monitor.run(newnym_interval_seconds=newnym_interval_seconds, drop_guards_interval_hours=drop_guards_interval_hours, done_ev=done_ev) diff --git a/onionperf/onionperf b/onionperf/onionperf index a7d32f6..52a779f 100755 --- a/onionperf/onionperf +++ b/onionperf/onionperf @@ -194,6 +194,12 @@ def main(): action="store", dest="tgenconnectport", default=8080)
+ measure_parser.add_argument('--drop-guards', + help="""Use and drop guards every N > 0 hours, or do not use guards at all if N = 0""", + metavar="N", type=type_nonnegative_integer, + action="store", dest="drop_guards_interval_hours", + default=0) + onion_or_inet_only_group = measure_parser.add_mutually_exclusive_group()
onion_or_inet_only_group.add_argument('-o', '--onion-only', @@ -360,7 +366,8 @@ def measure(args): args.additional_client_conf, args.torclient_conf_file, args.torserver_conf_file, - args.single_onion) + args.single_onion, + args.drop_guards_interval_hours)
meas.run(do_onion=not args.inet_only, do_inet=not args.onion_only,
tor-commits@lists.torproject.org