Skip to main content

Session

Struct Session 

Source
pub struct Session { /* private fields */ }
Expand description

An established WebTransport session, acting like a full QUIC connection. See quinn::Connection.

Remember that WebTransport is layered on top of QUIC:

  1. Each stream begins with bytes identifying the stream type and session ID.
  2. Error codes are encoded with the session ID, so they are not full QUIC error codes.
  3. Stream IDs may have gaps introduced by HTTP/3, transparent to the application.

Deref is used to expose non-overloaded methods on quinn::Connection. These should be safe with WebTransport; please file an issue if you find otherwise.

Implementations§

Source§

impl Session

Source

pub async fn connect(conn: Connection, url: Url) -> Result<Session, ClientError>

Connect using an established QUIC connection when creating the connection manually. This only works with a fresh QUIC connection negotiated with the HTTP/3 ALPN.

Source

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

Accept a new unidirectional stream. See quinn::Connection::accept_uni.

Source

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

Accept a new bidirectional stream. See quinn::Connection::accept_bi.

Source

pub async fn open_uni(&self) -> Result<SendStream, SessionError>

Open a new unidirectional stream. See quinn::Connection::open_uni.

Source

pub async fn open_bi(&self) -> Result<(SendStream, RecvStream), SessionError>

Open a new bidirectional stream. See quinn::Connection::open_bi.

Source

pub async fn read_datagram(&self) -> Result<Bytes, SessionError>

Asynchronously receive an application datagram from the remote peer.

Waits for a datagram to become available and returns the received bytes.

Source

pub fn send_datagram(&self, data: Bytes) -> Result<(), SessionError>

Send an application datagram to the remote peer.

Datagrams are unreliable and may be dropped or delivered out of order. The data must be smaller than max_datagram_size.

Source

pub fn max_datagram_size(&self) -> usize

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

Source

pub fn close(&self, code: u32, reason: &[u8])

Close the session with an error code and reason.

WebTransport sessions first send a CLOSE_WEBTRANSPORT_SESSION capsule from the background CONNECT task. Raw QUIC sessions close immediately.

Source

pub async fn closed(&self) -> SessionError

Wait until the session is closed and return the error. See quinn::Connection::closed.

Source

pub fn close_reason(&self) -> Option<SessionError>

Return the close reason, or None if the session is still open. See quinn::Connection::close_reason.

Source

pub fn raw(conn: Connection, url: Url) -> Self

Create a new session from a raw QUIC connection and a URL.

This adapts a QUIC connection to a WebTransport session, which simplifies supporting WebTransport and raw QUIC side by side.

Source

pub fn url(&self) -> &Url

Return the URL negotiated for this WebTransport session.

Methods from Deref<Target = Connection>§

Source

pub fn open_uni(&self) -> OpenUni<'_>

Initiate a new outgoing unidirectional stream.

Streams are cheap and instantaneous to open unless blocked by flow control. As a consequence, the peer won’t be notified that a stream has been opened until the stream is actually used.

Source

pub fn open_bi(&self) -> OpenBi<'_>

Initiate a new outgoing bidirectional stream.

Streams are cheap and instantaneous to open unless blocked by flow control. As a consequence, the peer won’t be notified that a stream has been opened until the stream is actually used. Calling open_bi() then waiting on the RecvStream without writing anything to SendStream will never succeed.

Source

pub fn accept_uni(&self) -> AcceptUni<'_>

Accept the next incoming uni-directional stream

Source

pub fn accept_bi(&self) -> AcceptBi<'_>

Accept the next incoming bidirectional stream

Important Note: The Connection that calls open_bi() must write to its SendStream before the other Connection is able to accept_bi(). Calling open_bi() then waiting on the RecvStream without writing anything to SendStream will never succeed.

Source

pub fn read_datagram(&self) -> ReadDatagram<'_>

Receive an application datagram

Source

pub async fn closed(&self) -> ConnectionError

Wait for the connection to be closed for any reason

Despite the return type’s name, closed connections are often not an error condition at the application layer. Cases that might be routine include ConnectionError::LocallyClosed and ConnectionError::ApplicationClosed.

Source

pub fn close_reason(&self) -> Option<ConnectionError>

If the connection is closed, the reason why.

Returns None if the connection is still open.

Source

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

Close the connection immediately.

Pending operations will fail immediately with ConnectionError::LocallyClosed. No more data is sent to the peer and the peer may drop buffered data upon receiving the CONNECTION_CLOSE frame.

error_code and reason are not interpreted, and are provided directly to the peer.

reason will be truncated to fit in a single packet with overhead; to improve odds that it is preserved in full, it should be kept under 1KiB.

§Gracefully closing a connection

Only the peer last receiving application data can be certain that all data is delivered. The only reliable action it can then take is to close the connection, potentially with a custom error code. The delivery of the final CONNECTION_CLOSE frame is very likely if both endpoints stay online long enough, and Endpoint::wait_idle() can be used to provide sufficient time. Otherwise, the remote peer will time out the connection, provided that the idle timeout is not disabled.

The sending side can not guarantee all stream data is delivered to the remote application. It only knows the data is delivered to the QUIC stack of the remote endpoint. Once the local side sends a CONNECTION_CLOSE frame in response to calling close() the remote endpoint may drop any data it received but is as yet undelivered to the application, including data that was acknowledged as received to the local endpoint.

Source

pub fn send_datagram(&self, data: Bytes) -> Result<(), SendDatagramError>

Transmit data as an unreliable, unordered application datagram

Application datagrams are a low-level primitive. They may be lost or delivered out of order, and data must both fit inside a single QUIC packet and be smaller than the maximum dictated by the peer.

Previously queued datagrams which are still unsent may be discarded to make space for this datagram, in order of oldest to newest.

Source

pub fn send_datagram_wait(&self, data: Bytes) -> SendDatagram<'_>

Transmit data as an unreliable, unordered application datagram

Unlike send_datagram(), this method will wait for buffer space during congestion conditions, which effectively prioritizes old datagrams over new datagrams.

See send_datagram() for details.

Source

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

Compute 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 datagram_send_buffer_space(&self) -> usize

Bytes available in the outgoing datagram buffer

When greater than zero, calling send_datagram() with a datagram of at most this size is guaranteed not to cause older datagrams to be dropped.

Source

pub fn side(&self) -> Side

The side of the connection (client or server)

Source

pub fn remote_address(&self) -> SocketAddr

The peer’s UDP address

If ServerConfig::migration is true, clients may change addresses at will, e.g. when switching to a cellular internet connection.

Source

pub fn local_ip(&self) -> Option<IpAddr>

The local IP address which was used when the peer established the connection

This can be different from the address the endpoint is bound to, in case the endpoint is bound to a wildcard address like 0.0.0.0 or ::.

This will return None for clients, or when the platform does not expose this information. See quinn_udp::RecvMeta::dst_ip for a list of supported platforms when using quinn_udp for I/O, which is the default.

Source

pub fn rtt(&self) -> Duration

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

Source

pub fn stats(&self) -> ConnectionStats

Returns connection statistics

Source

pub fn congestion_state(&self) -> Box<dyn Controller>

Current state of the congestion control algorithm, for debugging purposes

Source

pub fn handshake_data(&self) -> Option<Box<dyn Any>>

Parameters negotiated during the handshake

Guaranteed to return Some on fully established connections or after Connecting::handshake_data() succeeds. See that method’s documentations for details on the returned value.

Source

pub fn peer_identity(&self) -> Option<Box<dyn Any>>

Cryptographic identity of the peer

The dynamic type returned is determined by the configured Session. For the default rustls session, the return value can be downcast to a Vec<rustls::pki_types::CertificateDer>

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 force_key_update(&self)

Update traffic keys spontaneously

This primarily exists for testing purposes.

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 set_max_concurrent_uni_streams(&self, count: VarInt)

Modify the number of remotely initiated unidirectional streams that may be concurrently open

No streams may be opened by the peer unless fewer than count are already open. Large counts increase both minimum and worst-case memory consumption.

Source

pub fn set_send_window(&self, send_window: u64)

Source

pub fn set_receive_window(&self, receive_window: VarInt)

Source

pub fn set_max_concurrent_bi_streams(&self, count: VarInt)

Modify the number of remotely initiated bidirectional streams that may be concurrently open

No streams may be opened by the peer unless fewer than count are already open. Large counts increase both minimum and worst-case memory consumption.

Trait Implementations§

Source§

impl Clone for Session

Source§

fn clone(&self) -> Session

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Session

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Deref for Session

Source§

type Target = Connection

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Eq for Session

Source§

impl PartialEq for Session

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Session for Session

Source§

type SendStream = SendStream

Outgoing stream type returned by open_* and accept_bi.
Source§

type RecvStream = RecvStream

Incoming stream type returned by accept_* and open_bi.
Source§

type Error = SessionError

Error type returned by session operations.
Source§

async fn accept_uni(&self) -> Result<Self::RecvStream, Self::Error>

Block until the peer creates a new unidirectional stream.
Source§

async fn accept_bi( &self, ) -> Result<(Self::SendStream, Self::RecvStream), Self::Error>

Block until the peer creates a new bidirectional stream.
Source§

async fn open_bi( &self, ) -> Result<(Self::SendStream, Self::RecvStream), Self::Error>

Open a new bidirectional stream, which may block if too many streams are open.
Source§

async fn open_uni(&self) -> Result<Self::SendStream, Self::Error>

Open a new unidirectional stream, which may block if too many streams are open.
Source§

fn close(&self, code: u32, reason: &str)

Close the connection immediately with a code and reason.
Source§

async fn closed(&self) -> Self::Error

Block until the connection is closed by either side.
Source§

async fn send_datagram(&self, data: Bytes) -> Result<(), Self::Error>

Send a datagram over the network. Read more
Source§

async fn recv_datagram(&self) -> Result<Bytes, Self::Error>

Receive a datagram over the network.
Source§

fn max_datagram_size(&self) -> usize

Return the maximum size of a datagram that can be sent.

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<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSync for T
where T: Sync,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

Source§

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<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