Documentation
¶
Index ¶
- Constants
- Variables
- func GetSubnetsDistributionScores(stats *SubnetsStats, minPerSubnet int, mySubnets records.Subnets, ...) []int
- func GetTopScores(peerScores map[peer.ID]int, n int) map[peer.ID]int
- type ConnManager
- type ConnectionIndex
- type Index
- type MaxPeersProvider
- type NetworkKeyProvider
- type NodeInfoIndex
- type NodeScore
- type NodeState
- type NodeStates
- type ScoreIndex
- type SubnetsIndex
- type SubnetsStats
Constants ¶
const (
// NodeInfoProtocol is the protocol.ID used for handshake
NodeInfoProtocol = "/ssv/info/0.0.1"
)
Variables ¶
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.
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(logger *zap.Logger, n int, mySubnets records.Subnets, allPeers []peer.ID, topicMaxPeers int)
// TrimPeers will trim unprotected peers.
TrimPeers(ctx context.Context, logger *zap.Logger, 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(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(logger *zap.Logger, id peer.ID) bool
}
ConnectionIndex is an interface for accessing peers connections
type Index ¶
type Index interface {
ConnectionIndex
NodeInfoIndex
NodeStates
ScoreIndex
SubnetsIndex
io.Closer
}
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
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
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(logger *zap.Logger, 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 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 )
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
SubnetsStats holds a snapshot of subnets stats