Skip to main content

Handshake

Struct Handshake 

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

A paused server-side handshake.

Returned by Server::handshake once the peer’s advertised path is known but before the session is granted anything. Set the origins to serve, then call ok to complete the handshake, or close to reject it. Modeled on the WebTransport Request in moq-tokio.

Implementations§

Source§

impl Handshake

Source

pub fn path(&self) -> &str

The request path the client advertised in its SETUP.

Empty when the client advertised none: either it sent an empty path, or the version carries none in-band (lite 01-04). Those mean the same thing, so the wire distinction isn’t surfaced. Populated for moq-lite-05 and newer, and every moq-transport draft we speak. See the note on Server::handshake.

Source

pub fn role(&self) -> Option<Role>

The single Role the client advertised in its SETUP, or None for a bidirectional session.

Only moq-lite-05 and newer carry a role, so None covers three cases that the wire doesn’t distinguish: an older version, a client that omitted the parameter, and a client that explicitly advertised both directions. All three mean the same thing (the client may publish and subscribe), so authorize on what the token grants. See the note on Server::handshake.

Source

pub fn peer_node(&self) -> Option<NonZeroU64>

The identity the peer declared for itself, when the negotiated protocol carries one.

A moq-lite-05+ endpoint declares this when it attaches a publish or subscribe origin: its Hop ID, or from moq-lite-07 its Node ID. A moq-transport endpoint declares its Hop ID via the MoQ Cluster extension. Older versions and endpoints without one return None. origin::Producer::is_own tells whether it is ours.

Self-declared, so treat it as a correlation hint rather than an authenticated identity: authorize on the token or client certificate.

Source

pub fn peer_implementation(&self) -> Option<&str>

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

None when it advertised none or its version carries no SETUP (moq-lite 01-04), which in practice means it predates the parameter. Peer-controlled: use it for logs and rollout counts, never to authorize.

Source

pub fn auth(&self) -> Handle

The session’s auth handle, the same one Session::auth returns once accepted.

Source

pub fn requests(&mut self) -> Requests

Answer every token the client presents yourself, instead of the default acceptor: on its own AUTH stream, or riding one of its moq-transport SUBSCRIBE or PUBLISH_NAMESPACE requests as an AUTHORIZATION TOKEN.

Without it the session grants the client what its own origin handles allow for the connection’s credential, and refuses any other token as unsupported, along with the request that carried it. A later call hands the queue to the new auth::Requests, ending the earlier one.

The client’s credit bounds how many tokens wait unanswered: each AUTH token holds its stream open, and each request token holds its request’s slot, until it is answered or withdrawn. A withdrawn token leaves the queue.

Source

pub fn token(&self) -> Option<&Token>

The connection credential the client presented in its SETUP: moq-transport’s AUTHORIZATION TOKEN option, or moq-lite-07’s Token parameter.

Older moq-lite versions carry none, so they return None. The transport has not verified it: authorize on it the way you would a URL token.

Source

pub fn with_publisher(self, publish: impl Consume<Consumer>) -> Self

Publish to the connected client. Overrides any value from the Server builder; typically set after inspecting path.

Source

pub fn with_subscriber(self, subscribe: Producer) -> Self

Subscribe to the connected client. Overrides any value from the Server builder.

Source

pub fn with_peer_node(self, node: NonZeroU64) -> Self

Assign the hop id this peer’s routes are attributed to, overriding the fresh per-session default.

Only for a peer whose identity the server has actually established, such as one authenticated by mTLS or a token (crate::Client::with_peer_node is the dialing-side equivalent). An identity the peer declares on the wire still wins.

Two sessions given the same origin are treated as one endpoint: routes learned from either are kept off both, and content arriving on either is interchangeable with the other’s. That is the point when they really are one peer reconnecting or running redundant links, and a bug otherwise. Derive it from the authenticated identity, never from something coarser like the remote address.

Source

pub fn with_stats(self, stats: Session) -> Self

Set the per-connection stats::Session context. Overrides any value from the Server builder.

Source

pub fn with_limits(self, limits: Limits) -> Self

Set the session’s limits after authorizing the peer and before answering SETUP.

Source

pub fn with_keep_alive(self, keep_alive: KeepAlive) -> Self

Run keep_alive on this session. Overrides any value from the Server builder; see Server::with_keep_alive.

Source

pub fn with_cost(self, cost: impl Into<Cost>) -> Self

Price this session’s link; see Server::with_cost. Overrides any value from the Server builder, so a server can price a peer once it knows who it is.

Source

pub fn with_receive_window(self, window: NonZeroU64) -> Self

Open the receive window to window on ok. Overrides any value from the Server builder; see Server::with_receive_window.

Source

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

Resolve once the accept deadline passes, having refused the session with Error::Timeout; never, without a deadline.

Race the admission decision against it, so a peer cannot hold the connection open behind a decision that never comes. Once it resolves, ok fails with the timeout.

Source

pub async fn expired(&mut self)

Resolve once the accept deadline passes, having refused the session with Error::Timeout; never, without a deadline.

Race the admission decision against it, so a peer cannot hold the connection open behind a decision that never comes. Once it resolves, ok fails with the timeout.

Awaits poll_expired.

Source

pub async fn ok(self) -> Result<(Session, Driver), Error>

Accept the session, returning the Session and its Driver.

Opens the receive window first (with_receive_window). Fails with Error::Timeout once the accept deadline passes, whether admission or a moq-lite 01/02 peer that never takes the SETUP reply ran it out. Dropping a pending ok refuses the session the same way, so a caller’s own deadline counts too.

Poll or spawn the returned driver to run the session.

Source

pub fn close(self, err: Error)

Reject the session, closing the transport with err’s wire code. Does nothing once the deadline refused it.

Trait Implementations§

Source§

impl Drop for Handshake

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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> 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, 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