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.
common.go lookup.go node.go ntp.go table.go v4_udp.go v5_udp.go
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 ValidSchemes enr.IdentityScheme // allowed identity schemes Clock mclock.Clock }
Config holds settings for the discovery listener.
ReadPacket is a packet that couldn't be handled. Those packets are sent to the unhandled channel if configured.
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.
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 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 struct {
// contains filtered or unexported fields
}
UDPv4 implements the v4 wire protocol.
ListenUDP starts listening for discovery packets on the given UDP socket.
Close shuts down the socket and aborts any running queries.
LookupPubkey finds the closest nodes to the given public key.
Ping sends a ping message to the given node.
RandomNodes is an iterator yielding nodes from a random walk of the DHT.
RequestENR sends enrRequest to the given node and waits for a response.
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.
Self returns the local node.
type UDPv5 struct {
// contains filtered or unexported fields
}
UDPv5 is the implementation of protocol version 5.
ListenV5 listens on the given connection.
AllNodes returns all the nodes stored in the local table.
Close shuts down packet processing.
LocalNode returns the current local node running the protocol.
Lookup performs a recursive lookup for the given target. It returns the closest nodes to target.
Ping sends a ping message to the given node.
RandomNodes returns an iterator that finds random nodes in the DHT.
RegisterTalkHandler adds a handler for 'talk requests'. The handler function is called whenever a request for the given protocol is received and should return the response data or nil.
requestENR requests n's record.
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.
Self returns the local node record.
TalkRequest sends a talk request to n and waits for a response.
Path | Synopsis |
---|---|
v4wire | Package v4wire implements the Discovery v4 Wire Protocol. |
v5wire |
Package discover imports 28 packages (graph) and is imported by 1384 packages. Updated 2020-11-30. Refresh now. Tools for package owners.