GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Commit 4ff257c4 authored by Karsten Loesing's avatar Karsten Loesing

Merge branch 'task-33399' into develop

parents e333be25 e9fd47d9
......@@ -173,7 +173,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
......@@ -189,6 +189,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):
......@@ -389,7 +390,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"
......@@ -471,7 +472,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)
......
......@@ -23,7 +23,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()
......@@ -55,6 +55,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:
......@@ -62,9 +66,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
......@@ -80,6 +88,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)
......@@ -195,6 +195,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',
......@@ -356,7 +362,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,
......
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