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 NewLocalEnode(config Config, key *ecdsa.PrivateKey) (*enode.LocalNode, *enode.DB, error)
- func NewPingService(h host.Host, peers []peer.ID, callback func(peer.ID)) func(context.Context)
- func NewRelayReserver(tcpNode host.Host, relay Peer) lifecycle.HookFunc
- func NewSavedPrivKey(datadir string) (*ecdsa.PrivateKey, error)
- func NewTCPNode(cfg Config, key *ecdsa.PrivateKey, connGater ConnGater, ...) (host.Host, error)
- func NewUDPBootnodes(ctx context.Context, config Config, peers []Peer, localEnode enode.ID) ([]*enode.Node, error)
- func NewUDPNode(config Config, ln *enode.LocalNode, key *ecdsa.PrivateKey, ...) (*discover.UDPv5, 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 Peer
- type SendFunc
- type Sender
- type UDPNode
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 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
NewPingService returns a start function of a p2p ping service that pings all peers every second and collects metrics. TODO(corver): Cluster wide req/resp doesn't scale since it is O(n^2).
func NewRelayReserver ¶ added in v0.4.0
NewRelayReserver returns a life cycle hook function that continuously reserves a relay circuit until the context is closed.
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, udpNode *discover.UDPv5, peers, relays []Peer) (host.Host, error, )
NewTCPNode returns a started tcp-based libp2p host.
func NewUDPBootnodes ¶ added in v0.4.0
func NewUDPBootnodes(ctx context.Context, config Config, peers []Peer, localEnode enode.ID, ) ([]*enode.Node, error)
NewUDPBootnodes returns the udp bootnodes from the config.
func NewUDPNode ¶ added in v0.1.1
func NewUDPNode(config Config, ln *enode.LocalNode, key *ecdsa.PrivateKey, bootnodes []*enode.Node, ) (*discover.UDPv5, error)
NewUDPNode starts and returns a discv5 UDP implementation.
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
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 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.