diff --git a/mesh/gossip_channel.go b/mesh/gossip_channel.go index 796a88c8..c20a7963 100644 --- a/mesh/gossip_channel.go +++ b/mesh/gossip_channel.go @@ -151,11 +151,10 @@ func (c *GossipChannel) relayBroadcast(srcName PeerName, update GossipData) erro func (c *GossipChannel) sendBroadcast(srcName PeerName, update GossipData) { c.routes.EnsureRecalculated() - nextHops := c.routes.BroadcastAll(srcName) - if len(nextHops) == 0 { + connections := c.ourself.ConnectionsTo(c.routes.BroadcastAll(srcName)) + if len(connections) == 0 { return } - connections := c.ourself.ConnectionsTo(nextHops) for _, msg := range update.Encode() { protocolMsg := ProtocolMsg{ProtocolGossipBroadcast, GobEncode(c.name, srcName, msg)} // FIXME a single blocked connection can stall us @@ -167,20 +166,12 @@ func (c *GossipChannel) sendBroadcast(srcName PeerName, update GossipData) { func (c *GossipChannel) relay(srcName PeerName, data GossipData) { c.routes.EnsureRecalculated() - destinations := c.routes.RandomNeighbours(srcName) - if len(destinations) == 0 { - return - } - c.sendDown(c.ourself.ConnectionsTo(destinations), data) + c.sendDown(c.ourself.ConnectionsTo(c.routes.RandomNeighbours(srcName)), data) } func (c *GossipChannel) Send(data GossipData) { c.routes.EnsureRecalculated() - destinations := c.routes.RandomNeighbours(c.ourself.Name) - if len(destinations) == 0 { - return - } - c.sendDown(c.ourself.ConnectionsTo(destinations), data) + c.sendDown(c.ourself.ConnectionsTo(c.routes.RandomNeighbours(c.ourself.Name)), data) } func (c *GossipChannel) SendDown(conn Connection, data GossipData) { diff --git a/mesh/local_peer.go b/mesh/local_peer.go index 72262e59..7592c81b 100644 --- a/mesh/local_peer.go +++ b/mesh/local_peer.go @@ -45,6 +45,9 @@ func (peer *LocalPeer) ConnectionTo(name PeerName) (Connection, bool) { } func (peer *LocalPeer) ConnectionsTo(names []PeerName) []Connection { + if len(names) == 0 { + return nil + } conns := make([]Connection, 0, len(names)) peer.RLock() defer peer.RUnlock()