Skip to main content

SubscriptionStateMachine

Struct SubscriptionStateMachine 

Source
pub struct SubscriptionStateMachine {
    state: SubscriptionState,
}
Expand description

Pure state machine for a MoQT subscription. Transitions: Idle -> Subscribing -> Active -> Done.

Fields§

§state: SubscriptionState

Implementations§

Source§

impl SubscriptionStateMachine

Source

pub fn on_subscribe_received(&mut self) -> Result<(), SubscriptionError>

Idle -> Subscribing (SUBSCRIBE received from the peer).

Source

pub fn on_subscribe_ok_sent(&mut self) -> Result<(), SubscriptionError>

Subscribing -> Active (SUBSCRIBE_OK written on the peer’s stream).

Source

pub fn on_subscribe_error_sent(&mut self) -> Result<(), SubscriptionError>

Subscribing -> Done (REQUEST_ERROR written on the peer’s stream).

Source

pub fn on_publish_done_sent(&mut self) -> Result<(), SubscriptionError>

Active -> Done (PUBLISH_DONE written on the peer’s stream).

Source§

impl SubscriptionStateMachine

Source

pub fn new() -> Self

Creates a new state machine in the SubscriptionState::Idle state.

Source

pub fn state(&self) -> SubscriptionState

Returns the current state of the subscription.

Source

pub fn on_subscribe_sent(&mut self) -> Result<(), SubscriptionError>

Idle -> Subscribing (SUBSCRIBE sent).

Source

pub fn on_subscribe_ok(&mut self) -> Result<(), SubscriptionError>

Subscribing -> Active (SUBSCRIBE_OK received).

Source

pub fn on_subscribe_error(&mut self) -> Result<(), SubscriptionError>

Subscribing -> Done (REQUEST_ERROR received).

Source

pub fn on_request_cancelled(&mut self) -> Result<(), SubscriptionError>

Subscribing | Active -> Done, Done -> Done (this subscription’s request stream was cancelled).

This draft has no UNSUBSCRIBE message. Section 3.3.3: “Once a request stream has been opened, the request MAY be cancelled by either endpoint.”

Subscribing is accepted because the precondition is the stream being open, and it is open from the SUBSCRIBE that opened it: a subscription can be withdrawn before it is ever answered.

Idle is refused, on the other half of the same sentence: nothing has been written, so there is no stream to terminate. Done stays Done — nothing finishes a request stream’s send half on the ordinary path, so a caller that walks away from a request that has already ended still resets the stream, and that reset is an ordinary end rather than a fault.

Source

pub fn on_subscribe_update(&mut self) -> Result<(), SubscriptionError>

REQUEST_UPDATE received – a self-transition, from Subscribing as well as from Active.

Section 10.9 orders an update against the request rather than against the request’s answer: the sender of a SUBSCRIBE “can later send a REQUEST_UPDATE on the same bidi stream as the request to modify it”, where later is later than the SUBSCRIBE. The stream is open from the moment the SUBSCRIBE opens it.

Draft-20 contemplates the case outright. Section 10.3.1.7 bounds how many REQUEST_UPDATEs may be outstanding on one request stream at a time, a limit that means nothing to a sender that waits for each answer before sending the next message.

So a peer that sends SUBSCRIBE and REQUEST_UPDATE back to back breaks no rule this draft states, and an update arriving before the answer leaves the subscription where it found it. Idle and Done are still refused: in neither does the subscription an update names exist.

Source

pub fn on_publish_done(&mut self) -> Result<(), SubscriptionError>

Active -> Done (PUBLISH_DONE received).

Trait Implementations§

Source§

impl Default for SubscriptionStateMachine

Source§

fn default() -> Self

Returns the “default value” for a type. 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more