Remove some boxed futures. (#718)

This commit is contained in:
Toralf Wittner
2018-12-04 11:24:59 +01:00
committed by GitHub
parent a5766fdfac
commit acfa1c9c79
6 changed files with 321 additions and 162 deletions

View File

@ -20,7 +20,7 @@
//! Contains the `IdentifyTransport` type.
use futures::prelude::*;
use futures::{future, prelude::*, stream, AndThen, MapErr};
use libp2p_core::{
Multiaddr, PeerId, PublicKey, muxing, Transport,
upgrade::{self, OutboundUpgradeApply, UpgradeError}
@ -56,21 +56,20 @@ impl<TTrans> IdentifyTransport<TTrans> {
}
}
// TODO: don't use boxes
impl<TTrans, TMuxer> Transport for IdentifyTransport<TTrans>
where
TTrans: Transport<Output = TMuxer>,
TMuxer: muxing::StreamMuxer + Send + Sync + 'static, // TODO: remove unnecessary bounds
TMuxer::Substream: Send + Sync + 'static, // TODO: remove unnecessary bounds
TMuxer::OutboundSubstream: Send + 'static, // TODO: remove unnecessary bounds
TTrans::Dial: Send + Sync + 'static,
TTrans::Listener: Send + 'static,
TTrans::ListenerUpgrade: Send + 'static,
{
type Output = (PeerId, TMuxer);
type Listener = Box<Stream<Item = (Self::ListenerUpgrade, Multiaddr), Error = IoError> + Send>;
type ListenerUpgrade = Box<Future<Item = Self::Output, Error = IoError> + Send>;
type Dial = Box<Future<Item = Self::Output, Error = IoError> + Send>;
type Listener = stream::Empty<(Self::ListenerUpgrade, Multiaddr), IoError>;
type ListenerUpgrade = future::Empty<Self::Output, IoError>;
type Dial = AndThen<
TTrans::Dial,
MapErr<IdRetriever<TMuxer>, fn(UpgradeError<IoError>) -> IoError>,
fn(TMuxer) -> MapErr<IdRetriever<TMuxer>, fn(UpgradeError<IoError>) -> IoError>
>;
#[inline]
fn listen_on(self, addr: Multiaddr) -> Result<(Self::Listener, Multiaddr), (Self, Multiaddr)> {
@ -90,11 +89,9 @@ where
}
};
let dial = dial.and_then(move |muxer| {
Ok(dial.and_then(|muxer| {
IdRetriever::new(muxer, IdentifyProtocolConfig).map_err(|e| e.into_io_error())
});
Ok(Box::new(dial) as Box<_>)
}))
}
#[inline]
@ -105,7 +102,7 @@ where
/// Implementation of `Future` that asks the remote of its `PeerId`.
// TODO: remove unneeded bounds
struct IdRetriever<TMuxer>
pub struct IdRetriever<TMuxer>
where TMuxer: muxing::StreamMuxer + Send + Sync + 'static,
TMuxer::Substream: Send,
{