p2pv1

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2023 License: GPL-3.0 Imports: 61 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
	// prod enr
	Bootnodes string `` /* 626-byte string literal not displayed */
	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:"7s"`
	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:"8" 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"`
	// NetworkID is the network of this node
	NetworkID string `yaml:"NetworkID" env:"NETWORK_ID" env-description:"Network ID is the network of this node"`
	// 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
	// ForkVersion to use
	ForkVersion forksprotocol.ForkVersion
	// NodeStorage is used to get operator metadata.
	NodeStorage storage.Storage

	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
}

Config holds the configuration options for p2p network

func NewNetConfig added in v0.2.0

func NewNetConfig(netPrivKey *ecdsa.PrivateKey, operatorID string, forkVersion forksprotocol.ForkVersion, 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, fork forks.Fork) ([]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, forkVersion forksprotocol.ForkVersion, 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, forkVersion forksprotocol.ForkVersion, 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, forkVersion forksprotocol.ForkVersion, 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

Jump to

Keyboard shortcuts

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