mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-06 21:36:26 +00:00
* Move peer behaviour into it's own package
* refactor wip
* Adjust API and fix tests
* remove unused test struct
* Better error message
* Restructure:
+ Now behaviour is it's own package, we don't need to include
PeerBehaviour in every type.
+ Split up behaviours and reporters into seperate files
* doc string fixes
* Fix minor typos
* Update behaviour/reporter.go
Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com>
* Update behaviour/reporter.go
Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com>
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package behaviour
|
|
|
|
import (
|
|
"github.com/tendermint/tendermint/p2p"
|
|
)
|
|
|
|
// PeerBehaviour is a struct describing a behaviour a peer performed.
|
|
// `peerID` identifies the peer and reason characterizes the specific
|
|
// behaviour performed by the peer.
|
|
type PeerBehaviour struct {
|
|
peerID p2p.ID
|
|
reason interface{}
|
|
}
|
|
|
|
type badMessage struct {
|
|
explanation string
|
|
}
|
|
|
|
// BadMessage returns a badMessage PeerBehaviour.
|
|
func BadMessage(peerID p2p.ID, explanation string) PeerBehaviour {
|
|
return PeerBehaviour{peerID: peerID, reason: badMessage{explanation}}
|
|
}
|
|
|
|
type messageOutOfOrder struct {
|
|
explanation string
|
|
}
|
|
|
|
// MessageOutOfOrder returns a messagOutOfOrder PeerBehaviour.
|
|
func MessageOutOfOrder(peerID p2p.ID, explanation string) PeerBehaviour {
|
|
return PeerBehaviour{peerID: peerID, reason: badMessage{explanation}}
|
|
}
|
|
|
|
type consensusVote struct {
|
|
explanation string
|
|
}
|
|
|
|
// ConsensusVote returns a consensusVote PeerBehaviour.
|
|
func ConsensusVote(peerID p2p.ID, explanation string) PeerBehaviour {
|
|
return PeerBehaviour{peerID: peerID, reason: consensusVote{explanation}}
|
|
}
|
|
|
|
type blockPart struct {
|
|
explanation string
|
|
}
|
|
|
|
// BlockPart returns blockPart PeerBehaviour.
|
|
func BlockPart(peerID p2p.ID, explanation string) PeerBehaviour {
|
|
return PeerBehaviour{peerID: peerID, reason: blockPart{explanation}}
|
|
}
|