mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor: move RequestError from network to interfaces p2p (#197)
This commit is contained in:
30
crates/interfaces/src/p2p/error.rs
Normal file
30
crates/interfaces/src/p2p/error.rs
Normal file
@ -0,0 +1,30 @@
|
||||
use tokio::sync::{mpsc, oneshot};
|
||||
|
||||
/// Result alias for result of a request.
|
||||
pub type RequestResult<T> = Result<T, RequestError>;
|
||||
|
||||
/// Error variants that can happen when sending requests to a session.
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
#[allow(missing_docs)]
|
||||
pub enum RequestError {
|
||||
#[error("Closed channel to the peer.")]
|
||||
ChannelClosed,
|
||||
#[error("Not connected to the peer.")]
|
||||
NotConnected,
|
||||
#[error("Capability Message is not supported by remote peer.")]
|
||||
UnsupportedCapability,
|
||||
#[error("Request timed out while awaiting response.")]
|
||||
Timeout,
|
||||
}
|
||||
|
||||
impl<T> From<mpsc::error::SendError<T>> for RequestError {
|
||||
fn from(_: mpsc::error::SendError<T>) -> Self {
|
||||
RequestError::ChannelClosed
|
||||
}
|
||||
}
|
||||
|
||||
impl From<oneshot::error::RecvError> for RequestError {
|
||||
fn from(_: oneshot::error::RecvError) -> Self {
|
||||
RequestError::ChannelClosed
|
||||
}
|
||||
}
|
||||
@ -6,6 +6,10 @@
|
||||
/// [`HeadersClient`]: crate::p2p::headers::HeadersClient
|
||||
pub mod headers;
|
||||
|
||||
/// Error types broadly used by p2p interfaces for any operation which may produce an error when
|
||||
/// interacting with the network implementation
|
||||
pub mod error;
|
||||
|
||||
use futures::Stream;
|
||||
use std::pin::Pin;
|
||||
|
||||
|
||||
@ -1,12 +1,9 @@
|
||||
//! Fetch data from the network.
|
||||
|
||||
use crate::{
|
||||
message::{BlockRequest, RequestResult},
|
||||
NodeId,
|
||||
};
|
||||
use crate::{message::BlockRequest, NodeId};
|
||||
use futures::StreamExt;
|
||||
use reth_eth_wire::{BlockBody, EthMessage};
|
||||
use reth_interfaces::p2p::headers::client::HeadersRequest;
|
||||
use reth_interfaces::p2p::{error::RequestResult, headers::client::HeadersRequest};
|
||||
use reth_primitives::{Header, H256, U256};
|
||||
use std::{
|
||||
collections::{HashMap, VecDeque},
|
||||
|
||||
@ -13,38 +13,10 @@ use std::task::{ready, Context, Poll};
|
||||
|
||||
use crate::NodeId;
|
||||
use reth_eth_wire::capability::CapabilityMessage;
|
||||
use reth_interfaces::p2p::error::RequestResult;
|
||||
use reth_primitives::{Header, Receipt, TransactionSigned};
|
||||
use tokio::sync::{mpsc, mpsc::error::TrySendError, oneshot};
|
||||
|
||||
/// Result alias for result of a request.
|
||||
pub type RequestResult<T> = Result<T, RequestError>;
|
||||
|
||||
/// Error variants that can happen when sending requests to a session.
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
#[allow(missing_docs)]
|
||||
pub enum RequestError {
|
||||
#[error("Closed channel.")]
|
||||
ChannelClosed,
|
||||
#[error("Not connected to the node.")]
|
||||
NotConnected,
|
||||
#[error("Capability Message is not supported by remote peer.")]
|
||||
UnsupportedCapability,
|
||||
#[error("Network error: {0}")]
|
||||
Io(String),
|
||||
}
|
||||
|
||||
impl<T> From<mpsc::error::SendError<T>> for RequestError {
|
||||
fn from(_: mpsc::error::SendError<T>) -> Self {
|
||||
RequestError::ChannelClosed
|
||||
}
|
||||
}
|
||||
|
||||
impl From<oneshot::error::RecvError> for RequestError {
|
||||
fn from(_: oneshot::error::RecvError) -> Self {
|
||||
RequestError::ChannelClosed
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents all messages that can be sent to a peer session
|
||||
#[derive(Debug)]
|
||||
pub enum PeerMessage {
|
||||
|
||||
Reference in New Issue
Block a user