github.com/unionj-cloud/go-doudou/v2@v2.3.5/toolkit/memberlist/weightbroadcast.go (about) 1 package memberlist 2 3 /* 4 The broadcast mechanism works by maintaining a sorted list of messages to be 5 sent out. When a message is to be broadcast, the retransmit count 6 is set to zero and appended to the queue. The retransmit count serves 7 as the "priority", ensuring that newer messages get sent first. Once 8 a message hits the retransmit limit, it is removed from the queue. 9 10 Additionally, older entries can be invalidated by new messages that 11 are contradictory. For example, if we send "{suspect M1 inc: 1}, 12 then a following {alive M1 inc: 2} will invalidate that message 13 */ 14 15 type weightBroadcast struct { 16 node string 17 msg []byte 18 } 19 20 func NewWeightBroadcast(node string, msg []byte) *weightBroadcast { 21 return &weightBroadcast{ 22 node, 23 msg, 24 } 25 } 26 27 func (b *weightBroadcast) Invalidates(other Broadcast) bool { 28 // Check if that broadcast is a weight type 29 mb, ok := other.(*weightBroadcast) 30 if !ok { 31 return false 32 } 33 34 // Invalidates any message about the same node 35 return b.node == mb.node 36 } 37 38 func (b *weightBroadcast) Message() []byte { 39 return b.msg 40 } 41 42 func (b *weightBroadcast) Finished() { 43 }