-
Notifications
You must be signed in to change notification settings - Fork 0
/
chord.py
52 lines (46 loc) · 1.35 KB
/
chord.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
from pydht import DHT
import sys
import os
import time
import cPickle as pickle
class ChordNode():
"""docstring for ChordNode"""
def __init__(self, address, port, hostip):
self.address = address
self.port = port
self.hostip = hostip
def join(self):
print "Starting DHT Overlay"
if self.address == self.hostip:
print "Only node in swarm"
try:
print "Starting server"
dht = DHT(self.hostip, self.port)
print "DHT started"
return dht
except Exception, e:
raise e
else:
print "Joining DHT swarm"
try:
print "Starting server"
dht = DHT(self.hostip, self.port, boot_host=self.address, boot_port=self.port)
print "DHT started"
return dht
except Exception, e:
print e
class ChordSetter():
@staticmethod
def getval(dht, key):
print "Getting the host with key: " + key
try:
return dht[key]
except Exception, e:
print e
@staticmethod
def setval(dht, key, value):
print "Setting the host with key: " + key + " and value: " + value
try:
dht[key] = value
except Exception, e:
print e