Skip to main content

Module streaming

Module streaming 

Source
Expand description

Generic streaming infrastructure for authenticated PUB/SUB communication.

This module provides rate-controlled, MAC-authenticated streaming that works for both inference (UTF-8 tokens) and worker I/O (arbitrary binary data).

§Architecture

Producer                     Consumer
────────                     ────────
StreamChannel::publisher()   MoqStreamHandle::new()
      │                             │
      │ publish_data()              │ recv_next()
      ▼                             ▼
moq UDS track ──────────► StreamVerifier

§Wire Format

Moq track payload (binary): capnp StreamBlock + 16-byte truncated HMAC appended

§Security

  • DH key exchange: Ristretto255 ECDH derives topic + mac_key
  • MAC chain: Each block’s MAC depends on previous, enforces ordering

§Backend

  • Default: Blake3 keyed_hash() (~10+ GB/s with SIMD)
  • FIPS mode: HMAC-SHA256 (FIPS 198-1)

Re-exports§

pub use crate::stream_info::StreamInfo;
pub use crate::stream_consumer::StreamPayload;
pub use crate::stream_consumer::StreamVerifier;

Structs§

BatchingConfig
Configuration for adaptive batching (rate control).
ChannelProgressReporter
Channel-based progress sender for use with git2db or other progress-reporting operations.
ResponseStream
Wrapper type for streaming responses that coordinates the REP-before-PUB pattern.
StreamChannel
Service-level async streaming infrastructure that encapsulates socket management and stream pre-authorization.
StreamContext
Encapsulates all state needed to produce a stream.
StreamGuard
Codegen hook point for dispatch-level streaming continuation wrapping.
StreamHmacState
HMAC chain state for StreamBlock with 16-byte truncated MACs.

Enums§

ProgressUpdate
Progress update message for channel-based streaming.
StreamPayloadData
Input payload for StreamBuilder (what gets serialized).

Constants§

DEFAULT_MAX_CONCURRENT_STREAMS_PER_SERVICE
Default ceiling on concurrent server-side streaming responses per service — i.e. how many streaming RPCs one service may be actively pushing data for at once. Overridable via install_max_concurrent_streams_per_service (wired from ServerConfig::max_concurrent_streams_per_service).

Functions§

derive_client_stream_keys
Derive the (mac_key, enc_key, topic) triple from a client-side DH exchange (#321).
encode_stream_block
Encode a StreamBlock capnp message from a prev_mac + payload list.
encode_stream_block_with_provenance
Encode a StreamBlock with an optional per-host provenance signature (#321).
install_max_concurrent_streams_per_service
Install the per-service concurrent-streams cap. Call once at startup with ServerConfig::max_concurrent_streams_per_service. Values are clamped to a minimum of 1. Returns Err(existing) if already installed (first-write-wins).
progress_channel
Create a progress channel for streaming operations.
spawn_streaming_response
Spawn the server-side half of a streaming RPC — the task that keeps pushing data after the StreamInfo reply has been sent — onto the current LocalSet, bounded by a per-service admission permit.