From 6f7095ebb2ccefb3250372ada6a7db32204b1f20 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sat, 2 Dec 2006 20:29:09 -0700 Subject: [PATCH] avoid race conditions and multiple-notify in the Roster --- allmydata/client.py | 7 ++++--- allmydata/queen.py | 16 +++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/allmydata/client.py b/allmydata/client.py index d9e16a14..e973788f 100644 --- a/allmydata/client.py +++ b/allmydata/client.py @@ -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 diff --git a/allmydata/queen.py b/allmydata/queen.py index 1c84889f..2f50c300 100644 --- a/allmydata/queen.py +++ b/allmydata/queen.py @@ -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)]) -- 2.45.2