mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-21 05:41:33 +00:00
Wrap multistream-select streams under a Negotiated (#1001)
This commit is contained in:
@ -61,6 +61,7 @@
|
||||
|
||||
/// Multi-address re-export.
|
||||
pub use multiaddr;
|
||||
pub use multistream_select::Negotiated;
|
||||
|
||||
mod keys_proto;
|
||||
mod peer_id;
|
||||
|
@ -188,7 +188,7 @@ where
|
||||
self.pending_error = Some(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[inline]
|
||||
fn connection_keep_alive(&self) -> KeepAlive {
|
||||
self.keep_alive
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
use crate::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
|
||||
use futures::future;
|
||||
use multistream_select::Negotiated;
|
||||
use std::iter;
|
||||
use void::Void;
|
||||
|
||||
@ -42,7 +43,7 @@ impl<C> InboundUpgrade<C> for DeniedUpgrade {
|
||||
type Error = Void;
|
||||
type Future = future::Empty<Self::Output, Self::Error>;
|
||||
|
||||
fn upgrade_inbound(self, _: C, _: Self::Info) -> Self::Future {
|
||||
fn upgrade_inbound(self, _: Negotiated<C>, _: Self::Info) -> Self::Future {
|
||||
future::empty()
|
||||
}
|
||||
}
|
||||
@ -52,7 +53,7 @@ impl<C> OutboundUpgrade<C> for DeniedUpgrade {
|
||||
type Error = Void;
|
||||
type Future = future::Empty<Self::Output, Self::Error>;
|
||||
|
||||
fn upgrade_outbound(self, _: C, _: Self::Info) -> Self::Future {
|
||||
fn upgrade_outbound(self, _: Negotiated<C>, _: Self::Info) -> Self::Future {
|
||||
future::empty()
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ use crate::{
|
||||
either::{EitherOutput, EitherError, EitherFuture2, EitherName},
|
||||
upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}
|
||||
};
|
||||
use multistream_select::Negotiated;
|
||||
|
||||
/// A type to represent two possible upgrade types (inbound or outbound).
|
||||
#[derive(Debug, Clone)]
|
||||
@ -55,7 +56,7 @@ where
|
||||
type Error = EitherError<EA, EB>;
|
||||
type Future = EitherFuture2<A::Future, B::Future>;
|
||||
|
||||
fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future {
|
||||
fn upgrade_inbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
|
||||
match (self, info) {
|
||||
(EitherUpgrade::A(a), EitherName::A(info)) => EitherFuture2::A(a.upgrade_inbound(sock, info)),
|
||||
(EitherUpgrade::B(b), EitherName::B(info)) => EitherFuture2::B(b.upgrade_inbound(sock, info)),
|
||||
@ -73,7 +74,7 @@ where
|
||||
type Error = EitherError<EA, EB>;
|
||||
type Future = EitherFuture2<A::Future, B::Future>;
|
||||
|
||||
fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future {
|
||||
fn upgrade_outbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
|
||||
match (self, info) {
|
||||
(EitherUpgrade::A(a), EitherName::A(info)) => EitherFuture2::A(a.upgrade_outbound(sock, info)),
|
||||
(EitherUpgrade::B(b), EitherName::B(info)) => EitherFuture2::B(b.upgrade_outbound(sock, info)),
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
use crate::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
|
||||
use futures::{prelude::*, try_ready};
|
||||
use multistream_select::Negotiated;
|
||||
|
||||
/// Wraps around an upgrade and applies a closure to the output.
|
||||
#[derive(Debug, Clone)]
|
||||
@ -52,7 +53,7 @@ where
|
||||
type Error = U::Error;
|
||||
type Future = MapFuture<U::Future, F>;
|
||||
|
||||
fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future {
|
||||
fn upgrade_inbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
|
||||
MapFuture {
|
||||
inner: self.upgrade.upgrade_inbound(sock, info),
|
||||
map: Some(self.fun)
|
||||
@ -68,7 +69,7 @@ where
|
||||
type Error = U::Error;
|
||||
type Future = U::Future;
|
||||
|
||||
fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future {
|
||||
fn upgrade_outbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
|
||||
self.upgrade.upgrade_outbound(sock, info)
|
||||
}
|
||||
}
|
||||
@ -103,7 +104,7 @@ where
|
||||
type Error = U::Error;
|
||||
type Future = U::Future;
|
||||
|
||||
fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future {
|
||||
fn upgrade_inbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
|
||||
self.upgrade.upgrade_inbound(sock, info)
|
||||
}
|
||||
}
|
||||
@ -117,7 +118,7 @@ where
|
||||
type Error = U::Error;
|
||||
type Future = MapFuture<U::Future, F>;
|
||||
|
||||
fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future {
|
||||
fn upgrade_outbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
|
||||
MapFuture {
|
||||
inner: self.upgrade.upgrade_outbound(sock, info),
|
||||
map: Some(self.fun)
|
||||
@ -156,7 +157,7 @@ where
|
||||
type Error = T;
|
||||
type Future = MapErrFuture<U::Future, F>;
|
||||
|
||||
fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future {
|
||||
fn upgrade_inbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
|
||||
MapErrFuture {
|
||||
fut: self.upgrade.upgrade_inbound(sock, info),
|
||||
fun: Some(self.fun)
|
||||
@ -172,7 +173,7 @@ where
|
||||
type Error = U::Error;
|
||||
type Future = U::Future;
|
||||
|
||||
fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future {
|
||||
fn upgrade_outbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
|
||||
self.upgrade.upgrade_outbound(sock, info)
|
||||
}
|
||||
}
|
||||
@ -208,7 +209,7 @@ where
|
||||
type Error = T;
|
||||
type Future = MapErrFuture<U::Future, F>;
|
||||
|
||||
fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future {
|
||||
fn upgrade_outbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
|
||||
MapErrFuture {
|
||||
fut: self.upgrade.upgrade_outbound(sock, info),
|
||||
fun: Some(self.fun)
|
||||
@ -224,7 +225,7 @@ where
|
||||
type Error = U::Error;
|
||||
type Future = U::Future;
|
||||
|
||||
fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future {
|
||||
fn upgrade_inbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
|
||||
self.upgrade.upgrade_inbound(sock, info)
|
||||
}
|
||||
}
|
||||
|
@ -67,6 +67,7 @@ mod transfer;
|
||||
|
||||
use futures::future::Future;
|
||||
|
||||
pub use multistream_select::Negotiated;
|
||||
pub use self::{
|
||||
apply::{apply, apply_inbound, apply_outbound, InboundUpgradeApply, OutboundUpgradeApply},
|
||||
denied::DeniedUpgrade,
|
||||
@ -114,7 +115,7 @@ pub trait InboundUpgrade<C>: UpgradeInfo {
|
||||
/// method is called to start the handshake.
|
||||
///
|
||||
/// The `info` is the identifier of the protocol, as produced by `protocol_info`.
|
||||
fn upgrade_inbound(self, socket: C, info: Self::Info) -> Self::Future;
|
||||
fn upgrade_inbound(self, socket: Negotiated<C>, info: Self::Info) -> Self::Future;
|
||||
}
|
||||
|
||||
/// Extension trait for `InboundUpgrade`. Automatically implemented on all types that implement
|
||||
@ -154,7 +155,7 @@ pub trait OutboundUpgrade<C>: UpgradeInfo {
|
||||
/// method is called to start the handshake.
|
||||
///
|
||||
/// The `info` is the identifier of the protocol, as produced by `protocol_info`.
|
||||
fn upgrade_outbound(self, socket: C, info: Self::Info) -> Self::Future;
|
||||
fn upgrade_outbound(self, socket: Negotiated<C>, info: Self::Info) -> Self::Future;
|
||||
}
|
||||
|
||||
/// Extention trait for `OutboundUpgrade`. Automatically implemented on all types that implement
|
||||
|
@ -22,6 +22,7 @@ use crate::{
|
||||
either::{EitherOutput, EitherError, EitherFuture2, EitherName},
|
||||
upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}
|
||||
};
|
||||
use multistream_select::Negotiated;
|
||||
|
||||
/// Upgrade that combines two upgrades into one. Supports all the protocols supported by either
|
||||
/// sub-upgrade.
|
||||
@ -64,7 +65,7 @@ where
|
||||
type Error = EitherError<EA, EB>;
|
||||
type Future = EitherFuture2<A::Future, B::Future>;
|
||||
|
||||
fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future {
|
||||
fn upgrade_inbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
|
||||
match info {
|
||||
EitherName::A(info) => EitherFuture2::A(self.0.upgrade_inbound(sock, info)),
|
||||
EitherName::B(info) => EitherFuture2::B(self.1.upgrade_inbound(sock, info))
|
||||
@ -81,7 +82,7 @@ where
|
||||
type Error = EitherError<EA, EB>;
|
||||
type Future = EitherFuture2<A::Future, B::Future>;
|
||||
|
||||
fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future {
|
||||
fn upgrade_outbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
|
||||
match info {
|
||||
EitherName::A(info) => EitherFuture2::A(self.0.upgrade_outbound(sock, info)),
|
||||
EitherName::B(info) => EitherFuture2::B(self.1.upgrade_outbound(sock, info))
|
||||
|
Reference in New Issue
Block a user