mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-27 16:51:34 +00:00
Add upgrade::apply
for convenience. (#653)
This commit is contained in:
@ -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<C, U>(conn: C, up: U, cp: ConnectedPoint)
|
||||
-> Either<InboundUpgradeApply<C, U>, OutboundUpgradeApply<C, U>>
|
||||
where
|
||||
C: AsyncRead + AsyncWrite,
|
||||
U: InboundUpgrade<C> + OutboundUpgrade<C>,
|
||||
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<C, U>(conn: C, up: U) -> InboundUpgradeApply<C, U>
|
||||
where
|
||||
|
@ -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},
|
||||
|
Reference in New Issue
Block a user