peers

package
v0.2.1-rc.2 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2022 License: GPL-3.0 Imports: 23 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// NodeInfoProtocol is the protocol.ID used for handshake
	NodeInfoProtocol = "/ssv/info/0.0.1"
)

Variables

View Source
var (
	// ErrWasPruned means the desired peer was pruned
	ErrWasPruned = errors.New("peer was pruned")
	// ErrNotFound means the desired peer was not found
	ErrNotFound = errors.New("peer not found")
	// ErrIndexingInProcess means the desired peer is currently being indexed
	ErrIndexingInProcess = errors.New("peer indexing in process")
)
View Source
var ErrAtPeersLimit = errors.New("peers limit was reached")

ErrAtPeersLimit is thrown when we reached peers limit

Functions

func HandleConnections

func HandleConnections(ctx context.Context, logger *zap.Logger, handshaker Handshaker) *libp2pnetwork.NotifyBundle

HandleConnections configures a network notifications handler that handshakes and tracks all p2p connections note that the node MUST register stream handler for handshake

func NewConnectionGater

func NewConnectionGater(logger *zap.Logger, idx ConnectionIndex) connmgr.ConnectionGater

NewConnectionGater creates a new instance of ConnectionGater

Types

type ConnectionIndex

type ConnectionIndex interface {
	// Connectedness returns the connection state of the given peer
	Connectedness(id peer.ID) libp2pnetwork.Connectedness
	// CanConnect returns whether we can connect to the given peer,
	// by checking if it is already connected or if we tried to connect to it recently and failed
	CanConnect(id peer.ID) bool
	// Limit checks if the node has reached peers limit
	Limit(dir libp2pnetwork.Direction) bool
	// IsBad returns whether the given peer is bad
	IsBad(id peer.ID) bool
}

ConnectionIndex is an interface for accessing peers connections

type HandshakeFilter

type HandshakeFilter func(info *records.NodeInfo) (bool, error)

HandshakeFilter can be used to filter nodes once we handshaked with them

func ForkVersionFilter

func ForkVersionFilter(forkVersion func() forksprotocol.ForkVersion) HandshakeFilter

ForkVersionFilter determines whether we will connect to the given node by the fork version

func NetworkIDFilter

func NetworkIDFilter(networkID string) HandshakeFilter

NetworkIDFilter determines whether we will connect to the given node by the network ID

type Handshaker

type Handshaker interface {
	Handshake(conn libp2pnetwork.Conn) error
	Handler() libp2pnetwork.StreamHandler
}

Handshaker is the interface for handshaking with peers. it uses node info protocol to exchange information with other nodes and decide whether we want to connect.

NOTE: due to compatibility with v0, we accept nodes with user agent as a fallback when the new protocol is not supported.

func NewHandshaker

func NewHandshaker(ctx context.Context, logger *zap.Logger, streams streams.StreamController, idx NodeInfoStore, connIdx ConnectionIndex, ids *identify.IDService, filters ...HandshakeFilter) Handshaker

NewHandshaker creates a new instance of handshaker

type Index

type Index interface {
	ConnectionIndex
	NodeInfoStore
	ScoreIndex
	io.Closer
}

Index is an interface for storing and accessing peers data It uses libp2p's Peerstore (github.com/libp2p/go-libp2p-peerstore) to store metadata of peers.

func NewPeersIndex

func NewPeersIndex(logger *zap.Logger, network libp2pnetwork.Network, self *records.NodeInfo, maxPeers func() int, netKeyProvider func() crypto.PrivKey, pruneTTL time.Duration) Index

NewPeersIndex creates a new Index

type NodeInfoStore

type NodeInfoStore interface {
	// SelfSealed returns a sealed, encoded of self node info
	SelfSealed() ([]byte, error)
	// Self returns the current node info
	Self() *records.NodeInfo
	// UpdateSelfRecord updating current self with new one
	UpdateSelfRecord(newInfo *records.NodeInfo)
	// Add indexes the given peer info
	Add(id peer.ID, node *records.NodeInfo) (bool, error)
	// NodeInfo returns the info of the given node
	NodeInfo(id peer.ID) (*records.NodeInfo, error)
	// State returns the state of the peer in the identity store
	State(id peer.ID) NodeState
	// EvictPruned removes the given operator or peer from pruned list
	EvictPruned(id peer.ID)
	// Prune marks the given peer as pruned
	Prune(id peer.ID) error
	// GC does garbage collection on current peers and states
	GC()
}

NodeInfoStore is an interface for managing peers identity

type NodeScore

type NodeScore struct {
	Name  string
	Value float64
}

NodeScore is a wrapping objet for scores

type NodeState

type NodeState int32

NodeState is the state of the node w.r.t to the Index

var (
	// StatePruned is the state for pruned nodes
	StatePruned NodeState = -1
	// StateUnknown is the state for unknown peers
	StateUnknown NodeState = 0
	// StateIndexing is the state for nodes that are currently being indexed / pending
	StateIndexing NodeState = 1
	// StateReady is the state for a connected, identified node
	StateReady NodeState = 2
)

func (NodeState) String added in v0.3.0

func (ns NodeState) String() string

type ScoreIndex

type ScoreIndex interface {
	// Score adds score to the given peer
	Score(id peer.ID, scores ...NodeScore) error
	// GetScore returns the desired score for the given peer
	GetScore(id peer.ID, names ...string) ([]NodeScore, error)
}

ScoreIndex is an interface for managing peers scores

type Transactional

type Transactional interface {
	Commit() error
	Rollback() error
	Get(key string) (interface{}, error)
	Put(key string, val interface{})

	io.Closer
}

Transactional is an interface for transactional access to a peerstore object

Jump to

Keyboard shortcuts

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