network: rename alias to BoxError
This is shorter and consistent with Tower (which is why we use it in the first place).
This commit is contained in:
parent
5fbb07460c
commit
1d3892e1dc
|
@ -14,7 +14,7 @@ use tower::{
|
|||
Service,
|
||||
};
|
||||
|
||||
use crate::{peer, BoxedStdError, Config, Request, Response};
|
||||
use crate::{peer, BoxError, Config, Request, Response};
|
||||
|
||||
/// Use the provided TCP connection to create a Zcash connection completely
|
||||
/// isolated from all other node state.
|
||||
|
@ -67,7 +67,7 @@ struct Wrapper(peer::Client);
|
|||
|
||||
impl Service<Request> for Wrapper {
|
||||
type Response = Response;
|
||||
type Error = BoxedStdError;
|
||||
type Error = BoxError;
|
||||
type Future =
|
||||
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ extern crate bitflags;
|
|||
/// Note: the 'static lifetime bound means that the *type* cannot have any
|
||||
/// non-'static lifetimes, (e.g., when a type contains a borrow and is
|
||||
/// parameterized by 'a), *not* that the object itself has 'static lifetime.
|
||||
pub type BoxedStdError = Box<dyn std::error::Error + Send + Sync + 'static>;
|
||||
pub type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
|
||||
|
||||
mod address_book;
|
||||
mod config;
|
||||
|
|
|
@ -39,7 +39,7 @@ use crate::{
|
|||
external::{types::Nonce, InventoryHash, Message},
|
||||
internal::{Request, Response},
|
||||
},
|
||||
BoxedStdError,
|
||||
BoxError,
|
||||
};
|
||||
|
||||
use super::{ClientRequest, ErrorSlot, PeerError, SharedPeerError};
|
||||
|
@ -184,8 +184,8 @@ pub struct Connection<S, Tx> {
|
|||
|
||||
impl<S, Tx> Connection<S, Tx>
|
||||
where
|
||||
S: Service<Request, Response = Response, Error = BoxedStdError>,
|
||||
S::Error: Into<BoxedStdError>,
|
||||
S: Service<Request, Response = Response, Error = BoxError>,
|
||||
S::Error: Into<BoxError>,
|
||||
Tx: Sink<Message, Error = SerializationError> + Unpin,
|
||||
{
|
||||
/// Consume this `Connection` to form a spawnable future containing its event loop.
|
||||
|
|
|
@ -9,7 +9,7 @@ use futures::prelude::*;
|
|||
use tokio::net::TcpStream;
|
||||
use tower::{discover::Change, Service, ServiceExt};
|
||||
|
||||
use crate::{BoxedStdError, Request, Response};
|
||||
use crate::{BoxError, Request, Response};
|
||||
|
||||
use super::{Client, Handshake};
|
||||
|
||||
|
@ -36,11 +36,11 @@ impl<S> Connector<S> {
|
|||
|
||||
impl<S> Service<SocketAddr> for Connector<S>
|
||||
where
|
||||
S: Service<Request, Response = Response, Error = BoxedStdError> + Clone + Send + 'static,
|
||||
S: Service<Request, Response = Response, Error = BoxError> + Clone + Send + 'static,
|
||||
S::Future: Send,
|
||||
{
|
||||
type Response = Change<SocketAddr, Client>;
|
||||
type Error = BoxedStdError;
|
||||
type Error = BoxError;
|
||||
type Future =
|
||||
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ use crate::{
|
|||
internal::{Request, Response},
|
||||
},
|
||||
types::MetaAddr,
|
||||
BoxedStdError, Config,
|
||||
BoxError, Config,
|
||||
};
|
||||
|
||||
use super::{Client, Connection, ErrorSlot, HandshakeError};
|
||||
|
@ -58,7 +58,7 @@ pub struct Builder<S> {
|
|||
|
||||
impl<S> Builder<S>
|
||||
where
|
||||
S: Service<Request, Response = Response, Error = BoxedStdError> + Clone + Send + 'static,
|
||||
S: Service<Request, Response = Response, Error = BoxError> + Clone + Send + 'static,
|
||||
S::Future: Send,
|
||||
{
|
||||
/// Provide a config. Mandatory.
|
||||
|
@ -151,7 +151,7 @@ where
|
|||
|
||||
impl<S> Handshake<S>
|
||||
where
|
||||
S: Service<Request, Response = Response, Error = BoxedStdError> + Clone + Send + 'static,
|
||||
S: Service<Request, Response = Response, Error = BoxError> + Clone + Send + 'static,
|
||||
S::Future: Send,
|
||||
{
|
||||
/// Create a builder that configures a [`Handshake`] service.
|
||||
|
@ -173,11 +173,11 @@ where
|
|||
|
||||
impl<S> Service<(TcpStream, SocketAddr)> for Handshake<S>
|
||||
where
|
||||
S: Service<Request, Response = Response, Error = BoxedStdError> + Clone + Send + 'static,
|
||||
S: Service<Request, Response = Response, Error = BoxError> + Clone + Send + 'static,
|
||||
S::Future: Send,
|
||||
{
|
||||
type Response = Client;
|
||||
type Error = BoxedStdError;
|
||||
type Error = BoxError;
|
||||
type Future =
|
||||
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ use futures::stream::{FuturesUnordered, StreamExt};
|
|||
use tower::{Service, ServiceExt};
|
||||
use tracing::Level;
|
||||
|
||||
use crate::{types::MetaAddr, AddressBook, BoxedStdError, Request, Response};
|
||||
use crate::{types::MetaAddr, AddressBook, BoxError, Request, Response};
|
||||
|
||||
/// The `CandidateSet` maintains a pool of candidate peers.
|
||||
///
|
||||
|
@ -84,7 +84,7 @@ pub(super) struct CandidateSet<S> {
|
|||
|
||||
impl<S> CandidateSet<S>
|
||||
where
|
||||
S: Service<Request, Response = Response, Error = BoxedStdError>,
|
||||
S: Service<Request, Response = Response, Error = BoxError>,
|
||||
S::Future: Send + 'static,
|
||||
{
|
||||
pub fn new(peer_set: Arc<Mutex<AddressBook>>, peer_service: S) -> CandidateSet<S> {
|
||||
|
@ -97,7 +97,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn update(&mut self) -> Result<(), BoxedStdError> {
|
||||
pub async fn update(&mut self) -> Result<(), BoxError> {
|
||||
// Opportunistically crawl the network on every update call to ensure
|
||||
// we're actively fetching peers. Continue independently of whether we
|
||||
// actually receive any peers, but always ask the network for more.
|
||||
|
|
|
@ -28,7 +28,7 @@ use tower::{
|
|||
use tower_load::{peak_ewma::PeakEwmaDiscover, NoInstrument};
|
||||
|
||||
use crate::{
|
||||
constants, peer, timestamp_collector::TimestampCollector, AddressBook, BoxedStdError, Config,
|
||||
constants, peer, timestamp_collector::TimestampCollector, AddressBook, BoxError, Config,
|
||||
Request, Response,
|
||||
};
|
||||
|
||||
|
@ -37,18 +37,18 @@ use zebra_chain::parameters::Network;
|
|||
use super::CandidateSet;
|
||||
use super::PeerSet;
|
||||
|
||||
type PeerChange = Result<Change<SocketAddr, peer::Client>, BoxedStdError>;
|
||||
type PeerChange = Result<Change<SocketAddr, peer::Client>, BoxError>;
|
||||
|
||||
/// Initialize a peer set with the given `config`, forwarding peer requests to the `inbound_service`.
|
||||
pub async fn init<S>(
|
||||
config: Config,
|
||||
inbound_service: S,
|
||||
) -> (
|
||||
Buffer<BoxService<Request, Response, BoxedStdError>, Request>,
|
||||
Buffer<BoxService<Request, Response, BoxError>, Request>,
|
||||
Arc<Mutex<AddressBook>>,
|
||||
)
|
||||
where
|
||||
S: Service<Request, Response = Response, Error = BoxedStdError> + Clone + Send + 'static,
|
||||
S: Service<Request, Response = Response, Error = BoxError> + Clone + Send + 'static,
|
||||
S::Future: Send + 'static,
|
||||
{
|
||||
let (address_book, timestamp_collector) = TimestampCollector::spawn();
|
||||
|
@ -169,10 +169,9 @@ async fn add_initial_peers<S>(
|
|||
initial_peers: std::collections::HashSet<SocketAddr>,
|
||||
connector: S,
|
||||
mut tx: mpsc::Sender<PeerChange>,
|
||||
) -> Result<(), BoxedStdError>
|
||||
) -> Result<(), BoxError>
|
||||
where
|
||||
S: Service<SocketAddr, Response = Change<SocketAddr, peer::Client>, Error = BoxedStdError>
|
||||
+ Clone,
|
||||
S: Service<SocketAddr, Response = Change<SocketAddr, peer::Client>, Error = BoxError> + Clone,
|
||||
S::Future: Send + 'static,
|
||||
{
|
||||
info!(?initial_peers, "Connecting to initial peer set");
|
||||
|
@ -194,9 +193,9 @@ async fn listen<S>(
|
|||
addr: SocketAddr,
|
||||
mut handshaker: S,
|
||||
tx: mpsc::Sender<PeerChange>,
|
||||
) -> Result<(), BoxedStdError>
|
||||
) -> Result<(), BoxError>
|
||||
where
|
||||
S: Service<(TcpStream, SocketAddr), Response = peer::Client, Error = BoxedStdError> + Clone,
|
||||
S: Service<(TcpStream, SocketAddr), Response = peer::Client, Error = BoxError> + Clone,
|
||||
S::Future: Send + 'static,
|
||||
{
|
||||
let mut listener = TcpListener::bind(addr).await?;
|
||||
|
@ -236,12 +235,11 @@ async fn crawl_and_dial<C, S>(
|
|||
mut candidates: CandidateSet<S>,
|
||||
mut connector: C,
|
||||
mut success_tx: mpsc::Sender<PeerChange>,
|
||||
) -> Result<(), BoxedStdError>
|
||||
) -> Result<(), BoxError>
|
||||
where
|
||||
C: Service<SocketAddr, Response = Change<SocketAddr, peer::Client>, Error = BoxedStdError>
|
||||
+ Clone,
|
||||
C: Service<SocketAddr, Response = Change<SocketAddr, peer::Client>, Error = BoxError> + Clone,
|
||||
C::Future: Send + 'static,
|
||||
S: Service<Request, Response = Response, Error = BoxedStdError>,
|
||||
S: Service<Request, Response = Response, Error = BoxError>,
|
||||
S::Future: Send + 'static,
|
||||
{
|
||||
use futures::{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! Inventory Registry Implementation
|
||||
//!
|
||||
//! [RFC]: https://zebra.zfnd.org/dev/rfcs/0003-inventory-tracking.html
|
||||
use crate::{protocol::external::InventoryHash, BoxedStdError};
|
||||
use crate::{protocol::external::InventoryHash, BoxError};
|
||||
use futures::Stream;
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
|
@ -59,7 +59,7 @@ impl InventoryRegistry {
|
|||
///
|
||||
/// - rotates HashMaps based on interval events
|
||||
/// - drains the inv_stream channel and registers all advertised inventory
|
||||
pub fn poll_inventory(&mut self, cx: &mut Context<'_>) -> Result<(), BoxedStdError> {
|
||||
pub fn poll_inventory(&mut self, cx: &mut Context<'_>) -> Result<(), BoxError> {
|
||||
while let Poll::Ready(_) = self.interval.poll_tick(cx) {
|
||||
self.rotate();
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ use crate::{
|
|||
external::InventoryHash,
|
||||
internal::{Request, Response},
|
||||
},
|
||||
BoxedStdError,
|
||||
BoxError,
|
||||
};
|
||||
|
||||
use super::{
|
||||
|
@ -90,12 +90,12 @@ where
|
|||
/// Channel for passing ownership of tokio JoinHandles from PeerSet's background tasks
|
||||
///
|
||||
/// The join handles passed into the PeerSet are used populate the `guards` member
|
||||
handle_rx: tokio::sync::oneshot::Receiver<Vec<JoinHandle<Result<(), BoxedStdError>>>>,
|
||||
handle_rx: tokio::sync::oneshot::Receiver<Vec<JoinHandle<Result<(), BoxError>>>>,
|
||||
/// Unordered set of handles to background tasks associated with the `PeerSet`
|
||||
///
|
||||
/// These guards are checked for errors as part of `poll_ready` which lets
|
||||
/// the `PeerSet` propagate errors from background tasks back to the user
|
||||
guards: futures::stream::FuturesUnordered<JoinHandle<Result<(), BoxedStdError>>>,
|
||||
guards: futures::stream::FuturesUnordered<JoinHandle<Result<(), BoxError>>>,
|
||||
inventory_registry: InventoryRegistry,
|
||||
}
|
||||
|
||||
|
@ -103,8 +103,8 @@ impl<D> PeerSet<D>
|
|||
where
|
||||
D: Discover<Key = SocketAddr> + Unpin,
|
||||
D::Service: Service<Request, Response = Response> + Load,
|
||||
D::Error: Into<BoxedStdError>,
|
||||
<D::Service as Service<Request>>::Error: Into<BoxedStdError> + 'static,
|
||||
D::Error: Into<BoxError>,
|
||||
<D::Service as Service<Request>>::Error: Into<BoxError> + 'static,
|
||||
<D::Service as Service<Request>>::Future: Send + 'static,
|
||||
<D::Service as Load>::Metric: Debug,
|
||||
{
|
||||
|
@ -112,7 +112,7 @@ where
|
|||
pub fn new(
|
||||
discover: D,
|
||||
demand_signal: mpsc::Sender<()>,
|
||||
handle_rx: tokio::sync::oneshot::Receiver<Vec<JoinHandle<Result<(), BoxedStdError>>>>,
|
||||
handle_rx: tokio::sync::oneshot::Receiver<Vec<JoinHandle<Result<(), BoxError>>>>,
|
||||
inv_stream: broadcast::Receiver<(InventoryHash, SocketAddr)>,
|
||||
) -> Self {
|
||||
Self {
|
||||
|
@ -128,7 +128,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
fn poll_discover(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), BoxedStdError>> {
|
||||
fn poll_discover(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), BoxError>> {
|
||||
use futures::ready;
|
||||
loop {
|
||||
match ready!(Pin::new(&mut self.discover).poll_discover(cx)).map_err(Into::into)? {
|
||||
|
@ -179,7 +179,7 @@ where
|
|||
});
|
||||
}
|
||||
|
||||
fn check_for_background_errors(&mut self, cx: &mut Context) -> Result<(), BoxedStdError> {
|
||||
fn check_for_background_errors(&mut self, cx: &mut Context) -> Result<(), BoxError> {
|
||||
if self.guards.is_empty() {
|
||||
match self.handle_rx.try_recv() {
|
||||
Ok(handles) => {
|
||||
|
@ -340,13 +340,13 @@ impl<D> Service<Request> for PeerSet<D>
|
|||
where
|
||||
D: Discover<Key = SocketAddr> + Unpin,
|
||||
D::Service: Service<Request, Response = Response> + Load,
|
||||
D::Error: Into<BoxedStdError>,
|
||||
<D::Service as Service<Request>>::Error: Into<BoxedStdError> + 'static,
|
||||
D::Error: Into<BoxError>,
|
||||
<D::Service as Service<Request>>::Error: Into<BoxError> + 'static,
|
||||
<D::Service as Service<Request>>::Future: Send + 'static,
|
||||
<D::Service as Load>::Metric: Debug,
|
||||
{
|
||||
type Response = Response;
|
||||
type Error = BoxedStdError;
|
||||
type Error = BoxError;
|
||||
type Future =
|
||||
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ use abscissa_core::{Command, Options, Runnable};
|
|||
use futures::{channel::oneshot, prelude::*};
|
||||
use tower::{buffer::Buffer, Service, ServiceExt};
|
||||
|
||||
use zebra_network::{AddressBook, BoxedStdError, Request, Response};
|
||||
use zebra_network::{AddressBook, BoxError, Request, Response};
|
||||
|
||||
use crate::components::tokio::RuntimeRun;
|
||||
use crate::prelude::*;
|
||||
|
@ -33,7 +33,7 @@ struct SeedService {
|
|||
|
||||
impl Service<Request> for SeedService {
|
||||
type Response = Response;
|
||||
type Error = BoxedStdError;
|
||||
type Error = BoxError;
|
||||
type Future =
|
||||
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;
|
||||
|
||||
|
|
Loading…
Reference in New Issue