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.
This commit is contained in:
Olaoluwa Osuntokun
2022-12-06 18:33:56 -08:00
parent e8177ea427
commit 9a4701d709

View File

@@ -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 // Emit returns the set of de-duplicated announcements to be sent out during
// the next announcement epoch, in the order of channel announcements, channel // the next announcement epoch, in the order of channel announcements, channel
// updates, and node announcements. Each message emitted, contains the set of // updates, and node announcements. Each message emitted, contains the set of