Documentation ¶
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 { // These settings are required and configure the UDP listener: // 必选字段 PrivateKey *ecdsa.PrivateKey // These settings are optional: // 可选字段 NetRestrict *netutil.Netlist // list of allowed IP networks Bootnodes []*enode.Node // list of bootstrap nodes // 可选字段,所有没被处理的数据包发送到这里 Unhandled chan<- ReadPacket // unhandled packets are sent on this channel // 默认是log.Root() 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. 启动节点发现监听服务使用的配置 必须设置的字段是PrivateKey
type ReadPacket ¶
ReadPacket is a packet that couldn't be handled. Those packets are sent to the unhandled channel if configured. 用于表示不能被处理的数据包,他们被发送到unhandled管道
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.
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. UDPConn接口是节点发现过程中使用的网络连接 可以使用别的对象实现该接口就可以替换节点发现过程使用的通信链路
type UDPv4 ¶
type UDPv4 struct {
// contains filtered or unexported fields
}
UDPv4 implements the v4 wire protocol.
func ListenUDP ¶
ListenUDP starts listening for discovery packets on the given UDP socket. ListenUDP在UDP端口上启动监听节点发现的数据包 有ListenV4和ListenV5两个参数完全一致的函数,现在ListenUDP还默认使用ListenV4实现
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. 向远程节点请求最新的ENR记录 RequestENR的结构 packet = packet-header || packet-data packet-header = hash || signature || packet-type hash = keccak256(signature || packet-type || packet-data) signature = sign(packet-type || packet-data) packet-data = [expiration]
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.