比特币代码学习:P2P

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chaiyu2002/article/details/88056840

Constants And Defaults

Network Default Port Start String Max nBits
Mainnet 8333 0xf9beb4d9 0x1d00ffff
Testnet 18333 0x0b110907 0x1d00ffff
Regtest 18444 0xfabfb5da 0x207fffff

默认的端口,表示网络的一个开始串,nBits是最大难度?

Protocol Versions

网络协议的版本。

Message Headers

消息头的格式。

Data Messages

Overview Of P2P Protocol Data Request And Reply Messages

这个图没有箭头,有点不太理解。应该是从左到右地去阅读。

下面这部分应该是这样理解,getblocks和mempool请求,会得到一个inv的返回,然后根据inv里面提供的信息,使用getdata方法去获取不同类型的数据。

inventories怎么理解?应该是当做清单来理解,记得SOA设计中,也有这个东西。就是先获取一个清单,然后再根据清单里面的条目名称,一条一条去获取具体的内容。

inventories的格式如下:

Bytes Name Data Type Description
4 type identifier uint32_t The type of object which was hashed. See list of type identifiers below.
32 hash char[32] SHA256(SHA256()) hash of the object in internal byte order.

上面这个图验证了我的理解。

It can be sent unsolicited to announce new transactions or blocks, or it can be sent in reply to a getblocks message or mempool message.

inv既有可能是主动发的,也有可能是被动的一个回复。

Bitcoin Core (up until version 0.9.3) uses a simple initial block download (IBD) method we’ll call blocks-first. The goal is to download the blocks from the best block chain in sequence.

Overview Of Blocks-First Method

这个过程讲清楚了整个过程。

2019-03-01,暂时整理到此。

参考:

https://bitcoin.org/en/developer-guide#block-broadcasting

https://bitcoin.org/en/developer-reference#mempool

猜你喜欢

转载自blog.csdn.net/chaiyu2002/article/details/88056840
P2P