You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.3 KiB

  1. package behavior
  2. import (
  3. "github.com/tendermint/tendermint/p2p"
  4. )
  5. // PeerBehavior is a struct describing a behavior a peer performed.
  6. // `peerID` identifies the peer and reason characterizes the specific
  7. // behavior performed by the peer.
  8. type PeerBehavior struct {
  9. peerID p2p.NodeID
  10. reason interface{}
  11. }
  12. type badMessage struct {
  13. explanation string
  14. }
  15. // BadMessage returns a badMessage PeerBehavior.
  16. func BadMessage(peerID p2p.NodeID, explanation string) PeerBehavior {
  17. return PeerBehavior{peerID: peerID, reason: badMessage{explanation}}
  18. }
  19. type messageOutOfOrder struct {
  20. explanation string
  21. }
  22. // MessageOutOfOrder returns a messagOutOfOrder PeerBehavior.
  23. func MessageOutOfOrder(peerID p2p.NodeID, explanation string) PeerBehavior {
  24. return PeerBehavior{peerID: peerID, reason: messageOutOfOrder{explanation}}
  25. }
  26. type consensusVote struct {
  27. explanation string
  28. }
  29. // ConsensusVote returns a consensusVote PeerBehavior.
  30. func ConsensusVote(peerID p2p.NodeID, explanation string) PeerBehavior {
  31. return PeerBehavior{peerID: peerID, reason: consensusVote{explanation}}
  32. }
  33. type blockPart struct {
  34. explanation string
  35. }
  36. // BlockPart returns blockPart PeerBehavior.
  37. func BlockPart(peerID p2p.NodeID, explanation string) PeerBehavior {
  38. return PeerBehavior{peerID: peerID, reason: blockPart{explanation}}
  39. }