Skip to content

在了解过Aleth启动-P2PAleth启动-eth服务之后,发现P2P部分对于上层类来说只是一个成员变量m_net,而eth服务部分,只是上层类的另一个成员变量m_ethereum。这个上层类就名为WebThreeDirect

先看下那群开发者对WebThreeDirect的解释:

cpp
* @brief Main API hub for interfacing with Web 3 components. This doesn't do any local multiplexing, so you can only have one
* running on any given machine for the provided DB path.
*
* Keeps a libp2p Host going (administering the work thread with m_workNet).
*
* Encapsulates a bunch of P2P protocols (interfaces), each using the same underlying libp2p Host.
*
* Provides a baseline for the multiplexed multi-protocol session class, WebThree.


* @brief 用于与 Web 3 组件交互的主要 API 中心。 这不会执行任何本地多路复用,因此对于提供的数据库路径,您只能在任何给定机器上运行一个。
*
* 保持 libp2p 主机运行(使用 m_workNet 管理工作线程)。
*
* 封装了一堆 P2P 协议(接口),每个都使用相同的底层 libp2p Host。
*
* 为多路复用多协议会话类 WebThree 提供基线。

WebThreeDirect只有三个成员变量:

cpp
private:
    std::string m_clientVersion;   ///< Our end-application client's name/version.

    std::unique_ptr<eth::Client> m_ethereum;        ///< Client for Ethereum ("eth") protocol.

    p2p::Host m_net;    ///< Should run in background and send us events when blocks found and allow us to send blocks as required.

第一个就是个m_clientVersion字符串。

后两个就是我们已经探索过的eth服务和p2p服务。

感觉整个系统的架构清晰了起来,所有其他的代码都是为这个服务的。