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 ¶
- type Config
- type ReadPacket
- type Table
- type TalkRequestHandler
- type UDPConn
- type UDPv4
- func (t *UDPv4) Close()
- func (t *UDPv4) LookupPubkey(key *ecdsa.PublicKey) []*enode.Node
- func (t *UDPv4) Ping(n *enode.Node) error
- func (t *UDPv4) RandomNodes() enode.Iterator
- func (t *UDPv4) RequestENR(n *enode.Node) (*enode.Node, error)
- func (t *UDPv4) Resolve(n *enode.Node) *enode.Node
- func (t *UDPv4) Self() *enode.Node
- type UDPv5
- func (t *UDPv5) AllNodes() []*enode.Node
- func (t *UDPv5) Close()
- func (t *UDPv5) LocalNode() *enode.LocalNode
- func (t *UDPv5) Lookup(target enode.ID) []*enode.Node
- func (t *UDPv5) Ping(n *enode.Node) error
- func (t *UDPv5) RandomNodes() enode.Iterator
- func (t *UDPv5) RegisterTalkHandler(protocol string, handler TalkRequestHandler)
- func (t *UDPv5) RequestENR(n *enode.Node) (*enode.Node, error)
- func (t *UDPv5) Resolve(n *enode.Node) *enode.Node
- func (t *UDPv5) Self() *enode.Node
- func (t *UDPv5) TalkRequest(n *enode.Node, protocol string, request []byte) ([]byte, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // 需要这些设置并配置UDP侦听器: PrivateKey *ecdsa.PrivateKey // These settings are optional: NetRestrict *netutil.Netlist // 允许的IP网络列表 Bootnodes []*enode.Node // 引导节点列表 Unhandled chan<- ReadPacket // 未处理的数据包在此通道上发送 Log log.Logger // 如果设置了,则记录消息到此处 ValidSchemes enr.IdentityScheme // 允许的标识方案 Clock mclock.Clock }
Config holds settings for the discovery listener.
type ReadPacket ¶
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
}
表是“节点表”,是一个类似Kademlia的邻居节点索引。该表通过验证邻居的活跃度并在收到新记录版本的通知时请求其节点记录来保持自身最新。
type TalkRequestHandler ¶
TalkRequestHandler callback processes a talk request and optionally returns a reply
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 (*UDPv4) Close ¶
func (t *UDPv4) Close()
Close shuts down the socket and aborts any running queries.
func (*UDPv4) LookupPubkey ¶
LookupPubkey finds the closest nodes to the given public key.
func (*UDPv4) RandomNodes ¶
RandomNodes is an iterator yielding nodes from a random walk of the DHT.
func (*UDPv4) RequestENR ¶
RequestENR sends enrRequest to the given node and waits for a response.
type UDPv5 ¶
type UDPv5 struct {
// contains filtered or unexported fields
}
UDPv5 is the implementation of protocol version 5.
func (*UDPv5) Lookup ¶
Lookup performs a recursive lookup for the given target. It returns the closest nodes to target.
func (*UDPv5) RandomNodes ¶
RandomNodes returns an iterator that finds random nodes in the DHT.
func (*UDPv5) RegisterTalkHandler ¶
func (t *UDPv5) RegisterTalkHandler(protocol string, handler TalkRequestHandler)
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.
func (*UDPv5) RequestENR ¶
requestENR requests n's record.