[−][src]Struct libp2p_core::transport::upgrade::Builder
A Builder
facilitates upgrading of a Transport
for use with
a Network
.
The upgrade process is defined by the following stages:
authenticate
{1}
-> apply
{*}
-> multiplex
{1}
It thus enforces the following invariants on every transport
obtained from multiplex
:
- The transport must be authenticated and multiplexed.
- Authentication must precede the negotiation of a multiplexer.
- Applying a multiplexer is the last step in the upgrade process.
- The
Transport::Output
conforms to the requirements of aNetwork
, namely a tuple of aConnectionInfo
(from the authentication upgrade) and aStreamMuxer
(from the multiplexing upgrade).
Implementations
impl<T> Builder<T> where
T: Transport,
T::Error: 'static,
[src]
T: Transport,
T::Error: 'static,
pub fn new(inner: T, version: Version) -> Builder<T>
[src]
Creates a Builder
over the given (base) Transport
.
pub fn authenticate<C, D, U, I, E>(
self,
upgrade: U
) -> Builder<AndThen<T, impl FnOnce(C, ConnectedPoint) -> Authenticate<C, U> + Clone>> where
T: Transport<Output = C>,
I: ConnectionInfo,
C: AsyncRead + AsyncWrite + Unpin,
D: AsyncRead + AsyncWrite + Unpin,
U: InboundUpgrade<Negotiated<C>, Output = (I, D), Error = E>,
U: OutboundUpgrade<Negotiated<C>, Output = (I, D), Error = E> + Clone,
E: Error + 'static,
[src]
self,
upgrade: U
) -> Builder<AndThen<T, impl FnOnce(C, ConnectedPoint) -> Authenticate<C, U> + Clone>> where
T: Transport<Output = C>,
I: ConnectionInfo,
C: AsyncRead + AsyncWrite + Unpin,
D: AsyncRead + AsyncWrite + Unpin,
U: InboundUpgrade<Negotiated<C>, Output = (I, D), Error = E>,
U: OutboundUpgrade<Negotiated<C>, Output = (I, D), Error = E> + Clone,
E: Error + 'static,
Upgrades the transport to perform authentication of the remote.
The supplied upgrade receives the I/O resource C
and must
produce a pair (I, D)
, where I
is a ConnectionInfo
and
D
is a new I/O resource. The upgrade must thus at a minimum
identify the remote, which typically involves the use of a
cryptographic authentication protocol in the context of establishing
a secure channel.
Transitions
- I/O upgrade:
C -> (I, D)
. - Transport output:
C -> (I, D)
pub fn apply<C, D, U, I, E>(self, upgrade: U) -> Builder<Upgrade<T, U>> where
T: Transport<Output = (I, C)>,
C: AsyncRead + AsyncWrite + Unpin,
D: AsyncRead + AsyncWrite + Unpin,
I: ConnectionInfo,
U: InboundUpgrade<Negotiated<C>, Output = D, Error = E>,
U: OutboundUpgrade<Negotiated<C>, Output = D, Error = E> + Clone,
E: Error + 'static,
[src]
T: Transport<Output = (I, C)>,
C: AsyncRead + AsyncWrite + Unpin,
D: AsyncRead + AsyncWrite + Unpin,
I: ConnectionInfo,
U: InboundUpgrade<Negotiated<C>, Output = D, Error = E>,
U: OutboundUpgrade<Negotiated<C>, Output = D, Error = E> + Clone,
E: Error + 'static,
Applies an arbitrary upgrade on an authenticated, non-multiplexed transport.
The upgrade receives the I/O resource (i.e. connection) C
and
must produce a new I/O resource D
. Any number of such upgrades
can be performed.
Transitions
- I/O upgrade:
C -> D
. - Transport output:
(I, C) -> (I, D)
.
pub fn multiplex<C, M, U, I, E>(
self,
upgrade: U
) -> AndThen<T, impl FnOnce((I, C), ConnectedPoint) -> Multiplex<C, U, I> + Clone> where
T: Transport<Output = (I, C)>,
C: AsyncRead + AsyncWrite + Unpin,
M: StreamMuxer,
I: ConnectionInfo,
U: InboundUpgrade<Negotiated<C>, Output = M, Error = E>,
U: OutboundUpgrade<Negotiated<C>, Output = M, Error = E> + Clone,
E: Error + 'static,
[src]
self,
upgrade: U
) -> AndThen<T, impl FnOnce((I, C), ConnectedPoint) -> Multiplex<C, U, I> + Clone> where
T: Transport<Output = (I, C)>,
C: AsyncRead + AsyncWrite + Unpin,
M: StreamMuxer,
I: ConnectionInfo,
U: InboundUpgrade<Negotiated<C>, Output = M, Error = E>,
U: OutboundUpgrade<Negotiated<C>, Output = M, Error = E> + Clone,
E: Error + 'static,
Upgrades the transport with a (sub)stream multiplexer.
The supplied upgrade receives the I/O resource C
and must
produce a StreamMuxer
M
. The transport must already be authenticated.
This ends the (regular) transport upgrade process, yielding the underlying,
configured transport.
Transitions
- I/O upgrade:
C -> M
. - Transport output:
(I, C) -> (I, M)
.
pub fn multiplex_ext<C, M, U, I, E, F>(
self,
up: F
) -> AndThen<T, impl FnOnce((I, C), ConnectedPoint) -> Multiplex<C, U, I> + Clone> where
T: Transport<Output = (I, C)>,
C: AsyncRead + AsyncWrite + Unpin,
M: StreamMuxer,
I: ConnectionInfo,
U: InboundUpgrade<Negotiated<C>, Output = M, Error = E>,
U: OutboundUpgrade<Negotiated<C>, Output = M, Error = E> + Clone,
E: Error + 'static,
F: for<'a> FnOnce(&'a I, &'a ConnectedPoint) -> U + Clone,
[src]
self,
up: F
) -> AndThen<T, impl FnOnce((I, C), ConnectedPoint) -> Multiplex<C, U, I> + Clone> where
T: Transport<Output = (I, C)>,
C: AsyncRead + AsyncWrite + Unpin,
M: StreamMuxer,
I: ConnectionInfo,
U: InboundUpgrade<Negotiated<C>, Output = M, Error = E>,
U: OutboundUpgrade<Negotiated<C>, Output = M, Error = E> + Clone,
E: Error + 'static,
F: for<'a> FnOnce(&'a I, &'a ConnectedPoint) -> U + Clone,
Like Builder::multiplex
but accepts a function which returns the upgrade.
The supplied function is applied to ConnectionInfo
and ConnectedPoint
and returns an upgrade which receives the I/O resource C
and must
produce a StreamMuxer
M
. The transport must already be authenticated.
This ends the (regular) transport upgrade process, yielding the underlying,
configured transport.
Transitions
- I/O upgrade:
C -> M
. - Transport output:
(I, C) -> (I, M)
.
Auto Trait Implementations
impl<T> RefUnwindSafe for Builder<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Builder<T> where
T: Send,
T: Send,
impl<T> Sync for Builder<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Builder<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Builder<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,