peers

package
v0.3.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2022 License: GPL-3.0 Imports: 18 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")
)

Functions

func GetSubnetsDistributionScores added in v0.3.0

func GetSubnetsDistributionScores(stats *SubnetsStats, minPerSubnet int, mySubnets records.Subnets, topicMaxPeers int) []int

GetSubnetsDistributionScores returns current subnets scores based on peers distribution. subnets with low peer count would get higher score, and overloaded subnets gets a lower score.

func GetTopScores added in v0.3.0

func GetTopScores(peerScores map[peer.ID]int, n int) map[peer.ID]int

GetTopScores accepts a map of scores and returns the best n peers

Types

type ConnManager added in v0.3.0

type ConnManager interface {
	// TagBestPeers tags the best n peers from the given list, based on subnets distribution scores.
	TagBestPeers(n int, mySubnets records.Subnets, allPeers []peer.ID, topicMaxPeers int)
	// TrimPeers will trim unprotected peers.
	TrimPeers(ctx context.Context, net libp2pnetwork.Network)
}

ConnManager is a wrapper on top of go-libp2p-core/connmgr.ConnManager. exposing an abstract interface so we can have the flexibility of doing some stuff manually rather than relaying on libp2p's connection manager.

func NewConnManager added in v0.3.0

func NewConnManager(logger *zap.Logger, connMgr connmgrcore.ConnManager, subnetsIdx SubnetsIndex) ConnManager

NewConnManager creates a new conn manager. multiple instances can be created, but concurrency is not supported.

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 Index

Index is a facade interface of this package

func NewPeersIndex

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

NewPeersIndex creates a new Index

type MaxPeersProvider added in v0.3.0

type MaxPeersProvider func(topic string) int

MaxPeersProvider returns the max peers for the given topic. empty string means that we want to check the total max peers (for all topics).

type NetworkKeyProvider added in v0.3.0

type NetworkKeyProvider func() crypto.PrivKey

NetworkKeyProvider is a function that provides the network private key

type NodeInfoIndex added in v0.3.0

type NodeInfoIndex 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)
	// AddNodeInfo indexes the given peer info
	AddNodeInfo(id peer.ID, node *records.NodeInfo) (bool, error)
	// GetNodeInfo returns the info of the given node
	GetNodeInfo(id peer.ID) (*records.NodeInfo, error)
}

NodeInfoIndex is an interface for managing records.NodeInfo of network peers

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

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 NodeStates added in v0.3.0

type NodeStates interface {
	// 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()
}

NodeStates is an interface for managing NodeState across network peers

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 SubnetsIndex added in v0.3.0

type SubnetsIndex interface {
	// UpdatePeerSubnets updates the given peer's subnets
	UpdatePeerSubnets(id peer.ID, s records.Subnets) bool
	// GetSubnetPeers returns peers that are interested in the given subnet
	GetSubnetPeers(s int) []peer.ID
	// GetPeerSubnets returns subnets of the given peer
	GetPeerSubnets(id peer.ID) records.Subnets
	// GetSubnetsStats collects and returns subnets stats
	GetSubnetsStats() *SubnetsStats
}

SubnetsIndex stores information on subnets. it keeps track of subnets but doesn't mind regards actual connections that we have.

type SubnetsStats added in v0.3.0

type SubnetsStats struct {
	AvgConnected int
	PeersCount   []int
	Connected    []int
}

SubnetsStats holds a snapshot of subnets stats

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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