Ejemplo n.º 1
0
 def onResponsibilityChange(self):
     #print("BACKUP IS HAPPENING")
     records = list(self.database.getRecords())
     ##print(records)
     rlocs = list(map(lambda x: space.idToPoint(2, x), records))
     ##print(rlocs)
     lMap = {}
     for l,p in zip(rlocs,records):
         lMap[l]=p
     canidates = None
     with self.peersLock:
         candidates = self.seekCandidates[:]
     if candidates is None:
         return
     candidates.remove(self.loc)
     #print("canidates",candidates)
     if len(candidates) == 0:
         return #im alone, no backups to send
     for loc in rlocs:
         l = lMap[loc]
         bestLoc = space.getClosest(loc, candidates)
         peer = self.locPeerDict[bestLoc]
         value = self.database.get(l)
         #print(loc,l,peer)
         try:
             self.network.store(peer,l,value)#this backs up existing values, and stores old values on new nodes.
             #print("%s is backed up to %s"%(l,peer))
         except Exception as e:
             print(e)
             continue
Ejemplo n.º 2
0
    def seek(self,key):
        """
        Answers the question: of the nodes I know, which is the closest to key?
        Key is some key we are looking for.

        Essentially, seek(key) is a single step of a lookup(key) operation.
        Throw seek into a loop and you have iterative lookup!
        """
        loc = space.idToPoint(2, key)
        candidates = None
        with self.peersLock:
            candidates = self.seekCandidates
        if len(candidates) == 0:
            return self.info  # as Toad would say, "I'm the best!"
        bestLoc = space.getClosest(loc, candidates)
        peer = self.locPeerDict[bestLoc]
        return peer