-
Notifications
You must be signed in to change notification settings - Fork 1
/
DHTtest.py
62 lines (43 loc) · 1.16 KB
/
DHTtest.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
56
57
58
59
60
61
62
from ChordDHT import DHTnode as Node
import time, random
from threading import Thread
import multiprocessing
port = 9100
if __name__ == '__main__':
n1 = Node("127.0.0.1",port+1)
n2 = Node("127.0.0.1",port+2)
time.sleep(1)
n1.create()
print "yay1"
n2.join(n1.name)
print "yay2"
time.sleep(1)
nodes = [n1,n2]
for i in range(3,5):
n = Node("127.0.0.1",port+i)
print "yay"+str(i)
print "started", n
n.join(random.choice(nodes).name)
nodes.append(n)
time.sleep(1.0)
print "prepare to sleep"
time.sleep(3)
n = random.choice(nodes)
n.storeFile("constitution.txt")
n = random.choice(nodes)
blocks = n.retrieveFile("constitution.txt")
for block in blocks:
print block
for n in nodes:
print n.successorList
for i in range(0,100):
print "progress"
n = random.choice(nodes)
n.store(str(i)+"blah",str(i))
for i in range(0,100):
n = random.choice(nodes)
print n.retrieve(str(i)+"blah")
info = []
for n in nodes:
info.append(n.myInfo())
print sorted(info, key= lambda x: x[1])