peers

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package peers provides information about peers at the Ethereum consensus protocol level.

"Protocol level" is the level above the network level, so this layer never sees or interacts with (for example) hosts that are uncontactable due to being down, firewalled, etc. Instead, this works with peers that are contactable but may or may not be of the correct fork version, not currently required due to the number of current connections, etc.

A peer can have one of a number of states:

- connected if we are able to talk to the remote peer - connecting if we are attempting to be able to talk to the remote peer - disconnecting if we are attempting to stop being able to talk to the remote peer - disconnected if we are not able to talk to the remote peer

For convenience, there are two aggregate states expressed in functions:

- active if we are connecting or connected - inactive if we are disconnecting or disconnected

Peer information is persistent for the run of the service. This allows for collection of useful long-term statistics such as number of bad responses obtained from the peer, giving the basis for decisions to not talk to known-bad peers (by de-scoring them).

Index

Constants

View Source
const (
	// PeerDisconnected means there is no connection to the peer.
	PeerDisconnected peerdata.PeerConnectionState = iota
	// PeerDisconnecting means there is an on-going attempt to disconnect from the peer.
	PeerDisconnecting
	// PeerConnected means the peer has an active connection.
	PeerConnected
	// PeerConnecting means there is an on-going attempt to connect to the peer.
	PeerConnecting
)
View Source
const (
	// ColocationLimit restricts how many peer identities we can see from a single ip or ipv6 subnet.
	ColocationLimit = 5

	// InboundRatio is the proportion of our connected peer limit at which we will allow inbound peers.
	InboundRatio = float64(0.8)

	// MinBackOffDuration minimum amount (in milliseconds) to wait before peer is re-dialed.
	// When node and peer are dialing each other simultaneously connection may fail. In order, to break
	// of constant dialing, peer is assigned some backoff period, and only dialed again once that backoff is up.
	MinBackOffDuration = 100
	// MaxBackOffDuration maximum amount (in milliseconds) to wait before peer is re-dialed.
	MaxBackOffDuration = 5000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Status

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

Status is the structure holding the peer status information.

func NewStatus

func NewStatus(ctx context.Context, config *StatusConfig) *Status

NewStatus creates a new status entity.

func (*Status) Active

func (p *Status) Active() []peer.ID

Active returns the peers that are connecting or connected.

func (*Status) Add

func (p *Status) Add(record *enr.Record, pid peer.ID, address ma.Multiaddr, direction network.Direction)

Add adds a peer. If a peer already exists with this ID its address and direction are updated with the supplied data.

func (*Status) Address

func (p *Status) Address(pid peer.ID) (ma.Multiaddr, error)

Address returns the multiaddress of the given remote peer. This will error if the peer does not exist.

func (*Status) All

func (p *Status) All() []peer.ID

All returns all the peers regardless of state.

func (*Status) Bad

func (p *Status) Bad() []peer.ID

Bad returns the peers that are bad.

func (*Status) BestPeers

func (p *Status) BestPeers(wantPeers int, ourCurrentHeight *uint256.Int) (*uint256.Int, []peer.ID)

BestPeers returns the highest blockNumber higher than ours, and is shared by at least minPeers.

func (*Status) ChainState

func (p *Status) ChainState(pid peer.ID) (*sync_pb.Status, error)

ChainState gets the chain state of the given remote peer. This will error if the peer does not exist. This will error if there is no known chain state for the peer.

func (*Status) ChainStateLastUpdated

func (p *Status) ChainStateLastUpdated(pid peer.ID) (time.Time, error)

ChainStateLastUpdated gets the last time the chain state of the given remote peer was updated. This will error if the peer does not exist.

func (*Status) ConnState

func (p *Status) ConnState(pid peer.ID) (peerdata.PeerConnectionState, error)

ConnState

func (*Status) Connected

func (p *Status) Connected() []peer.ID

Connected returns the peers that are connected.

func (*Status) ConnectedPeerLimit

func (p *Status) ConnectedPeerLimit() uint64

ConnectedPeerLimit returns the peer limit of concurrent peers connected to the beacon-node.

func (*Status) Connecting

func (p *Status) Connecting() []peer.ID

Connecting returns the peers that are connecting.

func (*Status) ConnectionState

func (p *Status) ConnectionState(pid peer.ID) (peerdata.PeerConnectionState, error)

ConnectionState gets the connection state of the given remote peer. This will error if the peer does not exist.

func (*Status) DialArgs

func (p *Status) DialArgs(pid peer.ID) (string, error)

DialArgs returns the ip address for the corresponding peer id.

func (*Status) Direction

func (p *Status) Direction(pid peer.ID) (network.Direction, error)

Direction returns the direction of the given remote peer. This will error if the peer does not exist.

func (*Status) Disconnected

func (p *Status) Disconnected() []peer.ID

Disconnected returns the peers that are disconnected.

func (*Status) Disconnecting

func (p *Status) Disconnecting() []peer.ID

Disconnecting returns the peers that are disconnecting.

func (*Status) ENR

func (p *Status) ENR(pid peer.ID) (*enr.Record, error)

ENR returns the enr for the corresponding peer id.

func (*Status) GetPing

func (p *Status) GetPing(pid peer.ID) (*sync_pb.Ping, error)

GetSeqNumber

func (*Status) HighestBlockNumber

func (p *Status) HighestBlockNumber() *uint256.Int

HighestBlockNumber returns the highest epoch reported epoch amongst peers.

func (*Status) IP

func (p *Status) IP(pid peer.ID) (net.IP, error)

IP returns the ip address for the corresponding peer id.

func (*Status) Inactive

func (p *Status) Inactive() []peer.ID

Inactive returns the peers that are disconnecting or disconnected.

func (*Status) Inbound

func (p *Status) Inbound() []peer.ID

Inbound returns the current batch of inbound peers.

func (*Status) InboundConnected

func (p *Status) InboundConnected() []peer.ID

InboundConnected returns the current batch of inbound peers that are connected.

func (*Status) InboundLimit

func (p *Status) InboundLimit() int

InboundLimit returns the current inbound peer limit.

func (*Status) IsAboveInboundLimit

func (p *Status) IsAboveInboundLimit() bool

IsAboveInboundLimit checks if we are above our current inbound peer limit.

func (*Status) IsActive

func (p *Status) IsActive(pid peer.ID) bool

IsActive checks if a peers is active and returns the result appropriately.

func (*Status) IsBad

func (p *Status) IsBad(pid peer.ID) bool

IsBad states if the peer is to be considered bad (by *any* of the registered scorers). If the peer is unknown this will return `false`, which makes using this function easier than returning an error.

func (*Status) IsReadyToDial

func (p *Status) IsReadyToDial(pid peer.ID) bool

IsReadyToDial checks where the given peer is ready to be dialed again.

func (*Status) MaxPeerLimit

func (p *Status) MaxPeerLimit() int

MaxPeerLimit returns the max peer limit stored in the current peer store.

func (*Status) NextValidTime

func (p *Status) NextValidTime(pid peer.ID) (time.Time, error)

NextValidTime gets the earliest possible time it is to contact/dial a peer again. This is used to back-off from peers in the event they are 'full' or have banned us.

func (*Status) Outbound

func (p *Status) Outbound() []peer.ID

Outbound returns the current batch of outbound peers.

func (*Status) OutboundConnected

func (p *Status) OutboundConnected() []peer.ID

OutboundConnected returns the current batch of outbound peers that are connected.

func (*Status) PeersToPrune

func (p *Status) PeersToPrune() []peer.ID

PeersToPrune selects the most suitable inbound peers to disconnect the host peer from. As of this moment the pruning relies on simple heuristics such as bad response count. In the future scoring will be used to determine the most suitable peers to take out.

func (*Status) Prune

func (p *Status) Prune()

Prune clears out and removes outdated and disconnected peers.

func (*Status) RandomizeBackOff

func (p *Status) RandomizeBackOff(pid peer.ID)

RandomizeBackOff adds extra backoff period during which peer will not be dialed.

func (*Status) Scorers

func (p *Status) Scorers() *scorers.Service

Scorers exposes peer scoring management service.

func (*Status) SetChainState

func (p *Status) SetChainState(pid peer.ID, chainState *sync_pb.Status)

SetChainState sets the chain state of the given remote peer.

func (*Status) SetConnectionState

func (p *Status) SetConnectionState(pid peer.ID, state peerdata.PeerConnectionState)

SetConnectionState sets the connection state of the given remote peer.

func (*Status) SetNextValidTime

func (p *Status) SetNextValidTime(pid peer.ID, nextTime time.Time)

SetNextValidTime sets the earliest possible time we are able to contact this peer again.

func (*Status) SetPing

func (p *Status) SetPing(pid peer.ID, ping *sync_pb.Ping)

SetMetadata

type StatusConfig

type StatusConfig struct {
	// PeerLimit specifies maximum amount of concurrent peers that are expected to be connect to the node.
	PeerLimit int
	// ScorerParams holds peer scorer configuration params.
	ScorerParams *scorers.Config
}

StatusConfig represents peer status service params.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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