diff --git a/Cargo.lock b/Cargo.lock index f6fdade26..47520b49d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4016,6 +4016,9 @@ dependencies = [ [[package]] name = "reth-network-api" version = "0.1.0" +dependencies = [ + "reth-primitives", +] [[package]] name = "reth-primitives" diff --git a/crates/net/network-api/Cargo.toml b/crates/net/network-api/Cargo.toml index 0ebd92dc7..5f4018be4 100644 --- a/crates/net/network-api/Cargo.toml +++ b/crates/net/network-api/Cargo.toml @@ -7,4 +7,5 @@ repository = "https://github.com/paradigmxyz/reth" readme = "README.md" description = "Network interfaces" -[dependencies] \ No newline at end of file +[dependencies] +reth-primitives = { path = "../../primitives" } \ No newline at end of file diff --git a/crates/net/network-api/src/lib.rs b/crates/net/network-api/src/lib.rs index ea14a3ac6..5f5aea76f 100644 --- a/crates/net/network-api/src/lib.rs +++ b/crates/net/network-api/src/lib.rs @@ -9,6 +9,7 @@ //! //! Provides abstractions for the reth-network crate. +use reth_primitives::NodeRecord; use std::net::SocketAddr; /// Provides general purpose information about the network. @@ -23,4 +24,7 @@ pub trait PeersInfo: Send + Sync { /// /// Note: this should only include established connections and _not_ ongoing attempts. fn num_connected_peers(&self) -> usize; + + /// Returns the Ethereum Node Record of the node. + fn local_node_record(&self) -> NodeRecord; } diff --git a/crates/net/network/src/network.rs b/crates/net/network/src/network.rs index f7e2b92ab..6083b67a6 100644 --- a/crates/net/network/src/network.rs +++ b/crates/net/network/src/network.rs @@ -14,7 +14,7 @@ use reth_interfaces::{ }; use reth_net_common::bandwidth_meter::BandwidthMeter; use reth_network_api::{NetworkInfo, PeersInfo}; -use reth_primitives::{PeerId, TransactionSigned, TxHash, H256, U256}; +use reth_primitives::{NodeRecord, PeerId, TransactionSigned, TxHash, H256, U256}; use std::{ net::SocketAddr, sync::{ @@ -207,6 +207,12 @@ impl PeersInfo for NetworkHandle { fn num_connected_peers(&self) -> usize { self.inner.num_active_peers.load(Ordering::Relaxed) } + + fn local_node_record(&self) -> NodeRecord { + let id = *self.peer_id(); + let socket_addr = *self.inner.listener_address.lock(); + NodeRecord::new(socket_addr, id) + } } impl NetworkInfo for NetworkHandle {