Struct wtransport::connection::Connection

source ·
pub struct Connection { /* private fields */ }
Expand description

A WebTransport session connection.

For more details, see the module documentation.

Implementations§

source§

impl Connection

source

pub async fn accept_uni(&self) -> Result<RecvStream, ConnectionError>

Asynchronously accepts a unidirectional stream.

This method is used to accept incoming unidirectional streams that have been initiated by the remote peer. It waits for the next unidirectional stream to be available, then wraps it in a RecvStream that can be used to read data from the stream.

§Cancel safety

This method is cancel safe.

source

pub async fn accept_bi( &self ) -> Result<(SendStream, RecvStream), ConnectionError>

Asynchronously accepts a bidirectional stream.

This method is used to accept incoming bidirectional streams that have been initiated by the remote peer. It waits for the next bidirectional stream to be available, then wraps it in a tuple containing a SendStream for sending data and a RecvStream for receiving data on the stream.

§Cancel safety

This method is cancel safe.

source

pub async fn open_uni(&self) -> Result<OpeningUniStream, ConnectionError>

Asynchronously opens a new unidirectional stream.

This method is used to initiate the opening of a new unidirectional stream.

§Asynchronous Behavior

This method is asynchronous and involves two await points:

  1. The first await occurs during the initial phase of opening the stream, which may involve awaiting the flow controller. This wait is necessary to ensure proper resource allocation and flow control. It is safe to cancel this await point if needed.

  2. The second await is internal to the returned OpeningUniStream object when it is used to initialize the WebTransport stream. Cancelling this latter future before it completes may result in the stream being closed during initialization.

§Example
let send_stream = connection.open_uni().await?.await?;
source

pub async fn open_bi(&self) -> Result<OpeningBiStream, ConnectionError>

Asynchronously opens a new bidirectional stream.

This method is used to initiate the opening of a new bidirectional stream.

§Asynchronous Behavior

This method is asynchronous and involves two await points:

  1. The first await occurs during the initial phase of opening the stream, which may involve awaiting the flow controller. This wait is necessary to ensure proper resource allocation and flow control. It is safe to cancel this await point if needed.

  2. The second await is internal to the returned OpeningBiStream object when it is used to initialize the WebTransport stream. Cancelling this latter future before it completes may result in the stream being closed during initialization.

§Example
let (send_stream, recv_stream) = connection.open_bi().await?.await?;
source

pub async fn receive_datagram(&self) -> Result<Datagram, ConnectionError>

Asynchronously receives an application datagram from the remote peer.

This method is used to receive an application datagram sent by the remote peer over the connection. It waits for a datagram to become available and returns the received Datagram.

§Example
let datagram = connection.receive_datagram().await?;
source

pub fn send_datagram<D>(&self, payload: D) -> Result<(), SendDatagramError>
where D: AsRef<[u8]>,

Sends an application datagram to the remote peer.

This method is used to send an application datagram to the remote peer over the connection. The datagram payload is provided as a reference to a slice of bytes.

§Example
connection.send_datagram(b"Hello, wtransport!")?;
source

pub fn close(&self, error_code: VarInt, reason: &[u8])

Closes the connection immediately.

source

pub async fn closed(&self) -> ConnectionError

Waits for the connection to be closed for any reason.

source

pub fn session_id(&self) -> SessionId

Returns the WebTransport session identifier.

source

pub fn remote_address(&self) -> SocketAddr

Returns the peer’s UDP address.

Note: as QUIC supports migration, remote address may change during connection. Furthermore, when IPv6 support is enabled, IPv4 addresses may be mapped to IPv6.

source

pub fn stable_id(&self) -> usize

A stable identifier for this connection.

Peer addresses and connection IDs can change, but this value will remain fixed for the lifetime of the connection.

source

pub fn max_datagram_size(&self) -> Option<usize>

Computes the maximum size of datagrams that may be passed to send_datagram.

Returns None if datagrams are unsupported by the peer or disabled locally.

This may change over the lifetime of a connection according to variation in the path MTU estimate. The peer can also enforce an arbitrarily small fixed limit, but if the peer’s limit is large this is guaranteed to be a little over a kilobyte at minimum.

Not necessarily the maximum size of received datagrams.

source

pub fn rtt(&self) -> Duration

Current best estimate of this connection’s latency (round-trip-time).

source

pub fn export_keying_material( &self, output: &mut [u8], label: &[u8], context: &[u8] ) -> Result<(), ExportKeyingMaterialError>

Derive keying material from this connection’s TLS session secrets.

When both peers call this method with the same label and context arguments and output buffers of equal length, they will get the same sequence of bytes in output. These bytes are cryptographically strong and pseudorandom, and are suitable for use as keying material.

See RFC5705 for more information.

source

pub fn peer_identity(&self) -> Option<CertificateChain>

Returns the peer’s identity as a certificate chain if available.

This function returns an Option containing a CertificateChain. If the peer’s identity is available, it is converted into a CertificateChain and returned. If the peer’s identity is not available, None is returned.

source

pub fn handshake_data(&self) -> HandshakeData

Retrieves handshake data associated with the connection.

Trait Implementations§

source§

impl Debug for Connection

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

source§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more