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