github.com/annchain/OG@v0.0.9/consensus/bft_test/dummy_test.go (about) 1 package bft_test 2 3 import ( 4 "github.com/annchain/OG/consensus/bft" 5 ) 6 7 type LocalBftPeerCommunicator struct { 8 Myid int 9 PeerIns []chan *bft.BftMessageEvent 10 pipe chan *bft.BftMessageEvent //pipeIn is the receiver of the outside messages 11 } 12 13 func (d *LocalBftPeerCommunicator) HandleIncomingMessage(msgEvent *bft.BftMessageEvent) { 14 d.pipe <- msgEvent 15 } 16 17 func NewLocalBftPeerCommunicator(myid int, incoming chan *bft.BftMessageEvent, peers []chan *bft.BftMessageEvent) *LocalBftPeerCommunicator { 18 d := &LocalBftPeerCommunicator{ 19 PeerIns: peers, 20 Myid: myid, 21 pipe: incoming, 22 } 23 return d 24 } 25 26 func (d *LocalBftPeerCommunicator) Broadcast(msg bft.BftMessage, peers []bft.BftPeer) { 27 for _, peer := range peers { 28 go func(peer bft.BftPeer) { 29 //ffchan.NewTimeoutSenderShort(d.PeerIns[peer.Id], msg, "bft") 30 d.PeerIns[peer.Id] <- &bft.BftMessageEvent{ 31 Message: msg, 32 Peer: peer, 33 } 34 }(peer) 35 } 36 } 37 38 func (d *LocalBftPeerCommunicator) Unicast(msg bft.BftMessage, peer bft.BftPeer) { 39 go func() { 40 //ffchan.NewTimeoutSenderShort(d.PeerIns[peer.Id], msg, "bft") 41 d.PeerIns[peer.Id] <- &bft.BftMessageEvent{ 42 Message: msg, 43 Peer: peer, 44 } 45 }() 46 } 47 48 func (d *LocalBftPeerCommunicator) GetPipeIn() chan *bft.BftMessageEvent { 49 return d.pipe 50 } 51 52 func (d *LocalBftPeerCommunicator) GetPipeOut() chan *bft.BftMessageEvent { 53 return d.pipe 54 } 55 56 57 type dummyProposalGenerator struct { 58 CurrentHeight uint64 59 } 60 61 func (d dummyProposalGenerator) ProduceProposal() (proposal bft.Proposal, validCondition bft.ProposalCondition) { 62 p := bft.StringProposal{ 63 Content: "XXX", 64 } 65 return &p, bft.ProposalCondition{ValidHeight: d.CurrentHeight} 66 } 67 68 type dummyProposalValidator struct { 69 } 70 71 func (d dummyProposalValidator) ValidateProposal(proposal bft.Proposal) error { 72 return nil 73 } 74 75 type dummyDecisionMaker struct { 76 } 77 78 func (d dummyDecisionMaker) MakeDecision(proposal bft.Proposal, state *bft.HeightRoundState) (bft.ConsensusDecision, error) { 79 return proposal, nil 80 }