From 9a4701d7095062b2e7502ca04b90bbe8bfc96906 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 6 Dec 2022 18:33:56 -0800 Subject: [PATCH] discovery: add new msgsToBroadcast struct This struct will be used to later on do filtering when we go to broadcast, based on if a message was locally sourced or granted from a remote peer. --- discovery/gossiper.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/discovery/gossiper.go b/discovery/gossiper.go index 8fc2fcc3b..e1fa53843 100644 --- a/discovery/gossiper.go +++ b/discovery/gossiper.go @@ -1028,6 +1028,31 @@ func (d *deDupedAnnouncements) AddMsgs(msgs ...networkMsg) { } } +// msgsToBroadcast is returned by Emit() and partitions the messages we'd like +// to broadcast next into messages that are locally sourced and those that are +// sourced remotely. +type msgsToBroadcast struct { + // localMsgs is the set of messages we created locally. + localMsgs []msgWithSenders + + // remoteMsgs is the set of messages that we received from a remote party. + remoteMsgs []msgWithSenders +} + +// addMsg adds a new message to the appropriate sub-slice. +func (m *msgsToBroadcast) addMsg(msg msgWithSenders) { + if msg.isLocal { + m.localMsgs = append(m.localMsgs, msg) + } else { + m.remoteMsgs = append(m.remoteMsgs, msg) + } +} + +// isEmpty returns true if the batch is empty. +func (m *msgsToBroadcast) isEmpty() bool { + return len(m.localMsgs) == 0 && len(m.remoteMsgs) == 0 +} + // Emit returns the set of de-duplicated announcements to be sent out during // the next announcement epoch, in the order of channel announcements, channel // updates, and node announcements. Each message emitted, contains the set of