* New core

* Fix lifetime requirements

* Remove identify transport

* Address &mut & ref ref mut

* Fix whitespaces
This commit is contained in:
Pierre Krieger
2018-10-17 10:17:40 +01:00
committed by GitHub
parent 724d0f5d82
commit 5d1c54cc10
52 changed files with 849 additions and 1492 deletions

View File

@ -63,7 +63,7 @@
//! let ping_finished_future = libp2p_tcp_transport::TcpConfig::new()
//! .with_upgrade(Ping::default())
//! .dial("127.0.0.1:12345".parse::<libp2p_core::Multiaddr>().unwrap()).unwrap_or_else(|_| panic!())
//! .and_then(|(out, _)| {
//! .and_then(|out| {
//! match out {
//! PingOutput::Ponger(processing) => Box::new(processing) as Box<Future<Item = _, Error = _> + Send>,
//! PingOutput::Pinger(mut pinger) => {
@ -123,7 +123,7 @@ pub enum PingOutput<TSocket, TUserData> {
Ponger(PingListener<TSocket>),
}
impl<TSocket, TUserData, Maf> ConnectionUpgrade<TSocket, Maf> for Ping<TUserData>
impl<TSocket, TUserData> ConnectionUpgrade<TSocket> for Ping<TUserData>
where
TSocket: AsyncRead + AsyncWrite,
{
@ -136,8 +136,7 @@ where
}
type Output = PingOutput<TSocket, TUserData>;
type MultiaddrFuture = Maf;
type Future = FutureResult<(Self::Output, Self::MultiaddrFuture), IoError>;
type Future = FutureResult<Self::Output, IoError>;
#[inline]
fn upgrade(
@ -145,14 +144,13 @@ where
socket: TSocket,
_: Self::UpgradeIdentifier,
endpoint: Endpoint,
remote_addr: Maf,
) -> Self::Future {
let out = match endpoint {
Endpoint::Dialer => upgrade_as_dialer(socket),
Endpoint::Listener => upgrade_as_listener(socket),
};
Ok((out, remote_addr)).into_future()
Ok(out).into_future()
}
}
@ -399,9 +397,8 @@ mod tests {
use self::tokio_tcp::TcpListener;
use self::tokio_tcp::TcpStream;
use super::{Ping, PingOutput};
use futures::{future, Future, Stream};
use libp2p_core::{ConnectionUpgrade, Endpoint, Multiaddr};
use std::io::Error as IoError;
use futures::{Future, Stream};
use libp2p_core::{ConnectionUpgrade, Endpoint};
// TODO: rewrite tests with the MemoryTransport
@ -419,10 +416,9 @@ mod tests {
c.unwrap(),
(),
Endpoint::Listener,
future::ok::<Multiaddr, IoError>("/ip4/127.0.0.1/tcp/10000".parse().unwrap()),
)
})
.and_then(|(out, _)| match out {
.and_then(|out| match out {
PingOutput::Ponger(service) => service,
_ => unreachable!(),
});
@ -434,10 +430,9 @@ mod tests {
c,
(),
Endpoint::Dialer,
future::ok::<Multiaddr, IoError>("/ip4/127.0.0.1/tcp/10000".parse().unwrap()),
)
})
.and_then(|(out, _)| match out {
.and_then(|out| match out {
PingOutput::Pinger(mut pinger) => {
pinger.ping(());
pinger.into_future().map(|_| ()).map_err(|_| panic!())
@ -464,10 +459,9 @@ mod tests {
c.unwrap(),
(),
Endpoint::Listener,
future::ok::<Multiaddr, IoError>("/ip4/127.0.0.1/tcp/10000".parse().unwrap()),
)
})
.and_then(|(out, _)| match out {
.and_then(|out| match out {
PingOutput::Ponger(service) => service,
_ => unreachable!(),
});
@ -479,10 +473,9 @@ mod tests {
c,
(),
Endpoint::Dialer,
future::ok::<Multiaddr, IoError>("/ip4/127.0.0.1/tcp/10000".parse().unwrap()),
)
})
.and_then(|(out, _)| match out {
.and_then(|out| match out {
PingOutput::Pinger(mut pinger) => {
for n in 0..20 {
pinger.ping(n);