From 702bf7be29934f0e78a87bb06bb406b2cced6855 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 26 Dec 2017 16:25:35 +0100 Subject: [PATCH] server: Broadcast now takes a set of peers to skip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In this commit, we modify the Broadcast to take a *set* of peers to skip, rather than just a single peer. We make this modification as when a new channel is discovered, it’s likely the case that we get the announcement from several peers rather than a single peer. With this change, we’ll ensure that the caller (who is aware of the set of senders) is able to properly avoid wasting bandwidth by re-sending the message to all peers that sent it to us originally. --- server.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/server.go b/server.go index 692e59b3b..1239a4b9a 100644 --- a/server.go +++ b/server.go @@ -845,7 +845,7 @@ func (s *server) establishPersistentConnections() error { // messages to all peers other than the one specified by the `skip` parameter. // // NOTE: This function is safe for concurrent access. -func (s *server) BroadcastMessage(skip *btcec.PublicKey, +func (s *server) BroadcastMessage(skip map[routing.Vertex]struct{}, msgs ...lnwire.Message) error { s.mu.Lock() @@ -859,7 +859,7 @@ func (s *server) BroadcastMessage(skip *btcec.PublicKey, // // NOTE: This method MUST be called while the server's mutex is locked. func (s *server) broadcastMessages( - skip *btcec.PublicKey, + skips map[routing.Vertex]struct{}, msgs []lnwire.Message) error { srvrLog.Debugf("Broadcasting %v messages", len(msgs)) @@ -869,10 +869,13 @@ func (s *server) broadcastMessages( // throughout this process to ensure we deliver messages to exact set // of peers present at the time of invocation. var wg sync.WaitGroup - for pubStr, sPeer := range s.peersByPub { - if skip != nil && sPeer.addr.IdentityKey.IsEqual(skip) { - srvrLog.Debugf("Skipping %v in broadcast", pubStr) - continue + for _, sPeer := range s.peersByPub { + if skips != nil { + if _, ok := skips[sPeer.pubKeyBytes]; ok { + srvrLog.Tracef("Skipping %x in broadcast", + sPeer.pubKeyBytes[:]) + continue + } } // Dispatch a go routine to enqueue all messages to this peer.