p2p

package
v0.0.0-...-420b085 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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"`
	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"`
	// 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
	// Logger to used by network services
	Logger  *zap.Logger
	DB      *db.BoltDB
	GeoData *geodata.GeoIP2DB
}

Config holds the configuration options for p2p network

func (*Config) Libp2pOptions

func (c *Config) Libp2pOptions(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

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

TransformBootnodes converts bootnodes string and convert it to slice

type P2PNetwork

type P2PNetwork interface {
	io.Closer
	// Setup initialize the network layer and starts the libp2p host
	Setup() error
	// Start starts the network
	Start() error
	// UpdateSubnets will update the registered subnets according to active validators
	UpdateSubnets()
}

func New

func New(cfg *Config) P2PNetwork

New creates a new p2p network

Jump to

Keyboard shortcuts

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