上一节主要讲了Ethereum服务和以太坊P2P协议通讯模块 handler.go 的初始化和启动,以及以太坊通讯协议如何广播给其他的网络节点。
这一节讲讲,以太坊通讯协议如何处理接收到的广播消息。以及fetcher怎么工作。
ethereum共拥有两个Fetcher,分别为 BlockFetcher(eth/fetcher/block_fetcher.go),TxFetcher(eth/fetcher/tx_fetcher.go)
一,handler 接收网络节点广播消息
首先看看p2p.Protocol的结构
- type Protocol struct {
- // Name should contain the official protocol name,
- // often a three-letter word.
- Name string
-
- // Version should contain the version number of the protocol.
- Version uint
-
- // Length should contain the number of message codes used
- // by the protocol.
- Length uint64
-
- // Run is called in a new goroutine when the protocol has been
- // negotiated with a peer. It should read and write messages from
- // rw. The Payload for each message must be fully consumed.
- //
- // The peer connection is closed when Start returns. It should return
- // any protocol-level error (such as a