]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
introducer: allow nodes to refrain from publishing themselves, by passing furl=None...
authorBrian Warner <warner@allmydata.com>
Sat, 2 Feb 2008 02:48:38 +0000 (19:48 -0700)
committerBrian Warner <warner@allmydata.com>
Sat, 2 Feb 2008 02:48:38 +0000 (19:48 -0700)
src/allmydata/interfaces.py
src/allmydata/introducer.py
src/allmydata/test/test_introducer.py

index c65af491229b5162fbc8cd2c2afaf29613628bb7..84a3d5e6daba07e05fd6d239bcd0b1efaeaea87a 100644 (file)
@@ -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):
index 9feba696be303d4cdd856519d64adb35edb50cad..c8e08d2567f74fb1eda89fada346864f99890472 100644 (file)
@@ -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 = "<none>"
+        self.log("introducing ourselves: %s, %s" % (self, my_furl_s))
         self._connected = True
         d = introducer.callRemote("hello",
                                   node=self,
index 0e1831bfa7f21696f12bd1db7245860d6cf4d348..925acd0dc71dedafa8bcf8aaed1b49377d10ff54 100644 (file)
@@ -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)