Documentation
¶
Index ¶
- Constants
- Variables
- 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 NewGossipScoreIndex ¶
func NewGossipScoreIndex() *gossipScoreIndex
func NewPeerInfoIndex ¶
func NewPeerInfoIndex() *peerInfoIndex
func NewPeersIndex ¶
func NewPeersIndex( logger *zap.Logger, network libp2pnetwork.Network, self *records.NodeInfo, maxPeers MaxPeersProvider, netKeyProvider NetworkKeyProvider, gossipScoreIndex GossipScoreIndex, ) *peersIndex
NewPeersIndex creates a new Index
Types ¶
type ConnManager ¶
type ConnManager interface {
// TrimPeers will trim unprotected peers.
TrimPeers(ctx context.Context, net libp2pnetwork.Network, peersToTrim map[peer.ID]struct{})
// DisconnectFromBadPeers will disconnect from bad peers according to their Gossip scores. It returns the number of disconnected peers.
DisconnectFromBadPeers(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(disconnectQuota int, net libp2pnetwork.Network, allPeers []peer.ID, mySubnets commons.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 ¶
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) error
// AtLimit checks if the node has reached peers limit
AtLimit(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 GossipScoreIndex ¶
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 ¶
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 ¶
type NetworkKeyProvider func() libp2pcrypto.PrivKey
NetworkKeyProvider is a function that provides the network private key
type NodeInfoIndex ¶
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(update func(self *records.NodeInfo) *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 ¶
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 libp2pnetwork.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 ¶
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 ¶
type SubnetsIndex interface {
// UpdatePeerSubnets updates the given peer's subnets
UpdatePeerSubnets(id peer.ID, subnets commons.Subnets) bool
// GetSubnetPeers returns peers that are interested in the given subnet
GetSubnetPeers(subnet int) []peer.ID
// GetPeerSubnets returns subnets of the given peer and whether it was found
GetPeerSubnets(id peer.ID) (subnets commons.Subnets, ok bool)
// GetSubnetsStats collects and returns subnets stats
GetSubnetsStats() *SubnetsStats
}
SubnetsIndex stores information on subnets. It keeps track of subnets based on what peers advertise, but the actual subnets these peers have might change by the time we directly connect with them.
func NewSubnetsIndex ¶
func NewSubnetsIndex() SubnetsIndex
type SubnetsStats ¶
type SubnetsStats struct {
AvgConnected int
PeersCount [commons.SubnetsCount]int
Connected [commons.SubnetsCount]int
}
SubnetsStats holds a snapshot of subnets stats