behavior

package
v0.35.4 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package Behavior provides a mechanism for reactors to report behavior of peers.

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

There are four different behaviors 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 behavior in manufactured scenarios.

func NewMockReporter

func NewMockReporter() *MockReporter

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

func (*MockReporter) GetBehaviors

func (mpbr *MockReporter) GetBehaviors(peerID types.NodeID) []PeerBehavior

GetBehaviors returns all behaviors reported on the peer identified by peerID.

func (*MockReporter) Report

func (mpbr *MockReporter) Report(behavior PeerBehavior) error

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

type PeerBehavior

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

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

func BadMessage

func BadMessage(peerID types.NodeID, explanation string) PeerBehavior

BadMessage returns a badMessage PeerBehavior.

func BlockPart

func BlockPart(peerID types.NodeID, explanation string) PeerBehavior

BlockPart returns blockPart PeerBehavior.

func ConsensusVote

func ConsensusVote(peerID types.NodeID, explanation string) PeerBehavior

ConsensusVote returns a consensusVote PeerBehavior.

func MessageOutOfOrder

func MessageOutOfOrder(peerID types.NodeID, explanation string) PeerBehavior

MessageOutOfOrder returns a messagOutOfOrder PeerBehavior.

type Reporter

type Reporter interface {
	Report(behavior PeerBehavior) error
}

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

type SwitchReporter

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

SwitchReporter reports peer behavior 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(behavior PeerBehavior) error

Report reports the behavior of a peer to the Switch.

Jump to

Keyboard shortcuts

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