mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-04-27 11:42:16 +00:00
upgrade::or() requires same Output (#218)
This commit is contained in:
parent
c7f654a815
commit
c1cd10c034
@ -222,9 +222,9 @@ extern crate tokio_io;
|
||||
pub extern crate multiaddr;
|
||||
|
||||
mod connection_reuse;
|
||||
mod either;
|
||||
mod peer_id;
|
||||
|
||||
pub mod either;
|
||||
pub mod muxing;
|
||||
pub mod swarm;
|
||||
pub mod transport;
|
||||
|
@ -19,7 +19,6 @@
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
use bytes::Bytes;
|
||||
use either::EitherOutput;
|
||||
use futures::prelude::*;
|
||||
use multiaddr::Multiaddr;
|
||||
use std::io::Error as IoError;
|
||||
@ -39,11 +38,11 @@ pub fn or<A, B>(me: A, other: B) -> OrUpgrade<A, B> {
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct OrUpgrade<A, B>(A, B);
|
||||
|
||||
impl<C, A, B> ConnectionUpgrade<C> for OrUpgrade<A, B>
|
||||
impl<C, A, B, O> ConnectionUpgrade<C> for OrUpgrade<A, B>
|
||||
where
|
||||
C: AsyncRead + AsyncWrite,
|
||||
A: ConnectionUpgrade<C>,
|
||||
B: ConnectionUpgrade<C>,
|
||||
A: ConnectionUpgrade<C, Output = O>,
|
||||
B: ConnectionUpgrade<C, Output = O>,
|
||||
{
|
||||
type NamesIter = NamesIterChain<A::NamesIter, B::NamesIter>;
|
||||
type UpgradeIdentifier = EitherUpgradeIdentifier<A::UpgradeIdentifier, B::UpgradeIdentifier>;
|
||||
@ -56,7 +55,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
type Output = EitherOutput<A::Output, B::Output>;
|
||||
type Output = O;
|
||||
type Future = EitherConnUpgrFuture<A::Future, B::Future>;
|
||||
|
||||
#[inline]
|
||||
@ -98,12 +97,12 @@ pub enum EitherConnUpgrFuture<A, B> {
|
||||
Second(B),
|
||||
}
|
||||
|
||||
impl<A, B> Future for EitherConnUpgrFuture<A, B>
|
||||
impl<A, B, O> Future for EitherConnUpgrFuture<A, B>
|
||||
where
|
||||
A: Future<Error = IoError>,
|
||||
B: Future<Error = IoError>,
|
||||
A: Future<Error = IoError, Item = O>,
|
||||
B: Future<Error = IoError, Item = O>,
|
||||
{
|
||||
type Item = EitherOutput<A::Item, B::Item>;
|
||||
type Item = O;
|
||||
type Error = IoError;
|
||||
|
||||
#[inline]
|
||||
@ -111,11 +110,11 @@ where
|
||||
match self {
|
||||
&mut EitherConnUpgrFuture::First(ref mut a) => {
|
||||
let item = try_ready!(a.poll());
|
||||
Ok(Async::Ready(EitherOutput::First(item)))
|
||||
Ok(Async::Ready(item))
|
||||
}
|
||||
&mut EitherConnUpgrFuture::Second(ref mut b) => {
|
||||
let item = try_ready!(b.poll());
|
||||
Ok(Async::Ready(EitherOutput::Second(item)))
|
||||
Ok(Async::Ready(item))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ use futures::{Future, Sink, Stream};
|
||||
use std::env;
|
||||
use libp2p::SimpleProtocol;
|
||||
use libp2p::core::Transport;
|
||||
use libp2p::core::upgrade;
|
||||
use libp2p::core::{upgrade, either::EitherOutput};
|
||||
use libp2p::tcp::TcpConfig;
|
||||
use tokio_core::reactor::Core;
|
||||
use tokio_io::AsyncRead;
|
||||
@ -70,7 +70,10 @@ fn main() {
|
||||
}
|
||||
};
|
||||
|
||||
upgrade::or(plain_text, upgrade::map(secio, |(socket, _)| socket))
|
||||
upgrade::or(
|
||||
upgrade::map(plain_text, |pt| EitherOutput::First(pt)),
|
||||
upgrade::map(secio, |(socket, _)| EitherOutput::Second(socket))
|
||||
)
|
||||
})
|
||||
|
||||
// On top of plaintext or secio, we will use the multiplex protocol.
|
||||
|
@ -30,7 +30,7 @@ use futures::{Sink, Stream};
|
||||
use std::env;
|
||||
use libp2p::SimpleProtocol;
|
||||
use libp2p::core::Transport;
|
||||
use libp2p::core::upgrade;
|
||||
use libp2p::core::{upgrade, either::EitherOutput};
|
||||
use libp2p::tcp::TcpConfig;
|
||||
use tokio_core::reactor::Core;
|
||||
use tokio_io::AsyncRead;
|
||||
@ -69,7 +69,10 @@ fn main() {
|
||||
}
|
||||
};
|
||||
|
||||
upgrade::or(plain_text, upgrade::map(secio, |(socket, _)| socket))
|
||||
upgrade::or(
|
||||
upgrade::map(plain_text, |pt| EitherOutput::First(pt)),
|
||||
upgrade::map(secio, |(socket, _)| EitherOutput::Second(socket))
|
||||
)
|
||||
})
|
||||
|
||||
// On top of plaintext or secio, we will use the multiplex protocol.
|
||||
|
@ -30,7 +30,7 @@ extern crate tokio_stdin;
|
||||
use futures::Stream;
|
||||
use futures::future::Future;
|
||||
use std::{env, mem};
|
||||
use libp2p::core::upgrade;
|
||||
use libp2p::core::{either::EitherOutput, upgrade};
|
||||
use libp2p::core::{Multiaddr, Transport};
|
||||
use libp2p::peerstore::PeerId;
|
||||
use libp2p::tcp::TcpConfig;
|
||||
@ -69,7 +69,10 @@ fn main() {
|
||||
}
|
||||
};
|
||||
|
||||
upgrade::or(plain_text, upgrade::map(secio, |(socket, _)| socket))
|
||||
upgrade::or(
|
||||
upgrade::map(plain_text, |pt| EitherOutput::First(pt)),
|
||||
upgrade::map(secio, |(socket, _)| EitherOutput::Second(socket))
|
||||
)
|
||||
})
|
||||
|
||||
// On top of plaintext or secio, we will use the multiplex protocol.
|
||||
|
@ -34,7 +34,7 @@ use std::env;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use libp2p::core::Transport;
|
||||
use libp2p::core::upgrade;
|
||||
use libp2p::core::{upgrade, either::EitherOutput};
|
||||
use libp2p::tcp::TcpConfig;
|
||||
use tokio_core::reactor::Core;
|
||||
|
||||
@ -73,7 +73,10 @@ fn main() {
|
||||
}
|
||||
};
|
||||
|
||||
upgrade::or(plain_text, upgrade::map(secio, |(socket, _)| socket))
|
||||
upgrade::or(
|
||||
upgrade::map(plain_text, |pt| EitherOutput::First(pt)),
|
||||
upgrade::map(secio, |(socket, _)| EitherOutput::Second(socket))
|
||||
)
|
||||
})
|
||||
|
||||
// On top of plaintext or secio, we will use the multiplex protocol.
|
||||
|
@ -29,7 +29,7 @@ use futures::Future;
|
||||
use futures::sync::oneshot;
|
||||
use std::env;
|
||||
use libp2p::core::Transport;
|
||||
use libp2p::core::upgrade;
|
||||
use libp2p::core::{upgrade, either::EitherOutput};
|
||||
use libp2p::tcp::TcpConfig;
|
||||
use tokio_core::reactor::Core;
|
||||
|
||||
@ -61,7 +61,10 @@ fn main() {
|
||||
}
|
||||
};
|
||||
|
||||
upgrade::or(plain_text, upgrade::map(secio, |(socket, _)| socket))
|
||||
upgrade::or(
|
||||
upgrade::map(plain_text, |pt| EitherOutput::First(pt)),
|
||||
upgrade::map(secio, |(socket, _)| EitherOutput::Second(socket))
|
||||
)
|
||||
})
|
||||
|
||||
// On top of plaintext or secio, we will use the multiplex protocol.
|
||||
|
Loading…
x
Reference in New Issue
Block a user