aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan <me@jordan.im>2020-02-17 13:26:35 -0700
committerJordan <me@jordan.im>2020-02-17 13:26:35 -0700
commit0881b659d967a2d7f1725a32e2e95a8cbaf6d401 (patch)
treef9daf1a3586bce010fb313aa61629801ab28eae7
parenta189af05f77c0dcb6947f536acc051bd0795f3bb (diff)
downloadallium-0881b659d967a2d7f1725a32e2e95a8cbaf6d401.tar.gz
allium-0881b659d967a2d7f1725a32e2e95a8cbaf6d401.zip
support sorting by relay flag (exit, guard...)
-rwxr-xr-xtor-metrics/generate.py36
-rw-r--r--tor-metrics/templates/flag.html4
-rw-r--r--tor-metrics/templates/relay-list.html2
3 files changed, 41 insertions, 1 deletions
diff --git a/tor-metrics/generate.py b/tor-metrics/generate.py
index edea6a9..dba4e4b 100755
--- a/tor-metrics/generate.py
+++ b/tor-metrics/generate.py
@@ -35,6 +35,7 @@ def generate_html(relays):
pages_by_key(relays, 'country')
pages_by_key(relays, 'platform')
effective_family(relays)
+ pages_by_flag(relays)
unsorted(relays, 'index.html', is_index=True)
unsorted(relays.json['relays'], 'all.html', is_index=False)
relay_info(relays)
@@ -129,6 +130,41 @@ def pages_by_key(relays, key):
encoding='utf8') as html:
html.write(rendered)
+def pages_by_flag(relays):
+ '''
+ Render and write HTML listings to disk sorted by FLAG
+
+ :relays: relays class object containing relay set (list of dict)
+ :flag: onionoo JSON relay flag to sort by, e.g. 'exit'
+ '''
+ FLAGS = ['Exit','Fast','Guard','HSDir','Running','Stable','V2Dir','Valid',
+ 'Authority']
+ template = ENV.get_template('flag.html')
+ for flag in FLAGS:
+ output_path = os.path.join(config.CONFIG['output_root'], 'flag',
+ flag.lower())
+ if os.path.exists(output_path):
+ rmtree(output_path)
+ relay_list = relays.json['relays']
+ found_relays = []
+ bandwidth = 0 # total bandwidth for relay subset
+ for idx, relay in enumerate(relay_list):
+ if not relay.get('flags'):
+ continue
+ if flag in relay['flags']:
+ found_relays.append(relay)
+ bandwidth += relay['observed_bandwidth']
+ os.makedirs(output_path)
+ f_bandwidth = round(bandwidth / 1000000, 2) # convert to MB/s
+ rendered = template.render(relays=found_relays,
+ bandwidth=f_bandwidth, is_index=False,
+ path_prefix='../../', deactivate=flag,
+ special_countries=countries.THE_PREFIXED,
+ flag=flag)
+ with open(os.path.join(output_path, 'index.html'), 'w',
+ encoding='utf8') as html:
+ html.write(rendered)
+
def relay_info(relays):
'''
Render and write per-relay HTML info documents to disk
diff --git a/tor-metrics/templates/flag.html b/tor-metrics/templates/flag.html
new file mode 100644
index 0000000..3991eb4
--- /dev/null
+++ b/tor-metrics/templates/flag.html
@@ -0,0 +1,4 @@
+{% extends "relay-list.html" %}
+{% block title %}Tor Relays :: {{ flag|escape }} Flag{% endblock %}
+{% block header %}<a href="../../">Home</a> :: {{ flag|escape }}{% endblock %}
+{% block description %}Relays with the {{ flag }} flag are responsible for ~{{ bandwidth }} MB/s of traffic.{% endblock %}
diff --git a/tor-metrics/templates/relay-list.html b/tor-metrics/templates/relay-list.html
index 342bb86..475ee75 100644
--- a/tor-metrics/templates/relay-list.html
+++ b/tor-metrics/templates/relay-list.html
@@ -58,7 +58,7 @@
{% else %}
<td>{{ relay['platform']|escape }}</td>{% endif %}
- <td>{% for flag in relay['flags'] %}{% if flag != 'StaleDesc' %}<img src="{{ path_prefix}}static/images/flags/{{ flag.lower()|escape }}.png" title="{{ flag|escape }}" alt="{{ flag|escape }}"> {% endif %}{% endfor %}</td>
+ <td>{% for flag in relay['flags'] %}{% if flag != 'StaleDesc' %}<a href="{{ path_prefix }}flag/{{ flag.lower()|escape }}"><img src="{{ path_prefix}}static/images/flags/{{ flag.lower()|escape }}.png" title="{{ flag|escape }}" alt="{{ flag|escape }}"></a> {% endif %}{% endfor %}</td>
{% if relay['running'] %}
<td class="visible-md visible-lg"><font color="green">True</font></td>