mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-27 08:41:36 +00:00
Remove Negotiated from upgrade traits (#1388)
* Remove Negotiated from upgrade traits * Remove import
This commit is contained in:
@ -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>>;
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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)),
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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))
|
||||
|
Reference in New Issue
Block a user