-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_hashrings.py
50 lines (46 loc) · 1.54 KB
/
make_hashrings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from stem.descriptor import DocumentHandler
from stem.descriptor import parse_file
from stem.descriptor.reader import DescriptorReader
import os
import tarfile
import binascii
import json
def getHashRing(entry):
cons = next(parse_file(entry, document_handler=DocumentHandler.DOCUMENT))
descriptors = cons.routers.items()
fingerprints = [desc[1].fingerprint for desc in descriptors]
return fingerprints
def stripOnion(onion):
new_onion = onion[3:]
return new_onion[2:-3]
def openFiles():
onions = open("descriptor_list.txt", "r")
for onion in onions:
folder = stripOnion(onion)
data = os.listdir("/home/mge/%s" % folder)
for datum in data:
datum = datum.strip(".json")
dates = datum.split("-")
yr = dates[0]
mon = dates[1]
day = dates[2]
hr = dates[3]
if os.path.exists("/home/mge/hashrings/%s-%s-%s-%s.json" % (yr, mon, day, hr)):
continue
else:
print(folder)
tarName = "/home/mge/old_consensus/consensuses-%s-%s.tar.xz" % (yr, mon)
tarFileName = "consensuses-%s-%s/%s/%s-%s-%s-%s-00-00-consensus" % (yr, mon, day, yr, mon, day, hr)
with tarfile.open(tarName, mode='r:xz') as tf:
try:
f = tf.extractfile(tf.getmember(tarFileName))
except:
print("FAILED: %s" % tarFileName)
continue
fingerprints = getHashRing(f)
output = open("/home/mge/hashrings/%s-%s-%s-%s.json" % (yr, mon, day, hr), 'w')
json.dump(fingerprints, output)
f.close()
tf.members = []
onions.close()
return