sbws.core package

Submodules

sbws.core.cleanup module

Util functions to cleanup disk space.

sbws.core.cleanup.gen_parser(sub)[source]

Helper function for the broader argument parser generating code that adds in all the possible command line arguments for the cleanup command.

Parameters:sub (argparse._SubParsersAction) – what to add a sub-parser to
sbws.core.cleanup.main(args, conf)[source]

Main entry point in to the cleanup command.

Parameters:
  • args (argparse.Namespace) – command line arguments
  • conf (configparser.ConfigParser) – parsed config files

sbws.core.generate module

sbws.core.generate.gen_parser(sub)[source]
sbws.core.generate.main(args, conf)[source]

sbws.core.scanner module

Measure the relays.

sbws.core.scanner.create_path_relay(relay, dest, rl, cb, relay_as_entry=True)[source]
sbws.core.scanner.dispatch_worker_thread(*a, **kw)[source]
sbws.core.scanner.dumpstacks()[source]
sbws.core.scanner.error_no_circuit(circ_fps, nicknames, reason, relay, dest, our_nick)[source]
sbws.core.scanner.error_no_helper(relay, dest, our_nick='')[source]
sbws.core.scanner.gen_parser(sub)[source]
sbws.core.scanner.get_random_range_string(content_length, size)[source]

Return a random range of bytes of length size. content_length is the size of the file we will be requesting a range of bytes from.

For example, for content_length of 100 and size 10, this function will return one of the following: ‘0-9’, ‘1-10’, ‘2-11’, […] ‘89-98’, ‘90-99’

sbws.core.scanner.log_measurement_exception(target, exception)[source]
sbws.core.scanner.main(args, conf)[source]
sbws.core.scanner.main_loop(args, conf, controller, relay_list, circuit_builder, result_dump, relay_prioritizer, destinations)[source]

Create the queue of future measurements for every relay to measure.

It starts a loop that will be run while there is not and event signaling that sbws is stopping (because of SIGTERM or SIGINT).

Then the ThreadPoolExecutor (executor) queues all the relays to measure in Future objects. These objects have an state.

The executor starts a new thread for every relay to measure, which runs measure_relay until there are max_pending_results threads. After that, it will reuse a thread that has finished for every relay to measure.

Then process_completed_futures is call, to obtain the results in the completed futures.

sbws.core.scanner.measure_bandwidth_to_server(session, conf, dest, content_length)[source]
Returns tuple:results or None if the if the measurement fail. None or exception if the measurement fail.
sbws.core.scanner.measure_relay(args, conf, destinations, cb, rl, relay)[source]

Select a Web server, a relay to build the circuit, build the circuit and measure the bandwidth of the given relay.

Return Result:a measurement Result object
sbws.core.scanner.measure_rtt_to_server(session, conf, dest, content_length)[source]

Make multiple end-to-end RTT measurements by making small HTTP requests over a circuit + stream that should already exist, persist, and not need rebuilding. If something goes wrong and not all of the RTT measurements can be made, return None. Otherwise return a list of the RTTs (in seconds).

Returns tuple:results or None if the if the measurement fail. None or exception if the measurement fail.
sbws.core.scanner.measurement_writer(result_dump, measurement)[source]
sbws.core.scanner.process_completed_futures(executor, hbeat, result_dump, pending_results)[source]

Obtain the relays’ measurements as they finish.

For every Future measurements that gets completed, obtain the result and call measurement_writer, which put the Result in ResultDump queue and complete immediately.

ResultDump thread (started before and out of this function) will get the Result from the queue and write it to disk, so this doesn’t block the measurement threads.

If there was an exception not caught by measure_relay, it will call instead log_measurement_exception, which logs the error and complete immediately.

sbws.core.scanner.run_speedtest(args, conf)[source]

Initializes all the data and threads needed to measure the relays.

It launches or connect to Tor in a thread. It initializes the list of relays seen in the Tor network. It starts a thread to read the previous measurements and wait for new measurements to write them to the disk. It initializes a class that will be used to order the relays depending on their measurements age. It initializes the list of destinations that will be used for the measurements. It initializes the thread pool that will launch the measurement threads. The pool starts 3 other threads that are not the measurement (worker) threads. Finally, it calls the function that will manage the measurement threads.

sbws.core.scanner.sigint_handler()[source]
sbws.core.scanner.stop_threads(signal, frame, exit_code=0)[source]
sbws.core.scanner.timed_recv_from_server(session, dest, byte_range)[source]

Request the byte_range from the URL at dest. If successful, return True and the time it took to download. Otherwise return False and an exception.

sbws.core.scanner.wait_futures_completed(pending_results)[source]

Wait for last futures to finish, before starting new loop.

sbws.core.stats module

sbws.core.stats.gen_parser(sub)[source]

Helper function for the broader argument parser generating code that adds in all the possible command line arguments for the stats command.

Parameters:sub (argparse._SubParsersAction) – what to add a sub-parser to
sbws.core.stats.main(args, conf)[source]

Main entry point into the stats command.

Parameters:
  • args (argparse.Namespace) – command line arguments
  • conf (configparser.ConfigParser) – parsed config files
sbws.core.stats.print_stats(args, data)[source]

Called from main to print various statistics about the organized data to stdout.

Parameters:
  • args (argparse.Namespace) – command line arguments
  • data (dict) – keyed by relay fingerprint, and with values of sbws.lib.resultdump.Result subclasses

Module contents