pub struct Session { /* private fields */ }
Expand description
An established WebTransport session, acting like a full QUIC connection. See quinn::Connection
.
It is important to remember that WebTransport is layered on top of QUIC:
- Each stream starts with a few bytes identifying the stream type and session ID.
- Errors codes are encoded with the session ID, so they aren’t full QUIC error codes.
- Stream IDs may have gaps in them, used by HTTP/3 transparant to the application.
Deref is used to expose non-overloaded methods on quinn::Connection
.
These should be safe to use with WebTransport, but file a PR if you find one that isn’t.
Implementations§
Source§impl Session
impl Session
Sourcepub async fn accept_uni(&self) -> Result<RecvStream, SessionError>
pub async fn accept_uni(&self) -> Result<RecvStream, SessionError>
Accept a new unidirectional stream. See quinn::Connection::accept_uni
.
Sourcepub async fn accept_bi(&self) -> Result<(SendStream, RecvStream), SessionError>
pub async fn accept_bi(&self) -> Result<(SendStream, RecvStream), SessionError>
Accept a new bidirectional stream. See quinn::Connection::accept_bi
.
Sourcepub async fn open_uni(&self) -> Result<SendStream, SessionError>
pub async fn open_uni(&self) -> Result<SendStream, SessionError>
Open a new unidirectional stream. See quinn::Connection::open_uni
.
Sourcepub async fn open_bi(&self) -> Result<(SendStream, RecvStream), SessionError>
pub async fn open_bi(&self) -> Result<(SendStream, RecvStream), SessionError>
Open a new bidirectional stream. See quinn::Connection::open_bi
.
Sourcepub async fn read_datagram(&self) -> Result<Bytes, SessionError>
pub async fn read_datagram(&self) -> Result<Bytes, SessionError>
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 bytes.
Sourcepub fn send_datagram(&self, data: Bytes) -> Result<(), SessionError>
pub fn send_datagram(&self, data: Bytes) -> Result<(), SessionError>
Sends 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
.
Sourcepub fn max_datagram_size(&self) -> usize
pub fn max_datagram_size(&self) -> usize
Computes the maximum size of datagrams that may be passed to
send_datagram
.
Sourcepub fn close(&self, code: u32, reason: &[u8])
pub fn close(&self, code: u32, reason: &[u8])
Immediately close the connection with an error code and reason. See quinn::Connection::close
.
Sourcepub async fn closed(&self) -> SessionError
pub async fn closed(&self) -> SessionError
Wait until the session is closed, returning the error. See quinn::Connection::closed
.
Sourcepub fn close_reason(&self) -> Option<SessionError>
pub fn close_reason(&self) -> Option<SessionError>
Return why the session was closed, or None if it’s not closed. See quinn::Connection::close_reason
.
Methods from Deref<Target = Connection>§
Sourcepub fn open_uni(&self) -> OpenUni<'_> ⓘ
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.
Sourcepub fn open_bi(&self) -> OpenBi<'_> ⓘ
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.
Sourcepub fn accept_uni(&self) -> AcceptUni<'_> ⓘ
pub fn accept_uni(&self) -> AcceptUni<'_> ⓘ
Accept the next incoming uni-directional stream
Sourcepub fn accept_bi(&self) -> AcceptBi<'_> ⓘ
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.
Sourcepub fn read_datagram(&self) -> ReadDatagram<'_> ⓘ
pub fn read_datagram(&self) -> ReadDatagram<'_> ⓘ
Receive an application datagram
Sourcepub async fn closed(&self) -> ConnectionError
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
.
Sourcepub fn close_reason(&self) -> Option<ConnectionError>
pub fn close_reason(&self) -> Option<ConnectionError>
If the connection is closed, the reason why.
Returns None
if the connection is still open.
Sourcepub fn close(&self, error_code: VarInt, reason: &[u8])
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.
Sourcepub fn send_datagram(&self, data: Bytes) -> Result<(), SendDatagramError>
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.
Sourcepub fn send_datagram_wait(&self, data: Bytes) -> SendDatagram<'_>
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.
Sourcepub fn max_datagram_size(&self) -> Option<usize>
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.
Sourcepub fn datagram_send_buffer_space(&self) -> usize
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.
Sourcepub fn remote_address(&self) -> SocketAddr
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.
Sourcepub fn local_ip(&self) -> Option<IpAddr>
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.
Sourcepub fn rtt(&self) -> Duration
pub fn rtt(&self) -> Duration
Current best estimate of this connection’s latency (round-trip-time)
Sourcepub fn stats(&self) -> ConnectionStats
pub fn stats(&self) -> ConnectionStats
Returns connection statistics
Sourcepub fn congestion_state(&self) -> Box<dyn Controller>
pub fn congestion_state(&self) -> Box<dyn Controller>
Current state of the congestion control algorithm, for debugging purposes
Sourcepub fn handshake_data(&self) -> Option<Box<dyn Any>>
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.
Sourcepub fn peer_identity(&self) -> Option<Box<dyn Any>>
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>
Sourcepub fn stable_id(&self) -> usize
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.
Sourcepub fn export_keying_material(
&self,
output: &mut [u8],
label: &[u8],
context: &[u8],
) -> Result<(), ExportKeyingMaterialError>
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.
Sourcepub fn set_max_concurrent_uni_streams(&self, count: VarInt)
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
count
s increase both minimum and worst-case memory consumption.
Sourcepub fn set_receive_window(&self, receive_window: VarInt)
pub fn set_receive_window(&self, receive_window: VarInt)
Sourcepub fn set_max_concurrent_bi_streams(&self, count: VarInt)
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
count
s increase both minimum and worst-case memory consumption.
Trait Implementations§
Source§impl From<Connection> for Session
impl From<Connection> for Session
Source§fn from(conn: Connection) -> Self
fn from(conn: Connection) -> Self
Create a QuicTransport session without a Session ID or HTTP/3 nonsense. This is a bit of a hack for MoQ, so it can support both WebTransport and raw QUIC.
impl Eq for Session
Auto Trait Implementations§
impl Freeze for Session
impl RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnwindSafe for Session
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)