Documentation ¶
Index ¶
- Constants
- func DecorateNode(node *enode.LocalNode, args map[string]interface{}) error
- 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)
- 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 NodeFilter
- type NodeProvider
- type Options
- type PeerEvent
- type Service
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 ¶
This section is empty.
Functions ¶
func DecorateNode ¶ added in v1.1.0
DecorateNode will enrich the local node record with more entries, according to current fork
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.
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, 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 int `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 int // TCPPort is the TCP port exposed in the ENR TCPPort int // 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 // OperatorID is the operator id (optional) OperatorID string // 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) 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 Options ¶
type Options struct { Host host.Host DiscV5Opts *DiscV5Options ConnIndex peers.ConnectionIndex SubnetsIdx peers.SubnetsIndex HostAddress string HostDNS string }
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.