Documentation ¶
Index ¶
- Constants
- Variables
- func GetSubnetsDistributionScores(stats *SubnetsStats, minPerSubnet int, mySubnets records.Subnets, ...) []float64
- func GetTopScores(peerScores map[peer.ID]PeerScore, n int) map[peer.ID]PeerScore
- func NewGossipScoreIndex() *gossipScoreIndex
- func NewPeerInfoIndex() *peerInfoIndex
- func NewPeersIndex(logger *zap.Logger, network libp2pnetwork.Network, self *records.NodeInfo, ...) *peersIndex
- type ConnManager
- type ConnectionIndex
- type GossipScoreIndex
- type Index
- type MaxPeersProvider
- type NetworkKeyProvider
- type NodeInfoIndex
- type NodeScore
- type PeerInfo
- type PeerInfoIndex
- type PeerScore
- type PeerState
- type ScoreIndex
- type SubnetsIndex
- type SubnetsStats
Constants ¶
const (
// NodeInfoProtocol is the protocol.ID used for handshake
NodeInfoProtocol = "/ssv/info/0.0.1"
)
Variables ¶
var ( // ErrNotFound means the desired peer was not found ErrNotFound = errors.New("peer not found") )
Functions ¶
func GetSubnetsDistributionScores ¶ added in v0.3.0
func GetSubnetsDistributionScores(stats *SubnetsStats, minPerSubnet int, mySubnets records.Subnets, topicMaxPeers int) []float64
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 (possibly negative). Subnets in which the node doesn't participate receive a score of 0.
func GetTopScores ¶ added in v0.3.0
GetTopScores accepts a map of scores and returns the best n peers
func NewGossipScoreIndex ¶ added in v1.3.10
func NewGossipScoreIndex() *gossipScoreIndex
func NewPeerInfoIndex ¶ added in v1.1.0
func NewPeerInfoIndex() *peerInfoIndex
func NewPeersIndex ¶
func NewPeersIndex(logger *zap.Logger, network libp2pnetwork.Network, self *records.NodeInfo, maxPeers MaxPeersProvider, netKeyProvider NetworkKeyProvider, subnetsCount int, pruneTTL time.Duration, gossipScoreIndex GossipScoreIndex) *peersIndex
NewPeersIndex creates a new Index
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) // DisconnectFromBadPeers will disconnect from bad peers according to their gossip scores. It returns the number of disconnected peers. DisconnectFromBadPeers(logger *zap.Logger, net libp2pnetwork.Network, allPeers []peer.ID) int // DisconnectFromIrrelevantPeers will disconnect from at most [disconnectQuota] peers that doesn't share any subnet in common. It returns the number of disconnected peers. DisconnectFromIrrelevantPeers(logger *zap.Logger, disconnectQuota int, net libp2pnetwork.Network, allPeers []peer.ID, mySubnets records.Subnets) int }
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, gossipScoreIndex GossipScoreIndex) 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 // AtLimit checks if the node has reached peers limit AtLimit(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 GossipScoreIndex ¶ added in v1.3.10
type GossipScoreIndex interface { // AddScore adds a score for a peer SetScores(scores map[peer.ID]float64) // GetGossipScore returns the peer score and a boolean flag for whether it has such score or not GetGossipScore(peerID peer.ID) (float64, bool) // HasBadGossipScore returns true if the peer has a bad gossip score HasBadGossipScore(peerID peer.ID) (bool, float64) }
GossipScoreIndex serves as an interface to get a peer's gossip score
type Index ¶
type Index interface { ConnectionIndex NodeInfoIndex PeerInfoIndex ScoreIndex SubnetsIndex io.Closer GossipScoreIndex }
Index is a facade interface of this package
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
type NetworkKeyProvider func() libp2pcrypto.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(sender, recipient peer.ID, permissioned bool, operatorSigner keys.OperatorSigner) ([]byte, error) // Self returns the current node info Self() *records.NodeInfo // UpdateSelfRecord updating current self with new one UpdateSelfRecord(newInfo *records.NodeInfo) // SetNodeInfo updates the given peer with the NodeInfo. SetNodeInfo(id peer.ID, node *records.NodeInfo) // NodeInfo returns the NodeInfo of the given peers, or nil if not found. NodeInfo(id peer.ID) *records.NodeInfo }
NodeInfoIndex is an interface for managing records.NodeInfo of network peers
type PeerInfoIndex ¶ added in v1.1.0
type PeerInfoIndex interface { // PeerInfo returns the PeerInfo of the given peer, or nil if not found. PeerInfo(peer.ID) *PeerInfo // AddPeerInfo adds/updates the record for the given peer. AddPeerInfo(id peer.ID, address ma.Multiaddr, direction network.Direction) // UpdatePeerInfo calls the given function to update the PeerInfo of the given peer. UpdatePeerInfo(id peer.ID, update func(*PeerInfo)) // State returns the state of the peer. State(id peer.ID) PeerState // SetState sets the state of the peer. SetState(id peer.ID, state PeerState) }
PeerInfoIndex is an interface for managing PeerInfo of network peers
type PeerState ¶ added in v1.1.0
type PeerState int32
PeerState is the state of a peer
var ( // StateUnknown is the state for an unknown peer StateUnknown PeerState = 0 // StateDisconnected is the state for a disconnected peer StateDisconnected PeerState = 1 // StateConnecting is the state for a connecting peer StateConnecting PeerState = 2 // StateConnected is the state for a connected peer StateConnected PeerState = 3 )
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.
func NewSubnetsIndex ¶ added in v1.1.0
func NewSubnetsIndex(count int) SubnetsIndex
type SubnetsStats ¶ added in v0.3.0
SubnetsStats holds a snapshot of subnets stats