mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor: add network-api crate (#838)
This commit is contained in:
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -3607,6 +3607,7 @@ dependencies = [
|
||||
"reth-executor",
|
||||
"reth-interfaces",
|
||||
"reth-network",
|
||||
"reth-network-api",
|
||||
"reth-primitives",
|
||||
"reth-provider",
|
||||
"reth-rlp",
|
||||
@ -3993,6 +3994,7 @@ dependencies = [
|
||||
"reth-interfaces",
|
||||
"reth-metrics-derive",
|
||||
"reth-net-common",
|
||||
"reth-network-api",
|
||||
"reth-primitives",
|
||||
"reth-provider",
|
||||
"reth-rlp",
|
||||
@ -4010,6 +4012,10 @@ dependencies = [
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "reth-network-api"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "reth-primitives"
|
||||
version = "0.1.0"
|
||||
|
||||
@ -13,6 +13,7 @@ members = [
|
||||
"crates/net/discv4",
|
||||
"crates/net/dns",
|
||||
"crates/net/nat",
|
||||
"crates/net/network-api",
|
||||
"crates/net/network",
|
||||
"crates/net/ipc",
|
||||
"crates/net/rpc",
|
||||
|
||||
@ -20,6 +20,7 @@ reth-executor = { path = "../../crates/executor" }
|
||||
# reth-rpc = {path = "../../crates/net/rpc"}
|
||||
reth-rlp = { path = "../../crates/common/rlp" }
|
||||
reth-network = {path = "../../crates/net/network", features = ["serde"] }
|
||||
reth-network-api = {path = "../../crates/net/network-api" }
|
||||
reth-downloaders = {path = "../../crates/net/downloaders" }
|
||||
reth-cli-utils = { path = "../../crates/cli/utils" }
|
||||
reth-tracing = { path = "../../crates/tracing" }
|
||||
|
||||
@ -21,6 +21,7 @@ use reth_downloaders::{bodies, headers};
|
||||
use reth_executor::Config as ExecutorConfig;
|
||||
use reth_interfaces::consensus::ForkchoiceState;
|
||||
use reth_network::NetworkEvent;
|
||||
use reth_network_api::NetworkInfo;
|
||||
use reth_primitives::{BlockNumber, H256};
|
||||
use reth_stages::{
|
||||
metrics::HeaderMetrics,
|
||||
|
||||
10
crates/net/network-api/Cargo.toml
Normal file
10
crates/net/network-api/Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "reth-network-api"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/paradigmxyz/reth"
|
||||
readme = "README.md"
|
||||
description = "Network interfaces"
|
||||
|
||||
[dependencies]
|
||||
18
crates/net/network-api/src/lib.rs
Normal file
18
crates/net/network-api/src/lib.rs
Normal file
@ -0,0 +1,18 @@
|
||||
#![warn(missing_docs, unreachable_pub)]
|
||||
#![deny(unused_must_use, rust_2018_idioms)]
|
||||
#![doc(test(
|
||||
no_crate_inject,
|
||||
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
|
||||
))]
|
||||
|
||||
//! Reth network interface definitions.
|
||||
//!
|
||||
//! Provides abstractions for the reth-network crate.
|
||||
|
||||
use std::net::SocketAddr;
|
||||
|
||||
/// Provides general purpose information about the network
|
||||
pub trait NetworkInfo: Send + Sync {
|
||||
/// Returns the [`SocketAddr`] that listens for incoming connections.
|
||||
fn local_addr(&self) -> SocketAddr;
|
||||
}
|
||||
@ -20,6 +20,7 @@ normal = [
|
||||
reth-interfaces = { path = "../../interfaces" }
|
||||
reth-primitives = { path = "../../primitives" }
|
||||
reth-net-common = { path = "../common" }
|
||||
reth-network-api = { path = "../network-api" }
|
||||
reth-discv4 = { path = "../discv4" }
|
||||
reth-eth-wire = { path = "../eth-wire" }
|
||||
reth-ecies = { path = "../ecies" }
|
||||
|
||||
@ -17,6 +17,7 @@ use std::{
|
||||
sync::Arc,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
|
||||
use tokio::sync::{mpsc::UnboundedReceiver, oneshot};
|
||||
use tokio_stream::wrappers::UnboundedReceiverStream;
|
||||
|
||||
|
||||
@ -13,6 +13,7 @@ use reth_interfaces::{
|
||||
sync::{SyncState, SyncStateProvider, SyncStateUpdater},
|
||||
};
|
||||
use reth_net_common::bandwidth_meter::BandwidthMeter;
|
||||
use reth_network_api::NetworkInfo;
|
||||
use reth_primitives::{PeerId, TransactionSigned, TxHash, H256, U256};
|
||||
use std::{
|
||||
net::SocketAddr,
|
||||
@ -64,11 +65,6 @@ impl NetworkHandle {
|
||||
self.inner.num_active_peers.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// Returns the [`SocketAddr`] that listens for incoming connections.
|
||||
pub fn local_addr(&self) -> SocketAddr {
|
||||
*self.inner.listener_address.lock()
|
||||
}
|
||||
|
||||
/// Returns the [`PeerId`] used in the network.
|
||||
pub fn peer_id(&self) -> &PeerId {
|
||||
&self.inner.local_peer_id
|
||||
@ -210,6 +206,14 @@ impl NetworkHandle {
|
||||
}
|
||||
}
|
||||
|
||||
// === API Implementations ===
|
||||
|
||||
impl NetworkInfo for NetworkHandle {
|
||||
fn local_addr(&self) -> SocketAddr {
|
||||
*self.inner.listener_address.lock()
|
||||
}
|
||||
}
|
||||
|
||||
impl StatusUpdater for NetworkHandle {
|
||||
/// Update the status of the node.
|
||||
fn update_status(&self, height: u64, hash: H256, total_difficulty: U256) {
|
||||
|
||||
@ -14,6 +14,7 @@ use reth_interfaces::{
|
||||
};
|
||||
use reth_net_common::ban_list::BanList;
|
||||
use reth_network::{NetworkConfig, NetworkEvent, NetworkManager, PeersConfig};
|
||||
use reth_network_api::NetworkInfo;
|
||||
use reth_primitives::{HeadersDirection, NodeRecord, PeerId};
|
||||
use reth_provider::test_utils::NoopProvider;
|
||||
use reth_transaction_pool::test_utils::testing_pool;
|
||||
|
||||
@ -8,6 +8,7 @@ use reth_interfaces::p2p::{
|
||||
bodies::client::BodiesClient,
|
||||
headers::client::{HeadersClient, HeadersRequest},
|
||||
};
|
||||
use reth_network_api::NetworkInfo;
|
||||
use reth_primitives::{
|
||||
Block, Bytes, Header, HeadersDirection, Signature, Transaction, TransactionKind,
|
||||
TransactionSigned, TxEip2930, H256, U256,
|
||||
|
||||
Reference in New Issue
Block a user