Browse Source

first commit

master
trackingv2 4 months ago
commit
8d9f0508b6
  1. 19
      plotter.py
  2. 30
      plotter2.py
  3. 28
      plotter3.py
  4. 47
      trackingv2.py

19
plotter.py

@ -0,0 +1,19 @@
import pandas as pd
import datetime
import csv
import os
import matplotlib.pyplot as plt
from shutil import copyfile
x_axis='datetime'
y_axes=['v2','nonv2']
df = pd.read_csv("/home/trackingv2/trackingv2.csv")
filter = [x_axis] + y_axes
title = "Tracking how many Tor HSDirs run a version that is non-v2"
df[filter].plot(kind="line", x=x_axis, title=title, grid=True, rot=20, figsize=(6,5))
plt.savefig("/var/www/data/plot.png")
copyfile("/home/trackingv2/trackingv2.csv", "/var/www/data/v2.csv")
print("plotted "+title)

30
plotter2.py

@ -0,0 +1,30 @@
import pandas as pd
import datetime
import csv
import math
import os
import matplotlib.pyplot as plt
from shutil import copyfile
with open("/home/trackingv2/trackingv2.csv", "r") as f:
reader = csv.reader(f)
next(reader)
with open("/home/trackingv2/trackingv2.frac.csv", "w", newline='') as write:
writer = csv.writer(write)
writer.writerow(["fraction_nonv2", "datetime"])
for row in reader:
per = int(row[1]) / (int(row[0])+int(row[1]))
per = round(per, 4)
writer.writerow([per, row[2]])
x_axis='datetime'
y_axis='fraction_nonv2'
df = pd.read_csv("/home/trackingv2/trackingv2.frac.csv")
title = "Fraction of HSDirs that are non-v2"
df.plot(kind="line", x=x_axis, y=y_axis, ylim=([0,1]), title=title, grid=True, rot=20, figsize=(6,5))
plt.savefig("/var/www/data/fraction_plot.png")
copyfile("/home/trackingv2/trackingv2.frac.csv", "/var/www/data/fraction_v2.csv")
print("plotted "+title)

28
plotter3.py

@ -0,0 +1,28 @@
import pandas as pd
import datetime
import csv
import os
import matplotlib.pyplot as plt
from shutil import copyfile
with open("/home/trackingv2/trackingv2.frac.csv", "r") as f:
reader = csv.reader(f)
next(reader)
with open("/home/trackingv2/trackingv2.approx.csv", "w", newline='') as write:
writer = csv.writer(write)
writer.writerow(["frac_power6", "datetime"])
for row in reader:
per = pow(float(row[0]), 6)
writer.writerow([per, row[1]])
x_axis='datetime'
y_axis='frac_power6'
df = pd.read_csv("/home/trackingv2/trackingv2.approx.csv")
title = "Expected chance that a v2 onion is unreachable"
df.plot(kind="line", x=x_axis, y=y_axis, ylim=([0,1]), title=title, grid=True, rot=20, figsize=(6,5))
plt.savefig("/var/www/data/fraction_power6_plot.png")
copyfile("/home/trackingv2/trackingv2.approx.csv", "/var/www/data/fraction_power6_v2.csv")
print("plotted "+title)

47
trackingv2.py

@ -0,0 +1,47 @@
import re
import sys
import os
import requests
import datetime
dt = datetime.datetime.utcnow().strftime("%m-%d-%H")
numberOfHSDir = 0
numberOfNonv2 = 0
numberOfv2 = 0
consensus = "/home/trackingv2/consensus"
url = "https://collector.torproject.org/recent/relay-descriptors/consensuses/2021-{}-00-00-consensus".format(dt)
print(url)
r = requests.get(url)
os.remove(consensus)
with open(consensus,"wb") as output:
output.write(r.content)
#file = open("/var/lib/tor/cached-microdesc-consensus", "r")
file = open(consensus, "r")
while True:
line1 = file.readline()
if not line1: break
if re.search("^s.*HSDir", line1, re.IGNORECASE):
line2 = file.readline()
numberOfHSDir += 1
if re.search("^v.*Tor 0.4.[6-9]", line2, re.IGNORECASE):
numberOfNonv2 += 1
else:
numberOfv2 += 1
dt = datetime.datetime.utcnow().strftime("%Y/%m/%d %H")
with open("/home/trackingv2/trackingv2.csv", "a") as csvFile:
csvFile.write("{},{},{}\n".format(numberOfv2, numberOfNonv2,dt))
#print("Num HSDir: {}".format(numberOfHSDir))
#print("< 0.4.6: {}".format(numberOfv2))
#print(">= 0.4.6: {}".format(numberOfNonv2))
#print("DT: {}".format(dt))
Loading…
Cancel
Save