Skip to content
14 changes: 9 additions & 5 deletions doc/bin/relay/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,12 @@ subscribe = []

## Auth server

Upgrade auth servers before relays when adopting the `webtransport` transport value.
Upgrade auth servers before relays when adopting the `webtransport` or `tls` transport value.
WebTransport sessions report `webtransport`; native QUIC sessions report `quic`.
Older auth servers reject the new value. Updated Rust and JavaScript auth parsers
map future transport names to `unknown`, which your policy should handle explicitly.
`tls://` sessions report `tls`; plaintext `tcp://` sessions report `tcp`.
An auth server built before `tls` existed does not fail to parse it: the Rust and JavaScript
parsers read an unrecognized transport name as `unknown`, so admission then depends on how your
policy treats `unknown`. Update any policy keyed on `tcp` for stream links to handle `tls` too.

`moq auth serve` is the reference auth server, answering the contract above.

Expand Down Expand Up @@ -517,8 +519,10 @@ so count sessions only on the others. See

The plaintext TCP and Unix-socket listeners are admitted exactly like QUIC:
the path and query ride the `SETUP` (`tcp://127.0.0.1:4444/room?jwt=...`) and
reach the auth server with `transport` set to `tcp` or `unix`. A Unix socket
can also require a specific uid, gid, or pid:
reach the auth server with `transport` set to `tcp` or `unix`. A `tls://` link
(below) reports `tls`, so a policy keyed on `transport == "tcp"` for cluster
links over TLS now sees `"tls"`. A Unix socket can also require a specific uid,
gid, or pid:

```toml
[listen.unix]
Expand Down
2 changes: 2 additions & 0 deletions go/wrapper/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const (
TransportWebSocket = ffi.MoqTransportWebSocket
// TransportTCP is a session that arrived over a plaintext TCP connection.
TransportTCP = ffi.MoqTransportTcp
// TransportTLS is a session that arrived over a TCP connection inside TLS (a tls:// link).
TransportTLS = ffi.MoqTransportTls
// TransportUnix is a session that arrived over a Unix domain socket.
TransportUnix = ffi.MoqTransportUnix
// TransportWebTransport is a session that arrived over WebTransport (HTTP/3).
Expand Down
5 changes: 5 additions & 0 deletions js/auth/api/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ export const RequestSchema: ZodMiniDiscriminatedUnion<[ZodMiniObject<{
rtmp: "rtmp";
srt: "srt";
tcp: "tcp";
tls: "tls";
unix: "unix";
unknown: "unknown";
webrtc: "webrtc";
Expand Down Expand Up @@ -680,6 +681,7 @@ export const RequestSchema: ZodMiniDiscriminatedUnion<[ZodMiniObject<{
rtmp: "rtmp";
srt: "srt";
tcp: "tcp";
tls: "tls";
unix: "unix";
unknown: "unknown";
webrtc: "webrtc";
Expand Down Expand Up @@ -721,6 +723,7 @@ export const RequestSchema: ZodMiniDiscriminatedUnion<[ZodMiniObject<{
rtmp: "rtmp";
srt: "srt";
tcp: "tcp";
tls: "tls";
unix: "unix";
unknown: "unknown";
webrtc: "webrtc";
Expand Down Expand Up @@ -768,6 +771,7 @@ export const RequestSchema: ZodMiniDiscriminatedUnion<[ZodMiniObject<{
rtmp: "rtmp";
srt: "srt";
tcp: "tcp";
tls: "tls";
unix: "unix";
unknown: "unknown";
webrtc: "webrtc";
Expand Down Expand Up @@ -828,6 +832,7 @@ export const TransportSchema: ZodMiniPipe<ZodMiniString<string>, ZodMiniCatch<Zo
rtmp: "rtmp";
srt: "srt";
tcp: "tcp";
tls: "tls";
unix: "unix";
unknown: "unknown";
webrtc: "webrtc";
Expand Down
2 changes: 1 addition & 1 deletion js/auth/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const TierSchema = z.string().check(z.regex(/^([A-Za-z0-9._-]+(\/[A-Za-z0-9._-]+
export const TransportSchema = z.pipe(
z.string(),
z.catch(
z.enum(["quic", "websocket", "tcp", "unix", "http", "rtmp", "srt", "webrtc", "webtransport", "unknown"]),
z.enum(["quic", "websocket", "tcp", "tls", "unix", "http", "rtmp", "srt", "webrtc", "webtransport", "unknown"]),
"unknown",
),
);
Expand Down
6 changes: 6 additions & 0 deletions js/auth/src/interop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ describe("Rust-serialized contract", () => {
expect(request.reason).toBe("invalid");
});

test("parse the stream link transports from Rust", () => {
for (const transport of ["tcp", "tls"] as const) {
expect(RequestSchema.parse({ ...JSON.parse(RUST_REQUEST), transport }).transport).toBe(transport);
}
});

test("parse gateway transports and stable end reasons from Rust", () => {
for (const transport of ["rtmp", "srt", "webrtc"] as const) {
for (const reason of ["narrowed", "shutdown"]) {
Expand Down
3 changes: 1 addition & 2 deletions js/net/src/connection/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,7 @@ async function dialRace(
protocols: offered.alpns,
versions: Object.fromEntries(offered.alpns.map((alpn) => [alpn, QMUX[alpn] ?? null])),
config: {
maxStreamsBidi: maxStreams,
maxStreamsUni: maxStreams,
maxStreams,
receiveWindow: BigInt(props.websocket?.receiveWindow ?? DEFAULT_RECEIVE_WINDOW),
streamReceiveWindow: BigInt(
props.websocket?.streamReceiveWindow ?? DEFAULT_STREAM_RECEIVE_WINDOW,
Expand Down
12 changes: 6 additions & 6 deletions js/net/src/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2979,9 +2979,10 @@ test.each([Lite.ALPN_06, Lite.ALPN_07_WIP, Ietf.ALPN.DRAFT_22])(
30_000,
);

// A qmux session pair negotiating `protocol` over an in-memory socket, each side granting the other
// `maxStreamsUni` unidirectional streams.
function qmuxPair(protocol: string, maxStreamsUni: bigint): { client: Qmux; server: Qmux } {
// A qmux session pair negotiating `protocol` over an in-memory socket, the client letting the server
// open `maxStreams` streams of each kind. The client opens every bidirectional stream, so a small limit
// bounds only the server's group streams.
function qmuxPair(protocol: string, maxStreams: bigint): { client: Qmux; server: Qmux } {
const socket = (readable: ReadableStream<Uint8Array>, writable: WritableStream<Uint8Array>) => {
const closed = Promise.withResolvers<{ closeCode: number; reason: string }>();
return {
Expand All @@ -2996,9 +2997,8 @@ function qmuxPair(protocol: string, maxStreamsUni: bigint): { client: Qmux; serv
new TransformStream<Uint8Array, Uint8Array>({ transform: (chunk, c) => c.enqueue(chunk.slice()) });
const up = pipe();
const down = pipe();
const config = { idleTimeout: null, maxStreamsUni };
const client = new Qmux(socket(down.readable, up.writable), { config });
const server = Qmux.accept(socket(up.readable, down.writable), { config });
const client = new Qmux(socket(down.readable, up.writable), { config: { idleTimeout: null, maxStreams } });
const server = Qmux.accept(socket(up.readable, down.writable), { config: { idleTimeout: null } });
return { client, server };
}

Expand Down
6 changes: 3 additions & 3 deletions js/net/src/open.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { Writer } from "./stream.ts";
const version = Version.DRAFT_07;
const never = new Promise<void>(() => {});

// A qmux session pair over an in-memory socket, the server granting `maxStreamsUni`.
function qmuxPair(maxStreamsUni?: bigint): { client: WebTransport; server: WebTransport } {
// A qmux session pair over an in-memory socket, the server granting `maxStreams`.
function qmuxPair(maxStreams?: bigint): { client: WebTransport; server: WebTransport } {
const socket = (readable: ReadableStream<Uint8Array>, writable: WritableStream<Uint8Array>) => {
const closed = Promise.withResolvers<{ closeCode: number; reason: string }>();
return {
Expand All @@ -28,7 +28,7 @@ function qmuxPair(maxStreamsUni?: bigint): { client: WebTransport; server: WebTr
const down = pipe();
const config = { idleTimeout: null };
const client = new Qmux(socket(down.readable, up.writable), { config });
const server = Qmux.accept(socket(up.readable, down.writable), { config: { ...config, maxStreamsUni } });
const server = Qmux.accept(socket(up.readable, down.writable), { config: { ...config, maxStreams } });
return { client, server };
}

Expand Down
3 changes: 1 addition & 2 deletions js/qmux/api/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ export interface Config {
idleTimeout?: Duration | null;
maxDatagramFrameSize?: bigint | null;
maxRecordSize?: bigint;
maxStreamsBidi?: bigint;
maxStreamsUni?: bigint;
maxStreams?: bigint;
receiveWindow?: bigint;
streamReceiveWindow?: bigint;
}
Expand Down
34 changes: 25 additions & 9 deletions js/qmux/src/session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ describe("Session integration (scripted peer)", () => {
// The peer may open any index under its credit, implicitly opening every
// lower one. Tracking each skipped index would let one tiny frame make us
// allocate (and loop) once per stream below it.
const { session, peer } = connect({ maxStreamsUni: 1n << 40n });
const { session, peer } = connect({ maxStreams: 1n << 40n });
peer.send({ type: "transport_parameters", params: peerParams() });
await session.ready;

Expand Down Expand Up @@ -922,8 +922,10 @@ describe("Session integration (scripted peer)", () => {
{ receiveWindow: null },
{ receiveWindow: "64" },
{ streamReceiveWindow: 64 },
{ maxStreamsBidi: null },
{ maxStreamsUni: 1 },
{ maxStreams: null },
{ maxStreams: 1 },
{ maxStreamsBidi: 1n },
{ maxStreamsUni: 1n },
{ maxRecordSize: null },
{ maxDatagramFrameSize: 64 },
{ maxData: 64n },
Expand Down Expand Up @@ -957,6 +959,20 @@ describe("Session integration (scripted peer)", () => {
session.close();
});

test("one maxStreams is advertised for both directions", async () => {
const { session, peer } = connect({ maxStreams: 7n });
await started(peer);
await waitFor(() => peer.has("transport_parameters"));
const frame = peer
.received()
.find(
(frame): frame is Frame.TransportParameters => frame.type === "transport_parameters",
) as Frame.TransportParameters;
expect(frame.params.initialMaxStreamsBidi).toBe(7n);
expect(frame.params.initialMaxStreamsUni).toBe(7n);
session.close();
});

test("disabled config uses null and invalid durations fail before opening", () => {
// A plain number is the old millisecond config, refused rather than misread.
for (const value of [
Expand All @@ -979,7 +995,7 @@ describe("Session integration (scripted peer)", () => {
test("config values that don't fit a varint are refused up front", () => {
(globalThis as { WebSocketStream?: unknown }).WebSocketStream = FakePeer;
expect(() => new Session("https://example/test", { config: { receiveWindow: -1n } })).toThrow("VarInt");
expect(() => new Session("https://example/test", { config: { maxStreamsBidi: VarInt.MAX + 1n } })).toThrow(
expect(() => new Session("https://example/test", { config: { maxStreams: VarInt.MAX + 1n } })).toThrow(
"VarInt",
);
});
Expand Down Expand Up @@ -1853,7 +1869,7 @@ describe("Session integration (scripted peer)", () => {
// immediately observable. This is the reproduction from issue #299: the peer
// sends a full stream plus FIN while the application never reads the acceptor.
const { session, peer } = connect({
maxStreamsUni: 1n,
maxStreams: 1n,
receiveWindow: 100n,
streamReceiveWindow: 100n,
});
Expand Down Expand Up @@ -1891,7 +1907,7 @@ describe("Session integration (scripted peer)", () => {
});

test("accepted active streams do not recycle stream-count credit", async () => {
const { session, peer } = connect({ maxStreamsUni: 1n });
const { session, peer } = connect({ maxStreams: 1n });
peer.send({ type: "transport_parameters", params: peerParams() });
await session.ready;

Expand All @@ -1916,7 +1932,7 @@ describe("Session integration (scripted peer)", () => {
const id = Stream.Id.create(0n, Stream.Dir.Bi, true);

async function accept() {
const { session, peer } = connect({ maxStreamsBidi: 1n });
const { session, peer } = connect({ maxStreams: 1n });
peer.send({ type: "transport_parameters", params: peerParams() });
await session.ready;
peer.send({ type: "stream", id, data: new Uint8Array([1]), fin: false });
Expand Down Expand Up @@ -2028,7 +2044,7 @@ describe("Session integration (scripted peer)", () => {
// slot returns as soon as both halves are done on the wire.
describe("a refused peer stream returns its stream-count credit", () => {
test("uni, once the peer finishes it", async () => {
const { session, peer } = connect({ maxStreamsUni: 1n });
const { session, peer } = connect({ maxStreams: 1n });
peer.send({ type: "transport_parameters", params: peerParams() });
await session.ready;
await session.incomingUnidirectionalStreams.cancel();
Expand All @@ -2040,7 +2056,7 @@ describe("Session integration (scripted peer)", () => {
});

test("bidi, resetting our send half, once the peer finishes its own", async () => {
const { session, peer } = connect({ maxStreamsBidi: 1n });
const { session, peer } = connect({ maxStreams: 1n });
peer.send({ type: "transport_parameters", params: peerParams() });
await session.ready;
await session.incomingBidirectionalStreams.cancel();
Expand Down
17 changes: 7 additions & 10 deletions js/qmux/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ export type SendStreamOptions = WebTransportSendStreamOptions & {

/** Configuration for a QMux session. */
export interface Config {
/** Max concurrent bidirectional streams the peer can open. */
maxStreamsBidi?: bigint;
/** Max concurrent unidirectional streams the peer can open. */
maxStreamsUni?: bigint;
/** Max concurrent streams the peer can open, in each direction. */
maxStreams?: bigint;
/** Connection-level receive window in bytes. */
receiveWindow?: bigint;
/** Receive window in bytes for every stream. */
Expand All @@ -54,8 +52,7 @@ export interface Config {
}

const DEFAULT_CONFIG: Required<Config> = {
maxStreamsBidi: 100n,
maxStreamsUni: 100n,
maxStreams: 100n,
receiveWindow: 1_048_576n,
streamReceiveWindow: 262_144n,
idleTimeout: Duration.secs(30),
Expand Down Expand Up @@ -104,8 +101,8 @@ function configToTransportParams(config: Required<Config>): TransportParams {
initialMaxStreamDataBidiLocal: config.streamReceiveWindow,
initialMaxStreamDataBidiRemote: config.streamReceiveWindow,
initialMaxStreamDataUni: config.streamReceiveWindow,
initialMaxStreamsBidi: config.maxStreamsBidi,
initialMaxStreamsUni: config.maxStreamsUni,
initialMaxStreamsBidi: config.maxStreams,
initialMaxStreamsUni: config.maxStreams,
// Clamp to maxRecordSize so we never advertise a datagram larger than our
// record layer accepts.
maxDatagramFrameSize:
Expand Down Expand Up @@ -783,8 +780,8 @@ export class Session implements WebTransport {
// Receive limits are version-independent.
const notify = () => this.#scheduler?.notify();
this.#recvData = new Window(this.#ourParams.initialMaxData, notify);
this.#recvBiLimit = new StreamLimit(this.#config.maxStreamsBidi, notify);
this.#recvUniLimit = new StreamLimit(this.#config.maxStreamsUni, notify);
this.#recvBiLimit = new StreamLimit(this.#config.maxStreams, notify);
this.#recvUniLimit = new StreamLimit(this.#config.maxStreams, notify);

const ready = Promise.withResolvers<void>();
this.ready = ready.promise;
Expand Down
3 changes: 1 addition & 2 deletions quest/m2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ removal, a rename, or a wire, catalog, or format change that is free until
demos return to their earlier format.
- **Unused API.** [One sweep per area](/quest/m2/unused-api/README.md), each
item re-checked for a downstream caller first.
- **Relay and transports.** [Congestion names](/quest/m2/congestion-names.md)
and [transport names](/quest/m2/transport-names.md).
- **Relay and transports.** [Congestion names](/quest/m2/congestion-names.md).
- **Auth and crypto.** [Claims](/quest/m2/auth-claims.md). End-to-end encryption
[is its own unpublished crate again](/quest/m2/e2ee-crate.md); its
[finished format](/quest/m3/e2ee-format.md) follows in m3.
Expand Down
Loading