Skip to main content

ethrex_p2p/
p2p.rs

1//! # ethrex P2P Networking
2//!
3//! Peer-to-peer networking layer for the ethrex Ethereum client.
4//!
5//! ## Overview
6//!
7//! This crate implements the Ethereum P2P networking stack:
8//! - **Discovery**: Node discovery using discv4 (and experimental discv5)
9//! - **RLPx**: Encrypted transport protocol for peer communication
10//! - **eth Protocol**: Block and transaction propagation
11//! - **snap Protocol**: Fast state synchronization
12//!
13//! ## Architecture
14//!
15//! ```text
16//! ┌─────────────────────────────────────────────────────────────┐
17//! │                      Network Layer                           │
18//! │  ┌─────────────┐  ┌─────────────┐  ┌─────────────────────┐ │
19//! │  │   discv4    │  │    RLPx     │  │   Peer Handler      │ │
20//! │  │ (Discovery) │  │ (Transport) │  │   (Messages)        │ │
21//! │  └─────────────┘  └─────────────┘  └─────────────────────┘ │
22//! └─────────────────────────────────────────────────────────────┘
23//!                              │
24//!           ┌──────────────────┼──────────────────┐
25//!           ▼                  ▼                  ▼
26//! ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
27//! │   Sync Manager  │ │ TX Broadcaster  │ │  Snap Sync      │
28//! └─────────────────┘ └─────────────────┘ └─────────────────┘
29//! ```
30//!
31//! ## Key Components
32//!
33//! - [`network`]: Network initialization and peer management
34//! - [`peer_handler`]: Message handling for connected peers
35//! - [`sync_manager`]: Block synchronization coordination
36//! - [`sync`]: Full and snap sync implementations
37//! - [`tx_broadcaster`]: Transaction pool broadcasting
38//! - [`discv4`]: Node discovery protocol v4
39//! - [`rlpx`]: RLPx encrypted transport
40//!
41//! ## Usage
42//!
43//! ```ignore
44//! use ethrex_p2p::{start_network, SyncManager};
45//!
46//! // Start the P2P network
47//! let (sync_manager, peer_handler) = start_network(
48//!     udp_addr,
49//!     tcp_addr,
50//!     bootnodes,
51//!     signer,
52//!     storage,
53//!     blockchain,
54//! ).await?;
55//!
56//! // Start synchronization
57//! sync_manager.start_sync().await?;
58//! ```
59//!
60//! ## Protocols
61//!
62//! - **eth/68**: Block and transaction exchange
63//! - **snap/1**: State snapshot synchronization
64//!
65pub mod backend;
66pub mod discovery;
67pub mod discv4;
68pub mod discv5;
69pub(crate) mod metrics;
70pub mod network;
71pub mod peer_handler;
72pub mod peer_table;
73pub mod rlpx;
74pub mod snap;
75pub mod sync;
76pub mod sync_manager;
77pub mod tx_broadcaster;
78pub mod types;
79pub mod utils;
80
81pub use discovery::DiscoveryConfig;
82pub use network::periodically_show_peer_stats;
83pub use network::start_network;