Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tor-circumvention-analytics
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
briar
tor-circumvention-analytics
Commits
94a6d815
Verified
Commit
94a6d815
authored
6 years ago
by
Torsten Grote
Browse files
Options
Downloads
Patches
Plain Diff
Make countries to check for bridge blocking configurable
parent
7ca0d8df
No related branches found
No related tags found
1 merge request
!2
Add hard-coded parameters as command line arguments
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
countries-that-block-bridges.py
+15
-9
15 additions, 9 deletions
countries-that-block-bridges.py
with
15 additions
and
9 deletions
countries-that-block-bridges.py
+
15
−
9
View file @
94a6d815
#!/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
]:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment