p2pv1

package
v2.4.1-0...-6c2315b Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: GPL-3.0 Imports: 70 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(
	logger *zap.Logger,
	cfg *Config,
) (*p2pNetwork, error)

New creates a new p2p network

Types

type Config

type Config struct {
	Ctx          context.Context
	Bootnodes    string   `` /* 156-byte string literal not displayed */
	Discovery    string   `yaml:"Discovery" env:"P2P_DISCOVERY" env-default:"discv5" env-description:"Discovery protocol to use (discv5, mdns)" `
	TrustedPeers []string `yaml:"TrustedPeers" env:"TRUSTED_PEERS" env-default:"" env-description:"List of peer IDs to always connect to"`

	TCPPort     uint16 `yaml:"TcpPort" env:"TCP_PORT" env-default:"13001" env-description:"TCP port for P2P transport"`
	UDPPort     uint16 `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 address for discovery (mutually exclusive with HostDNS)"`
	HostDNS     string `yaml:"HostDNS" env:"HOST_DNS" env-description:"External DNS name for discovery (mutually exclusive with HostAddress)"`

	RequestTimeout   time.Duration `yaml:"RequestTimeout" env:"P2P_REQUEST_TIMEOUT"  env-default:"10s" env-description:"Timeout for P2P requests"`
	MaxBatchResponse uint64        `` /* 142-byte string literal not displayed */

	MaxPeers             int  `yaml:"MaxPeers" env:"P2P_MAX_PEERS" env-default:"60" env-description:"Maximum number of connected peers"`
	DynamicMaxPeers      bool `` /* 142-byte string literal not displayed */
	DynamicMaxPeersLimit int  `` /* 154-byte string literal not displayed */
	TopicMaxPeers        int  `yaml:"TopicMaxPeers" env:"P2P_TOPIC_MAX_PEERS" env-default:"10" env-description:"Maximum peers per pubsub topic"`

	// Subnets is a static bit list of subnets that this node will register upon start.
	Subnets string `` /* 312-byte string literal not displayed */
	// PubSubScoring is a flag to turn on/off pubsub scoring
	PubSubScoring bool `yaml:"PubSubScoring" env:"PUBSUB_SCORING" env-default:"true" env-description:"Enable pubsub peer scoring"`
	// PubSubTrace is a flag to turn on/off pubsub tracing in logs
	PubSubTrace bool `yaml:"PubSubTrace" env:"PUBSUB_TRACE" env-description:"Enable pubsub debug tracing in logs"`
	// DiscoveryTrace is a flag to turn on/off discovery tracing in logs
	DiscoveryTrace bool `yaml:"DiscoveryTrace" env:"DISCOVERY_TRACE" env-description:"Enable discovery debug tracing in logs"`
	// NetworkPrivateKey is used for network identity, MUST be injected
	NetworkPrivateKey *ecdsa.PrivateKey
	// OperatorSigner is used for signing with operator private key, MUST be injected
	OperatorSigner keys.OperatorSigner
	// OperatorPubKeyHash is hash of operator public key, used for identity, optional
	OperatorPubKeyHash string
	// OperatorDataStore contains own operator data including its ID
	OperatorDataStore operatordatastore.OperatorDataStore
	// 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
	// NetworkConfig defines a network configuration.
	NetworkConfig *networkconfig.Network
	// MessageValidator validates incoming messages.
	MessageValidator validation.MessageValidator

	PubsubMsgCacheTTL         time.Duration `yaml:"PubsubMsgCacheTTL" env:"PUBSUB_MSG_CACHE_TTL" env-description:"Duration to remember a message ID as seen"`
	PubsubOutQueueSize        int           `yaml:"PubsubOutQueueSize" env:"PUBSUB_OUT_Q_SIZE" env-description:"Size of the outbound pubsub message queue"`
	PubsubValidationQueueSize int           `yaml:"PubsubValidationQueueSize" env:"PUBSUB_VAL_Q_SIZE" env-description:"Size of the pubsub validation queue"`
	PubsubValidateThrottle    int           `yaml:"PubsubValidateThrottle" env:"PUBSUB_VAL_THROTTLE" env-description:"Number of goroutines for pubsub message validation"`

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

	DisableIPRateLimit bool `yaml:"DisableIPRateLimit" env:"DISABLE_IP_RATE_LIMIT" default:"false" env-description:"Disable IP-based rate limiting"`

	GetValidatorStats network.GetValidatorStats

	// PeerScoreInspector is called periodically to inspect the peer scores.
	PeerScoreInspector func(peerMap map[peer.ID]*pubsub.PeerScoreSnapshot)

	// PeerScoreInspectorInterval is the interval at which the PeerScoreInspector is called.
	PeerScoreInspectorInterval time.Duration
}

Config holds the configuration options for p2p network

func NewNetConfig

func NewNetConfig(keys testing.NodeKeys, operatorPubKeyHash string, bn *discovery.Bootnode, tcpPort, udpPort uint16, maxPeers int) *Config

NewNetConfig creates a new config for tests

func (*Config) Libp2pOptions

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

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

TransformBootnodes converts bootnodes string and convert it to slice

type HealthChecker

type HealthChecker interface {
	Healthy(ctx context.Context) error
}

HealthChecker provides health checking capability for the node prober.

type HostProvider

type HostProvider interface {
	Host() host.Host
}

HostProvider holds host instance

type LocalNet

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

LocalNet holds the nodes in the local network

func CreateAndStartLocalNet

func CreateAndStartLocalNet(pCtx context.Context, logger *zap.Logger, options LocalNetOptions) (*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

func NewLocalNet(ctx context.Context, logger *zap.Logger, options LocalNetOptions) (*LocalNet, error)

NewLocalNet creates a new mdns network

func (*LocalNet) NewTestP2pNetwork

func (ln *LocalNet) NewTestP2pNetwork(ctx context.Context, nodeIndex uint64, keys testing.NodeKeys, logger *zap.Logger, options LocalNetOptions) (network.P2PNetwork, error)

NewTestP2pNetwork creates a new network.P2PNetwork instance

func (*LocalNet) WithBootnode

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

WithBootnode adds a bootnode to the network

type LocalNetOptions

type LocalNetOptions struct {
	MessageValidatorProvider                        func(uint64) validation.MessageValidator
	Nodes                                           int
	MinConnected                                    int
	UseDiscv5                                       bool
	TotalValidators, ActiveValidators, MyValidators uint64
	PeerScoreInspector                              func(selfPeer peer.ID, peerMap map[peer.ID]*pubsub.PeerScoreSnapshot)
	PeerScoreInspectorInterval                      time.Duration
	Shares                                          []*ssvtypes.SSVShare
}

type PeersIndexProvider

type PeersIndexProvider interface {
	PeersIndex() peers.Index
}

PeersIndexProvider holds peers index instance

type SubnetPeers

type SubnetPeers [commons.SubnetsCount]uint16

SubnetPeers maps subnets to the number of peers connected to each of those subnets.

func (SubnetPeers) Add

func (SubnetPeers) Score

func (a SubnetPeers) Score(ours, theirs commons.Subnets) float64

Score estimates how many valuable subnets the given peer would contribute. Param ours defines subnets we are interested in. Param theirs defines subnets given peer has to offer.

func (SubnetPeers) String

func (a SubnetPeers) String() string

Jump to

Keyboard shortcuts

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