mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Create Network variant in reth_interfaces::Error (#950)
This commit is contained in:
committed by
GitHub
parent
009d2056f9
commit
a331b54bb0
@ -11,8 +11,11 @@ description = "Network interfaces"
|
||||
# reth
|
||||
reth-primitives = { path = "../../primitives" }
|
||||
|
||||
|
||||
# io
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
|
||||
# misc
|
||||
async-trait = "0.1"
|
||||
async-trait = "0.1"
|
||||
thiserror = "1.0.37"
|
||||
tokio = { version = "1.21.2", features = ["sync"] }
|
||||
22
crates/net/network-api/src/error.rs
Normal file
22
crates/net/network-api/src/error.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use thiserror::Error;
|
||||
use tokio::sync::{mpsc, oneshot};
|
||||
|
||||
/// Network Errors
|
||||
#[allow(missing_docs)]
|
||||
#[derive(Error, Debug, Clone, PartialEq, Eq)]
|
||||
pub enum NetworkError {
|
||||
#[error("Sender has been dropped")]
|
||||
ChannelClosed,
|
||||
}
|
||||
|
||||
impl<T> From<mpsc::error::SendError<T>> for NetworkError {
|
||||
fn from(_: mpsc::error::SendError<T>) -> Self {
|
||||
NetworkError::ChannelClosed
|
||||
}
|
||||
}
|
||||
|
||||
impl From<oneshot::error::RecvError> for NetworkError {
|
||||
fn from(_: oneshot::error::RecvError) -> Self {
|
||||
NetworkError::ChannelClosed
|
||||
}
|
||||
}
|
||||
@ -12,19 +12,20 @@
|
||||
use async_trait::async_trait;
|
||||
use reth_primitives::{NodeRecord, H256, U256};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{error::Error, net::SocketAddr};
|
||||
use std::net::SocketAddr;
|
||||
|
||||
/// Network Error
|
||||
pub mod error;
|
||||
pub use error::NetworkError;
|
||||
|
||||
/// Provides general purpose information about the network.
|
||||
#[async_trait]
|
||||
pub trait NetworkInfo: Send + Sync {
|
||||
/// Associated error type for the network implementation.
|
||||
type Error: Send + Sync + Error;
|
||||
|
||||
/// Returns the [`SocketAddr`] that listens for incoming connections.
|
||||
fn local_addr(&self) -> SocketAddr;
|
||||
|
||||
/// Returns the current status of the network being ran by the local node.
|
||||
async fn network_status(&self) -> Result<NetworkStatus, Self::Error>;
|
||||
async fn network_status(&self) -> Result<NetworkStatus, NetworkError>;
|
||||
}
|
||||
|
||||
/// Provides general purpose information about Peers in the network.
|
||||
|
||||
Reference in New Issue
Block a user