Skip to main content

StreamContext

Struct StreamContext 

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

Encapsulates all state needed to produce a stream.

Created by an identified stream preparation API after the pinned hybrid post-quantum handshake, or by the explicitly named third-party interoperability DH edge. Contains everything needed to:

  • Return stream info to client (stream_id, server_pubkey)
  • Create a StreamPublisher for sending data

§Example

ⓘ
// In service handler:
let ctx = self.prepare_identified_stream(envelope_ctx, accepted_binding, 600).await?;

// Return to client:
let response = Response::stream_started(ctx.stream_id(), ctx.server_pubkey());

// After response sent, create publisher:
let mut publisher = StreamPublisher::new(&push_socket, &ctx)?;
publisher.publish_data(b"hello")?;
publisher.complete(b"{}")?;

Implementations§

Source§

impl StreamContext

Source

pub fn new( stream_id: String, topic: String, mac_key: [u8; 32], server_pubkey: [u8; 32], ) -> Self

Create a new stream context with pre-computed DH values.

Source

pub fn from_third_party_interop_dh( client_ephemeral_pubkey: &[u8], ) -> Result<Self>

Create a stream context for the explicitly named third-party interoperability edge by performing a classical DH key exchange.

Same-cell and federated callers must use Self::from_hybrid_identified instead. Keeping this constructor explicitly named prevents a verified HyKEM recipient from being silently downgraded to classical AEAD.

§Arguments
  • client_ephemeral_pubkey - Client’s ephemeral public key from request
§Returns

Stream context with DH-derived topic and mac_key

Source

pub fn from_hybrid_identified( client_kem_public: &[u8], binding: IdentifiedStreamBinding, ) -> Result<Self>

Create a stream context via the hybrid post-quantum handshake (S3 #554).

client_kem_public is the client’s encoded ephemeral RecipientPublic (from RequestEnvelope.clientKemPublic). The server encapsulates to it and derives the stream keys from the hybrid combiner secret; the per-component ciphertexts are stored in kem_ciphertexts for emission in StreamInfo.kemCiphertexts. Forward secrecy comes from the client’s ephemeral keypair (X25519 + ML-KEM legs).

Fail-closed: a malformed / wrong-suite client_kem_public is rejected. This is the required path for same-cell and federated callers with a verified identified-stream recipient.

Source

pub fn kem_ciphertexts(&self) -> Option<&[u8]>

The hybrid KEM ciphertexts to emit in StreamInfo.kemCiphertexts (S3 #554): Some on the hybrid path (from_hybrid_identified), None otherwise.

Source

pub fn stream_id(&self) -> &str

Get the stream ID (for logging/display).

Source

pub fn topic(&self) -> &str

Get the key-exchange-derived topic (for stream routing).

Source

pub fn mac_key(&self) -> &[u8; 32]

Get the MAC key (for HMAC chain).

Source

pub fn enc_key(&self) -> Option<&[u8; 32]>

Get the transport AEAD key (#321), if this is a keyed stream.

Some on identified hybrid and third-party interoperability streams (AEAD ON), None on the keyless new() path (payloads already E2E-encrypted at the app layer).

Source

pub fn without_aead(self) -> Self

Disable transport-level AEAD for this stream (#321).

Clears the AEAD key so a legacy publisher emits cleartext (HMAC-chained) blocks. Identified epoch contexts retain an internal profile marker and are rejected by MoqStreamOrigin::publisher if this escape hatch is used; it exists only for legacy same-host streams whose consumer receives (mac_key, topic) out of band and cannot derive the classical DH key.

Source

pub fn server_pubkey(&self) -> &[u8; 32]

Get the server’s ephemeral public key for the interoperability DH edge.

Source

pub fn ctrl_topic(&self) -> &str

Get the control channel topic.

Source

pub fn ctrl_mac_key(&self) -> &[u8; 32]

Get the control channel MAC key.

Source

pub fn cancel_token(&self) -> &CancellationToken

Get the cancellation token.

Source

pub fn with_qos_preset<Q: StreamOptPreset>(self) -> Self

Set the QoS options for this stream using a typed preset (#169).

Call with a preset ZST: .with_qos_preset::<Job>(), .with_qos_preset::<Pipe>().

Source

pub fn with_qos(self, qos: StreamOpt) -> Self

Set the QoS options for this stream from a runtime value (#169).

Source

pub fn qos(&self) -> &StreamOpt

Get the QoS options for this stream (#169).

Source

pub fn with_relay_choice(self, relay_choice: RelayChoice) -> Self

Set the per-stream relay choice (#384). Server-authored — never from a client request. Use crate::moq_stream::RelayChoice::Only for an anonymized relay-only stream, or Override for per-tenant isolation.

Source

pub fn relay_choice(&self) -> &RelayChoice

Get the per-stream relay choice (#384).

Source

pub fn with_reach_config(self, reach_config: ProducerReachConfig) -> Self

Thread an explicit per-server reach config into this stream (#384).

Supplies the per-server ProducerReachConfig for this stream, so the base (iroh/QUIC) reach this stream advertises is the server’s own — StreamChannel::prepare_identified_stream_with_claims and StreamChannel::prepare_third_party_interop_stream_with_claims apply their current service config before it returns the context.

Source

pub fn reach_config(&self) -> &ProducerReachConfig

Get this stream’s reach config (#384).

Source

pub fn reach(&self) -> Vec<Destination>

Build this stream’s StreamInfo.reach from the node’s per-server reach config and this stream’s relay_choice (#384).

A producer that holds a StreamContext calls this so the stream’s relay/anonymization posture and its base iroh/QUIC reach are honoured per-stream. Both come from the context’s own reach_config field — captured at construction (and overridable via with_reach_config) — so this no longer reads the process-global OnceLocks on each call.

Source

pub fn moql_server_identity(&self) -> MoqlServerIdentity

The server accepted-state witness carried with this signed StreamInfo. A missing witness decodes as the default and is rejected before a native Iroh admission exchange; it does not affect Quinn/UDS consumers.

Trait Implementations§

Source§

impl Clone for StreamContext

Source§

fn clone(&self) -> StreamContext

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ServiceExt for T

§

fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>
where Self: Sized,

Apply a transformation to the response body. Read more
§

fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using HTTP status codes. Read more
§

fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using gRPC headers. Read more
§

fn follow_redirects(self) -> FollowRedirect<Self>
where Self: Sized,

Follow redirect resposes using the Standard policy. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

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
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSync for T
where T: Sync,

§

impl<T> MaybeSync for T
where T: Sync,

Source§

impl<T> TerminalState for T
where T: Clone + Send + Sync,