discover

package
v0.10.6 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2021 License: ISC Imports: 33 Imported by: 0

Documentation

Overview

Package discover implements the Node Discovery Protocol.

The Node Discovery protocol provides a way to find RLPx nodes that can be connected to. It uses a Kademlia-like protocol to maintain a distributed database of the IDs and endpoints of all listening nodes.

Index

Constants

View Source
const (
	MinTableNodes = 5
	PollingPeriod = 6 * time.Second
)

Variables

This section is empty.

Functions

func UseLogger

func UseLogger(logger l.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type Config

type Config struct {
	// These settings are required and configure the UDP listener:
	PrivateKey *ecdsa.PrivateKey

	// These settings are optional:
	NetRestrict  *netutil.Netlist   // network whitelist
	Bootnodes    []*qnode.Node      // list of bootstrap nodes
	Unhandled    chan<- ReadPacket  // unhandled packets are sent on this channel
	ValidSchemes qnr.IdentityScheme // allowed identity schemes
	Clock        mclock.Clock
}

Config holds settings for the discovery listener.

type ReadPacket

type ReadPacket struct {
	Data []byte
	Addr *net.UDPAddr
}

ReadPacket is a packet that couldn't be handled. Those packets are sent to the unhandled channel if configured.

type Table

type Table struct {
	// contains filtered or unexported fields
}

Table is the 'node table', a Kademlia-like index of neighbor nodes. The table keeps itself up-to-date by verifying the liveness of neighbors and requesting their node records when announcements of a new record version are received.

func (*Table) ReadRandomNodes

func (tab *Table) ReadRandomNodes(buf []*qnode.Node) (n int)

ReadRandomNodes fills the given slice with random nodes from the table. The results are guaranteed to be unique for a single invocation, no node will appear twice.

type UDPConn

type UDPConn interface {
	ReadFromUDP(b []byte) (n int, addr *net.UDPAddr, err error)
	WriteToUDP(b []byte, addr *net.UDPAddr) (n int, err error)
	Close() error
	LocalAddr() net.Addr
}

UDPConn is a network connection on which discovery can operate.

type UDPv4

type UDPv4 struct {
	// contains filtered or unexported fields
}

UDPv4 implements the v4 wire protocol.

func ListenUDP

func ListenUDP(c UDPConn, ln *qnode.LocalNode, cfg Config) (*UDPv4, error)

ListenUDP starts listening for discovery packets on the given UDP socket.

func ListenV4

func ListenV4(c UDPConn, ln *qnode.LocalNode, cfg Config) (*UDPv4, error)

func (*UDPv4) Close

func (t *UDPv4) Close()

Close shuts down the socket and aborts any running queries.

func (*UDPv4) LookupPubkey

func (t *UDPv4) LookupPubkey(key *ecdsa.PublicKey) []*qnode.Node

LookupPubkey finds the closest nodes to the given public key.

func (*UDPv4) Ping

func (t *UDPv4) Ping(n *qnode.Node) error

Ping sends a ping message to the given node.

func (*UDPv4) RandomNodes

func (t *UDPv4) RandomNodes() qnode.Iterator

RandomNodes is an iterator yielding nodes from a random walk of the DHT.

func (*UDPv4) RequestQNR

func (t *UDPv4) RequestQNR(n *qnode.Node) (*qnode.Node, error)

RequestQNR sends qnrRequest to the given node and waits for a response.

func (*UDPv4) Resolve

func (t *UDPv4) Resolve(n *qnode.Node) *qnode.Node

Resolve searches for a specific node with the given ID and tries to get the most recent version of the node record for it. It returns n if the node could not be resolved.

func (*UDPv4) Self

func (t *UDPv4) Self() *qnode.Node

Self returns the local node.

type UDPv5

type UDPv5 struct {
	// contains filtered or unexported fields
}

UDPv5 is the implementation of protocol version 5.

func ListenV5

func ListenV5(conn UDPConn, ln *qnode.LocalNode, cfg Config) (*UDPv5, error)

ListenV5 listens on the given connection.

func (*UDPv5) AllNodes

func (t *UDPv5) AllNodes() []*qnode.Node

AllNodes returns all the nodes stored in the local table.

func (*UDPv5) Close

func (t *UDPv5) Close()

Close shuts down packet processing.

func (*UDPv5) LocalNode

func (t *UDPv5) LocalNode() *qnode.LocalNode

LocalNode returns the current local node running the protocol.

func (*UDPv5) Lookup

func (t *UDPv5) Lookup(target qnode.ID) []*qnode.Node

Lookup performs a recursive lookup for the given target. It returns the closest nodes to target.

func (*UDPv5) Ping

func (t *UDPv5) Ping(n *qnode.Node) error

Ping sends a ping message to the given node.

func (*UDPv5) RandomNodes

func (t *UDPv5) RandomNodes() qnode.Iterator

func (*UDPv5) RequestQNR

func (t *UDPv5) RequestQNR(n *qnode.Node) (*qnode.Node, error)

requestQNR requests n's record.

func (*UDPv5) Resolve

func (t *UDPv5) Resolve(n *qnode.Node) *qnode.Node

Resolve searches for a specific node with the given ID and tries to get the most recent version of the node record for it. It returns n if the node could not be resolved.

func (*UDPv5) Self

func (t *UDPv5) Self() *qnode.Node

Self returns the local node record.

Jump to

Keyboard shortcuts

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