peerset

package
v0.0.0-...-c69f244 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2022 License: LGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// BadMessageValue used when fail to decode message.
	BadMessageValue Reputation = -(1 << 12)
	// BadMessageReason used when fail to decode message.
	BadMessageReason = "Bad message"

	// BadProtocolValue used when a peer is on unsupported protocol version.
	BadProtocolValue Reputation = math.MinInt32
	// BadProtocolReason used when a peer is on unsupported protocol version.
	BadProtocolReason = "Unsupported protocol"

	// TimeOutValue used when a peer doesn't respond in time to our messages.
	TimeOutValue Reputation = -(1 << 10)
	// TimeOutReason used when a peer doesn't respond in time to our messages.
	TimeOutReason = "Request timeout"

	// GossipSuccessValue used when a peer successfully sends a gossip messages.
	GossipSuccessValue Reputation = 1 << 4
	// GossipSuccessReason used when a peer successfully sends a gossip messages.
	GossipSuccessReason = "Successful gossip"

	// DuplicateGossipValue used when a peer sends us a gossip message that we already knew about.
	DuplicateGossipValue Reputation = -(1 << 2)
	// DuplicateGossipReason used when a peer send duplicate gossip message.
	DuplicateGossipReason = "Duplicate gossip"

	// GoodTransactionValue is the used for good transaction.
	GoodTransactionValue Reputation = 1 << 7
	// GoodTransactionReason is the reason for used for good transaction.
	GoodTransactionReason = "Good Transaction"

	// BadTransactionValue used when transaction import was not performed.
	BadTransactionValue Reputation = -(1 << 12)
	// BadTransactionReason when transaction import was not performed.
	BadTransactionReason = "Bad Transaction"

	// BadBlockAnnouncementValue is used when peer announces invalid block.
	BadBlockAnnouncementValue Reputation = -(1 << 12)
	// BadBlockAnnouncementReason is used when peer announces invalid block.
	BadBlockAnnouncementReason = "Bad block announcement"

	// IncompleteHeaderValue  is used when peer sends block with invalid header.
	IncompleteHeaderValue Reputation = -(1 << 20)
	// IncompleteHeaderReason is used when peer sends block with invalid header.
	IncompleteHeaderReason = "Incomplete header"

	// BannedThresholdValue used when we need to ban peer.
	BannedThresholdValue Reputation = 82 * (math.MinInt32 / 100)
	// BannedReason used when we need to ban peer.
	BannedReason = "Banned"

	// BadJustificationValue is used when peer send invalid justification.
	BadJustificationValue Reputation = -(1 << 16)
	// BadJustificationReason is used when peer send invalid justification.
	BadJustificationReason = "Bad justification"

	// GenesisMismatch is used when peer has a different genesis
	GenesisMismatch Reputation = math.MinInt32
	// GenesisMismatchReason used when a peer has a different genesis
	GenesisMismatchReason = "Genesis mismatch"
)

ReputationChange value and reason

Variables

View Source
var (
	ErrDisconnectReceivedForNonConnectedPeer = errors.New("received disconnect for non-connected node")

	ErrConfigSetIsEmpty = errors.New("config set is empty")

	ErrPeerDoesNotExist = errors.New("peer doesn't exist")

	ErrPeerDisconnected = errors.New("node is already disconnected")

	ErrOutgoingSlotsUnavailable = errors.New("not enough outgoing slots")

	ErrIncomingSlotsUnavailable = errors.New("not enough incoming slots")
)

Functions

This section is empty.

Types

type ActionReceiver

type ActionReceiver uint8

ActionReceiver represents the enum value for action to be performed on peerSet

func (ActionReceiver) String

func (a ActionReceiver) String() string

type ConfigSet

type ConfigSet struct {
	Set []*config
}

ConfigSet set of peerSet config.

func NewConfigSet

func NewConfigSet(maxInPeers, maxOutPeers uint32, reservedOnly bool, allocTime time.Duration) *ConfigSet

NewConfigSet creates a new config set for the peerSet

type DropReason

type DropReason int

DropReason represents reason for disconnection of the peer

const (
	// UnknownDrop is used when substream or connection has been closed for an unknown reason
	UnknownDrop DropReason = iota
	// RefusedDrop is used when sub-stream or connection has been explicitly refused by the target.
	// In other words, the peer doesn't actually belong to this set.
	RefusedDrop
)

type Handler

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

Handler manages peerSet.

func NewPeerSetHandler

func NewPeerSetHandler(cfg *ConfigSet) (*Handler, error)

NewPeerSetHandler creates a new *peerset.Handler.

func (*Handler) AddPeer

func (h *Handler) AddPeer(setID int, peers ...peer.ID)

AddPeer adds peer to peerSet.

func (*Handler) AddReservedPeer

func (h *Handler) AddReservedPeer(setID int, peers ...peer.ID)

AddReservedPeer adds reserved peer into peerSet.

func (*Handler) DisconnectPeer

func (h *Handler) DisconnectPeer(setID int, peers ...peer.ID)

DisconnectPeer calls for disconnecting a connection from peer.

func (*Handler) Incoming

func (h *Handler) Incoming(setID int, peers ...peer.ID)

Incoming calls when we have an incoming connection from peer.

func (*Handler) Messages

func (h *Handler) Messages() chan Message

Messages return result message chan.

func (*Handler) PeerReputation

func (h *Handler) PeerReputation(peerID peer.ID) (Reputation, error)

PeerReputation returns the reputation of the peer.

func (*Handler) RemovePeer

func (h *Handler) RemovePeer(setID int, peers ...peer.ID)

RemovePeer removes peer from peerSet.

func (*Handler) RemoveReservedPeer

func (h *Handler) RemoveReservedPeer(setID int, peers ...peer.ID)

RemoveReservedPeer remove reserved peer from peerSet.

func (*Handler) ReportPeer

func (h *Handler) ReportPeer(rep ReputationChange, peers ...peer.ID)

ReportPeer reports ReputationChange according to the peer behaviour.

func (*Handler) SetReservedPeer

func (h *Handler) SetReservedPeer(setID int, peers ...peer.ID)

SetReservedPeer set the reserve peer into peerSet

func (*Handler) SortedPeers

func (h *Handler) SortedPeers(setIdx int) chan peer.IDSlice

SortedPeers return chan for sorted connected peer in the peerSet.

func (*Handler) Start

func (h *Handler) Start(ctx context.Context)

Start starts peerSet processing

func (*Handler) Stop

func (h *Handler) Stop()

Stop closes the actionQueue and result message chan.

type Info

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

Info is state of a single set.

type MembershipState

type MembershipState int

MembershipState represent the state of node ingoing the set.

type Message

type Message struct {
	// Status of the peer in current set.
	Status Status

	// PeerID peer in message.
	PeerID peer.ID
	// contains filtered or unexported fields
}

Message that will be sent by the peerSet.

type MessageProcessor

type MessageProcessor interface {
	Process(Message)
}

MessageProcessor interface allows the network layer to receive and process messages from the peerstate layer

type PeerSet

type PeerSet struct {
	sync.Mutex
	// contains filtered or unexported fields
}

PeerSet is a container for all the components of a peerSet.

type PeersState

type PeersState struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

PeersState struct contains a list of nodes, where each node has a reputation and is either connected to us or not

func NewPeerState

func NewPeerState(cfgs []*config) (*PeersState, error)

NewPeerState initiates a new PeersState

type Reputation

type Reputation int32

Reputation represents reputation value of the node

type ReputationChange

type ReputationChange struct {
	// PeerReputation value
	Value Reputation
	// Reason for reputation change
	Reason string
}

ReputationChange is description of a reputation adjustment for a node

func (ReputationChange) String

func (r ReputationChange) String() string

type Status

type Status uint8

Status represents the enum value for Message

const (
	// Connect is request to open a connection to the given peer.
	Connect Status = iota
	// Drop the connection to the given peer, or cancel the connection attempt after a Connect.
	Drop
	// Accept incoming connect request.
	Accept
	// Reject incoming connect request.
	Reject
)

Jump to

Keyboard shortcuts

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