Struct libp2p_core::transport::upgrade::Builder
source · pub struct Builder<T> { /* private fields */ }
Expand description
A Builder
facilitates upgrading of a Transport
for use with
a Swarm
.
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 aSwarm
, namely a tuple of aPeerId
(from the authentication upgrade) and aStreamMuxer
(from the multiplexing upgrade).
Implementations§
source§impl<T> Builder<T>
impl<T> Builder<T>
sourcepub fn new(inner: T, version: Version) -> Builder<T>
pub fn new(inner: T, version: Version) -> Builder<T>
Creates a Builder
over the given (base) Transport
.
sourcepub fn authenticate<C, D, U, E>(
self,
upgrade: U,
) -> Authenticated<AndThen<T, impl FnOnce(C, ConnectedPoint) -> Authenticate<C, U> + Clone>>where
T: Transport<Output = C>,
C: AsyncRead + AsyncWrite + Unpin,
D: AsyncRead + AsyncWrite + Unpin,
U: InboundConnectionUpgrade<Negotiated<C>, Output = (PeerId, D), Error = E> + OutboundConnectionUpgrade<Negotiated<C>, Output = (PeerId, D), Error = E> + Clone,
E: Error + 'static,
pub fn authenticate<C, D, U, E>(
self,
upgrade: U,
) -> Authenticated<AndThen<T, impl FnOnce(C, ConnectedPoint) -> Authenticate<C, U> + Clone>>where
T: Transport<Output = C>,
C: AsyncRead + AsyncWrite + Unpin,
D: AsyncRead + AsyncWrite + Unpin,
U: InboundConnectionUpgrade<Negotiated<C>, Output = (PeerId, D), Error = E> + OutboundConnectionUpgrade<Negotiated<C>, Output = (PeerId, 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 (PeerId, D)
, where 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 -> (PeerId, D)
. - Transport output:
C -> (PeerId, D)
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Builder<T>where
T: Freeze,
impl<T> RefUnwindSafe for Builder<T>where
T: RefUnwindSafe,
impl<T> Send for Builder<T>where
T: Send,
impl<T> Sync for Builder<T>where
T: Sync,
impl<T> Unpin for Builder<T>where
T: Unpin,
impl<T> UnwindSafe for Builder<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more