Create Network variant in reth_interfaces::Error (#950)

This commit is contained in:
Ikechukwu Ahiara Marvellous
2023-01-22 20:59:50 +01:00
committed by GitHub
parent 009d2056f9
commit a331b54bb0
8 changed files with 98 additions and 14 deletions

View File

@ -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"] }

View 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
}
}

View File

@ -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.