Skip to main content

SubscriptionStateMachine

Struct SubscriptionStateMachine 

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

Pure state machine for a MoQT subscription (draft-07). Transitions: Idle → Subscribing → Active → Done.

Fields§

§state: SubscriptionState

Implementations§

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 (SUBSCRIBE_ERROR received).

Source

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

Active → Done (UNSUBSCRIBE sent).

Source

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

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

Section 6.5 orders an update against the subscription rather than against the subscription’s answer. All it asks of the identifier is that it already name something: “This MUST match an existing Subscribe ID” — and a Subscribe ID exists from the moment the SUBSCRIBE carrying it is sent, not from the moment it is answered.

So a peer that sends SUBSCRIBE and SUBSCRIBE_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_subscribe_done(&mut self) -> Result<(), SubscriptionError>

Active → Done (SUBSCRIBE_DONE received — publisher finished, and Done unchanged).

§Why Done is not refused

Because UNSUBSCRIBE is usually what put the subscription there, and this message is what a publisher is meant to answer one with. A subscriber that withdraws is told the subscription has ended, with a code saying it was its own doing — so on_unsubscribe followed by on_subscribe_done is the ordinary end of a subscription rather than a peer misbehaving.

Refusing the second half would make a conforming relay’s last message read as a protocol error against this endpoint’s own bookkeeping — an invalid transition from Done raised against this endpoint, not the relay, and so a wall rather than a finding about the peer.

Idle and Subscribing are still refused. In neither is there an active subscription for this message to end.

Source§

impl SubscriptionStateMachine

The same six transitions, named for the end that sees them.

A subscription this endpoint publishes runs through the states in the same order as one it subscribes to, with every message going the other way: the SUBSCRIBE arrives instead of leaving, the answer leaves instead of arriving. Sharing the transitions and not the names is what lets a refusal say which event was refused, rather than naming the mirror image of it.

Source

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

Idle -> Subscribing (SUBSCRIBE received from a subscribing peer).

Source

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

Subscribing -> Active (SUBSCRIBE_OK sent to the subscribing peer).

Source

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

Subscribing -> Done (SUBSCRIBE_ERROR sent to the subscribing peer).

Source

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

Active -> Done (UNSUBSCRIBE received from the subscribing peer).

Source

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

Active -> Done (SUBSCRIBE_DONE sent to the subscribing peer), and Done unchanged — this endpoint answers a peer’s UNSUBSCRIBE with this message, and the withdrawal it answers has already recorded the end. See SubscriptionStateMachine::on_subscribe_done, whose tolerance this inherits.

Source

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

Subscribing or Active, unchanged (SUBSCRIBE_UPDATE received from the subscribing peer).

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