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

Commit 75f819a

Browse files
committed
Move hardcoded tor options to config file
1 parent 92abe44 commit 75f819a

4 files changed

Lines changed: 48 additions & 14 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/scanner.py

Lines changed: 2 additions & 1 deletion
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
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)

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)