feat: add NetworkPrimitives to NetworkBuilder (#13169)

Co-authored-by: Arsenii Kulikov <klkvrr@gmail.com>
This commit is contained in:
Dan Cline
2024-12-10 15:56:32 -05:00
committed by GitHub
parent 73f1583455
commit 37f3933db2
26 changed files with 201 additions and 143 deletions

View File

@ -133,9 +133,12 @@ pub trait NetworkPeersEvents: Send + Sync {
/// Provides event subscription for the network.
#[auto_impl::auto_impl(&, Arc)]
pub trait NetworkEventListenerProvider<R = PeerRequest>: NetworkPeersEvents {
pub trait NetworkEventListenerProvider: NetworkPeersEvents {
/// The primitive types to use in the `PeerRequest` used in the stream.
type Primitives: NetworkPrimitives;
/// Creates a new [`NetworkEvent`] listener channel.
fn event_listener(&self) -> EventStream<NetworkEvent<R>>;
fn event_listener(&self) -> EventStream<NetworkEvent<PeerRequest<Self::Primitives>>>;
/// Returns a new [`DiscoveryEvent`] stream.
///
/// This stream yields [`DiscoveryEvent`]s for each peer that is discovered.

View File

@ -36,7 +36,6 @@ pub use events::{
use std::{future::Future, net::SocketAddr, sync::Arc, time::Instant};
use reth_eth_wire_types::{capability::Capabilities, DisconnectReason, EthVersion, Status};
use reth_network_p2p::EthBlockClient;
use reth_network_peers::NodeRecord;
/// The `PeerId` type.
@ -44,7 +43,7 @@ pub type PeerId = alloy_primitives::B512;
/// Helper trait that unifies network API needed to launch node.
pub trait FullNetwork:
BlockDownloaderProvider<Client: EthBlockClient>
BlockDownloaderProvider
+ NetworkSyncUpdater
+ NetworkInfo
+ NetworkEventListenerProvider
@ -56,7 +55,7 @@ pub trait FullNetwork:
}
impl<T> FullNetwork for T where
T: BlockDownloaderProvider<Client: EthBlockClient>
T: BlockDownloaderProvider
+ NetworkSyncUpdater
+ NetworkInfo
+ NetworkEventListenerProvider