|
@@ -34,8 +34,8 @@ class DummyEnterExit:
|
|
|
#
|
|
|
class Experiment:
|
|
|
def __init__(self, save_data_path, measureme_log_path, num_bytes, num_streams_per_client,
|
|
|
- num_clients, num_guards, num_authorities, num_exits,
|
|
|
- buffer_len=None, wait_range=None, measureme=False):
|
|
|
+ num_clients, num_guards, num_authorities, num_exits, circuit_generator_builder,
|
|
|
+ buffer_len=None, wait_range=None, measureme=False, test_network=True):
|
|
|
self.save_data_path = save_data_path
|
|
|
self.measureme_log_path = measureme_log_path
|
|
|
self.num_bytes = num_bytes
|
|
@@ -44,9 +44,11 @@ class Experiment:
|
|
|
self.num_guards = num_guards
|
|
|
self.num_authorities = num_authorities
|
|
|
self.num_exits = num_exits
|
|
|
+ self.circuit_generator_builder = circuit_generator_builder
|
|
|
self.buffer_len = buffer_len
|
|
|
self.wait_range = wait_range
|
|
|
self.measureme = measureme
|
|
|
+ self.test_network = test_network
|
|
|
#
|
|
|
self.chutney_path = '/home/sengler/code/measureme/chutney'
|
|
|
self.tor_path = '/home/sengler/code/measureme/tor'
|
|
@@ -121,17 +123,19 @@ class Experiment:
|
|
|
#
|
|
|
try:
|
|
|
chutney_network = None
|
|
|
- num_attemtps = 0
|
|
|
+ num_attempts = 0
|
|
|
while chutney_network is None:
|
|
|
try:
|
|
|
- num_attemtps += 1
|
|
|
- chutney_network = chutney_manager.ChutneyNetwork(self.chutney_path, self.tor_path, tmp_network_file)
|
|
|
+ num_attempts += 1
|
|
|
+ verification_rounds = 1 if self.test_network else 0
|
|
|
+ chutney_network = chutney_manager.ChutneyNetwork(self.chutney_path, self.tor_path, tmp_network_file, verification_rounds=verification_rounds)
|
|
|
except KeyboardInterrupt:
|
|
|
raise
|
|
|
except:
|
|
|
logging.exception('The Chutney network failed to start (attempt {})'.format(num_attempts))
|
|
|
#
|
|
|
#
|
|
|
+ logging.debug('Last 40 lines of Chutney output:\n'+'\n'.join(chutney_network.startup_output.split('\n')[-40:]))
|
|
|
#with chutney_network as net:
|
|
|
with chutney_network:
|
|
|
nicknames = [self.nodes[x].guess_nickname(x) for x in range(len(self.nodes))]
|
|
@@ -164,7 +168,14 @@ class Experiment:
|
|
|
def start_throughput_server(self, next_action=None):
|
|
|
stop_event = multiprocessing.Event()
|
|
|
server = throughput_server.ThroughputServer(self.server_address, stop_event)
|
|
|
- p = multiprocessing.Process(target=server.run)
|
|
|
+ def server_run_wrapper():
|
|
|
+ try:
|
|
|
+ server.run()
|
|
|
+ except KeyboardInterrupt:
|
|
|
+ logging.info('Stopping server (KeyboardInterrupt)')
|
|
|
+ #
|
|
|
+ #
|
|
|
+ p = multiprocessing.Process(target=server_run_wrapper)
|
|
|
p.start()
|
|
|
#
|
|
|
try:
|
|
@@ -176,14 +187,16 @@ class Experiment:
|
|
|
#
|
|
|
p.join()
|
|
|
#
|
|
|
- with gzip.GzipFile(os.path.join(self.save_data_path, 'server_results.pickle.gz'), 'wb') as f:
|
|
|
- pickle.dump([x['results'] for x in server.results], f, protocol=4)
|
|
|
+ if self.save_data_path is not None:
|
|
|
+ with gzip.GzipFile(os.path.join(self.save_data_path, 'server_results.pickle.gz'), 'wb') as f:
|
|
|
+ pickle.dump([x['results'] for x in server.results], f, protocol=4)
|
|
|
+ #
|
|
|
#
|
|
|
#
|
|
|
def start_system_logging(self, next_action=None):
|
|
|
stop_cpu_logging_event = multiprocessing.Event()
|
|
|
p = multiprocessing.Process(target=log_system_usage.log_cpu_stats,
|
|
|
- args=(os.path.join(save_data_path, 'cpu_stats.pickle.gz'), 0.1, stop_cpu_logging_event))
|
|
|
+ args=(os.path.join(self.save_data_path, 'cpu_stats.pickle.gz'), 0.1, stop_cpu_logging_event))
|
|
|
p.start()
|
|
|
#
|
|
|
try:
|
|
@@ -202,14 +215,7 @@ class Experiment:
|
|
|
except Exception as e:
|
|
|
raise Exception('Unable to retrieve the consensus') from e
|
|
|
#
|
|
|
- fingerprints = experiment_client.get_fingerprints(consensus)
|
|
|
- exit_fingerprints = experiment_client.get_exit_fingerprints(consensus, self.server_address)
|
|
|
- non_exit_fingerprints = list(set(fingerprints)-set(exit_fingerprints))
|
|
|
- #
|
|
|
- assert len(exit_fingerprints) == 1, 'Need exactly one exit relay'
|
|
|
- assert len(non_exit_fingerprints) >= 1, 'Need at least one non-exit relay'
|
|
|
- #
|
|
|
- circuit_generator = lambda: [random.choice(non_exit_fingerprints), exit_fingerprints[0]]
|
|
|
+ circuit_generator = self.circuit_generator_builder(consensus, self.server_address)
|
|
|
#
|
|
|
proxy_addresses = []
|
|
|
for control_port in self.proxy_control_ports:
|
|
@@ -277,6 +283,16 @@ def wait_for_keyboard_interrupt():
|
|
|
print('')
|
|
|
#
|
|
|
#
|
|
|
+def build_circuit_generator(consensus, server_address):
|
|
|
+ fingerprints = experiment_client.get_fingerprints(consensus)
|
|
|
+ exit_fingerprints = experiment_client.get_exit_fingerprints(consensus, server_address)
|
|
|
+ non_exit_fingerprints = list(set(fingerprints)-set(exit_fingerprints))
|
|
|
+ #
|
|
|
+ assert len(exit_fingerprints) == 1, 'Need exactly one exit relay'
|
|
|
+ assert len(non_exit_fingerprints) >= 1, 'Need at least one non-exit relay'
|
|
|
+ #
|
|
|
+ return lambda: [random.choice(non_exit_fingerprints), exit_fingerprints[0]]
|
|
|
+#
|
|
|
'''
|
|
|
if __name__ == '__main__':
|
|
|
#
|
|
@@ -376,7 +392,7 @@ if __name__ == '__main__':
|
|
|
os.mkdir(measureme_log_path)
|
|
|
#
|
|
|
experiment = Experiment(save_data_path, measureme_log_path, args.num_bytes, num_streams_per_client,
|
|
|
- num_clients, num_guards, num_authorities, num_exits,
|
|
|
+ num_clients, num_guards, num_authorities, num_exits, build_circuit_generator,
|
|
|
args.buffer_len, args.wait_range, args.measureme)
|
|
|
#
|
|
|
if args.debugging == 'no-chutney':
|