From: Brian Warner Date: Sat, 2 Feb 2008 02:48:38 +0000 (-0700) Subject: introducer: allow nodes to refrain from publishing themselves, by passing furl=None... X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/frontends/%3C?a=commitdiff_plain;h=a01f9ce9ccfd31641a81d1038a5d5c35f4cb8e01;p=tahoe-lafs%2Ftahoe-lafs.git introducer: allow nodes to refrain from publishing themselves, by passing furl=None. This would be useful for clients who do not run storage servers. --- diff --git a/src/allmydata/interfaces.py b/src/allmydata/interfaces.py index c65af491..84a3d5e6 100644 --- a/src/allmydata/interfaces.py +++ b/src/allmydata/interfaces.py @@ -44,7 +44,7 @@ class RIIntroducerClient(RemoteInterface): return None class RIIntroducer(RemoteInterface): - def hello(node=RIIntroducerClient, furl=FURL): + def hello(node=RIIntroducerClient, furl=ChoiceOf(FURL, None)): return None class RIClient(RemoteInterface): diff --git a/src/allmydata/introducer.py b/src/allmydata/introducer.py index 9feba696..c8e08d25 100644 --- a/src/allmydata/introducer.py +++ b/src/allmydata/introducer.py @@ -44,15 +44,17 @@ class IntroducerService(service.MultiService, Referenceable): def _remove(): log.msg(" introducer: removing %s %s" % (node, furl)) self.nodes.remove(node) - self.furls.remove(furl) + if furl is not None: + self.furls.remove(furl) node.notifyOnDisconnect(_remove) - self.furls.add(furl) + if furl is not None: + self.furls.add(furl) + for othernode in self.nodes: + othernode.callRemote("new_peers", set([furl])) node.callRemote("new_peers", self.furls) if self._encoding_parameters is not None: node.callRemote("set_encoding_parameters", self._encoding_parameters) - for othernode in self.nodes: - othernode.callRemote("new_peers", set([furl])) self.nodes.add(node) class IntroducerClient(service.Service, Referenceable): @@ -176,7 +178,11 @@ class IntroducerClient(service.Service, Referenceable): self.reconnectors[furl] = self.tub.connectTo(furl, _got_peer) def _got_introducer(self, introducer): - self.log("introducing ourselves: %s, %s" % (self, self.my_furl[6:13])) + if self.my_furl: + my_furl_s = self.my_furl[6:13] + else: + my_furl_s = "" + self.log("introducing ourselves: %s, %s" % (self, my_furl_s)) self._connected = True d = introducer.callRemote("hello", node=self, diff --git a/src/allmydata/test/test_introducer.py b/src/allmydata/test/test_introducer.py index 0e1831bf..925acd0d 100644 --- a/src/allmydata/test/test_introducer.py +++ b/src/allmydata/test/test_introducer.py @@ -89,10 +89,13 @@ class TestIntroducer(unittest.TestCase, testutil.PollMixin): i.setServiceParent(self.parent) iurl = tub.registerReference(i) NUMCLIENTS = 5 + # we have 5 clients who publish themselves, and an extra one which + # does not. When the connections are fully established, all six nodes + # should have 5 connections each. clients = [] tubs = {} - for i in range(NUMCLIENTS): + for i in range(NUMCLIENTS+1): tub = Tub() #tub.setOption("logLocalFailures", True) #tub.setOption("logRemoteFailures", True) @@ -102,7 +105,11 @@ class TestIntroducer(unittest.TestCase, testutil.PollMixin): tub.setLocation("localhost:%d" % portnum) n = FakeNode() - node_furl = tub.registerReference(n) + log.msg("creating client %d: %s" % (i, tub.getShortTubID())) + if i < NUMCLIENTS: + node_furl = tub.registerReference(n) + else: + node_furl = None c = IntroducerClient(tub, iurl, node_furl) c.setServiceParent(self.parent)