示例#1
0
 def fastFindSucc (self, key):
   """
     scalable key location
     returns: the peer
   """
   succ= self.getSucc ()
   self.debug (1, "being asked about succ of %d" % (key))
   if succ and ocBetween (self.key (), key, succ.key ()):
     return succ
   else:
     try:
       # ask the closest one
       # WRONG: must find the closest one not connected (or something)
       # we can try to defer the realization of this new peer.
       # peer= self.findAuth (key)
       peer= self.findKnownSucc (key)
       if not peer==self._self:
         self.debug (1, "asking %s about succ of %d" % (peer, key))
         (url, key)= peer.findSucc (key)
         if peer.kind ()==Normal:
           peer.close ()
       else:
         self.debug (1, 'fallbacking to myself')
         (url, key)= self.params ()
         url= str(url)
       # add it to the known peer's list
       return self._peers.getNavel (url, key)
     except UmbDead:
       # that guy's dead! let's bury him!
       self._peers.delNavel (peer.key ())
       # and try again
       return self.fastFindSucc (key)
示例#2
0
 def findSucc (self, key):
   """
     simple key location
     returns: the peer
   """
   succ= self.getSucc ()
   if ocBetween (self.key (), key, succ.key ()):
     return succ
   else:
     # ask the next one
     self.debug (1, "asking %s about succ of %d" % (succ, key))
     (url, key)= succ.findSucc (key)
     # succ.close ()
     # add it to the known peer's list
     return self._peers.getNavel (url, key)