go-ethereum: github.com/ethereum/go-ethereum/p2p/discover Index | Files

package discover

import "github.com/ethereum/go-ethereum/p2p/discover"

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.


Package Files

common.go lookup.go node.go ntp.go table.go v4_udp.go

type Config Uses

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   []*enode.Node     // list of bootstrap nodes
    Unhandled   chan<- ReadPacket // unhandled packets are sent on this channel
    Log         log.Logger        // if set, log messages go here

Config holds settings for the discovery listener.

type ReadPacket Uses

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. This is exported for internal use, do not use this type.

type Table Uses

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 Uses

func (tab *Table) ReadRandomNodes(buf []*enode.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 Uses

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 Uses

type UDPv4 struct {
    // contains filtered or unexported fields

UDPv4 implements the v4 wire protocol.

func ListenUDP Uses

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

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

func ListenV4 Uses

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

func (*UDPv4) Close Uses

func (t *UDPv4) Close()

Close shuts down the socket and aborts any running queries.

func (*UDPv4) LookupPubkey Uses

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

LookupPubkey finds the closest nodes to the given public key.

func (*UDPv4) Ping Uses

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

Ping sends a ping message to the given node.

func (*UDPv4) RandomNodes Uses

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

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

func (*UDPv4) RequestENR Uses

func (t *UDPv4) RequestENR(n *enode.Node) (*enode.Node, error)

RequestENR sends enrRequest to the given node and waits for a response.

func (*UDPv4) Resolve Uses

func (t *UDPv4) Resolve(n *enode.Node) *enode.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 Uses

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

Self returns the local node.

Package discover imports 23 packages (graph) and is imported by 1314 packages. Updated 2019-11-26. Refresh now. Tools for package owners.