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.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use crate::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeError};
|
use crate::{nodes::ConnectedPoint, upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeError}};
|
||||||
use futures::prelude::*;
|
use futures::{future::Either, prelude::*};
|
||||||
use multistream_select::{self, DialerSelectFuture, ListenerSelectFuture};
|
use multistream_select::{self, DialerSelectFuture, ListenerSelectFuture};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use tokio_io::{AsyncRead, AsyncWrite};
|
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.
|
/// Tries to perform an upgrade on an inbound connection or substream.
|
||||||
pub fn apply_inbound<C, U>(conn: C, up: U) -> InboundUpgradeApply<C, U>
|
pub fn apply_inbound<C, U>(conn: C, up: U) -> InboundUpgradeApply<C, U>
|
||||||
where
|
where
|
||||||
|
@ -68,7 +68,7 @@ use bytes::Bytes;
|
|||||||
use futures::future::Future;
|
use futures::future::Future;
|
||||||
|
|
||||||
pub use self::{
|
pub use self::{
|
||||||
apply::{apply_inbound, apply_outbound, InboundUpgradeApply, OutboundUpgradeApply},
|
apply::{apply, apply_inbound, apply_outbound, InboundUpgradeApply, OutboundUpgradeApply},
|
||||||
denied::DeniedUpgrade,
|
denied::DeniedUpgrade,
|
||||||
error::UpgradeError,
|
error::UpgradeError,
|
||||||
map::{MapInboundUpgrade, MapOutboundUpgrade, MapUpgradeErr},
|
map::{MapInboundUpgrade, MapOutboundUpgrade, MapUpgradeErr},
|
||||||
|
Reference in New Issue
Block a user