import os.path
+import sha
from foolscap import Tub, Referenceable
from twisted.application import service
from twisted.python import log
def get_remote_service(self, nodeid, servicename):
if nodeid not in self.connections:
raise IndexError("no connection to that peer")
- d = self.connections[nodeid].callRemote("get_service", name=servicename)
+ d = self.connections[nodeid].callRemote("get_service",
+ name=servicename)
return d
+
+
+ def permute_peerids(self, key, max_count=None):
+ # TODO: eventually reduce memory consumption by doing an insertion
+ # sort of at most max_count elements
+ results = []
+ for nodeid in self.all_peers:
+ permuted = sha.new(key + nodeid).digest()
+ results.append((permuted, nodeid))
+ results.sort()
+ results = [r[1] for r in results]
+ if max_count is None:
+ return results
+ return results[:max_count]
from allmydata import client
class Basic(unittest.TestCase):
- def testLoadable(self):
+ def test_loadable(self):
c = client.Client("")
c.startService()
return c.stopService()
+ def test_permute(self):
+ c = client.Client("")
+ c.all_peers = ["%d" % i for i in range(5)]
+ self.failUnlessEqual(c.permute_peerids("one"), ['3','1','0','4','2'])
+ self.failUnlessEqual(c.permute_peerids("one", 3), ['3','1','0'])
+ self.failUnlessEqual(c.permute_peerids("two"), ['0','4','2','1','3'])
+ c.all_peers = []
+ self.failUnlessEqual(c.permute_peerids("one"), [])