p2p 层的实现

本节记录了 CometBFT 中点对点(p2p)通信层的实现。 本文档以本仓库的 v0.34.* 版本发布和分支 v0.34.x 为参考,生成而成。 由于 p2p 实现没有发生实质性变化,因此本文档同样适用于 v0.37.* 和 v0.38.* 版本 1。

目录

本文档遵循 p2p 包的组织结构,该包实现了以下抽象:
  • Transport:与对等节点建立安全且经过认证的连接;
  • Switch:负责拨号连接对等节点和接受来自对等节点的连接,管理已建立的连接,以及在 reactor 与对等节点之间路由消息,也就是在 CometBFT 协议的本地实例与远程实例之间路由消息;
  • PEX Reactor:由于该组件承担多个角色,相关文档被拆分为多个部分:
    • Peer Exchange protocol:使节点能够交换对等节点地址,从而实现对等节点发现服务;
    • Address Book:存储发现到的对等节点地址,以及节点与之交互过的对等节点相关质量指标;
    • Peer Manager:定义节点应在何时以及向哪些对等节点发起拨号,以建立出站连接;
  • Types 和 Configuration 提供了 p2p 包中现有类型及所用配置参数的列表。

Implementation of the p2p layer

This section documents the implementation of the peer-to-peer (p2p) communication layer in CometBFT. The documentation was produced using the v0.34.* releases and the branch v0.34.x of this repository as reference. As there were no substancial changes in the p2p implementation, the documentation also applies to the releases v0.37.* and v0.38.* 1.

Contents

The documentation follows the organization of the p2p package, which implements the following abstractions:
  • Transport: establishes secure and authenticated connections with peers;
  • Switch: responsible for dialing peers and accepting connections from peers, for managing established connections, and for routing messages between the reactors and peers, that is, between local and remote instances of the CometBFT protocols;
  • PEX Reactor: due to the several roles of this component, the documentation is split in several parts:
    • Peer Exchange protocol: enables nodes to exchange peer addresses, thus implementing a peer discovery service;
    • Address Book: stores discovered peer addresses and quality metrics associated to peers with which the node has interacted;
    • Peer Manager: defines when and to which peers a node should dial, in order to establish outbound connections;
  • Types and Configuration provide a list of existing types and configuration parameters used by the p2p package.

Footnotes

  1. 包含 p2p 层实现重大重构的 v0.35.* 和 v0.36.* 版本已被停止维护。 ↩ ↩2