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
StreamPublisherfor 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
impl StreamContext
Sourcepub fn new(
stream_id: String,
topic: String,
mac_key: [u8; 32],
server_pubkey: [u8; 32],
) -> Self
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.
Sourcepub fn from_third_party_interop_dh(
client_ephemeral_pubkey: &[u8],
) -> Result<Self>
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
Sourcepub fn from_hybrid_identified(
client_kem_public: &[u8],
binding: IdentifiedStreamBinding,
) -> Result<Self>
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.
Sourcepub fn kem_ciphertexts(&self) -> Option<&[u8]>
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.
Sourcepub fn enc_key(&self) -> Option<&[u8; 32]>
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).
Sourcepub fn without_aead(self) -> Self
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.
Sourcepub fn server_pubkey(&self) -> &[u8; 32]
pub fn server_pubkey(&self) -> &[u8; 32]
Get the server’s ephemeral public key for the interoperability DH edge.
Sourcepub fn ctrl_topic(&self) -> &str
pub fn ctrl_topic(&self) -> &str
Get the control channel topic.
Sourcepub fn ctrl_mac_key(&self) -> &[u8; 32]
pub fn ctrl_mac_key(&self) -> &[u8; 32]
Get the control channel MAC key.
Sourcepub fn cancel_token(&self) -> &CancellationToken
pub fn cancel_token(&self) -> &CancellationToken
Get the cancellation token.
Sourcepub fn with_qos_preset<Q: StreamOptPreset>(self) -> Self
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>().
Sourcepub fn with_qos(self, qos: StreamOpt) -> Self
pub fn with_qos(self, qos: StreamOpt) -> Self
Set the QoS options for this stream from a runtime value (#169).
Sourcepub fn with_relay_choice(self, relay_choice: RelayChoice) -> Self
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.
Sourcepub fn relay_choice(&self) -> &RelayChoice
pub fn relay_choice(&self) -> &RelayChoice
Get the per-stream relay choice (#384).
Sourcepub fn with_reach_config(self, reach_config: ProducerReachConfig) -> Self
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.
Sourcepub fn reach_config(&self) -> &ProducerReachConfig
pub fn reach_config(&self) -> &ProducerReachConfig
Get this stream’s reach config (#384).
Sourcepub fn reach(&self) -> Vec<Destination>
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.
Sourcepub fn moql_server_identity(&self) -> MoqlServerIdentity
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
impl Clone for StreamContext
Source§fn clone(&self) -> StreamContext
fn clone(&self) -> StreamContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for StreamContext
impl !RefUnwindSafe for StreamContext
impl Send for StreamContext
impl Sync for StreamContext
impl Unpin for StreamContext
impl UnsafeUnpin for StreamContext
impl !UnwindSafe for StreamContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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