def __init__(self,host,ip): Node.__init__(self,host,ip) self.data = {} # data I'm responsible for self.backups = {} # data I'm holding onto for someone else self.predecessorList = [self.name]*NUM_PREDECESSORS self.predecessorLock = Lock() self.addNewFunc(self.getPredecessorList, "getPredecessorList") self.addNewFunc(self.put,"put") self.addNewFunc(self.get,"get") self.addNewFunc(self.store,"store") self.addNewFunc(self.storeFile,"storeFile") self.addNewFunc(self.retrieve,"retrieve") self.addNewFunc(self.retrieveFile,"retrieveFile") self.addNewFunc(self.backup,"backup") self.addNewFunc(self.myInfo,"myInfo")
import random from threading import Thread from hashlib import sha1 def randomLookups(nodes): for i in range(1000): target = sha1(str(random.randint(0,1000000))).hexdigest() print i n = random.choice(nodes) n.findSuccessor(target) print "done" port = 9500 n1 = Node("127.0.0.1",port+1) n2 = Node("127.0.0.1",port+2) n1.create() n2.join(n1.name) time.sleep(1) nodes = [n1,n2] for i in range(3,5): time.sleep(0.5) n = Node("127.0.0.1",port+i) print "started", n nodes.append(n) n.join(n1.name)