コード例 #1
0
ファイル: storeserver.py プロジェクト: atl/thrifty-p2p
 def cleanup(self):
     self.ring.remove(self.here)
     informed = set()
     if self.ring.nodes:
         for key, value in ((a, b) for (a, b) in self.store.items() if b):
             dest = self.get_node(key)
             try:
                 if location.loc2str(dest) not in informed:
                     remote_call('remove', dest, self.location, [self.location])
                 remote_call('ping', dest)
                 informed.add(location.loc2str(dest))
                 remote_call('put', dest, key, value)
             except location.NodeNotFound, tx:
                 print "not found"
                 pass
         if not informed:
             for dest in location.select_peers(self.ring.nodes):
                 try:
                     remote_call('remove', location.str2loc(dest), self.location, [self.location])
                     informed.add(dest)
                     break
                 except location.NodeNotFound, tx:
                     self.ring.remove(location.loc2str(tx.location))            
コード例 #2
0
ファイル: storeserver.py プロジェクト: atl/thrifty-p2p
 def add(self, loc, authorities):
     """
     Parameters:
      - location
      - authorities
     """
     key = location.loc2str(loc)
     authorities.append(self.location)
     destinations = location.select_peers(self.ring.nodes.difference(map(location.loc2str,authorities)))
     for destination in destinations:
         try:
             remote_call('add', location.str2loc(destination), loc, authorities)
             break
         except location.NodeNotFound, tx:
             self.remove(tx.location, map(location.str2loc, self.ring.nodes))
コード例 #3
0
ファイル: storeserver.py プロジェクト: atl/thrifty-p2p
 def get(self, key):
     """
     Parameters:
      - key
     """
     dest = self.get_node(key)
     if location.loc2str(dest) == self.here:
         if key in self.store:
             print 'found %s' % key
         return self.store[key]
     else:
         try:
             return remote_call('get', dest, key)
         except location.NodeNotFound, tx:
             self.remove(tx.location, map(location.str2loc, self.ring.nodes))
             return ''
コード例 #4
0
ファイル: storeserver.py プロジェクト: atl/thrifty-p2p
 def put(self, key, value):
     """
     Parameters:
      - key
      - value
     """
     dest = self.get_node(key)
     if location.loc2str(dest) == self.here:
         print 'received %s' % key
         self.store[key] = value
         return
     else:
         try:
             remote_call('put', dest, key, value)
         except location.NodeNotFound, tx:
             self.remove(tx.location, map(location.str2loc, self.ring.nodes))
             return
コード例 #5
0
ファイル: storeserver.py プロジェクト: atl/thrifty-p2p
 def add(self, loc, authorities):
     """
     Parameters:
      - location
      - authorities
     """
     key = location.loc2str(loc)
     authorities.append(self.location)
     destinations = location.select_peers(self.ring.nodes.difference(map(location.loc2str,authorities)))
     for destination in destinations:
         try:
             remote_call('add', location.str2loc(destination), loc, authorities)
             break
         except location.NodeNotFound, tx:
             self.remove(tx.location, map(location.str2loc, self.ring.nodes))
     locstr = location.loc2str(loc)
     self.ring.append(locstr)
     sleep(WAITPERIOD)
     for key, value in self.store.items():
         if location.loc2str(self.get_node(key)) == locstr:
             remote_call('put', loc, key, value)
             del self.store[key] 
             print 'dropped %s' % key
     print "added %s:%d" % (loc.address, loc.port)
 
 def debug(self):
     a = "self.location: %r\n" % self.location
     a += "self.ring.nodes:\n%r\n" % self.ring.nodes
     a += "self.store:\n%r\n" % self.store
     print a