Remove Negotiated from upgrade traits (#1388)

* Remove Negotiated from upgrade traits

* Remove import
This commit is contained in:
Pierre Krieger
2020-01-13 14:34:43 +01:00
committed by GitHub
parent ff780b5bff
commit 42a45e2630
31 changed files with 218 additions and 220 deletions

View File

@ -25,6 +25,7 @@ pub use crate::upgrade::Version;
use crate::{
ConnectedPoint,
ConnectionInfo,
Negotiated,
transport::{
Transport,
TransportError,
@ -106,8 +107,8 @@ where
I: ConnectionInfo,
C: AsyncRead + AsyncWrite + Unpin,
D: AsyncRead + AsyncWrite + Unpin,
U: InboundUpgrade<C, Output = (I, D), Error = E>,
U: OutboundUpgrade<C, Output = (I, D), Error = E> + Clone,
U: InboundUpgrade<Negotiated<C>, Output = (I, D), Error = E>,
U: OutboundUpgrade<Negotiated<C>, Output = (I, D), Error = E> + Clone,
E: Error + 'static,
{
let version = self.version;
@ -138,8 +139,8 @@ where
C: AsyncRead + AsyncWrite + Unpin,
D: AsyncRead + AsyncWrite + Unpin,
I: ConnectionInfo,
U: InboundUpgrade<C, Output = D, Error = E>,
U: OutboundUpgrade<C, Output = D, Error = E> + Clone,
U: InboundUpgrade<Negotiated<C>, Output = D, Error = E>,
U: OutboundUpgrade<Negotiated<C>, Output = D, Error = E> + Clone,
E: Error + 'static,
{
Builder::new(Upgrade::new(self.inner, upgrade), self.version)
@ -166,8 +167,8 @@ where
C: AsyncRead + AsyncWrite + Unpin,
M: StreamMuxer,
I: ConnectionInfo,
U: InboundUpgrade<C, Output = M, Error = E>,
U: OutboundUpgrade<C, Output = M, Error = E> + Clone,
U: InboundUpgrade<Negotiated<C>, Output = M, Error = E>,
U: OutboundUpgrade<Negotiated<C>, Output = M, Error = E> + Clone,
E: Error + 'static,
{
let version = self.version;
@ -185,7 +186,7 @@ where
pub struct Authenticate<C, U>
where
C: AsyncRead + AsyncWrite + Unpin,
U: InboundUpgrade<C> + OutboundUpgrade<C>
U: InboundUpgrade<Negotiated<C>> + OutboundUpgrade<Negotiated<C>>
{
inner: EitherUpgrade<C, U>
}
@ -193,9 +194,9 @@ where
impl<C, U> Future for Authenticate<C, U>
where
C: AsyncRead + AsyncWrite + Unpin,
U: InboundUpgrade<C> + OutboundUpgrade<C,
Output = <U as InboundUpgrade<C>>::Output,
Error = <U as InboundUpgrade<C>>::Error
U: InboundUpgrade<Negotiated<C>> + OutboundUpgrade<Negotiated<C>,
Output = <U as InboundUpgrade<Negotiated<C>>>::Output,
Error = <U as InboundUpgrade<Negotiated<C>>>::Error
>
{
type Output = <EitherUpgrade<C, U> as Future>::Output;
@ -212,7 +213,7 @@ where
pub struct Multiplex<C, U, I>
where
C: AsyncRead + AsyncWrite + Unpin,
U: InboundUpgrade<C> + OutboundUpgrade<C>,
U: InboundUpgrade<Negotiated<C>> + OutboundUpgrade<Negotiated<C>>,
{
info: Option<I>,
upgrade: EitherUpgrade<C, U>,
@ -221,8 +222,8 @@ where
impl<C, U, I, M, E> Future for Multiplex<C, U, I>
where
C: AsyncRead + AsyncWrite + Unpin,
U: InboundUpgrade<C, Output = M, Error = E>,
U: OutboundUpgrade<C, Output = M, Error = E>
U: InboundUpgrade<Negotiated<C>, Output = M, Error = E>,
U: OutboundUpgrade<Negotiated<C>, Output = M, Error = E>
{
type Output = Result<(I, M), UpgradeError<E>>;
@ -239,7 +240,7 @@ where
impl<C, U, I> Unpin for Multiplex<C, U, I>
where
C: AsyncRead + AsyncWrite + Unpin,
U: InboundUpgrade<C> + OutboundUpgrade<C>,
U: InboundUpgrade<Negotiated<C>> + OutboundUpgrade<Negotiated<C>>,
{
}
@ -266,8 +267,8 @@ where
T::ListenerUpgrade: Unpin,
T::Error: 'static,
C: AsyncRead + AsyncWrite + Unpin,
U: InboundUpgrade<C, Output = D, Error = E>,
U: OutboundUpgrade<C, Output = D, Error = E> + Clone,
U: InboundUpgrade<Negotiated<C>, Output = D, Error = E>,
U: OutboundUpgrade<Negotiated<C>, Output = D, Error = E> + Clone,
E: Error + 'static
{
type Output = (I, D);
@ -333,7 +334,7 @@ where
/// The [`Transport::Dial`] future of an [`Upgrade`]d transport.
pub struct DialUpgradeFuture<F, U, I, C>
where
U: OutboundUpgrade<C>,
U: OutboundUpgrade<Negotiated<C>>,
C: AsyncRead + AsyncWrite + Unpin,
{
future: F,
@ -344,7 +345,7 @@ impl<F, U, I, C, D> Future for DialUpgradeFuture<F, U, I, C>
where
F: TryFuture<Ok = (I, C)> + Unpin,
C: AsyncRead + AsyncWrite + Unpin,
U: OutboundUpgrade<C, Output = D>,
U: OutboundUpgrade<Negotiated<C>, Output = D>,
U::Error: Error
{
type Output = Result<(I, D), TransportUpgradeError<F::Error, U::Error>>;
@ -379,7 +380,7 @@ where
impl<F, U, I, C> Unpin for DialUpgradeFuture<F, U, I, C>
where
U: OutboundUpgrade<C>,
U: OutboundUpgrade<Negotiated<C>>,
C: AsyncRead + AsyncWrite + Unpin,
{
}
@ -395,7 +396,7 @@ where
S: TryStream<Ok = ListenerEvent<F>> + Unpin,
F: TryFuture<Ok = (I, C)>,
C: AsyncRead + AsyncWrite + Unpin,
U: InboundUpgrade<C, Output = D> + Clone
U: InboundUpgrade<Negotiated<C>, Output = D> + Clone
{
type Item = Result<ListenerEvent<ListenerUpgradeFuture<F, U, I, C>>, TransportUpgradeError<S::Error, U::Error>>;
@ -425,7 +426,7 @@ impl<S, U> Unpin for ListenerStream<S, U> {
pub struct ListenerUpgradeFuture<F, U, I, C>
where
C: AsyncRead + AsyncWrite + Unpin,
U: InboundUpgrade<C>
U: InboundUpgrade<Negotiated<C>>
{
future: F,
upgrade: future::Either<Option<U>, (Option<I>, InboundUpgradeApply<C, U>)>
@ -435,7 +436,7 @@ impl<F, U, I, C, D> Future for ListenerUpgradeFuture<F, U, I, C>
where
F: TryFuture<Ok = (I, C)> + Unpin,
C: AsyncRead + AsyncWrite + Unpin,
U: InboundUpgrade<C, Output = D>,
U: InboundUpgrade<Negotiated<C>, Output = D>,
U::Error: Error
{
type Output = Result<(I, D), TransportUpgradeError<F::Error, U::Error>>;
@ -471,6 +472,6 @@ where
impl<F, U, I, C> Unpin for ListenerUpgradeFuture<F, U, I, C>
where
C: AsyncRead + AsyncWrite + Unpin,
U: InboundUpgrade<C>
U: InboundUpgrade<Negotiated<C>>
{
}

View File

@ -18,7 +18,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
use crate::ConnectedPoint;
use crate::{ConnectedPoint, Negotiated};
use crate::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeError, ProtocolName};
use futures::{future::Either, prelude::*, compat::Compat, compat::Compat01As03, compat::Future01CompatExt};
use log::debug;
@ -32,7 +32,7 @@ pub fn apply<C, U>(conn: C, up: U, cp: ConnectedPoint, v: Version)
-> Either<InboundUpgradeApply<C, U>, OutboundUpgradeApply<C, U>>
where
C: AsyncRead + AsyncWrite + Unpin,
U: InboundUpgrade<C> + OutboundUpgrade<C>,
U: InboundUpgrade<Negotiated<C>> + OutboundUpgrade<Negotiated<C>>,
{
if cp.is_listener() {
Either::Left(apply_inbound(conn, up))
@ -45,7 +45,7 @@ where
pub fn apply_inbound<C, U>(conn: C, up: U) -> InboundUpgradeApply<C, U>
where
C: AsyncRead + AsyncWrite + Unpin,
U: InboundUpgrade<C>,
U: InboundUpgrade<Negotiated<C>>,
{
let iter = up.protocol_info().into_iter().map(NameWrap as fn(_) -> NameWrap<_>);
let future = multistream_select::listener_select_proto(Compat::new(conn), iter).compat();
@ -58,7 +58,7 @@ where
pub fn apply_outbound<C, U>(conn: C, up: U, v: Version) -> OutboundUpgradeApply<C, U>
where
C: AsyncRead + AsyncWrite + Unpin,
U: OutboundUpgrade<C>
U: OutboundUpgrade<Negotiated<C>>
{
let iter = up.protocol_info().into_iter().map(NameWrap as fn(_) -> NameWrap<_>);
let future = multistream_select::dialer_select_proto(Compat::new(conn), iter, v).compat();
@ -71,7 +71,7 @@ where
pub struct InboundUpgradeApply<C, U>
where
C: AsyncRead + AsyncWrite + Unpin,
U: InboundUpgrade<C>
U: InboundUpgrade<Negotiated<C>>
{
inner: InboundUpgradeApplyState<C, U>
}
@ -79,7 +79,7 @@ where
enum InboundUpgradeApplyState<C, U>
where
C: AsyncRead + AsyncWrite + Unpin,
U: InboundUpgrade<C>,
U: InboundUpgrade<Negotiated<C>>,
{
Init {
future: Compat01As03<ListenerSelectFuture<Compat<C>, NameWrap<U::Info>>>,
@ -94,14 +94,14 @@ where
impl<C, U> Unpin for InboundUpgradeApply<C, U>
where
C: AsyncRead + AsyncWrite + Unpin,
U: InboundUpgrade<C>,
U: InboundUpgrade<Negotiated<C>>,
{
}
impl<C, U> Future for InboundUpgradeApply<C, U>
where
C: AsyncRead + AsyncWrite + Unpin,
U: InboundUpgrade<C>,
U: InboundUpgrade<Negotiated<C>>,
U::Future: Unpin,
{
type Output = Result<U::Output, UpgradeError<U::Error>>;
@ -148,7 +148,7 @@ where
pub struct OutboundUpgradeApply<C, U>
where
C: AsyncRead + AsyncWrite + Unpin,
U: OutboundUpgrade<C>
U: OutboundUpgrade<Negotiated<C>>
{
inner: OutboundUpgradeApplyState<C, U>
}
@ -156,7 +156,7 @@ where
enum OutboundUpgradeApplyState<C, U>
where
C: AsyncRead + AsyncWrite + Unpin,
U: OutboundUpgrade<C>
U: OutboundUpgrade<Negotiated<C>>
{
Init {
future: Compat01As03<DialerSelectFuture<Compat<C>, NameWrapIter<<U::InfoIter as IntoIterator>::IntoIter>>>,
@ -171,14 +171,14 @@ where
impl<C, U> Unpin for OutboundUpgradeApply<C, U>
where
C: AsyncRead + AsyncWrite + Unpin,
U: OutboundUpgrade<C>,
U: OutboundUpgrade<Negotiated<C>>,
{
}
impl<C, U> Future for OutboundUpgradeApply<C, U>
where
C: AsyncRead + AsyncWrite + Unpin,
U: OutboundUpgrade<C>,
U: OutboundUpgrade<Negotiated<C>>,
U::Future: Unpin,
{
type Output = Result<U::Output, UpgradeError<U::Error>>;

View File

@ -18,7 +18,6 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
use crate::Negotiated;
use crate::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
use futures::future;
use std::iter;
@ -43,7 +42,7 @@ impl<C> InboundUpgrade<C> for DeniedUpgrade {
type Error = Void;
type Future = future::Pending<Result<Self::Output, Self::Error>>;
fn upgrade_inbound(self, _: Negotiated<C>, _: Self::Info) -> Self::Future {
fn upgrade_inbound(self, _: C, _: Self::Info) -> Self::Future {
future::pending()
}
}
@ -53,7 +52,7 @@ impl<C> OutboundUpgrade<C> for DeniedUpgrade {
type Error = Void;
type Future = future::Pending<Result<Self::Output, Self::Error>>;
fn upgrade_outbound(self, _: Negotiated<C>, _: Self::Info) -> Self::Future {
fn upgrade_outbound(self, _: C, _: Self::Info) -> Self::Future {
future::pending()
}
}

View File

@ -19,7 +19,6 @@
// DEALINGS IN THE SOFTWARE.
use crate::{
Negotiated,
either::{EitherOutput, EitherError, EitherFuture2, EitherName},
upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}
};
@ -56,7 +55,7 @@ where
type Error = EitherError<EA, EB>;
type Future = EitherFuture2<A::Future, B::Future>;
fn upgrade_inbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
fn upgrade_inbound(self, sock: 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)),
@ -74,7 +73,7 @@ where
type Error = EitherError<EA, EB>;
type Future = EitherFuture2<A::Future, B::Future>;
fn upgrade_outbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
fn upgrade_outbound(self, sock: 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)),

View File

@ -18,7 +18,6 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
use crate::Negotiated;
use crate::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
use futures::prelude::*;
use std::{pin::Pin, task::Context, task::Poll};
@ -54,7 +53,7 @@ where
type Error = U::Error;
type Future = MapFuture<U::Future, F>;
fn upgrade_inbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future {
MapFuture {
inner: self.upgrade.upgrade_inbound(sock, info),
map: Some(self.fun)
@ -70,7 +69,7 @@ where
type Error = U::Error;
type Future = U::Future;
fn upgrade_outbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future {
self.upgrade.upgrade_outbound(sock, info)
}
}
@ -105,7 +104,7 @@ where
type Error = U::Error;
type Future = U::Future;
fn upgrade_inbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future {
self.upgrade.upgrade_inbound(sock, info)
}
}
@ -119,7 +118,7 @@ where
type Error = U::Error;
type Future = MapFuture<U::Future, F>;
fn upgrade_outbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future {
MapFuture {
inner: self.upgrade.upgrade_outbound(sock, info),
map: Some(self.fun)
@ -158,7 +157,7 @@ where
type Error = T;
type Future = MapErrFuture<U::Future, F>;
fn upgrade_inbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future {
MapErrFuture {
fut: self.upgrade.upgrade_inbound(sock, info),
fun: Some(self.fun)
@ -174,7 +173,7 @@ where
type Error = U::Error;
type Future = U::Future;
fn upgrade_outbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future {
self.upgrade.upgrade_outbound(sock, info)
}
}
@ -210,7 +209,7 @@ where
type Error = T;
type Future = MapErrFuture<U::Future, F>;
fn upgrade_outbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future {
MapErrFuture {
fut: self.upgrade.upgrade_outbound(sock, info),
fun: Some(self.fun)
@ -226,7 +225,7 @@ where
type Error = U::Error;
type Future = U::Future;
fn upgrade_inbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future {
self.upgrade.upgrade_inbound(sock, info)
}
}

View File

@ -150,7 +150,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: Negotiated<C>, info: Self::Info) -> Self::Future;
fn upgrade_inbound(self, socket: C, info: Self::Info) -> Self::Future;
}
/// Extension trait for `InboundUpgrade`. Automatically implemented on all types that implement
@ -190,7 +190,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: Negotiated<C>, info: Self::Info) -> Self::Future;
fn upgrade_outbound(self, socket: C, info: Self::Info) -> Self::Future;
}
/// Extention trait for `OutboundUpgrade`. Automatically implemented on all types that implement

View File

@ -19,7 +19,6 @@
// DEALINGS IN THE SOFTWARE.
use crate::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};
use crate::Negotiated;
/// Upgrade that can be disabled at runtime.
///
@ -60,7 +59,7 @@ where
type Error = T::Error;
type Future = T::Future;
fn upgrade_inbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
fn upgrade_inbound(self, sock: C, info: Self::Info) -> Self::Future {
if let Some(inner) = self.0 {
inner.upgrade_inbound(sock, info)
} else {
@ -77,7 +76,7 @@ where
type Error = T::Error;
type Future = T::Future;
fn upgrade_outbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
fn upgrade_outbound(self, sock: C, info: Self::Info) -> Self::Future {
if let Some(inner) = self.0 {
inner.upgrade_outbound(sock, info)
} else {

View File

@ -19,7 +19,6 @@
// DEALINGS IN THE SOFTWARE.
use crate::{
Negotiated,
either::{EitherOutput, EitherError, EitherFuture2, EitherName},
upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}
};
@ -65,7 +64,7 @@ where
type Error = EitherError<EA, EB>;
type Future = EitherFuture2<A::Future, B::Future>;
fn upgrade_inbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
fn upgrade_inbound(self, sock: 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))
@ -82,7 +81,7 @@ where
type Error = EitherError<EA, EB>;
type Future = EitherFuture2<A::Future, B::Future>;
fn upgrade_outbound(self, sock: Negotiated<C>, info: Self::Info) -> Self::Future {
fn upgrade_outbound(self, sock: 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))