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
impl Session
Sourcepub async fn peer_implementation(&self) -> Option<String>
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.
Sourcepub fn send_bandwidth(&self) -> Option<Consumer>
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.
Sourcepub fn allocator(&self) -> Allocator
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.
Sourcepub fn recv_bandwidth(&self) -> Option<Consumer>
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+).
Sourcepub fn viewers(&self) -> Viewers
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.
Sourcepub fn stats(&self) -> Stats
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.
Sourcepub fn abort(&self, err: Error)
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).
Sourcepub async fn close(self) -> Result<(), Error>
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.
Sourcepub async fn closed(&self) -> Error
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.
Sourcepub fn goaway(&self, goaway: Goaway) -> Result<(), Error>
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.
Sourcepub fn draining(&self) -> Consumer
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.
Sourcepub fn poll_idle(&self, waiter: &Waiter) -> Poll<()>
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.
Sourcepub async fn idle(&self)
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.
Sourcepub fn liveness(&self) -> Option<Liveness>
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.
Sourcepub fn poll_liveness_changed(
&self,
waiter: &Waiter,
last: Liveness,
) -> Poll<Option<Liveness>>
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.
Sourcepub async fn liveness_changed(&self, last: Liveness) -> Option<Liveness>
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.
Sourcepub fn auth(&self) -> Handle
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§
Auto Trait Implementations§
impl Freeze for Session
impl RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnsafeUnpin 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§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.