p2p

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: Apache-2.0 Imports: 35 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeENR added in v0.2.0

func DecodeENR(enrStr string) (enr.Record, error)

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 EncodeENR added in v0.2.0

func EncodeENR(record enr.Record) (string, error)

EncodeENR returns an encoded string format of the enr record.

func LoadOrCreatePrivKey added in v0.2.0

func LoadOrCreatePrivKey(dataDir string) (*ecdsa.PrivateKey, bool, error)

LoadOrCreatePrivKey returns a k1 (secp256k1) private key and true from the provided folder. If it doesn't exist, a new key is generated and stored and returned with false.

func NewLocalEnode added in v0.1.1

func NewLocalEnode(config Config, key *ecdsa.PrivateKey) (*enode.LocalNode, *enode.DB, error)

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, callback func(peer.ID)) func(context.Context)

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 NewTCPNode added in v0.1.1

func NewTCPNode(cfg Config, key *ecdsa.PrivateKey, connGater ConnGater,
	udpNode *discover.UDPv5, peers []Peer) (host.Host, error,
)

NewTCPNode returns a started tcp-based libp2p node.

func NewUDPNode added in v0.1.1

func NewUDPNode(config Config, ln *enode.LocalNode, key *ecdsa.PrivateKey,
	enrs []enr.Record,
) (*discover.UDPv5, error)

NewUDPNode starts and returns a discv5 UDP implementation.

func ShortID added in v0.1.1

func ShortID(p peer.ID) string

ShortID returns the short ID string of the peer ID. It was inspired by peer.ID.ShortString() but even shorter.

Types

type Config

type Config struct {
	// DBPath defines the discv5 peer database file path.
	DBPath string
	// UDPBootnodes defines the discv5 boot node URLs.
	UDPBootnodes []string
	// UDPBootManifest enables using manifest ENRS as discv5 boot nodes.
	UDPBootManifest bool
	// UDPAddr defines the discv5 udp listen address.
	UDPAddr 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
}

func (Config) Multiaddrs

func (c Config) Multiaddrs() ([]ma.Multiaddr, error)

Multiaddrs returns the configured addresses as libp2p multiaddrs.

func (Config) ParseTCPAddrs added in v0.1.1

func (c Config) ParseTCPAddrs() ([]*net.TCPAddr, error)

ParseTCPAddrs returns the configured tcp addresses as typed net tcp addresses.

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) (ConnGater, error)

NewConnGater return a new connection gater that limits access to the cluster peers.

func (ConnGater) InterceptAccept

func (ConnGater) InterceptAccept(_ network.ConnMultiaddrs) (allow bool)

func (ConnGater) InterceptAddrDial

func (ConnGater) InterceptAddrDial(_ peer.ID, _ multiaddr.Multiaddr) (allow bool)

func (ConnGater) InterceptPeerDial

func (ConnGater) InterceptPeerDial(_ peer.ID) (allow bool)

InterceptPeerDial does nothing.

func (ConnGater) InterceptSecured

func (c ConnGater) InterceptSecured(_ network.Direction, id peer.ID, _ network.ConnMultiaddrs) bool

InterceptSecured rejects nodes with a peer ID that isn't part of any known DV.

func (ConnGater) InterceptUpgraded

func (ConnGater) InterceptUpgraded(_ network.Conn) (bool, control.DisconnectReason)

InterceptUpgraded does nothing.

type Peer added in v0.2.0

type Peer struct {
	// ENR defines the networking information of the peer.
	ENR enr.Record

	// 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.
	Index int
}

Peer represents a charon node in a cluster.

func NewPeer added in v0.2.0

func NewPeer(record enr.Record, index int) (Peer, error)

NewPeer returns a new peer from an.

Jump to

Keyboard shortcuts

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