behaviour

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package Behaviour provides a mechanism for reactors to report behaviour of peers.

Instead of a reactor calling the switch directly it will call the behaviour module which will handle the stoping and marking peer as good on behalf of the reactor.

There are four different behaviours a reactor can report.

1. bad message

type badMessage struct {
	explanation string
}

This message will request the peer be stopped for an error

2. message out of order

type messageOutOfOrder struct {
	explanation string
}

This message will request the peer be stopped for an error

3. consesnsus Vote

type consensusVote struct {
	explanation string
}

This message will request the peer be marked as good

4. block part

type blockPart struct {
	explanation string
}

This message will request the peer be marked as good

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MockReporter

type MockReporter struct {
	// contains filtered or unexported fields
}

MockReporter is a concrete implementation of the Reporter interface used in reactor tests to ensure reactors report the correct behaviour in manufactured scenarios.

func NewMockReporter

func NewMockReporter() *MockReporter

NewMockReporter returns a Reporter which records all reported behaviours in memory.

func (*MockReporter) GetBehaviours

func (mpbr *MockReporter) GetBehaviours(peerID p2p.ID) []PeerBehaviour

GetBehaviours returns all behaviours reported on the peer identified by peerID.

func (*MockReporter) Report

func (mpbr *MockReporter) Report(behaviour PeerBehaviour) error

Report stores the PeerBehaviour produced by the peer identified by peerID.

type PeerBehaviour

type PeerBehaviour struct {
	// contains filtered or unexported fields
}

PeerBehaviour is a struct describing a behaviour a peer performed. `peerID` identifies the peer and reason characterizes the specific behaviour performed by the peer.

func BadMessage

func BadMessage(peerID p2p.ID, explanation string) PeerBehaviour

BadMessage returns a badMessage PeerBehaviour.

func BlockPart

func BlockPart(peerID p2p.ID, explanation string) PeerBehaviour

BlockPart returns blockPart PeerBehaviour.

func ConsensusVote

func ConsensusVote(peerID p2p.ID, explanation string) PeerBehaviour

ConsensusVote returns a consensusVote PeerBehaviour.

func MessageOutOfOrder

func MessageOutOfOrder(peerID p2p.ID, explanation string) PeerBehaviour

MessageOutOfOrder returns a messagOutOfOrder PeerBehaviour.

type Reporter

type Reporter interface {
	Report(behaviour PeerBehaviour) error
}

Reporter provides an interface for reactors to report the behaviour of peers synchronously to other components.

type SwitchReporter

type SwitchReporter struct {
	// contains filtered or unexported fields
}

SwitchReporter reports peer behaviour to an internal Switch.

func NewSwitchReporter

func NewSwitchReporter(sw *p2p.Switch) *SwitchReporter

NewSwitchReporter return a new SwitchReporter instance which wraps the Switch.

func (*SwitchReporter) Report

func (spbr *SwitchReporter) Report(behaviour PeerBehaviour) error

Report reports the behaviour of a peer to the Switch.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL