0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

bitcoin: dns seed

Posted at

为什么需要dns seed

当bitcoin客户端第一次启动的时候, 程序不知道任何活跃的bitcoin全节点。
为了发现一些IP地址, 需要把一些DNS地址(也叫dns种子)硬编码到比特币源码中。如果没有dns seed, 客户端不能自动联上节点。

Dns Seed 由比特币的社区成员维护, 其中一些提供动态的dns seed服务,通过扫描网络自动获取活跃的节点IP地址,其中一些提供静态dns seed, 这些种子是手动添加的。

查看dns seed

我们看下sipa维护的 dns seed

dig seed.bitcoin.sipa.be

; <<>> DiG 9.10.3-P4-Ubuntu <<>> seed.bitcoin.sipa.be
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 33331
;; flags: qr rd ra; QUERY: 1, ANSWER: 25, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;seed.bitcoin.sipa.be.    IN  A

;; ANSWER SECTION:
seed.bitcoin.sipa.be. 30  IN  A 83.162.254.34
seed.bitcoin.sipa.be. 30  IN  A 176.115.25.48
seed.bitcoin.sipa.be. 30  IN  A 78.47.68.244
seed.bitcoin.sipa.be. 30  IN  A 96.53.77.134
seed.bitcoin.sipa.be. 30  IN  A 158.69.251.126

...

;; Query time: 1 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Wed Jan 10 18:17:53 CST 2018
;; MSG SIZE  rcvd: 449

83.162.254.34 176.115.25.48 ... 158.69.251.126 都是节点地址,当客户端启动的时候, 会自动链接这些地址。

peers.png

dns seed 硬编码在什么地方了?

# src/chainparams.cpp
vSeeds.emplace_back("seed.bitcoin.sipa.be", true);  
vSeeds.emplace_back("dnsseed.bluematt.me", true); 
vSeeds.emplace_back("dnsseed.bitcoin.dashjr.org", false);  
vSeeds.emplace_back("seed.bitcoinstats.com", true);
vSeeds.emplace_back("seed.bitcoin.jonasschnelli.ch", true); 
vSeeds.emplace_back("seed.btc.petertodd.org", true);

如何提供动态dns seed服务

1 需要爬虫一类的服务,通过bitcoin protocol 嗅探到一些节点

2 可以模仿dns请求, dns通过UDP协议的53端口进行通讯, 把嗅探到节点发送出去

这些工作,敬爱的sipa在 bitcoin-seeder 都帮我们做了。

我们先了解下sipa的服务器

dig -t ns seed.bitcoin.sipa.be

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1280
;; QUESTION SECTION:
;seed.bitcoin.sipa.be.		IN	NS

;; ANSWER SECTION:
seed.bitcoin.sipa.be.	14852	IN	NS	xps.sipa.be.

;; ADDITIONAL SECTION:
xps.sipa.be.		16014	IN	A	45.32.130.19
xps.sipa.be.		18051	IN	AAAA	2001:19f0:ac01:2fb:5400:ff:fe5b:c3ff

;; Query time: 7 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Wed Jan 17 19:08:48 CST 2018
;; MSG SIZE  rcvd: 111

seed.bitcoin.sipa.be. 14852 IN NS xps.sipa.be. 了解到seed域名的ns服务(即 nameserver)
是由 xps提供的. 我们在dnspod 做如下配置.

dns-seed.png

需要在xps服务器启动bitocin-seeder

如何使用bitcoin-seeder

1 先编译 make, 得到 dnsseed执行文件

2 启动爬虫

./dnsseed -? # help命令

Usage: ./dnsseed -h <host> -n <ns> [-m <mbox>] [-t <threads>] [-p <port>]

Options:
-h <host>       Hostname of the DNS seed
-n <ns>         Hostname of the nameserver
-m <mbox>    E-Mail address reported in SOA records
-t <threads>    Number of crawlers to run in parallel (default 96)
-d <threads>    Number of DNS server threads (default 4)
-p <port>       UDP port to listen on (default 53)
-o <ip:port>    Tor proxy IP/Port
-i <ip:port>    IPV4 SOCKS5 proxy IP/Port
-k <ip:port>    IPV6 SOCKS5 proxy IP/Port
-w f1,f2,...    Allow these flag combinations as filters
--testnet       Use testnet
--wipeban       Wipe list of banned nodes
--wipeignore    Wipe list of ignored nodes
-?, --help      Show this text
./dnsseed -h seed.liushooter.cc -n xps.liushooter.cc

等一段时间, dig seed.liushooter.cc 就会看到结果.


参考:

https://en.bitcoin.it/wiki/Satoshi_Client_Node_Discovery#DNS_Addresses
https://bitcoin.org/en/developer-guide#p2p-network

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?