Skip to content
Snippets Groups Projects
Verified Commit 94a6d815 authored by Torsten Grote's avatar Torsten Grote
Browse files

Make countries to check for bridge blocking configurable

parent 7ca0d8df
No related branches found
No related tags found
1 merge request!2Add hard-coded parameters as command line arguments
#!/usr/bin/env python3 #!/usr/bin/env python3
import collections
import csv import csv
import datetime import datetime
import json
import statistics import statistics
import pendulum import pendulum
from tqdm import tqdm from tqdm import tqdm
import json
from analyzer import OoniAnalyser from analyzer import OoniAnalyser
...@@ -18,7 +17,6 @@ UNIT = 'days' # hours, days, weeks ...@@ -18,7 +17,6 @@ UNIT = 'days' # hours, days, weeks
INTERVAL = 1 INTERVAL = 1
BRIDGE_CONTROL_THRESHOLD = 80 # only consider bridges with a control success rate higher than this BRIDGE_CONTROL_THRESHOLD = 80 # only consider bridges with a control success rate higher than this
COUNTRIES = BLOCKING_COUNTRIES + CONTROL_COUNTRIES
FAILURES = [ FAILURES = [
'generic_timeout_error', 'generic_timeout_error',
'connection_refused_error', 'connection_refused_error',
...@@ -35,16 +33,25 @@ def main(): ...@@ -35,16 +33,25 @@ def main():
class BridgeAnalyzer(OoniAnalyser): class BridgeAnalyzer(OoniAnalyser):
pre_report_init = False pre_report_init = False
period = None period = None
blocking_countries = []
countries = []
bridge_data = {} bridge_data = {}
def init_arg_parser(self): def init_arg_parser(self):
parser = super().init_arg_parser() parser = super().init_arg_parser()
parser.add_argument('-n', '--nicknames', dest='nicknames', action='store_true', parser.add_argument('-n', '--nicknames', dest='nicknames', action='store_true',
help='replace bridge addresses with nicknames') help='replace bridge addresses with nicknames')
parser.add_argument('-c', '--countries', nargs='+', metavar='COUNTRY_CODE',
default=BLOCKING_COUNTRIES, help='list of country codes to consider')
return parser return parser
def analyze(self):
self.blocking_countries = [country.upper() for country in self.args.countries]
self.countries = self.blocking_countries + CONTROL_COUNTRIES
super().analyze()
def use_country(self, cc): def use_country(self, cc):
return cc in COUNTRIES return cc in self.countries
@staticmethod @staticmethod
def use_report(data): def use_report(data):
...@@ -108,12 +115,11 @@ class BridgeAnalyzer(OoniAnalyser): ...@@ -108,12 +115,11 @@ class BridgeAnalyzer(OoniAnalyser):
data['countries'][cc]['success'] += country['success'] data['countries'][cc]['success'] += country['success']
data['countries'][cc]['failure'] += country['failure'] data['countries'][cc]['failure'] += country['failure']
@staticmethod def get_field_names(self):
def get_field_names(): blocking_total = [cc + "#" for cc in self.blocking_countries]
blocking_total = [cc + "#" for cc in BLOCKING_COUNTRIES]
control_total = [cc + "#" for cc in CONTROL_COUNTRIES] control_total = [cc + "#" for cc in CONTROL_COUNTRIES]
return ('bridge', 'type', 'total') + \ return ('bridge', 'type', 'total') + \
tuple(sorted(BLOCKING_COUNTRIES)) + \ tuple(sorted(self.blocking_countries)) + \
tuple(['ctrl'] + sorted(CONTROL_COUNTRIES)) + \ tuple(['ctrl'] + sorted(CONTROL_COUNTRIES)) + \
tuple(sorted(blocking_total)) + \ tuple(sorted(blocking_total)) + \
tuple(sorted(control_total)) tuple(sorted(control_total))
...@@ -155,7 +161,7 @@ class BridgeAnalyzer(OoniAnalyser): ...@@ -155,7 +161,7 @@ class BridgeAnalyzer(OoniAnalyser):
continue continue
# remember success rates for blocking countries # remember success rates for blocking countries
if output_dict[bridge]['ctrl'] >= BRIDGE_CONTROL_THRESHOLD: if output_dict[bridge]['ctrl'] >= BRIDGE_CONTROL_THRESHOLD:
for cc in BLOCKING_COUNTRIES: for cc in self.blocking_countries:
bridge_type = output_dict[bridge]["type"] bridge_type = output_dict[bridge]["type"]
if bridge_type == "B" or bridge_type == "TB": if bridge_type == "B" or bridge_type == "TB":
if cc not in output_dict[bridge]: if cc not in output_dict[bridge]:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment