diff --git a/core/src/upgrade/apply.rs b/core/src/upgrade/apply.rs index 9d21057d..1c886b88 100644 --- a/core/src/upgrade/apply.rs +++ b/core/src/upgrade/apply.rs @@ -19,12 +19,27 @@ // DEALINGS IN THE SOFTWARE. use bytes::Bytes; -use crate::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeError}; -use futures::prelude::*; +use crate::{nodes::ConnectedPoint, upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeError}}; +use futures::{future::Either, prelude::*}; use multistream_select::{self, DialerSelectFuture, ListenerSelectFuture}; use std::mem; use tokio_io::{AsyncRead, AsyncWrite}; +/// Applies an upgrade to the inbound and outbound direction of a connection or substream. +pub fn apply(conn: C, up: U, cp: ConnectedPoint) + -> Either, OutboundUpgradeApply> +where + C: AsyncRead + AsyncWrite, + U: InboundUpgrade + OutboundUpgrade, + U::NamesIter: Clone +{ + if cp.is_listener() { + Either::A(apply_inbound(conn, up)) + } else { + Either::B(apply_outbound(conn, up)) + } +} + /// Tries to perform an upgrade on an inbound connection or substream. pub fn apply_inbound(conn: C, up: U) -> InboundUpgradeApply where diff --git a/core/src/upgrade/mod.rs b/core/src/upgrade/mod.rs index 59b8b5d4..596d3ef6 100644 --- a/core/src/upgrade/mod.rs +++ b/core/src/upgrade/mod.rs @@ -68,7 +68,7 @@ use bytes::Bytes; use futures::future::Future; pub use self::{ - apply::{apply_inbound, apply_outbound, InboundUpgradeApply, OutboundUpgradeApply}, + apply::{apply, apply_inbound, apply_outbound, InboundUpgradeApply, OutboundUpgradeApply}, denied::DeniedUpgrade, error::UpgradeError, map::{MapInboundUpgrade, MapOutboundUpgrade, MapUpgradeErr},