-
Notifications
You must be signed in to change notification settings - Fork 0
/
dkg.py
55 lines (46 loc) · 1.4 KB
/
dkg.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
50
51
52
53
54
55
# import threading
import subprocess
import os
import re
import threading
import pyinotify
nodeid = 0
tempcontlist = []
status = "nosecret"
def onChange(ev):
global status
status = "sharegen"
def watch_secrets():
wm = pyinotify.WatchManager()
wm.add_watch('files/secrets', pyinotify.IN_CLOSE_WRITE, onChange)
notifier = pyinotify.Notifier(wm)
notifier.loop()
def dkg(nid):
global nodeid
# print "DKG starting...."
threading.Thread(target=startdkg).start()
threading.Thread(target=watch_secrets).start()
# print "DKG started...."
# startdkg()
def startdkg():
global nodeid
fp = open("files/contlist", "r")
while 1:
line = fp.readline()
if not line:
break
parse = re.search("([\S]+)\s([\S]+)\s([\S]+)\s([\S]+)\s([L]*)", line)
tempcontlist.append([parse.group(1), parse.group(2), parse.group(3), parse.group(4), parse.group(5)])
fp.close()
[nid, c_ip, c_port, cert_file, l] = tempcontlist[int(nodeid) - 1]
ltr = "./dkg/node %d certs/%d.pem certs/%d-key.pem files/contlist 0 0 0" % (int(c_port), int(nid), int(nid))
print
nodeid, ltr
# fp = open("dkg/rundkg","w")
# fp.write(ltr)
# fp.close()
# ltr = "../dkg/node %d ../dkg/certs/%d.pem ../dkg/certs/%d-key.pem ../dkg/contlist 0 0 0" % (int(c_port),
# int(nid), int(nid))
# print ltr
# os.chdir("dkg/")
subprocess.call(ltr)