]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
avoid race conditions and multiple-notify in the Roster
authorBrian Warner <warner@lothar.com>
Sun, 3 Dec 2006 03:29:09 +0000 (20:29 -0700)
committerBrian Warner <warner@lothar.com>
Sun, 3 Dec 2006 03:29:09 +0000 (20:29 -0700)
allmydata/client.py
allmydata/queen.py

index d9e16a14fcfd17b0b6bb134a232232cb202404e4..e973788f62bb8f16bc65b41f7d9fa57017ea07e1 100644 (file)
@@ -77,7 +77,8 @@ class Client(node.Node, Referenceable):
                 continue
             self.log("adding peer %s" % idlib.b2a(nodeid))
             if nodeid in self.all_peers:
-                log.msg("weird, I already had an entry for them")
+                self.log("weird, I already had an entry for them")
+                return
             self.all_peers.add(nodeid)
             if nodeid not in self.connections:
                 d = self.tub.getReference(pburl)
@@ -100,8 +101,8 @@ class Client(node.Node, Referenceable):
     def get_remote_service(self, nodeid, servicename):
         if nodeid not in self.connections:
             return defer.fail(IndexError("no connection to that peer"))
-        d = self.connections[nodeid].callRemote("get_service",
-                                                name=servicename)
+        peer = self.connections[nodeid]
+        d = peer.callRemote("get_service", name=servicename)
         return d
 
 
index 1c84889f941fd63a7212df6d83d18d5527799c19..2f50c300acf9b318f7b64c2dce8623af0e6ca942 100644 (file)
@@ -18,18 +18,20 @@ class Roster(service.MultiService, Referenceable):
         self.connections = {}
 
     def remote_hello(self, nodeid, node, pburl):
-        log.msg("contact from %s" % idlib.b2a(nodeid))
-        eventually(self._educate_the_new_peer, node)
-        eventually(self._announce_new_peer, nodeid, pburl)
+        log.msg("roster: contact from %s" % idlib.b2a(nodeid))
+        eventually(self._educate_the_new_peer,
+                   node, list(self.phonebook.items()))
+        eventually(self._announce_new_peer,
+                   nodeid, pburl, list(self.connections.values()))
         self.phonebook[nodeid] = pburl
         self.connections[nodeid] = node
         node.notifyOnDisconnect(self._lost_node, nodeid)
 
-    def _educate_the_new_peer(self, node):
-        node.callRemote("add_peers", new_peers=list(self.phonebook.items()))
+    def _educate_the_new_peer(self, node, new_peers):
+        node.callRemote("add_peers", new_peers=new_peers)
 
-    def _announce_new_peer(self, new_nodeid, new_node_pburl):
-        for targetnode in self.connections.values():
+    def _announce_new_peer(self, new_nodeid, new_node_pburl, peers):
+        for targetnode in peers:
             targetnode.callRemote("add_peers",
                                   new_peers=[(new_nodeid, new_node_pburl)])