Documentation
¶
Index ¶
- Constants
- Variables
- func HandleConnections(ctx context.Context, logger *zap.Logger, handshaker Handshaker) *libp2pnetwork.NotifyBundle
- func NewConnectionGater(logger *zap.Logger, idx ConnectionIndex) connmgr.ConnectionGater
- type ConnectionIndex
- type HandshakeFilter
- type Handshaker
- type Index
- type NodeInfoStore
- type NodeScore
- type NodeState
- type ScoreIndex
- type Transactional
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") )
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 ¶
HandshakeFilter can be used to filter nodes once we handshaked with them
func ForkVersionFilter ¶
func ForkVersionFilter(forkVersion 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.
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
// 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 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 )