dnsdisc

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2022 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

Package dnsdisc implements node discovery via DNS (EIP-1459).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseURL

func ParseURL(url string) (domain string, pubkey *ecdsa.PublicKey, err error)

ParseURL parses an enrtree:// URL and returns its components. 将以下格式链接切分成域名和公钥 enrtree://AM5FCQLWIZX2QFPNJAP7VUERCCRNGRHWZG3YYHIUV7BVDQ5FDPRT2@morenodes.example.org

Types

type Client

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

Client discovers nodes by querying DNS servers. Client对象用于执行DNS查询 查询时先查询缓存entries,缓存中没有则使用cfg.Resolver执行DNS查询

func NewClient

func NewClient(cfg Config) *Client

NewClient creates a client. 创建Client对象,用来从某一个链接同步节点数据

func (*Client) NewIterator

func (c *Client) NewIterator(urls ...string) (enode.Iterator, error)

NewIterator creates an iterator that visits all nodes at the given tree URLs. 传入多个链接,生成一个节点的迭代器,在传入的这些链接间迭代节点

func (*Client) SyncTree

func (c *Client) SyncTree(url string) (*Tree, error)

SyncTree downloads the entire node tree at the given URL. 从指定的链接开始同步节点信息的梅克尔树

type Config

type Config struct {
	Timeout time.Duration // timeout used for DNS lookups (default 5s)
	// 每三十分钟重新查询一次域名的根记录
	RecheckInterval time.Duration      // time between tree root update checks (default 30min)
	CacheLimit      int                // maximum number of cached records (default 1000)
	RateLimit       float64            // maximum DNS requests / second (default 3)
	ValidSchemes    enr.IdentityScheme // acceptable ENR identity schemes (default enode.ValidSchemes)
	Resolver        Resolver           // the DNS resolver to use (defaults to system DNS)
	Logger          log.Logger         // destination of client log messages (defaults to root logger)
}

Config holds configuration options for the client.

type Resolver

type Resolver interface {
	LookupTXT(ctx context.Context, domain string) ([]string, error)
}

Resolver is a DNS resolver that can query TXT records. 用来查询DNS请求的对象

type Tree

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

Tree is a merkle tree of node records. Tree对象里面保存了两棵树,分别是节点信息的树和其他可以查询的链接组成的树 节点信息树 最底层是enrEntry(enr:xxx),中间各层都是branchEntry(enrtree-branch:xxx,xxx,xxx)直至树根 链接树 最底层是linkEntry(enrtree://xxx),中间各层也都是branchEntry直至树根

func MakeTree

func MakeTree(seq uint, nodes []*enode.Node, links []string) (*Tree, error)

MakeTree creates a tree containing the given nodes and links. 给定节点和链接信息,构造Tree对象

func (t *Tree) Links() []string

Links returns all links contained in the tree. 返回树中所有的链接信息

func (*Tree) Nodes

func (t *Tree) Nodes() []*enode.Node

Nodes returns all nodes contained in the tree. 返回树中的所有节点信息

func (*Tree) Seq

func (t *Tree) Seq() uint

Seq returns the sequence number of the tree.

func (*Tree) SetSignature

func (t *Tree) SetSignature(pubkey *ecdsa.PublicKey, signature string) error

SetSignature verifies the given signature and assigns it as the tree's current signature if valid. 验证给定的签名对这棵树是否合法,合法的话就保存这个签名到树中

func (*Tree) Sign

func (t *Tree) Sign(key *ecdsa.PrivateKey, domain string) (url string, err error)

Sign signs the tree with the given private key and sets the sequence number. 对给定的树进行签名,签名保存在t.root.sig里面 返回链接,例如 enrtree://AM5FCQLWIZX2QFPNJAP7VUERCCRNGRHWZG3YYHIUV7BVDQ5FDPRT2@morenodes.example.org

func (*Tree) Signature

func (t *Tree) Signature() string

Signature returns the signature of the tree.

func (*Tree) ToTXT

func (t *Tree) ToTXT(domain string) map[string]string

ToTXT returns all DNS TXT records required for the tree.

Jump to

Keyboard shortcuts

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