pub struct Endpoint {Show 16 fields
session: SessionStateMachine,
request_ids: RequestIdAllocator,
advertised_max_id: u64,
subscriptions: HashMap<u64, SubscriptionStateMachine>,
fetches: HashMap<u64, FetchStateMachine>,
subscribe_namespaces: HashMap<u64, SubscribeAnnouncesStateMachine>,
announces: HashMap<u64, AnnounceStateMachine>,
announce_ids: HashMap<Vec<Vec<u8>>, u64>,
subscribe_namespace_ids: HashMap<Vec<Vec<u8>>, u64>,
track_statuses: HashMap<u64, TrackStatusStateMachine>,
subscribe_track_aliases: HashMap<u64, VarInt>,
inbound_publishes: HashMap<u64, Publish>,
negotiated_version: Option<VarInt>,
offered_versions: Vec<VarInt>,
goaway_uri: Option<Vec<u8>>,
peer_reported_max_request_id: Option<VarInt>,
}Expand description
Unified draft-13 MoQT endpoint wrapping session lifecycle, request ID allocation, and all per-flow state machines (subscriptions, fetches, announces, subscribe-namespaces, track statuses).
Fields§
§session: SessionStateMachine§request_ids: RequestIdAllocator§advertised_max_id: u64Tracks the MAX_REQUEST_ID we have advertised to the peer.
subscriptions: HashMap<u64, SubscriptionStateMachine>§fetches: HashMap<u64, FetchStateMachine>§subscribe_namespaces: HashMap<u64, SubscribeAnnouncesStateMachine>§announces: HashMap<u64, AnnounceStateMachine>§announce_ids: HashMap<Vec<Vec<u8>>, u64>Maps namespace tuple -> request_id, so callers can UNANNOUNCE / cancel by namespace without threading the id through every API.
subscribe_namespace_ids: HashMap<Vec<Vec<u8>>, u64>Maps namespace prefix tuple -> request_id for subscribe-namespaces.
track_statuses: HashMap<u64, TrackStatusStateMachine>§subscribe_track_aliases: HashMap<u64, VarInt>Track aliases assigned by the publisher in SUBSCRIBE_OK, keyed by the subscriber-chosen request id.
inbound_publishes: HashMap<u64, Publish>Inbound PUBLISH requests received from the peer, keyed by their request id. Tracked so the application can respond with PUBLISH_OK / PUBLISH_ERROR using the correct id.
negotiated_version: Option<VarInt>§offered_versions: Vec<VarInt>§goaway_uri: Option<Vec<u8>>§peer_reported_max_request_id: Option<VarInt>The most recent maximum_request_id reported by the peer via a
REQUESTS_BLOCKED message.
Implementations§
Source§impl Endpoint
impl Endpoint
Sourcepub fn session_state(&self) -> SessionState
pub fn session_state(&self) -> SessionState
Returns the current session state.
Sourcepub fn negotiated_version(&self) -> Option<VarInt>
pub fn negotiated_version(&self) -> Option<VarInt>
Returns the negotiated MoQT version, if setup is complete.
Sourcepub fn goaway_uri(&self) -> Option<&[u8]>
pub fn goaway_uri(&self) -> Option<&[u8]>
Returns the URI from a received GOAWAY message, if any.
Sourcepub fn is_blocked(&self) -> bool
pub fn is_blocked(&self) -> bool
Returns whether this endpoint is blocked on request ID allocation.
Sourcepub fn active_subscription_count(&self) -> usize
pub fn active_subscription_count(&self) -> usize
Returns the number of active subscription state machines.
Sourcepub fn active_fetch_count(&self) -> usize
pub fn active_fetch_count(&self) -> usize
Returns the number of active fetch state machines.
Sourcepub fn active_subscribe_namespace_count(&self) -> usize
pub fn active_subscribe_namespace_count(&self) -> usize
Returns the number of active subscribe-namespace state machines.
Sourcepub fn active_announce_count(&self) -> usize
pub fn active_announce_count(&self) -> usize
Returns the number of active announce state machines.
Sourcepub fn active_track_status_count(&self) -> usize
pub fn active_track_status_count(&self) -> usize
Returns the number of active track status state machines.
Sourcepub fn connect(&mut self) -> Result<(), EndpointError>
pub fn connect(&mut self) -> Result<(), EndpointError>
Transition from Connecting to SetupExchange.
Sourcepub fn close(&mut self) -> Result<(), EndpointError>
pub fn close(&mut self) -> Result<(), EndpointError>
Close the session (Active or Draining -> Closed).
Sourcepub fn send_client_setup(
&mut self,
versions: Vec<VarInt>,
parameters: Vec<KeyValuePair>,
) -> Result<ControlMessage, EndpointError>
pub fn send_client_setup( &mut self, versions: Vec<VarInt>, parameters: Vec<KeyValuePair>, ) -> Result<ControlMessage, EndpointError>
Generate a CLIENT_SETUP message (client-side).
Sourcepub fn receive_server_setup(
&mut self,
msg: &ServerSetup,
) -> Result<(), EndpointError>
pub fn receive_server_setup( &mut self, msg: &ServerSetup, ) -> Result<(), EndpointError>
Process a SERVER_SETUP message (client-side). Transitions to Active. If the server includes a MAX_REQUEST_ID parameter (key 0x02), the request ID allocator is initialized with that value.
Sourcepub fn receive_client_setup_and_respond(
&mut self,
client_setup: &ClientSetup,
selected_version: VarInt,
) -> Result<ControlMessage, EndpointError>
pub fn receive_client_setup_and_respond( &mut self, client_setup: &ClientSetup, selected_version: VarInt, ) -> Result<ControlMessage, EndpointError>
Process CLIENT_SETUP and generate SERVER_SETUP (server-side).
Sourcepub fn receive_max_request_id(
&mut self,
msg: &MaxRequestId,
) -> Result<(), EndpointError>
pub fn receive_max_request_id( &mut self, msg: &MaxRequestId, ) -> Result<(), EndpointError>
Process an incoming MAX_REQUEST_ID message.
Sourcepub fn send_max_request_id(
&mut self,
max_id: VarInt,
) -> Result<ControlMessage, EndpointError>
pub fn send_max_request_id( &mut self, max_id: VarInt, ) -> Result<ControlMessage, EndpointError>
Generate a MAX_REQUEST_ID message (typically server-side). The value must strictly increase over previous sends.
Sourcepub fn receive_goaway(&mut self, msg: &GoAway) -> Result<(), EndpointError>
pub fn receive_goaway(&mut self, msg: &GoAway) -> Result<(), EndpointError>
Process an incoming GOAWAY message. Transitions to Draining.
fn require_active_or_err(&self) -> Result<(), EndpointError>
Sourcepub fn subscribe(
&mut self,
track_namespace: TrackNamespace,
track_name: Vec<u8>,
subscriber_priority: u8,
group_order: VarInt,
filter_type: VarInt,
) -> Result<(VarInt, ControlMessage), EndpointError>
pub fn subscribe( &mut self, track_namespace: TrackNamespace, track_name: Vec<u8>, subscriber_priority: u8, group_order: VarInt, filter_type: VarInt, ) -> Result<(VarInt, ControlMessage), EndpointError>
Send a SUBSCRIBE message. Allocates a request ID and creates a
subscription state machine. The filter_type must be a valid
varint filter-type discriminant (see the draft-13 codec for
definitions). LargestObject (2) is a reasonable default.
Draft-13 note: the track alias is no longer chosen by the subscriber
— it is returned by the publisher in SUBSCRIBE_OK. Callers that
need the alias should inspect track_alias_for after the OK arrives.
Sourcepub fn receive_subscribe_ok(
&mut self,
msg: &SubscribeOk,
) -> Result<(), EndpointError>
pub fn receive_subscribe_ok( &mut self, msg: &SubscribeOk, ) -> Result<(), EndpointError>
Process an incoming SUBSCRIBE_OK.
Draft-13 carries the publisher-assigned track_alias on SUBSCRIBE_OK,
which is recorded here so callers can retrieve it via
Endpoint::track_alias_for.
Sourcepub fn track_alias_for(&self, request_id: VarInt) -> Option<VarInt>
pub fn track_alias_for(&self, request_id: VarInt) -> Option<VarInt>
Returns the publisher-assigned track alias for a subscription, if SUBSCRIBE_OK has been processed for the given request id.
Sourcepub fn receive_subscribe_error(
&mut self,
msg: &SubscribeError,
) -> Result<(), EndpointError>
pub fn receive_subscribe_error( &mut self, msg: &SubscribeError, ) -> Result<(), EndpointError>
Process an incoming SUBSCRIBE_ERROR.
Sourcepub fn unsubscribe(
&mut self,
request_id: VarInt,
) -> Result<ControlMessage, EndpointError>
pub fn unsubscribe( &mut self, request_id: VarInt, ) -> Result<ControlMessage, EndpointError>
Send an UNSUBSCRIBE message for an active subscription.
Sourcepub fn receive_subscribe_update(
&mut self,
msg: &SubscribeUpdate,
) -> Result<(), EndpointError>
pub fn receive_subscribe_update( &mut self, msg: &SubscribeUpdate, ) -> Result<(), EndpointError>
Process an incoming SUBSCRIBE_UPDATE.
Sourcepub fn receive_subscribe_done(
&mut self,
msg: &SubscribeDone,
) -> Result<(), EndpointError>
pub fn receive_subscribe_done( &mut self, msg: &SubscribeDone, ) -> Result<(), EndpointError>
Process an incoming SUBSCRIBE_DONE (subscriber side — publisher finished).
Sourcepub fn fetch(
&mut self,
track_namespace: TrackNamespace,
track_name: Vec<u8>,
subscriber_priority: u8,
group_order: VarInt,
start_group: VarInt,
start_object: VarInt,
end_group: VarInt,
end_object: VarInt,
) -> Result<(VarInt, ControlMessage), EndpointError>
pub fn fetch( &mut self, track_namespace: TrackNamespace, track_name: Vec<u8>, subscriber_priority: u8, group_order: VarInt, start_group: VarInt, start_object: VarInt, end_group: VarInt, end_object: VarInt, ) -> Result<(VarInt, ControlMessage), EndpointError>
Send a standalone FETCH message. Allocates a request ID and creates a fetch state machine.
Sourcepub fn joining_fetch(
&mut self,
subscriber_priority: u8,
group_order: VarInt,
fetch_type: FetchType,
joining_subscribe_id: VarInt,
joining_start: VarInt,
) -> Result<(VarInt, ControlMessage), EndpointError>
pub fn joining_fetch( &mut self, subscriber_priority: u8, group_order: VarInt, fetch_type: FetchType, joining_subscribe_id: VarInt, joining_start: VarInt, ) -> Result<(VarInt, ControlMessage), EndpointError>
Send a joining FETCH message that attaches to an existing subscription.
Allocates a new request ID for the fetch and tracks it in its own
fetch state machine. joining_start is interpreted per fetch_type
(relative offset vs absolute group id).
Sourcepub fn receive_fetch_ok(&mut self, msg: &FetchOk) -> Result<(), EndpointError>
pub fn receive_fetch_ok(&mut self, msg: &FetchOk) -> Result<(), EndpointError>
Process an incoming FETCH_OK.
Sourcepub fn receive_fetch_error(
&mut self,
msg: &FetchError,
) -> Result<(), EndpointError>
pub fn receive_fetch_error( &mut self, msg: &FetchError, ) -> Result<(), EndpointError>
Process an incoming FETCH_ERROR.
Sourcepub fn fetch_cancel(
&mut self,
request_id: VarInt,
) -> Result<ControlMessage, EndpointError>
pub fn fetch_cancel( &mut self, request_id: VarInt, ) -> Result<ControlMessage, EndpointError>
Send a FETCH_CANCEL message.
Sourcepub fn on_fetch_stream_fin(
&mut self,
request_id: VarInt,
) -> Result<(), EndpointError>
pub fn on_fetch_stream_fin( &mut self, request_id: VarInt, ) -> Result<(), EndpointError>
Notify that a fetch data stream received FIN.
Sourcepub fn on_fetch_stream_reset(
&mut self,
request_id: VarInt,
) -> Result<(), EndpointError>
pub fn on_fetch_stream_reset( &mut self, request_id: VarInt, ) -> Result<(), EndpointError>
Notify that a fetch data stream was reset.
Sourcepub fn subscribe_namespace(
&mut self,
track_namespace_prefix: TrackNamespace,
) -> Result<(VarInt, ControlMessage), EndpointError>
pub fn subscribe_namespace( &mut self, track_namespace_prefix: TrackNamespace, ) -> Result<(VarInt, ControlMessage), EndpointError>
Send a SUBSCRIBE_NAMESPACE message. Returns the allocated request ID alongside the control message so the caller can correlate replies.
Sourcepub fn receive_subscribe_namespace_ok(
&mut self,
msg: &SubscribeNamespaceOk,
) -> Result<(), EndpointError>
pub fn receive_subscribe_namespace_ok( &mut self, msg: &SubscribeNamespaceOk, ) -> Result<(), EndpointError>
Process an incoming SUBSCRIBE_NAMESPACE_OK.
Sourcepub fn receive_subscribe_namespace_error(
&mut self,
msg: &SubscribeNamespaceError,
) -> Result<(), EndpointError>
pub fn receive_subscribe_namespace_error( &mut self, msg: &SubscribeNamespaceError, ) -> Result<(), EndpointError>
Process an incoming SUBSCRIBE_NAMESPACE_ERROR.
Sourcepub fn unsubscribe_namespace(
&mut self,
track_namespace_prefix: TrackNamespace,
) -> Result<ControlMessage, EndpointError>
pub fn unsubscribe_namespace( &mut self, track_namespace_prefix: TrackNamespace, ) -> Result<ControlMessage, EndpointError>
Send an UNSUBSCRIBE_NAMESPACE message.
Sourcepub fn announce(
&mut self,
track_namespace: TrackNamespace,
) -> Result<(VarInt, ControlMessage), EndpointError>
pub fn announce( &mut self, track_namespace: TrackNamespace, ) -> Result<(VarInt, ControlMessage), EndpointError>
Send an ANNOUNCE message. Returns the allocated request ID alongside the control message.
Sourcepub fn receive_announce_ok(
&mut self,
msg: &AnnounceOk,
) -> Result<(), EndpointError>
pub fn receive_announce_ok( &mut self, msg: &AnnounceOk, ) -> Result<(), EndpointError>
Process an incoming ANNOUNCE_OK.
Sourcepub fn receive_announce_error(
&mut self,
msg: &AnnounceError,
) -> Result<(), EndpointError>
pub fn receive_announce_error( &mut self, msg: &AnnounceError, ) -> Result<(), EndpointError>
Process an incoming ANNOUNCE_ERROR.
Sourcepub fn receive_announce_cancel(
&mut self,
msg: &AnnounceCancel,
) -> Result<(), EndpointError>
pub fn receive_announce_cancel( &mut self, msg: &AnnounceCancel, ) -> Result<(), EndpointError>
Process an incoming ANNOUNCE_CANCEL.
Sourcepub fn unannounce(
&mut self,
track_namespace: TrackNamespace,
) -> Result<ControlMessage, EndpointError>
pub fn unannounce( &mut self, track_namespace: TrackNamespace, ) -> Result<ControlMessage, EndpointError>
Send an UNANNOUNCE message (publisher withdrawing).
Sourcepub fn track_status_request(
&mut self,
track_namespace: TrackNamespace,
track_name: Vec<u8>,
subscriber_priority: u8,
group_order: VarInt,
forward: VarInt,
filter_type: VarInt,
) -> Result<(VarInt, ControlMessage), EndpointError>
pub fn track_status_request( &mut self, track_namespace: TrackNamespace, track_name: Vec<u8>, subscriber_priority: u8, group_order: VarInt, forward: VarInt, filter_type: VarInt, ) -> Result<(VarInt, ControlMessage), EndpointError>
Send a TRACK_STATUS message (draft-13: subscribe-like request). Returns the allocated request ID alongside the control message.
Sourcepub fn receive_track_status_ok(
&mut self,
msg: &TrackStatusOk,
) -> Result<(), EndpointError>
pub fn receive_track_status_ok( &mut self, msg: &TrackStatusOk, ) -> Result<(), EndpointError>
Process an incoming TRACK_STATUS_OK reply (draft-13).
Sourcepub fn receive_track_status_error(
&mut self,
msg: &TrackStatusErrorMsg,
) -> Result<(), EndpointError>
pub fn receive_track_status_error( &mut self, msg: &TrackStatusErrorMsg, ) -> Result<(), EndpointError>
Process an incoming TRACK_STATUS_ERROR reply (draft-13).
Sourcepub fn receive_requests_blocked(
&mut self,
msg: &RequestsBlocked,
) -> Result<(), EndpointError>
pub fn receive_requests_blocked( &mut self, msg: &RequestsBlocked, ) -> Result<(), EndpointError>
Process an incoming REQUESTS_BLOCKED message.
The peer explicitly reports that a new request id would exceed our
advertised maximum. The endpoint records the peer’s reported maximum;
acting on it (issuing a new MAX_REQUEST_ID) is up to the caller.
Sourcepub fn peer_reported_max_request_id(&self) -> Option<VarInt>
pub fn peer_reported_max_request_id(&self) -> Option<VarInt>
The maximum request id that the peer most recently reported in a
REQUESTS_BLOCKED message, if any.
Sourcepub fn receive_publish(&mut self, msg: &Publish) -> Result<(), EndpointError>
pub fn receive_publish(&mut self, msg: &Publish) -> Result<(), EndpointError>
Process an incoming PUBLISH message. The message is recorded so the
application can respond with Endpoint::send_publish_ok or
Endpoint::send_publish_error using the same request id. This is a
pass-through: no full state machine is modelled here — the codec
struct carries everything the application needs to decide.
Sourcepub fn pending_publish(&self, request_id: VarInt) -> Option<&Publish>
pub fn pending_publish(&self, request_id: VarInt) -> Option<&Publish>
Returns the inbound PUBLISH message for a given request id, if any.
Sourcepub fn pending_publish_count(&self) -> usize
pub fn pending_publish_count(&self) -> usize
Number of PUBLISH requests received but not yet responded to.
Sourcepub fn send_publish_ok(
&mut self,
request_id: VarInt,
forward: VarInt,
subscriber_priority: u8,
group_order: VarInt,
filter_type: VarInt,
start_group: Option<VarInt>,
start_object: Option<VarInt>,
end_group: Option<VarInt>,
) -> Result<ControlMessage, EndpointError>
pub fn send_publish_ok( &mut self, request_id: VarInt, forward: VarInt, subscriber_priority: u8, group_order: VarInt, filter_type: VarInt, start_group: Option<VarInt>, start_object: Option<VarInt>, end_group: Option<VarInt>, ) -> Result<ControlMessage, EndpointError>
Generate a PUBLISH_OK response for a previously received PUBLISH. Removes the pending publish entry on success.
Sourcepub fn send_publish_error(
&mut self,
request_id: VarInt,
error_code: VarInt,
reason_phrase: Vec<u8>,
) -> Result<ControlMessage, EndpointError>
pub fn send_publish_error( &mut self, request_id: VarInt, error_code: VarInt, reason_phrase: Vec<u8>, ) -> Result<ControlMessage, EndpointError>
Generate a PUBLISH_ERROR response for a previously received PUBLISH. Removes the pending publish entry on success.
Sourcepub fn receive_publish_ok(
&mut self,
_msg: &PublishOk,
) -> Result<(), EndpointError>
pub fn receive_publish_ok( &mut self, _msg: &PublishOk, ) -> Result<(), EndpointError>
Process an incoming PUBLISH_OK (publisher side — peer accepted our PUBLISH offer). Pass-through: no state machine is currently modelled.
Sourcepub fn receive_publish_error(
&mut self,
_msg: &PublishError,
) -> Result<(), EndpointError>
pub fn receive_publish_error( &mut self, _msg: &PublishError, ) -> Result<(), EndpointError>
Process an incoming PUBLISH_ERROR (publisher side — peer rejected our PUBLISH offer). Pass-through: no state machine is currently modelled.
Sourcepub fn receive_message(
&mut self,
msg: ControlMessage,
) -> Result<(), EndpointError>
pub fn receive_message( &mut self, msg: ControlMessage, ) -> Result<(), EndpointError>
Dispatch an incoming control message to the appropriate handler.