OSDN Git Service

netsync add test case (#365)
[bytom/vapor.git] / netsync / consensusmgr / broadcast_msg.go
1 package consensusmgr
2
3 import (
4         "github.com/vapor/netsync/peers"
5 )
6
7 // BroadcastMsg the message that can be broadcast
8 // by peer set.
9 type BroadcastMsg struct {
10         msg       ConsensusMessage
11         transChan byte
12 }
13
14 // NewBroadcastMsg create concrete broadcast message, implement peers.BroadcastMsg interface.
15 func NewBroadcastMsg(msg ConsensusMessage, transChan byte) *BroadcastMsg {
16         return &BroadcastMsg{
17                 msg:       msg,
18                 transChan: transChan,
19         }
20 }
21
22 // GetChan get message transfer channel.
23 func (b *BroadcastMsg) GetChan() byte {
24         return b.transChan
25 }
26
27 // GetMsg get ConsensusMessage.
28 func (b *BroadcastMsg) GetMsg() interface{} {
29         return struct{ ConsensusMessage }{b.msg}
30 }
31
32 // MsgString get a string representation of the message.
33 func (b *BroadcastMsg) MsgString() string {
34         return b.msg.String()
35 }
36
37 // MarkSendRecord mark send message record to prevent messages from being sent repeatedly.
38 func (b *BroadcastMsg) MarkSendRecord(ps *peers.PeerSet, peers []string) {
39         b.msg.BroadcastMarkSendRecord(ps, peers)
40 }
41
42 // FilterTargetPeers filter target peers to filter the nodes that need to send messages.
43 func (b *BroadcastMsg) FilterTargetPeers(ps *peers.PeerSet) []string {
44         return b.msg.BroadcastFilterTargetPeers(ps)
45 }