sbws.core package¶
Submodules¶
sbws.core.cleanup module¶
Util functions to cleanup disk space.
sbws.core.generate module¶
sbws.core.scanner module¶
Measure the relays.
- 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.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 inFuture
objects. These objects have anstate
.The executor starts a new thread for every relay to measure, which runs
measure_relay
until there aremax_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 completedfuture
s.
- 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.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 theresult
and callmeasurement_writer
, which put theResult
inResultDump
queue and complete immediately.ResultDump
thread (started before and out of this function) will get theResult
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 insteadlog_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.select_helper_candidates(relay, rl, dest, relay_as_entry=True)[source]¶
Return helper candidates list.
- Return type:
list
- 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.upload_data(session, conf, dest, cont, circ_id)[source]¶
Upload data to a destination URL over
circ_id
via HTTP POST request.This function is equivalent to the HTTP HEAD and GET requests implemented with the functions:
sbws.lib.destination.connect_to_destination_over_circuit
which in turn calls``sbws.lib.stem.attach_stream_to_circuit_listener`` andsbws.lib.stem.add_event_listener
: to listen for stream event.measure_bandwidth_to_server
: to calculate download sizes, not needed anymore.timed_recv_from_server
: the measurement itself.
- Returns:
measurement
Result
(or None) and error or None- Return type:
tuple(Result, str)
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