Skip to main content

Session

Struct Session 

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

A MoQ transport session, wrapping a WebTransport connection.

Returned with a Driver by crate::Client::connect and crate::Server::accept. The caller must poll or spawn that driver to run the session.

Like every handle in this library, the lifecycle is reference counted: clones share the connection, the transport closes when the last clone drops, and abort closes it explicitly with an error. The handle and the driver are severed in both directions: the driver holds no Session clone, so running it never keeps the session alive, and the Session holds no transport, so the handle is Send + Sync whatever transport the driver uses. Everything transport-shaped (the close, the close reason, the stats sample) is relayed through the driver.

Implementations§

Source§

impl Session

Source

pub fn version(&self) -> Version

Returns the negotiated protocol version.

Source

pub async fn peer_implementation(&self) -> Option<String>

The implementation the peer advertised in its SETUP, such as moq-net-rs/0.3.10.

Waits for the peer’s SETUP, which a dialing client may not have read yet. None when the peer advertised none, its version carries no SETUP (moq-lite 01-04), or the session ended first. Peer-controlled: use it for logs and rollout counts, never to authorize.

Source

pub fn send_bandwidth(&self) -> Option<Consumer>

Returns a consumer for the estimated send bitrate (from the congestion controller).

Returns None if the QUIC backend doesn’t support bandwidth estimation. Otherwise it holds an estimate from the start, the session’s first sample.

Source

pub fn allocator(&self) -> Allocator

Divides send_bandwidth among this session’s senders.

The session probes up to what the reservations add up to, through its transport’s Probe when it has one, so reserve here rather than on an allocator of your own. Clones share one registry: a Client::with_allocator allocator’s when the session was dialed with one, so reservations outlive a reconnect. Reservations report None when the transport has no estimate.

Source

pub fn recv_bandwidth(&self) -> Option<Consumer>

Returns a consumer for the estimated receive bitrate (from PROBE).

Holding the consumer requests PROBE; dropping the last one stops it. Returns None if the MoQ version doesn’t support PROBE (requires moq-lite-03+).

Source

pub fn viewers(&self) -> Viewers

Divides recv_bandwidth among the broadcasts watched over this session.

The session sends what the viewers add up to as its PROBE target, so a peer that advertised Increase probes the connection up to it. Holding a viewer requests PROBE. Clones share one registry: a Client::with_viewers registry’s when the session was dialed with one, so their claims outlive a reconnect, like allocator’s. Viewers taken here read this session’s estimate, and report None once it ends or when the version has no PROBE; take them from the reconnecting handle (moq_tokio::Connection::viewers) to read each new session’s.

Source

pub fn stats(&self) -> Stats

Returns a snapshot of the current connection statistics.

Cheap and non-blocking: this reads the latest sample the session’s driver took, and schedules a refresh, so periodic polling observes fresh counters (100ms cadence), and reads the session’s own counters live. See Stats for which metrics each backend reports.

Source

pub fn abort(&self, err: Error)

Close the transport with an explicit error, instead of waiting for the last clone to drop. Idempotent: the first abort wins, and it cuts short a close still draining.

The close is executed by the session’s driver, so it reaches the wire once the runtime polls it (immediately on a live runtime).

Source

pub async fn close(self) -> Result<(), Error>

Close the session after draining its queued data.

Waits until every stream still serving the peer (a subscription whose track finished, a fetch, a track info reply) has written its data and FIN and the transport acknowledged them, then closes the transport. Lite-05 and newer, including the default lite-06, also wait for the subscriber to receive a subscription’s tail. Older Lite versions and IETF wait only for transport ACKs. Returns Error::Timeout if that takes longer than one second, closing anyway, or the session’s terminal error if it ended some other way first. A track that is still live never finishes, so finish or abort tracks before closing.

Both protocols withdraw this session’s announcements and wait for their delivery.

Source

pub async fn closed(&self) -> Error

Block until the transport session is closed, returning the reason.

A close this side sent counts as closed once the transport confirms it, or after three round trips (at least 100ms) without that, since a peer that is gone may never let it; the transport keeps delivering the close in the background.

The driver keeps draining group streams already delivered to the transport after this resolves, so keep driving it until it completes.

A clean close is Error::Cancel, whichever side closed. A close code the peer sent is otherwise decoded through the session registry (so an auth rejection arrives as Error::Session(SessionError::Unauthorized)) and preserved as Error::Session. When the transport reports that this side closed it, this is this side’s reason: the abort error, or the protocol failure that ended the session. A close carrying no application code is otherwise Error::IdleTimeout for an idle timeout and Error::Transport for anything else. See Error::from_transport. If the runtime drops the driver instead of running it to completion, this resolves with Error::Cancel. A panic while polling the driver is a transport failure instead.

Source

pub fn goaway(&self, goaway: Goaway) -> Result<(), Error>

Drain the peer gracefully: send this session’s single GOAWAY.

The graceful counterpart to abort. Await closed afterwards to observe the peer leaving.

Only a Goaway carrying a timeout schedules a close of our own, so without one this waits for a peer that may never leave. Set a deadline when the drain has to finish. It starts at the driver poll this send wakes, so the session must stay driven for the message to reach the wire and for the deadline to close it.

Available on every version. A version with no GOAWAY message (moq-lite-03 and earlier) simply carries no explanation to the peer; the deadline is the sender’s own timer either way, so the session still closes on schedule and the caller does not branch on the negotiated version.

§Errors

Returns Error::ProtocolViolation when a client names a redirect URI, which the peer would be required to close the session over (draft-22 section 9.2), or when the URI exceeds the 8,192-byte wire cap.

Returns Error::Duplicate if this session already sent one. The wire carries at most one, so the second is dropped rather than replacing the first, but the caller is told rather than left guessing. A session that already closed has nothing left to drain, which is no error.

Source

pub fn draining(&self) -> Consumer

Observe a GOAWAY from the peer, telling us to migrate elsewhere.

poll it with a no-op waiter for a synchronous check, or wait on it for one. Once a GOAWAY arrives, this session’s routes rank as draining: below every eligible route of their claim that is not, whatever their preference or cost, though a more specific claim still shadows a broader one. Requests keep opening on it until a replacement session’s route outranks it, and existing subscriptions keep flowing until the session closes. A relay still forwards the routes at their real cost, and tells a moq-lite-07 peer they drain so it ranks them alike; an older version carries no drain, so its peers rank them as before.

Source

pub fn poll_idle(&self, waiter: &Waiter) -> Poll<()>

Ready once the session carries no subscription or fetch, in either direction.

Ready at once while it carries none. A track request still being set up, waiting on authorization or the track’s info, counts too. Announcements and the other control streams don’t, so a session can be idle while it still serves discovery. A session that sent a GOAWAY can then close without cutting any reader off.

Source

pub async fn idle(&self)

Ready once the session carries no subscription or fetch, in either direction.

Ready at once while it carries none. A track request still being set up, waiting on authorization or the track’s info, counts too. Announcements and the other control streams don’t, so a session can be idle while it still serves discovery. A session that sent a GOAWAY can then close without cutting any reader off.

Awaits poll_idle.

Source

pub fn liveness(&self) -> Option<Liveness>

Whether the peer was heard within the KeepAlive’s soft limit, or None when the session runs without one.

Source

pub fn poll_liveness_changed( &self, waiter: &Waiter, last: Liveness, ) -> Poll<Option<Liveness>>

Ready with the peer’s liveness once it differs from last, or None once the session ends or when it runs without a KeepAlive.

Source

pub async fn liveness_changed(&self, last: Liveness) -> Option<Liveness>

Ready with the peer’s liveness once it differs from last, or None once the session ends or when it runs without a KeepAlive.

Awaits poll_liveness_changed.

Source

pub fn auth(&self) -> Handle

The tokens this side presented and the grant they earned, plus the tokens the peer presents. See auth.

The handle passed to Client::with_auth, or else one this session created for itself, which ends with it.

On moq-lite-07-wip each side presents its connection’s credential right after setup. Older versions and moq-transport leave the grant None.

Trait Implementations§

Source§

impl Clone for Session

Source§

fn clone(&self) -> Self

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 Eq for Session

Source§

impl PartialEq for Session

Two handles are equal when they are clones of the same 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

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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