Skip to content
This repository was archived by the owner on Mar 2, 2022. It is now read-only.

Commit 6563764

Browse files
authored
Merge pull request #105 from juga0/config_constants
Config constants
2 parents 92abe44 + 499e875 commit 6563764

5 files changed

Lines changed: 56 additions & 26 deletions

File tree

bwscanner/attacher.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,16 @@ def got_newconsensus(event):
3131

3232

3333
@defer.inlineCallbacks
34-
def connect_to_tor(launch_tor, circuit_build_timeout, tor_dir=None, control_port=None,
34+
def connect_to_tor(launch_tor, circuit_build_timeout, tor_options,
35+
tor_dir=None, control_port=None,
3536
tor_overrides=None):
3637
"""
3738
Launch or connect to a Tor instance
3839
3940
Configure Tor with the passed options and return a Deferred
4041
"""
42+
# FIXME: tor_overrides should probably be removed
4143
# Options for spawned or running Tor to load the correct descriptors.
42-
tor_options = {
43-
'LearnCircuitBuildTimeout': 0, # Disable adaptive circuit timeouts.
44-
'CircuitBuildTimeout': circuit_build_timeout,
45-
'UseEntryGuards': 0, # Disable UseEntryGuards to avoid PathBias warnings.
46-
'UseMicroDescriptors': 0,
47-
'FetchUselessDescriptors': 1,
48-
'FetchDirInfoEarly': 1,
49-
'FetchDirInfoExtraEarly': 1,
50-
'SafeLogging': 0,
51-
'LogTimeGranularity': 1,
52-
}
53-
5444
if tor_overrides:
5545
tor_options.update(tor_overrides)
5646

bwscanner/config.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#
2+
""""""
3+
import os.path
4+
import click
5+
6+
DEFAULT = {
7+
'data_dir': click.get_app_dir('bwscanner'),
8+
'measurement_dir': os.path.join(click.get_app_dir('bwscanner'),
9+
'measurements'),
10+
'tor_dir': os.path.join(click.get_app_dir('bwscanner'),
11+
'tordata'),
12+
'logfile': os.path.join(click.get_app_dir('bwscanner'),
13+
'bwscanner.log'),
14+
'loglevel': 'debug',
15+
'baseurl': 'https://siv.sunet.se/bwauth/',
16+
'launch_tor': True,
17+
'circuit_build_timeout': 20,
18+
'partitions': 1,
19+
'current_partition': 1,
20+
'timeout': 120,
21+
'request_limit': 10
22+
}
23+
BW_FILES = {
24+
64*1024: ("64M", "6258de4f4d602be75a3458117b29d2c580c4bcb7ba5b9d2c4135c7603109f554"),
25+
32*1024: ("32M", "5a5d66d7865f09498d776f20c9e9791b055a4fff357185f84fb4ecfca7da93f0"),
26+
16*1024: ("(16M", "6258de4f4d602be75a3458117b29d2c580c4bcb7ba5b9d2c4135c7603109f554"),
27+
8*1024: ("8M", "738c5604295b9377f7636ce0c2c116f093bb50372f589a6c2332a3bb6bba096a"),
28+
4*1024: ("4M", "4daaa42377d3c87577797d44a8fa569038e7a9d6a5d417a09d8ba41a69456164"),
29+
2*1024: ("2M", "3e39b0bb92912cf1ad6c01fb7c9d592e814a691c61de1f649416f6bba2d15082"),
30+
}
31+
TOR_OPTIONS = {
32+
'LearnCircuitBuildTimeout': 0, # Disable adaptive circuit timeouts.
33+
'CircuitBuildTimeout': 20,
34+
'UseEntryGuards': 0, # Disable UseEntryGuards to avoid PathBias warnings.
35+
'UseMicroDescriptors': 0,
36+
'FetchUselessDescriptors': 1,
37+
'FetchDirInfoEarly': 1,
38+
'FetchDirInfoExtraEarly': 1,
39+
'SafeLogging': 0,
40+
'LogTimeGranularity': 1,
41+
}

bwscanner/measurement.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,8 @@ def __init__(self, state, clock, measurement_dir, **kwargs):
4343

4444
self.tasks = []
4545
self.circuits = None
46-
self.baseurl = 'https://bwauth.torproject.org/bwauth.torproject.org'
47-
self.bw_files = {
48-
64*1024: ("64M", "913b3c5df256d62235f955fa936e7a4e2d5e0cb6"),
49-
32*1024: ("32M", "a536076ef51c2cfff607fec2d362671e031d6b48"),
50-
16*1024: ("16M", "e91690ed2abf05e347b61aafaa23abf2a2b3292f"),
51-
8*1024: ("8M", "c690229b300945ec4ba872b80e8c443e2e1750f0"),
52-
4*1024: ("4M", "94f7bc6679a4419b080debd70166c2e43e80533d"),
53-
2*1024: ("2M", "9793cc92932598898d22497acdd5d732037b1a13"),
54-
}
55-
46+
self.baseurl = kwargs.get('baseurl')
47+
self.bw_files = kwargs.get('bw_files')
5648
self.result_sink = ResultSink(self.measurement_dir, chunk_size=10)
5749

5850
def now(self):

bwscanner/scanner.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from bwscanner.logger import setup_logging, log
1010
from bwscanner.measurement import BwScan
1111
from bwscanner.aggregate import write_aggregate_data
12+
from bwscanner.config import TOR_OPTIONS, DEFAULT, BW_FILES
1213
from bwscanner import __version__
1314

1415

@@ -58,7 +59,7 @@ def cli(ctx, data_dir, loglevel, logfile, launch_tor, circuit_build_timeout):
5859

5960
# Create a connection to a Tor instance
6061
ctx.obj.tor_state = connect_to_tor(launch_tor, circuit_build_timeout,
61-
ctx.obj.tor_dir)
62+
TOR_OPTIONS, ctx.obj.tor_dir)
6263

6364
# Set up the logger to only output log lines of level `loglevel` and above.
6465
setup_logging(log_level=loglevel, log_name=logfile)
@@ -74,13 +75,15 @@ def cli(ctx, data_dir, loglevel, logfile, launch_tor, circuit_build_timeout):
7475
@click.option('--request-limit', default=10,
7576
help='Limit the number of simultaneous bandwidth measurements '
7677
'(default: %d).' % 10)
78+
@click.option('--baseurl', default=DEFAULT.get('baseurl'),
79+
help='File server URL')
7780
@pass_scan
78-
def scan(scan, partitions, current_partition, timeout, request_limit):
81+
def scan(scan, partitions, current_partition, timeout, request_limit, baseurl):
7982
"""
8083
Start a scan through each Tor relay to measure it's bandwidth.
8184
"""
8285
log.info("Using {data_dir} as the data directory.", data_dir=scan.data_dir)
83-
86+
assert isinstance(BW_FILES, dict)
8487
# XXX: check that each run is producing the same input set!
8588
scan_time = str(int(time.time()))
8689
scan_data_dir = os.path.join(scan.measurement_dir, '{}.running'.format(scan_time))
@@ -92,6 +95,8 @@ def rename_finished_scan(deferred):
9295
os.rename(scan_data_dir, os.path.join(scan.measurement_dir, scan_time))
9396

9497
scan.tor_state.addCallback(BwScan, reactor, scan_data_dir,
98+
baseurl=baseurl,
99+
bw_files=BW_FILES,
95100
request_timeout=timeout,
96101
request_limit=request_limit,
97102
partitions=partitions,

test/template.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from bwscanner import circuit
88
from bwscanner.attacher import connect_to_tor
9+
from bwscanner.config import TOR_OPTIONS
910

1011

1112
class TorTestCase(unittest.TestCase):
@@ -16,6 +17,7 @@ def setUp(self):
1617
launch_tor=False,
1718
control_port=int(os.environ.get('CHUTNEY_CONTROL_PORT')),
1819
circuit_build_timeout=30,
20+
tor_options=TOR_OPTIONS
1921
)
2022

2123
@property

0 commit comments

Comments
 (0)