Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/net/src/ietf/active_count.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SetupOption, type SetupOptions } from "./parameters.ts";
import { SetupOption, type SetupOptions } from "./setup_options.ts";
import { type IetfVersion, Version } from "./version.ts";

/**
Expand Down
3 changes: 2 additions & 1 deletion js/net/src/ietf/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
PublishNamespaceDone,
PublishNamespaceUpdate,
} from "./publish_namespace.ts";
import { initialMaxRequestId, MaxRequestId, REQUEST_WINDOW, RequestError, RequestOk } from "./request.ts";
import { MaxRequestId, RequestError, RequestOk } from "./request.ts";
import { initialMaxRequestId, REQUEST_WINDOW } from "./setup_options.ts";
import { Subscribe, SubscribeUpdate } from "./subscribe.ts";
import { SubscribeNamespaceLegacy } from "./subscribe_namespace.ts";
import { TrackStatusRequest } from "./track.ts";
Expand Down
3 changes: 2 additions & 1 deletion js/net/src/ietf/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { untilAborted } from "../util/abort.ts";
import * as Varint from "../varint.ts";
import { GoAway } from "./goaway.ts";
import * as Namespace from "./namespace.ts";
import { initialMaxRequestId, MaxRequestId, REQUEST_WINDOW } from "./request.ts";
import { MaxRequestId } from "./request.ts";
import { refuseUpdate } from "./request_stream.ts";
import { initialMaxRequestId, REQUEST_WINDOW } from "./setup_options.ts";
import { type IetfVersion, Version } from "./version.ts";

/** The peer used a request ID the draft closes the session for. */
Expand Down
2 changes: 1 addition & 1 deletion js/net/src/ietf/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as Path from "../path.ts";
import { Reader, Writer } from "../stream.ts";
import { AuthError, AuthMessage, AuthOk } from "./auth.ts";
import { fromSetup, intoSetup } from "./auth_setup.ts";
import { SetupOption, SetupOptions } from "./parameters.ts";
import { SetupOption, SetupOptions } from "./setup_options.ts";
import { Version } from "./version.ts";

function patterns(...prefixes: string[]): Path.Patterns {
Expand Down
2 changes: 1 addition & 1 deletion js/net/src/ietf/auth_setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SetupOption, type SetupOptions } from "./parameters.ts";
import { SetupOption, type SetupOptions } from "./setup_options.ts";
import { type IetfVersion, Version } from "./version.ts";

/**
Expand Down
25 changes: 16 additions & 9 deletions js/net/src/ietf/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { Reader, Writer } from "../stream.ts";
import * as Cluster from "./cluster.ts";
import * as Message from "./message.ts";
import * as Namespace from "./namespace.ts";
import { Parameters, SetupOption, SetupOptions } from "./parameters.ts";
import { Parameters } from "./parameters.ts";
import { PublishNamespace, PublishNamespaceUpdate } from "./publish_namespace.ts";
import { SetupOption, SetupOptions } from "./setup_options.ts";
import { SubscribeNamespaceEntry } from "./subscribe_namespace.ts";
import { MalformedAuthToken } from "./token.ts";
import { type IetfVersion, Version } from "./version.ts";
Expand Down Expand Up @@ -51,6 +52,12 @@ async function encode<T extends { encode(w: Writer, v: IetfVersion): Promise<voi
return out;
}

function intoParams(advert: Cluster.Advert): Parameters {
const params = new Parameters();
Cluster.intoParams(advert, params);
return params;
}

function reader(bytes: Uint8Array, version: IetfVersion = VERSION): Reader {
return new Reader(undefined, bytes, version);
}
Expand All @@ -68,7 +75,7 @@ test("Cluster: the registry code points and their parity", () => {
test("Cluster: the hop path carries no count of its own", async () => {
// The entries fill the parameter length; a count would make us unreadable to every
// other implementation.
const params = Cluster.intoParams({ hops: hops(1n, 2n, 3n), cost: 0n });
const params = intoParams({ hops: hops(1n, 2n, 3n), cost: 0n });
expect(Array.from(await encode(params))).toEqual([
0x01, // parameter count
0xc4,
Expand All @@ -83,14 +90,14 @@ test("Cluster: the hop path carries no count of its own", async () => {

test("Cluster: an advertisement round trips through the parameters", async () => {
const advert = { hops: hops(7n, 9n), cost: 5n };
const encoded = await encode(Cluster.intoParams(advert));
const encoded = await encode(intoParams(advert));
const decoded = await Parameters.decode(reader(encoded), VERSION);
expect(Cluster.fromParams(decoded)).toEqual(advert);
});

test("Cluster: a zero route cost is absent from the wire", async () => {
const free = await encode(Cluster.intoParams({ hops: hops(7n), cost: 0n }));
const priced = await encode(Cluster.intoParams({ hops: hops(7n), cost: 1n }));
const free = await encode(intoParams({ hops: hops(7n), cost: 0n }));
const priced = await encode(intoParams({ hops: hops(7n), cost: 1n }));
expect(free.length).toBeLessThan(priced.length);

// Absent means 0, so it comes back as one.
Expand All @@ -100,7 +107,7 @@ test("Cluster: a zero route cost is absent from the wire", async () => {

test("Cluster: a repeated zero is not a loop", async () => {
const advert = { hops: hops(0n, 5n, 0n), cost: 0n };
const encoded = await encode(Cluster.intoParams(advert));
const encoded = await encode(intoParams(advert));
const decoded = await Parameters.decode(reader(encoded), VERSION);
expect(Cluster.fromParams(decoded)).toEqual(advert);
});
Expand All @@ -119,7 +126,7 @@ test("Cluster: a malformed advertisement is a session-fatal violation", () => {

test("Cluster: a path that cannot have come from a conforming sender is rejected", () => {
// A non-zero id appearing twice is a loop.
expect(() => Cluster.intoParams({ hops: hops(4n, 8n, 4n), cost: 0n })).toThrow();
expect(() => intoParams({ hops: hops(4n, 8n, 4n), cost: 0n })).toThrow();

// The list always has at least one entry: the original publisher.
const empty = new Parameters();
Expand All @@ -137,7 +144,7 @@ test("Cluster: a path that cannot have come from a conforming sender is rejected

// Longer than we accept, which a real path never is and a loop is.
const long = Array.from({ length: 33 }, (_, i) => origin(BigInt(i + 1)));
expect(() => Cluster.intoParams({ hops: long, cost: 0n })).toThrow();
expect(() => intoParams({ hops: long, cost: 0n })).toThrow();
});

test("Cluster: the setup options round trip", async () => {
Expand Down Expand Up @@ -250,7 +257,7 @@ test("Cluster: a negotiated PUBLISH_NAMESPACE may carry AUTHORIZATION_TOKEN", as
await Message.encode(w, async (wr) => {
await wr.u62(1n);
await Namespace.encode(wr, Path.from("alice.hang"));
const params = Cluster.intoParams(advert);
const params = intoParams(advert);
params.bytes.set(0x03n, new Uint8Array([0x03, 0x00, 0xaa])); // AUTHORIZATION_TOKEN: USE_VALUE, type 0
await params.encode(wr, version);
});
Expand Down
19 changes: 8 additions & 11 deletions js/net/src/ietf/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import { ProtocolViolation, reason } from "../error.ts";
import { type Hop, HopSchema, MAX_HOPS, UNKNOWN_HOP } from "../hop.ts";
import * as Varint from "../varint.ts";
import { Parameters, SetupOption, type SetupOptions } from "./parameters.ts";
// Type-only: SETUP loads eagerly and must not pull in the message parameter codec.
import type { Parameters } from "./parameters.ts";
import { SetupOption, type SetupOptions } from "./setup_options.ts";
import { type IetfVersion, Version } from "./version.ts";

/**
Expand Down Expand Up @@ -160,31 +162,26 @@ export function loops(advert: Advert, self: Hop): boolean {
}

/**
* Write an advertisement's parameters, ready to encode onto the wire.
* Write an advertisement's parameters into `params`, ready to encode onto the wire.
*
* @internal
*/
export function intoParams(advert: Advert): Parameters {
const params = new Parameters();
export function intoParams(advert: Advert, params: Parameters) {
params.hopPath = encodeHops(advert.hops);

// Absent means 0, so a free path sends nothing.
if (advert.cost !== 0n) params.routeCost = advert.cost;

return params;
}

/**
* Write a REQUEST_UPDATE's parameters: only what changed, and a cost of 0 explicitly,
* since an omitted parameter keeps its value.
* Write a REQUEST_UPDATE's parameters into `params`: only what changed, and a cost of 0
* explicitly, since an omitted parameter keeps its value.
*
* @internal
*/
export function updateIntoParams(update: Update): Parameters {
const params = new Parameters();
export function updateIntoParams(update: Update, params: Parameters) {
if (update.hops !== undefined) params.hopPath = encodeHops(update.hops);
if (update.cost !== undefined) params.routeCost = update.cost;
return params;
}

/** Write a HOP_PATH value: the entries fill it with no count of their own, framed by the
Expand Down
5 changes: 3 additions & 2 deletions js/net/src/ietf/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import { Connection } from "./connection.ts";
import * as Message from "./message.ts";
import * as Namespace from "./namespace.ts";
import { Group } from "./object.ts";
import { Parameters, SetupOption, SetupOptions } from "./parameters.ts";
import { initialMaxRequestId, MaxRequestId, RequestError, RequestOk } from "./request.ts";
import { Parameters } from "./parameters.ts";
import { MaxRequestId, RequestError, RequestOk } from "./request.ts";
import { Setup } from "./setup.ts";
import { initialMaxRequestId, SetupOption, SetupOptions } from "./setup_options.ts";
import { SubscribeError, SubscribeOk } from "./subscribe.ts";
import {
SUBSCRIBE_TRACKS_ID,
Expand Down
3 changes: 2 additions & 1 deletion js/net/src/ietf/epoch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import type * as Cluster from "./cluster.ts";
import * as EpochExt from "./epoch.ts";
import { Fetch } from "./fetch.ts";
import * as Message from "./message.ts";
import { Parameters, SetupOption, SetupOptions } from "./parameters.ts";
import { Parameters } from "./parameters.ts";
import { type AdvertParams, PublishNamespace } from "./publish_namespace.ts";
import { SetupOption, SetupOptions } from "./setup_options.ts";
import { Subscribe } from "./subscribe.ts";
import { SubscribeNamespaceEntry } from "./subscribe_namespace.ts";
import { TrackStatusRequest } from "./track.ts";
Expand Down
2 changes: 1 addition & 1 deletion js/net/src/ietf/epoch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SetupOption, type SetupOptions } from "./parameters.ts";
import { SetupOption, type SetupOptions } from "./setup_options.ts";
import { type IetfVersion, Version } from "./version.ts";

/**
Expand Down
2 changes: 1 addition & 1 deletion js/net/src/ietf/hidden.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SetupOption, type SetupOptions } from "./parameters.ts";
import { SetupOption, type SetupOptions } from "./setup_options.ts";

/**
* The MoQ Hidden extension (draft-lcurley-moq-hidden-00).
Expand Down
3 changes: 2 additions & 1 deletion js/net/src/ietf/ietf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import { Fetch } from "./fetch.ts";
import * as GoAway from "./goaway.ts";
import * as Namespace from "./namespace.ts";
import { FetchFrame, type FetchPosition, Frame, Group, type GroupFlags } from "./object.ts";
import { Parameters, SetupOptions } from "./parameters.ts";
import { Parameters } from "./parameters.ts";
import { Publish, PublishDone } from "./publish.ts";
import * as Announce from "./publish_namespace.ts";
import { RequestError, RequestOk } from "./request.ts";
import * as Setup from "./setup.ts";
import { SetupOptions } from "./setup_options.ts";
import * as Subscribe from "./subscribe.ts";
import * as SubscribeNamespace from "./subscribe_namespace.ts";
import * as Track from "./track.ts";
Expand Down
5 changes: 4 additions & 1 deletion js/net/src/ietf/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ test("the package entry loads the IETF session code on demand", async () => {

const eager = [...reached].map((file) => relative(src, file));
expect(eager).toContain("ietf/setup.ts");
for (const lazy of ["ietf/connection.ts", "ietf/request_stream.ts"]) expect(eager).not.toContain(lazy);
// SETUP shares no module with the message parameter codec, which only a session uses.
for (const lazy of ["ietf/connection.ts", "ietf/request_stream.ts", "ietf/parameters.ts"]) {
expect(eager).not.toContain(lazy);
}
});
3 changes: 1 addition & 2 deletions js/net/src/ietf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ export * as Cluster from "./cluster.ts";
export * as Epoch from "./epoch.ts";
export * from "./hidden.ts";
export * from "./max_age.ts";
export * from "./parameters.ts";
export { initialMaxRequestId } from "./request.ts";
export * from "./setup.ts";
export * from "./setup_options.ts";
export * from "./solicit.ts";
export * from "./token.ts";
export * from "./version.ts";
2 changes: 1 addition & 1 deletion js/net/src/ietf/malformed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { Stream, Writer } from "../stream.ts";
import { Timescale } from "../time.ts";
import { Connection } from "./connection.ts";
import { GoAway } from "./goaway.ts";
import { SetupOption, SetupOptions } from "./parameters.ts";
import { RequestOk } from "./request.ts";
import { Setup } from "./setup.ts";
import { SetupOption, SetupOptions } from "./setup_options.ts";
import { SubscribeOk } from "./subscribe.ts";
import { SUBSCRIBE_TRACKS_ID, SubscribeNamespace } from "./subscribe_namespace.ts";
import { ALPN, type IetfVersion, Version } from "./version.ts";
Expand Down
3 changes: 2 additions & 1 deletion js/net/src/ietf/max-age.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { expect, test } from "bun:test";
import * as Path from "../path.ts";
import { Reader, Writer } from "../stream.ts";
import { maxAgeFromSetup, maxAgeIntoSetup } from "./max_age.ts";
import { Parameters, SetupOptions } from "./parameters.ts";
import { Parameters } from "./parameters.ts";
import { SetupOptions } from "./setup_options.ts";
import { Subscribe, SubscribeOk, SubscribeUpdate } from "./subscribe.ts";
import { type IetfVersion, Version } from "./version.ts";

Expand Down
2 changes: 1 addition & 1 deletion js/net/src/ietf/max_age.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** Subscriber age budgets from the MoQ Timestamp extension. @module @internal */
import { SetupOption, type SetupOptions } from "./parameters.ts";
import { SetupOption, type SetupOptions } from "./setup_options.ts";

/** The negotiated max-age Setup Option. @internal */
export const MAX_AGE_OPTION = SetupOption.MaxAge;
Expand Down
Loading
Loading