Documentation
¶
Index ¶
- func DecodeENR(enrStr string) (enr.Record, error)
- func EncodeENR(record enr.Record) (string, error)
- func KeyPath(datadir string) string
- func LoadPrivKey(dataDir string) (*ecdsa.PrivateKey, error)
- func NamedAddr(addr ma.Multiaddr) string
- func NewDiscoveryRouter(tcpNode host.Host, udpNode *MutableUDPNode, peers []Peer) lifecycle.HookFuncCtx
- func NewEventCollector(tcpNode host.Host) lifecycle.HookFuncCtx
- func NewLocalEnode(config Config, key *ecdsa.PrivateKey) (*enode.LocalNode, *enode.DB, error)
- func NewPingService(h host.Host, peers []peer.ID, conf TestPingConfig) lifecycle.HookFuncCtx
- func NewRelayReserver(tcpNode host.Host, relay *MutablePeer) lifecycle.HookFunc
- func NewRelayRouter(tcpNode host.Host, peers []Peer, relays []*MutablePeer) lifecycle.HookFuncCtx
- func NewSavedPrivKey(datadir string) (*ecdsa.PrivateKey, error)
- func NewTCPNode(cfg Config, key *ecdsa.PrivateKey, connGater ConnGater, opts ...libp2p.Option) (host.Host, error)
- func PeerName(id peer.ID) string
- func Send(ctx context.Context, tcpNode host.Host, protoID protocol.ID, peerID peer.ID, ...) error
- type Config
- type ConnGater
- func (ConnGater) InterceptAccept(_ network.ConnMultiaddrs) (allow bool)
- func (ConnGater) InterceptAddrDial(_ peer.ID, _ multiaddr.Multiaddr) (allow bool)
- func (ConnGater) InterceptPeerDial(_ peer.ID) (allow bool)
- func (c ConnGater) InterceptSecured(_ network.Direction, id peer.ID, _ network.ConnMultiaddrs) bool
- func (ConnGater) InterceptUpgraded(_ network.Conn) (bool, control.DisconnectReason)
- type MutablePeer
- type MutableUDPNode
- type Peer
- type SendFunc
- type Sender
- type TestPingConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeENR ¶ added in v0.2.0
DecodeENR returns a enr record decoded from the string. See reference github.com/ethereum/go-ethereum@v1.10.10/p2p/dnsdisc/tree.go:378.
func KeyPath ¶ added in v0.3.0
KeyPath returns the charon-enr-private-key path relative to the data dir.
func LoadPrivKey ¶ added in v0.3.0
func LoadPrivKey(dataDir string) (*ecdsa.PrivateKey, error)
LoadPrivKey returns the ecdsa k1 key saved in the directory.
func NamedAddr ¶ added in v0.10.0
NamedAddr returns the multiaddr as a string with peer names instead of peer IDs.
func NewDiscoveryRouter ¶ added in v0.10.0
func NewDiscoveryRouter(tcpNode host.Host, udpNode *MutableUDPNode, peers []Peer) lifecycle.HookFuncCtx
NewDiscoveryRouter returns a life cycle hook that links discv5 to libp2p by continuously polling discv5 for latest peer ENRs and adding then to libp2p peer store.
func NewEventCollector ¶ added in v0.10.0
func NewEventCollector(tcpNode host.Host) lifecycle.HookFuncCtx
NewEventCollector returns a lifecycle hook that instruments libp2p events.
func NewLocalEnode ¶ added in v0.1.1
NewLocalEnode returns a local enode and a peer DB or an error.
func NewPingService ¶ added in v0.2.0
func NewPingService(h host.Host, peers []peer.ID, conf TestPingConfig) lifecycle.HookFuncCtx
NewPingService returns a start function of a p2p ping service that pings all peers every second and collects metrics.
func NewRelayReserver ¶ added in v0.4.0
func NewRelayReserver(tcpNode host.Host, relay *MutablePeer) lifecycle.HookFunc
NewRelayReserver returns a life cycle hook function that continuously reserves a relay circuit until the context is closed.
func NewRelayRouter ¶ added in v0.10.0
func NewRelayRouter(tcpNode host.Host, peers []Peer, relays []*MutablePeer) lifecycle.HookFuncCtx
NewRelayRouter returns a life cycle hook that routes peers via relays in libp2p by continuously adding peer relay addresses to libp2p peer store.
func NewSavedPrivKey ¶ added in v0.3.0
func NewSavedPrivKey(datadir string) (*ecdsa.PrivateKey, error)
NewSavedPrivKey generates a new ecdsa k1 key and saves it to the directory.
func NewTCPNode ¶ added in v0.1.1
func NewTCPNode(cfg Config, key *ecdsa.PrivateKey, connGater ConnGater, opts ...libp2p.Option, ) (host.Host, error)
NewTCPNode returns a started tcp-based libp2p host.
Types ¶
type Config ¶
type Config struct {
// UDPBootnodes defines the discv5 boot node URLs.
UDPBootnodes []string
// UDPBootLock enables using cluster-lock ENRs as discv5 boot nodes.
UDPBootLock bool
// UDPAddr defines the discv5 udp listen address.
UDPAddr string
// ExternalIP is the IP advertised by libp2p.
ExternalIP string
// ExternalHost is the DNS hostname advertised by libp2p.
ExternalHost string
// TCPAddrs defines the lib-p2p tcp listen addresses.
TCPAddrs []string
// Allowlist defines csv CIDR blocks for lib-p2p allowed connections.
Allowlist string
// Allowlist defines csv CIDR blocks for lib-p2p denied connections.
Denylist string
// BootnodeRelay enables circuit relay via bootnodes if direct connections fail.
// Only applicable to charon nodes not bootnodes.
BootnodeRelay bool
}
func (Config) Multiaddrs ¶
Multiaddrs returns the configured addresses as libp2p multiaddrs.
type ConnGater ¶
type ConnGater struct {
// contains filtered or unexported fields
}
ConnGater filters incoming connections by the cluster peers.
func NewConnGater ¶ added in v0.1.1
func NewConnGater(peers []peer.ID, relays []*MutablePeer) (ConnGater, error)
NewConnGater return a new connection gater that limits access to the cluster peers and relays.
func NewOpenGater ¶ added in v0.4.0
func NewOpenGater() ConnGater
NewOpenGater returns a connection gater that is open, not gating any connections.
func (ConnGater) InterceptAccept ¶
func (ConnGater) InterceptAccept(_ network.ConnMultiaddrs) (allow bool)
func (ConnGater) InterceptAddrDial ¶
func (ConnGater) InterceptPeerDial ¶
InterceptPeerDial does nothing.
func (ConnGater) InterceptSecured ¶
InterceptSecured rejects nodes with a peer ID that isn't part of any known DV.
func (ConnGater) InterceptUpgraded ¶
InterceptUpgraded does nothing.
type MutablePeer ¶ added in v0.10.0
type MutablePeer struct {
// contains filtered or unexported fields
}
MutablePeer defines a mutable peer used mostly for stateless bootnodes/relays that change ID on restart but have a consistent URL to resolve them. The zero value is a valid empty MutablePeer.
func NewMutablePeer ¶ added in v0.10.0
func NewMutablePeer(p Peer) *MutablePeer
NewMutablePeer returns a new non-empty mutable peer.
func NewRelays ¶ added in v0.4.0
func NewRelays(conf Config, bootnodes []*MutablePeer) []*MutablePeer
NewRelays returns the libp2p circuit relays from bootnodes if enabled.
func NewUDPBootnodes ¶ added in v0.4.0
func NewUDPBootnodes(ctx context.Context, config Config, peers []Peer, localEnode enode.ID, lockHashHex string, ) ([]*MutablePeer, error)
NewUDPBootnodes returns the discv5 udp bootnodes from the config.
func (*MutablePeer) Peer ¶ added in v0.10.0
func (p *MutablePeer) Peer() (Peer, bool)
Peer returns the current peer or false if not available.
func (*MutablePeer) Set ¶ added in v0.10.0
func (p *MutablePeer) Set(peer Peer)
Set updates the mutable enode and calls all subscribers.
func (*MutablePeer) Subscribe ¶ added in v0.10.0
func (p *MutablePeer) Subscribe(sub func(Peer))
Subscribe registers a function that is called when the peer is updated.
type MutableUDPNode ¶ added in v0.10.0
type MutableUDPNode struct {
// contains filtered or unexported fields
}
MutableUDPNode wraps a discv5 udp node providing support to recreate it if bootnodes change.
func NewUDPNode ¶ added in v0.1.1
func NewUDPNode(ctx context.Context, config Config, ln *enode.LocalNode, key *ecdsa.PrivateKey, bootnodes []*MutablePeer, ) (*MutableUDPNode, error)
NewUDPNode starts and returns a discv5 UDP provider.
func (*MutableUDPNode) AllNodes ¶ added in v0.10.0
func (n *MutableUDPNode) AllNodes() []*enode.Node
func (*MutableUDPNode) Close ¶ added in v0.10.0
func (n *MutableUDPNode) Close()
func (*MutableUDPNode) Resolve ¶ added in v0.10.0
func (n *MutableUDPNode) Resolve(node *enode.Node) *enode.Node
func (*MutableUDPNode) Set ¶ added in v0.10.0
func (n *MutableUDPNode) Set(node *discover.UDPv5)
type Peer ¶ added in v0.2.0
type Peer struct {
// ENR defines the networking information of the peer.
ENR enr.Record
// Enode represents the networking host of the peer.
Enode enode.Node
// ID is a libp2p peer identity. It is inferred from the ENR.
ID peer.ID
// Index is the order of this node in the cluster.
// This is only applicable to charon nodes, not relays.
Index int
// Name represents a human friendly name for the peer.
Name string
}
Peer represents a peer in the libp2p network, either a charon node or a relay.
type SendFunc ¶ added in v0.7.0
SendFunc is an abstract function responsible for sending libp2p messages.
type Sender ¶ added in v0.7.0
type Sender struct {
// contains filtered or unexported fields
}
Sender provides an API for sending libp2p messages, both synchronous and asynchronous. It also provides log filtering for async sending, mitigating error storms when peers are down.
func (*Sender) SendAsync ¶ added in v0.7.0
func (s *Sender) SendAsync(parent context.Context, tcpNode host.Host, protoID protocol.ID, peerID peer.ID, msg proto.Message) error
SendAsync returns nil sends a libp2p message asynchronously. It logs results on state change (success to/from failure). It implements SendFunc.