p2pv1

package
v1.0.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: GPL-3.0 Imports: 59 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// MetricsAllConnectedPeers counts all connected peers
	MetricsAllConnectedPeers = promauto.NewGauge(prometheus.GaugeOpts{
		Name: "ssv_p2p_all_connected_peers",
		Help: "Count connected peers",
	})
	// MetricsConnectedPeers counts connected peers for a topic
	MetricsConnectedPeers = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Name: "ssv_p2p_connected_peers",
		Help: "Count connected peers for a validator",
	}, []string{"pubKey"})
	// MetricsPeersIdentity tracks peers identity
	MetricsPeersIdentity = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Name: "ssv:network:peers_identity",
		Help: "Peers identity",
	}, []string{"pubKey", "operatorID", "v", "pid", "type"})
)

Functions

func New

func New(logger *zap.Logger, cfg *Config) network.P2PNetwork

New creates a new p2p network

Types

type Config

type Config struct {
	Ctx       context.Context
	Bootnodes string `yaml:"Bootnodes" env:"BOOTNODES" env-description:"Bootnodes to use to start discovery, seperated with ';'" env-default:""`
	Discovery string `yaml:"Discovery" env:"P2P_DISCOVERY" env-description:"Discovery system to use" env-default:"discv5"`

	TCPPort     int    `yaml:"TcpPort" env:"TCP_PORT" env-default:"13001" env-description:"TCP port for p2p transport"`
	UDPPort     int    `yaml:"UdpPort" env:"UDP_PORT" env-default:"12001" env-description:"UDP port for discovery"`
	HostAddress string `yaml:"HostAddress" env:"HOST_ADDRESS" env-description:"External ip node is exposed for discovery"`
	HostDNS     string `yaml:"HostDNS" env:"HOST_DNS" env-description:"External DNS node is exposed for discovery"`

	RequestTimeout   time.Duration `yaml:"RequestTimeout" env:"P2P_REQUEST_TIMEOUT"  env-default:"10s"`
	MaxBatchResponse uint64        `` /* 133-byte string literal not displayed */
	MaxPeers         int           `yaml:"MaxPeers" env:"P2P_MAX_PEERS" env-default:"60" env-description:"Connected peers limit for connections"`
	TopicMaxPeers    int           `yaml:"TopicMaxPeers" env:"P2P_TOPIC_MAX_PEERS" env-default:"10" env-description:"Connected peers limit per pubsub topic"`

	// Subnets is a static bit list of subnets that this node will register upon start.
	Subnets string `yaml:"Subnets" env:"SUBNETS" env-description:"Hex string that represents the subnets that this node will join upon start"`
	// PubSubScoring is a flag to turn on/off pubsub scoring
	PubSubScoring bool `yaml:"PubSubScoring" env:"PUBSUB_SCORING" env-default:"true" env-description:"Flag to turn on/off pubsub scoring"`
	// PubSubTrace is a flag to turn on/off pubsub tracing in logs
	PubSubTrace bool `yaml:"PubSubTrace" env:"PUBSUB_TRACE" env-description:"Flag to turn on/off pubsub tracing in logs"`
	// DiscoveryTrace is a flag to turn on/off discovery tracing in logs
	DiscoveryTrace bool `yaml:"DiscoveryTrace" env:"DISCOVERY_TRACE" env-description:"Flag to turn on/off discovery tracing in logs"`
	// NetworkPrivateKey is used for network identity, MUST be injected
	NetworkPrivateKey *ecdsa.PrivateKey
	// OperatorPublicKey is used for operator identity, optional
	OperatorID string
	// Router propagate incoming network messages to the responsive components
	Router network.MessageRouter
	// UserAgent to use by libp2p identify protocol
	UserAgent string
	// NodeStorage is used to get operator metadata.
	NodeStorage storage.Storage
	// Network defines a network configuration.
	Network networkconfig.NetworkConfig

	PubsubMsgCacheTTL         time.Duration `yaml:"PubsubMsgCacheTTL" env:"PUBSUB_MSG_CACHE_TTL" env-description:"How long a message ID will be remembered as seen"`
	PubsubOutQueueSize        int           `` /* 128-byte string literal not displayed */
	PubsubValidationQueueSize int           `` /* 129-byte string literal not displayed */
	PubsubValidateThrottle    int           `` /* 135-byte string literal not displayed */

	// FullNode determines whether the network should sync decided history from peers.
	// If false, SyncDecidedByRange becomes a no-op.
	FullNode bool

	GetValidatorStats network.GetValidatorStats

	PermissionedActivateEpoch   uint64 `` /* 189-byte string literal not displayed */
	PermissionedDeactivateEpoch uint64 `` /* 169-byte string literal not displayed */

	Permissioned func() bool // this is not loaded from config file but set up in full node setup
	// WhitelistedOperatorKeys is an array of Operator Public Key PEMs not registered in the contract with which the node will accept connections
	WhitelistedOperatorKeys []string `` /* 162-byte string literal not displayed */
}

Config holds the configuration options for p2p network

func NewNetConfig added in v0.2.0

func NewNetConfig(netPrivKey *ecdsa.PrivateKey, operatorID string, bn *discovery.Bootnode, tcpPort, udpPort, maxPeers int) *Config

NewNetConfig creates a new config for tests

func (*Config) Libp2pOptions added in v0.2.0

func (c *Config) Libp2pOptions(logger *zap.Logger) ([]libp2p.Option, error)

Libp2pOptions creates options list for the libp2p host these are the most basic options required to start a network instance, other options and libp2p components can be configured on top

func (*Config) TransformBootnodes added in v0.2.0

func (c *Config) TransformBootnodes() []string

TransformBootnodes converts bootnodes string and convert it to slice

type HostProvider added in v0.2.0

type HostProvider interface {
	Host() host.Host
}

HostProvider holds host instance

type LocalNet added in v0.2.0

type LocalNet struct {
	Nodes    []network.P2PNetwork
	NodeKeys []testing.NodeKeys
	Bootnode *discovery.Bootnode
	// contains filtered or unexported fields
}

LocalNet holds the nodes in the local network

func CreateAndStartLocalNet added in v0.2.0

func CreateAndStartLocalNet(pCtx context.Context, logger *zap.Logger, nodesQuantity, minConnected int, useDiscv5 bool) (*LocalNet, error)

CreateAndStartLocalNet creates a new local network and starts it if any errors occurs during starting local network CreateAndStartLocalNet trying to create and start local net one more time until pCtx is not Done()

func NewLocalNet added in v0.2.0

func NewLocalNet(ctx context.Context, logger *zap.Logger, n int, useDiscv5 bool) (*LocalNet, error)

NewLocalNet creates a new mdns network

func (*LocalNet) NewTestP2pNetwork added in v0.2.0

func (ln *LocalNet) NewTestP2pNetwork(ctx context.Context, keys testing.NodeKeys, logger *zap.Logger, maxPeers int) (network.P2PNetwork, error)

NewTestP2pNetwork creates a new network.P2PNetwork instance

func (*LocalNet) WithBootnode added in v0.2.0

func (ln *LocalNet) WithBootnode(ctx context.Context, logger *zap.Logger) error

WithBootnode adds a bootnode to the network

type PeersIndexProvider added in v1.1.0

type PeersIndexProvider interface {
	PeersIndex() peers.Index
}

PeersIndexProvider holds peers index instance

Jump to

Keyboard shortcuts

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