From: Brian Warner Date: Sun, 3 Dec 2006 03:29:09 +0000 (-0700) Subject: avoid race conditions and multiple-notify in the Roster X-Git-Tag: tahoe_v0.1.0-0-UNSTABLE~489 X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/uri/frontends/somewhere?a=commitdiff_plain;h=6f7095ebb2ccefb3250372ada6a7db32204b1f20;p=tahoe-lafs%2Ftahoe-lafs.git avoid race conditions and multiple-notify in the Roster --- 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)])