Documentation ¶
Index ¶
- Constants
- Variables
- func DecorateNode(node *enode.LocalNode, decorations ...NodeRecordDecoration) error
- func NewForkingDV5Listener(logger *zap.Logger, preFork, postFork Listener, iteratorTimeout time.Duration, ...) *forkingDV5Listener
- func NewKadDHT(ctx context.Context, host host.Host, mode dht.ModeOpt) (routing.Routing, discovery.Discovery, error)
- func ParseENR(schemes enr.SchemeMap, tcpRequired bool, enrs ...string) ([]*enode.Node, error)
- func PeerID(node *enode.Node) (peer.ID, error)
- func ToMultiAddr(node *enode.Node) (ma.Multiaddr, error)
- func ToPeer(node *enode.Node) (*peer.AddrInfo, error)
- func WithProtocolID(protocolID [6]byte) func(config *discover.Config)
- func WithUnhandled(unhandled chan<- discover.ReadPacket) func(config *discover.Config)
- type Bootnode
- type BootnodeOptions
- type CheckPeerLimit
- type DiscV5Options
- type DiscV5Service
- func (dvs *DiscV5Service) Advertise(ctx context.Context, ns string, opt ...discovery.Option) (time.Duration, error)
- func (dvs *DiscV5Service) Bootstrap(logger *zap.Logger, handler HandleNewPeer) error
- func (dvs *DiscV5Service) Close() error
- func (dvs *DiscV5Service) DeregisterSubnets(logger *zap.Logger, subnets ...int) error
- func (dvs *DiscV5Service) FindPeers(ctx context.Context, ns string, opt ...discovery.Option) (<-chan peer.AddrInfo, error)
- func (dvs *DiscV5Service) Node(logger *zap.Logger, info peer.AddrInfo) (*enode.Node, error)
- func (dvs *DiscV5Service) RegisterSubnets(logger *zap.Logger, subnets ...int) error
- func (dvs *DiscV5Service) Self() *enode.LocalNode
- type HandleNewPeer
- type Listener
- type NodeFilter
- type NodeProvider
- type NodeRecordDecoration
- type Options
- type PeerEvent
- type Service
- type SharedUDPConn
- func (s *SharedUDPConn) Close() error
- func (s *SharedUDPConn) LocalAddr() net.Addr
- func (s *SharedUDPConn) ReadFromUDP(b []byte) (n int, addr *net.UDPAddr, err error)
- func (s *SharedUDPConn) ReadFromUDPAddrPort(b []byte) (n int, addr *net.UDPAddr, err error)
- func (s *SharedUDPConn) WriteToUDP(b []byte, addr *net.UDPAddr) (n int, err error)
Constants ¶
const (
// DHTDiscoveryProtocol is the protocol prefix used for local discovery (routingTbl), in addition to mDNS
DHTDiscoveryProtocol = "/ssv/discovery/0.0.1"
)
const (
// LocalDiscoveryServiceTag is used in our mDNS advertisements to discover other peers
LocalDiscoveryServiceTag = "ssv.discovery"
)
Variables ¶
var DefaultSSVProtocolID = [6]byte{'s', 's', 'v', 'd', 'v', '5'}
Functions ¶
func DecorateNode ¶ added in v1.1.0
func DecorateNode(node *enode.LocalNode, decorations ...NodeRecordDecoration) error
DecorateNode will enrich the local node record with more entries, according to current fork
func NewForkingDV5Listener ¶ added in v1.3.10
func NewForkingDV5Listener(logger *zap.Logger, preFork, postFork Listener, iteratorTimeout time.Duration, netConfig networkconfig.NetworkConfig) *forkingDV5Listener
func NewKadDHT ¶
func NewKadDHT(ctx context.Context, host host.Host, mode dht.ModeOpt) (routing.Routing, discovery.Discovery, error)
NewKadDHT creates a new kademlia DHT and a corresponding discovery service NOTE: that the caller must bootstrap the routing.Routing instance
func ParseENR ¶
ParseENR takes a list of ENR strings and returns the corresponding enode.Node objects. it also accepts custom schemes, defaults to enode.ValidSchemes (v4)
func ToMultiAddr ¶
ToMultiAddr returns the node's multiaddr.
func WithProtocolID ¶ added in v1.3.10
func WithUnhandled ¶ added in v1.3.10
func WithUnhandled(unhandled chan<- discover.ReadPacket) func(config *discover.Config)
Types ¶
type Bootnode ¶
type Bootnode struct { ENR string // Ethereum Node Records https://eips.ethereum.org/EIPS/eip-778 // contains filtered or unexported fields }
Bootnode represents a bootnode used for tests
func NewBootnode ¶
func NewBootnode(pctx context.Context, logger *zap.Logger, networkCfg networkconfig.NetworkConfig, opts *BootnodeOptions) (*Bootnode, error)
NewBootnode creates a new bootnode
type BootnodeOptions ¶
type BootnodeOptions struct { PrivateKey string `yaml:"PrivateKey" env:"BOOTNODE_NETWORK_KEY" env-description:"Bootnode private key (default will generate new)"` ExternalIP string `yaml:"ExternalIP" env:"BOOTNODE_EXTERNAL_IP" env-description:"Override boot node's IP' "` Port uint16 `yaml:"Port" env:"BOOTNODE_PORT" env-description:"Override boot node's port' "` }
BootnodeOptions contains options to create the node
type CheckPeerLimit ¶
type CheckPeerLimit func() bool
CheckPeerLimit enables listener to check peers limit
type DiscV5Options ¶
type DiscV5Options struct { // StoragePath is the path used to store the DB (DHT) // if an empty path was given, the DB will be created in memory StoragePath string // IP of the node IP string // BindIP is the IP to bind to the UDP listener BindIP string // Port is the UDP port used by discv5 Port uint16 // TCPPort is the TCP port exposed in the ENR TCPPort uint16 // NetworkKey is the private key used to create the peer.ID if the node NetworkKey *ecdsa.PrivateKey // Bootnodes is a list of bootstrapper nodes Bootnodes []string // Subnets is a bool slice represents all the subnets the node is intreseted in Subnets []byte // EnableLogging when true enables logs to be emitted EnableLogging bool }
DiscV5Options for creating a new discv5 listener
func DefaultOptions ¶
func DefaultOptions(privateKey *ecdsa.PrivateKey) DiscV5Options
DefaultOptions returns the default options
func (*DiscV5Options) DiscV5Cfg ¶
func (opts *DiscV5Options) DiscV5Cfg(logger *zap.Logger, funcOpts ...func(config *discover.Config)) (*discover.Config, error)
DiscV5Cfg creates discv5 config from the options
func (*DiscV5Options) Validate ¶
func (opts *DiscV5Options) Validate() error
Validate validates the options
type DiscV5Service ¶
type DiscV5Service struct {
// contains filtered or unexported fields
}
DiscV5Service wraps discover.UDPv5 with additional functionality it implements go-libp2p/core/discovery.Discovery currently using ENR entry (subnets) to facilitate subnets discovery TODO: should be changed once discv5 supports topics (v5.2)
func (*DiscV5Service) Advertise ¶
func (dvs *DiscV5Service) Advertise(ctx context.Context, ns string, opt ...discovery.Option) (time.Duration, error)
Advertise advertises a service implementation of discovery.Advertiser
func (*DiscV5Service) Bootstrap ¶
func (dvs *DiscV5Service) Bootstrap(logger *zap.Logger, handler HandleNewPeer) error
Bootstrap start looking for new nodes, note that this function blocks. if we reached peers limit, make sure to accept peers with more than 1 shared subnet, which lets other components to determine whether we'll want to connect to this node or not.
func (*DiscV5Service) DeregisterSubnets ¶
func (dvs *DiscV5Service) DeregisterSubnets(logger *zap.Logger, subnets ...int) error
DeregisterSubnets removes the given subnets and publish the updated node record
func (*DiscV5Service) FindPeers ¶
func (dvs *DiscV5Service) FindPeers(ctx context.Context, ns string, opt ...discovery.Option) (<-chan peer.AddrInfo, error)
FindPeers discovers peers providing a service implementation of discovery.Discoverer
func (*DiscV5Service) RegisterSubnets ¶
func (dvs *DiscV5Service) RegisterSubnets(logger *zap.Logger, subnets ...int) error
RegisterSubnets adds the given subnets and publish the updated node record
func (*DiscV5Service) Self ¶
func (dvs *DiscV5Service) Self() *enode.LocalNode
Self returns self node
type HandleNewPeer ¶
type HandleNewPeer func(e PeerEvent)
HandleNewPeer is the function interface for handling new peer
type NodeFilter ¶
NodeFilter can be used for nodes filtering during discovery
type NodeProvider ¶
type NodeProvider interface { Self() *enode.LocalNode Node(logger *zap.Logger, info peer.AddrInfo) (*enode.Node, error) }
NodeProvider is an interface for managing ENRs
type NodeRecordDecoration ¶ added in v1.1.0
func DecorateWithDomainType ¶ added in v1.1.0
func DecorateWithDomainType(domainType spectypes.DomainType) NodeRecordDecoration
func DecorateWithSubnets ¶ added in v1.1.0
func DecorateWithSubnets(subnets []byte) NodeRecordDecoration
type Options ¶
type Options struct { Host host.Host DiscV5Opts *DiscV5Options ConnIndex peers.ConnectionIndex SubnetsIdx peers.SubnetsIndex HostAddress string HostDNS string NetworkConfig networkconfig.NetworkConfig }
Options represents the options passed to create a service
type Service ¶
type Service interface { discovery.Discovery io.Closer RegisterSubnets(logger *zap.Logger, subnets ...int) error DeregisterSubnets(logger *zap.Logger, subnets ...int) error Bootstrap(logger *zap.Logger, handler HandleNewPeer) error }
Service is the interface for discovery
func NewLocalDiscovery ¶
NewLocalDiscovery creates an mDNS discovery service and attaches it to the libp2p Host. This lets us automatically discover peers on the same LAN and connect to them.
type SharedUDPConn ¶ added in v1.3.10
type SharedUDPConn struct {}
SharedUDPConn implements a shared connection. Write sends messages to the underlying connection while read returns messages that were found unprocessable and sent to the unhandled channel by the primary listener. It's copied from https://github.com/ethereum/go-ethereum/blob/v1.14.8/p2p/server.go#L435
func (*SharedUDPConn) Close ¶ added in v1.3.10
func (s *SharedUDPConn) Close() error
Close implements discover.UDPConn
func (*SharedUDPConn) LocalAddr ¶ added in v1.3.10
func (s *SharedUDPConn) LocalAddr() net.Addr
func (*SharedUDPConn) ReadFromUDP ¶ added in v1.3.10
ReadFromUDP implements discover.UDPConn It's being called in go-ethereum@1.13.14
func (*SharedUDPConn) ReadFromUDPAddrPort ¶ added in v1.3.10
ReadFromUDPAddrPort implements discover.UDPConn It's being called in go-ethereum@1.14.8