@moq/net 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/announced.d.ts +14 -0
- package/announced.d.ts.map +1 -1
- package/announced.js.map +1 -1
- package/broadcast.d.ts +6 -3
- package/broadcast.d.ts.map +1 -1
- package/broadcast.js +9 -5
- package/broadcast.js.map +1 -1
- package/connection/accept.js +9 -1
- package/connection/accept.js.map +1 -1
- package/connection/connect.d.ts.map +1 -1
- package/connection/connect.js +10 -1
- package/connection/connect.js.map +1 -1
- package/connection/established.d.ts +2 -1
- package/connection/established.d.ts.map +1 -1
- package/connection/established.js.map +1 -1
- package/connection/forward.js +9 -2
- package/connection/forward.js.map +1 -1
- package/connection/handshake.d.ts +1 -0
- package/connection/handshake.d.ts.map +1 -1
- package/connection/handshake.js +3 -0
- package/connection/handshake.js.map +1 -1
- package/connection/pool.d.ts +8 -10
- package/connection/pool.d.ts.map +1 -1
- package/connection/pool.js +18 -8
- package/connection/pool.js.map +1 -1
- package/connection/reload.js +6 -6
- package/connection/reload.js.map +1 -1
- package/error.d.ts.map +1 -1
- package/error.js +21 -0
- package/error.js.map +1 -1
- package/ietf/adapter.d.ts +5 -1
- package/ietf/adapter.d.ts.map +1 -1
- package/ietf/adapter.js +27 -9
- package/ietf/adapter.js.map +1 -1
- package/ietf/connection.d.ts +1 -1
- package/ietf/connection.d.ts.map +1 -1
- package/ietf/connection.js +9 -5
- package/ietf/connection.js.map +1 -1
- package/ietf/error.js +27 -2
- package/ietf/error.js.map +1 -1
- package/ietf/hidden.d.ts +2 -0
- package/ietf/hidden.d.ts.map +1 -0
- package/ietf/hidden.js +30 -0
- package/ietf/hidden.js.map +1 -0
- package/ietf/index.d.ts +1 -0
- package/ietf/index.d.ts.map +1 -1
- package/ietf/index.js +1 -0
- package/ietf/index.js.map +1 -1
- package/ietf/object.d.ts +8 -2
- package/ietf/object.d.ts.map +1 -1
- package/ietf/object.js +17 -3
- package/ietf/object.js.map +1 -1
- package/ietf/parameters.d.ts +5 -0
- package/ietf/parameters.d.ts.map +1 -1
- package/ietf/parameters.js +20 -0
- package/ietf/parameters.js.map +1 -1
- package/ietf/properties.d.ts +1 -0
- package/ietf/properties.d.ts.map +1 -1
- package/ietf/properties.js +14 -0
- package/ietf/properties.js.map +1 -1
- package/ietf/publish.d.ts +19 -2
- package/ietf/publish.d.ts.map +1 -1
- package/ietf/publish.js +40 -6
- package/ietf/publish.js.map +1 -1
- package/ietf/publisher.js +114 -60
- package/ietf/publisher.js.map +1 -1
- package/ietf/subscribe.d.ts.map +1 -1
- package/ietf/subscribe.js +3 -4
- package/ietf/subscribe.js.map +1 -1
- package/ietf/subscribe_namespace.d.ts +8 -2
- package/ietf/subscribe_namespace.d.ts.map +1 -1
- package/ietf/subscribe_namespace.js +18 -8
- package/ietf/subscribe_namespace.js.map +1 -1
- package/ietf/subscriber.js +189 -66
- package/ietf/subscriber.js.map +1 -1
- package/internal.d.ts +7 -0
- package/internal.d.ts.map +1 -1
- package/internal.js +11 -0
- package/internal.js.map +1 -1
- package/lite/announce.d.ts +46 -2
- package/lite/announce.d.ts.map +1 -1
- package/lite/announce.js +126 -11
- package/lite/announce.js.map +1 -1
- package/lite/connection.d.ts +1 -1
- package/lite/connection.d.ts.map +1 -1
- package/lite/connection.js +9 -3
- package/lite/connection.js.map +1 -1
- package/lite/publisher.js +168 -109
- package/lite/publisher.js.map +1 -1
- package/lite/subscribe.d.ts +10 -4
- package/lite/subscribe.d.ts.map +1 -1
- package/lite/subscribe.js +20 -10
- package/lite/subscribe.js.map +1 -1
- package/lite/subscriber.d.ts +10 -2
- package/lite/subscriber.d.ts.map +1 -1
- package/lite/subscriber.js +159 -93
- package/lite/subscriber.js.map +1 -1
- package/lite/version.d.ts +11 -0
- package/lite/version.d.ts.map +1 -1
- package/lite/version.js +56 -0
- package/lite/version.js.map +1 -1
- package/origin.d.ts +37 -18
- package/origin.d.ts.map +1 -1
- package/origin.js +248 -103
- package/origin.js.map +1 -1
- package/package.json +7 -3
- package/stream.d.ts +2 -2
- package/stream.d.ts.map +1 -1
- package/stream.js +16 -11
- package/stream.js.map +1 -1
- package/tail.d.ts +11 -0
- package/tail.d.ts.map +1 -0
- package/tail.js +121 -0
- package/tail.js.map +1 -0
- package/track.d.ts +33 -5
- package/track.d.ts.map +1 -1
- package/track.js +98 -30
- package/track.js.map +1 -1
- package/wire.d.ts +2 -0
- package/wire.d.ts.map +1 -1
- package/wire.js.map +1 -1
package/stream.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE/F,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,kFAAkF;AAClF,4EAA4E;AAC5E,SAAS,QAAQ,CAAC,MAAe,EAAE,OAAqB;IACvD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IACnD,MAAM,IAAI,GAAG,YAAY,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IAChD,OAAO,IAAI,KAAK,UAAU,CAAC,QAAQ,IAAI,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;AACzG,CAAC;AAED,MAAM,OAAO,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAC5B,MAAM,aAAa,GAAG,IAAI,GAAG,IA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AI,CAAC,UAAU,CAAC,CAAC;AACtE,CAAC;AAED,SAAS,QAAQ,CAAC,GAAgB,EAAE,CAAS;IAC5C,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACrC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACpB,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;AACtE,CAAC;AAED,8CAA8C;AAC9C,MAAM,OAAO,OAAO;IACnB,OAAO,CAA0D;IACjE,QAAQ,CAAe;IAEvB,YAAY,IAAkB,EAAE,OAAqB;QACpD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,6BAA6B,CAAC,SAAS,EAE1D,CAAC;QACF,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,IAAI;QACT,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QACvC,IAAI,IAAI,CAAC,IAAI;YAAE,OAAO;QACtB,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzD,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;CACD","sourcesContent":["import { fromTransport, StreamCode, StreamError, toStreamCode, toTransport } from \"./error.ts\";\nimport type { IetfVersion } from \"./ietf/version.ts\";\nimport { Version } from \"./ietf/version.ts\";\nimport { TimeoutError, withTimeout } from \"./util/timeout.ts\";\nimport { decodeUtf8 } from \"./util/utf8.ts\";\nimport * as Varint from \"./varint.ts\";\n\n// Decode raw transport errors before mapping so they cannot bypass the negotiated\n// registry. Ordinary errors already send 0 and retain their local identity.\nfunction withCode(reason: unknown, version?: IetfVersion): unknown {\n\tconst decoded = fromTransport(reason, { version });\n\tconst code = toStreamCode(decoded, { version });\n\treturn code === StreamCode.Internal && decoded === reason ? reason : toTransport(code, decoded.message);\n}\n\nconst MAX_U31 = 2 ** 31 - 1;\nconst MAX_READ_SIZE = 1024 * 1024 * 64; // don't allocate more than 64MB for a message\n\n/**\n * Options handed to the transport for one outgoing stream.\n *\n * `waitUntilAvailable` waits for the peer's concurrent stream limit to free a slot instead\n * of rejecting with a `QuotaExceededError`, which is what we want for the streams a session\n * opens occasionally. `@types/web` doesn't declare it yet, hence the intersection.\n */\nexport function sendOptions(options?: OpenOptions): WebTransportSendStreamOptions & { waitUntilAvailable?: boolean } {\n\treturn { sendOrder: options?.sendOrder, waitUntilAvailable: options?.waitUntilAvailable ?? true };\n}\n\n// How long any open may wait for the peer to free a stream slot. Every open needs this,\n// whether or not it asked to wait: an implementation may park an over-limit open rather\n// than rejecting it, and a peer can advertise a stream limit of zero and never raise it.\n// Matches the subscribe budget.\nconst OPEN_TIMEOUT_MS = 10_000;\n\n/**\n * Bound an open that would otherwise park until the peer grants stream credit, restoring\n * the pre-waitUntilAvailable failure after a grace period. A stream arriving after the\n * deadline is discarded, since nobody is waiting for it any more.\n */\nasync function openWithin<T>(opening: Promise<T>, timeout: number, discard: (stream: T) => void): Promise<T> {\n\ttry {\n\t\treturn await withTimeout(opening, timeout, `stream open timed out after ${timeout}ms waiting for a slot`);\n\t} catch (err: unknown) {\n\t\topening.then(discard).catch(() => void 0);\n\t\tthrow err;\n\t}\n}\n\nfunction isLeadingOnes(version?: IetfVersion): boolean {\n\treturn (\n\t\tversion !== undefined &&\n\t\tversion !== Version.DRAFT_14 &&\n\t\tversion !== Version.DRAFT_15 &&\n\t\tversion !== Version.DRAFT_16\n\t);\n}\n\n/**\n * The `WebTransportSendStream` that every outgoing stream is, narrowed to the one attribute\n * this package uses. The DOM types available here still describe them as plain\n * `WritableStream`s, so the interface has to be named structurally.\n *\n * `sendOrder` is optional because it is absent until set, and stays absent on an\n * implementation that doesn't carry the interface at all.\n *\n * @see https://www.w3.org/TR/webtransport/#webtransportsendstream\n */\nexport type SendStream = WritableStream<Uint8Array> & { sendOrder?: number };\n\n/** Options for opening an outgoing stream. */\nexport interface OpenOptions {\n\t/** The negotiated IETF version, which selects the varint encoding. */\n\tversion?: IetfVersion;\n\n\t/**\n\t * The transport send order, where HIGHER values are transmitted first.\n\t * Left to the transport's default when unset.\n\t */\n\tsendOrder?: number;\n\n\t/**\n\t * Reject if the peer hasn't freed a stream slot within this many milliseconds. Defaults\n\t * to 10s. There is no way to wait indefinitely: a peer can advertise a stream limit of\n\t * zero and never raise it, so every open needs a way out.\n\t */\n\ttimeout?: number;\n\n\t/**\n\t * Ask the transport to wait for a stream slot rather than failing when the peer's\n\t * concurrent stream limit is exhausted. Defaults to true.\n\t *\n\t * Set it false on a path that opens streams faster than the peer can retire them. The\n\t * transport queues the opens it can't satisfy and serves them in order, with no way to\n\t * cancel one, so waiting there spends returning credit on whatever was requested first\n\t * rather than on what matters now.\n\t */\n\twaitUntilAvailable?: boolean;\n}\n\n/** Options for {@link Writer.tryOpen}. */\nexport interface TryOpenOptions extends OpenOptions {\n\t/** Give up once this settles, however it settles. */\n\tcancel: Promise<unknown>;\n}\n\nexport class Stream {\n\treader: Reader;\n\twriter: Writer;\n\n\t/** Wrap the two halves of a transport stream. */\n\tconstructor(props: {\n\t\twritable: WritableStream<Uint8Array>;\n\t\treadable: ReadableStream<Uint8Array>;\n\t\tversion?: IetfVersion;\n\t});\n\t/** Pair halves that were opened separately, as the SETUP exchange does. */\n\tconstructor(props: { writer: Writer; reader: Reader });\n\tconstructor(props: {\n\t\twritable?: WritableStream<Uint8Array>;\n\t\treadable?: ReadableStream<Uint8Array>;\n\t\twriter?: Writer;\n\t\treader?: Reader;\n\t\tversion?: IetfVersion;\n\t}) {\n\t\tconst writer = props.writer ?? (props.writable && new Writer(props.writable, props.version));\n\t\tconst reader = props.reader ?? (props.readable && new Reader(props.readable, undefined, props.version));\n\t\tif (!writer || !reader) throw new Error(\"stream needs both halves\");\n\n\t\tthis.writer = writer;\n\t\tthis.reader = reader;\n\t}\n\n\tstatic async accept(quic: WebTransport, version?: IetfVersion): Promise<Stream | undefined> {\n\t\tfor (;;) {\n\t\t\tconst reader =\n\t\t\t\tquic.incomingBidirectionalStreams.getReader() as ReadableStreamDefaultReader<WebTransportBidirectionalStream>;\n\t\t\tconst next = await reader.read();\n\t\t\treader.releaseLock();\n\n\t\t\tif (next.done) return;\n\t\t\tconst { readable, writable } = next.value;\n\t\t\treturn new Stream({ readable, writable, version });\n\t\t}\n\t}\n\n\t/**\n\t * Open an outgoing bidirectional stream.\n\t * @param quic - The session to open it on\n\t * @param options - The version its varints encode with, and the send order ranking it\n\t * against the session's other streams\n\t */\n\tstatic async open(quic: WebTransport, options?: OpenOptions): Promise<Stream> {\n\t\tconst { readable, writable } = await openWithin(\n\t\t\tquic.createBidirectionalStream(sendOptions(options)),\n\t\t\toptions?.timeout ?? OPEN_TIMEOUT_MS,\n\t\t\t(stream) => {\n\t\t\t\tvoid stream.writable.abort().catch(() => void 0);\n\t\t\t\tvoid stream.readable.cancel().catch(() => void 0);\n\t\t\t},\n\t\t);\n\t\treturn new Stream({ readable, writable, version: options?.version });\n\t}\n\n\tclose() {\n\t\tthis.writer.close();\n\t\t// A routine unsubscribe, so send CANCELLED. A bare Error would put 0 on the wire,\n\t\t// which the stream registry reads as INTERNAL_ERROR: the peer would log a failure\n\t\t// for every subscription we walk away from.\n\t\tthis.reader.stop(new StreamError(StreamCode.Cancel, { message: \"cancel\" }));\n\t}\n\n\tabort(reason: Error) {\n\t\tthis.writer.reset(reason);\n\t\tthis.reader.stop(reason);\n\t}\n}\n\n// Reader wraps a stream and provides convience methods for reading pieces from a stream\n// Unfortunately we can't use a BYOB reader because it's not supported with WebTransport+WebWorkers yet.\nexport class Reader {\n\t#buffer: Uint8Array;\n\t#stream?: ReadableStream<Uint8Array>; // if undefined, the buffer is consumed then EOF\n\t#reader?: ReadableStreamDefaultReader<Uint8Array>;\n\t#closed?: Promise<void>;\n\tversion?: IetfVersion;\n\n\t// Either stream or buffer MUST be provided.\n\tconstructor(stream: ReadableStream<Uint8Array>, buffer?: Uint8Array, version?: IetfVersion);\n\tconstructor(stream: undefined, buffer: Uint8Array, version?: IetfVersion);\n\tconstructor(stream?: ReadableStream<Uint8Array>, buffer?: Uint8Array, version?: IetfVersion) {\n\t\tthis.#buffer = buffer ?? new Uint8Array();\n\t\tthis.#stream = stream;\n\t\tthis.#reader = this.#stream?.getReader();\n\t\tthis.version = version;\n\t}\n\n\t// Adds more data to the buffer, returning true if more data was added.\n\tasync #fill(): Promise<boolean> {\n\t\tif (!this.#reader) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Every read of this stream funnels through here, so decoding the peer's reset code\n\t\t// once is enough to keep the raw transport error out of every caller (and every app).\n\t\tconst result = await this.#reader.read().catch((err: unknown) => {\n\t\t\tthrow fromTransport(err, { version: this.version });\n\t\t});\n\n\t\tif (result.done) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (result.value.byteLength === 0) {\n\t\t\tthrow new Error(\"unexpected empty chunk\");\n\t\t}\n\n\t\tconst buffer = result.value;\n\n\t\tif (this.#buffer.byteLength === 0) {\n\t\t\tthis.#buffer = new Uint8Array(buffer);\n\t\t} else {\n\t\t\tconst temp = new Uint8Array(this.#buffer.byteLength + buffer.byteLength);\n\t\t\ttemp.set(this.#buffer);\n\t\t\ttemp.set(buffer, this.#buffer.byteLength);\n\t\t\tthis.#buffer = temp;\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t// Add more data to the buffer until it's at least size bytes.\n\tasync #fillTo(size: number) {\n\t\tif (size > MAX_READ_SIZE) {\n\t\t\tthrow new Error(`read size ${size} exceeds max size ${MAX_READ_SIZE}`);\n\t\t}\n\n\t\twhile (this.#buffer.byteLength < size) {\n\t\t\tif (!(await this.#fill())) {\n\t\t\t\tthrow new Error(\"unexpected end of stream\");\n\t\t\t}\n\t\t}\n\t}\n\n\t// Consumes the first size bytes of the buffer.\n\t#slice(size: number): Uint8Array {\n\t\tconst result = new Uint8Array(this.#buffer.buffer, this.#buffer.byteOffset, size);\n\t\tthis.#buffer = new Uint8Array(\n\t\t\tthis.#buffer.buffer,\n\t\t\tthis.#buffer.byteOffset + size,\n\t\t\tthis.#buffer.byteLength - size,\n\t\t);\n\n\t\treturn result;\n\t}\n\n\tasync read(size: number): Promise<Uint8Array> {\n\t\tif (size === 0) return new Uint8Array();\n\n\t\tawait this.#fillTo(size);\n\t\treturn this.#slice(size);\n\t}\n\n\tasync readAll(): Promise<Uint8Array> {\n\t\twhile (await this.#fill()) {\n\t\t\t// keep going\n\t\t}\n\t\treturn this.#slice(this.#buffer.byteLength);\n\t}\n\n\tasync string(): Promise<string> {\n\t\tconst length = await this.u53();\n\t\tconst buffer = await this.read(length);\n\t\treturn decodeUtf8(buffer);\n\t}\n\n\tasync bool(): Promise<boolean> {\n\t\tconst v = await this.u8();\n\t\tif (v === 0) return false;\n\t\tif (v === 1) return true;\n\t\tthrow new Error(\"invalid bool value\");\n\t}\n\n\tasync u8(): Promise<number> {\n\t\tawait this.#fillTo(1);\n\t\treturn this.#slice(1)[0];\n\t}\n\n\tasync u16(): Promise<number> {\n\t\tawait this.#fillTo(2);\n\t\tconst view = new DataView(this.#buffer.buffer, this.#buffer.byteOffset, 2);\n\t\tconst result = view.getUint16(0);\n\t\tthis.#slice(2);\n\t\treturn result;\n\t}\n\n\t// Returns a Number using 53-bits, the max Javascript can use for integer math.\n\tasync u53(): Promise<number> {\n\t\tconst v = await this.u62();\n\t\tif (v > Varint.MAX_U53) {\n\t\t\tthrow new Error(`value larger than 53-bits: ${v.toString()}`);\n\t\t}\n\n\t\treturn Number(v);\n\t}\n\n\t// NOTE: Returns a bigint instead of a number since it may be larger than 53-bits\n\tasync u62(): Promise<bigint> {\n\t\tif (isLeadingOnes(this.version)) {\n\t\t\treturn this.#readLeadingOnes();\n\t\t}\n\t\treturn this.#readQuicVarint();\n\t}\n\n\tasync #readQuicVarint(): Promise<bigint> {\n\t\tawait this.#fillTo(1);\n\t\tconst size = (this.#buffer[0] & 0xc0) >> 6;\n\n\t\tif (size === 0) {\n\t\t\tconst first = this.#slice(1)[0];\n\t\t\treturn BigInt(first) & 0x3fn;\n\t\t}\n\t\tif (size === 1) {\n\t\t\tawait this.#fillTo(2);\n\t\t\tconst slice = this.#slice(2);\n\t\t\tconst view = new DataView(slice.buffer, slice.byteOffset, slice.byteLength);\n\n\t\t\treturn BigInt(view.getUint16(0)) & 0x3fffn;\n\t\t}\n\t\tif (size === 2) {\n\t\t\tawait this.#fillTo(4);\n\t\t\tconst slice = this.#slice(4);\n\t\t\tconst view = new DataView(slice.buffer, slice.byteOffset, slice.byteLength);\n\n\t\t\treturn BigInt(view.getUint32(0)) & 0x3fffffffn;\n\t\t}\n\t\tawait this.#fillTo(8);\n\t\tconst slice = this.#slice(8);\n\t\tconst view = new DataView(slice.buffer, slice.byteOffset, slice.byteLength);\n\n\t\treturn view.getBigUint64(0) & 0x3fffffffffffffffn;\n\t}\n\n\tasync #readLeadingOnes(): Promise<bigint> {\n\t\tawait this.#fillTo(1);\n\t\tconst b = this.#buffer[0];\n\n\t\t// Count leading 1-bits\n\t\tlet ones = 0;\n\t\tfor (let bit = 7; bit >= 0; bit--) {\n\t\t\tif (b & (1 << bit)) ones++;\n\t\t\telse break;\n\t\t}\n\n\t\t// 1111110x is a 7-byte form. Draft-17 rejects it; draft-18+ allows it per #1595.\n\t\tif (ones === 6 && this.version === Version.DRAFT_17) {\n\t\t\tthrow new Error(\"invalid leading-ones varint: 1111110x prefix is reserved on draft-17\");\n\t\t}\n\n\t\tlet totalSize: number;\n\t\tif (ones <= 5) totalSize = ones + 1;\n\t\telse if (ones === 6) totalSize = 7;\n\t\telse if (ones === 7) totalSize = 8;\n\t\telse totalSize = 9; // ones === 8\n\n\t\tawait this.#fillTo(totalSize);\n\t\tconst slice = this.#slice(totalSize);\n\n\t\tconst [value] = Varint.decodeLeadingOnes(slice);\n\t\treturn value;\n\t}\n\n\t// Returns false if there is more data to read, blocking if it hasn't been received yet.\n\tasync done(): Promise<boolean> {\n\t\tif (this.#buffer.byteLength > 0) return false;\n\t\treturn !(await this.#fill());\n\t}\n\n\tstop(reason: unknown) {\n\t\tthis.#reader?.cancel(withCode(reason, this.version)).catch(() => void 0);\n\t}\n\n\t// Decoded like #fill: a caller racing this against a read must not get a different error\n\t// shape depending on which one won. Derived once, so racing it per frame doesn't allocate.\n\tget closed(): Promise<void> {\n\t\tthis.#closed ??= (this.#reader?.closed ?? Promise.resolve()).catch((err: unknown) => {\n\t\t\tthrow fromTransport(err, { version: this.version });\n\t\t});\n\t\treturn this.#closed;\n\t}\n}\n\n// Writer wraps a stream and writes chunks of data\nexport class Writer {\n\t#writer: WritableStreamDefaultWriter<Uint8Array>;\n\t#stream: WritableStream<Uint8Array>;\n\t#closed?: Promise<void>;\n\n\t// Scratch buffer for writing varints.\n\t// Fixed at 9 bytes (leading-ones max).\n\t#scratch: ArrayBuffer;\n\n\tversion?: IetfVersion;\n\n\tconstructor(stream: WritableStream<Uint8Array>, version?: IetfVersion) {\n\t\tthis.#stream = stream;\n\t\tthis.#scratch = new ArrayBuffer(9);\n\t\tthis.#writer = this.#stream.getWriter();\n\t\tthis.version = version;\n\t}\n\n\t/**\n\t * Rank this stream against the session's others, where HIGHER values are sent first.\n\t *\n\t * A send order only schedules the local end, so a stream the peer opened has to be ranked\n\t * here rather than at the peer's {@link open}.\n\t *\n\t * The spec makes `sendOrder` a settable attribute on every {@link SendStream}. Where the\n\t * interface isn't implemented (Chrome as of writing, a mock, a polyfill) this just sets an\n\t * ignored property, the same way an ignored `sendOrder` option does at {@link open}.\n\t */\n\tsetPriority(sendOrder: number) {\n\t\t(this.#stream as SendStream).sendOrder = sendOrder;\n\t}\n\n\tasync bool(v: boolean) {\n\t\tawait this.write(setUint8(this.#scratch, v ? 1 : 0));\n\t}\n\n\tasync u8(v: number) {\n\t\tif (!Number.isInteger(v) || v < 0 || v > 255) {\n\t\t\tthrow new RangeError(`invalid u8: ${v}`);\n\t\t}\n\t\tawait this.write(setUint8(this.#scratch, v));\n\t}\n\n\tasync u16(v: number) {\n\t\tawait this.write(setUint16(this.#scratch, v));\n\t}\n\n\tasync i32(v: number) {\n\t\tif (Math.abs(v) > MAX_U31) {\n\t\t\tthrow new Error(`overflow, value larger than 32-bits: ${v.toString()}`);\n\t\t}\n\n\t\t// We don't use a VarInt, so it always takes 4 bytes.\n\t\t// This could be improved but nothing is standardized yet.\n\t\tawait this.write(setInt32(this.#scratch, v));\n\t}\n\n\tasync u53(v: number) {\n\t\tif (!Number.isSafeInteger(v) || v < 0) {\n\t\t\tthrow new RangeError(`invalid u53: ${v}`);\n\t\t}\n\t\tif (isLeadingOnes(this.version)) {\n\t\t\tawait this.write(Varint.encodeLeadingOnesTo(this.#scratch, v));\n\t\t} else {\n\t\t\tawait this.write(Varint.encodeTo(this.#scratch, v));\n\t\t}\n\t}\n\n\tasync u62(v: bigint) {\n\t\tif (isLeadingOnes(this.version)) {\n\t\t\tawait this.write(Varint.encodeLeadingOnesTo(this.#scratch, v));\n\t\t} else {\n\t\t\tawait this.write(Varint.encodeTo(this.#scratch, v));\n\t\t}\n\t}\n\n\tasync write(v: Uint8Array) {\n\t\t// Mirrors Reader.#fill: every write funnels through here, so a STOP_SENDING from the\n\t\t// peer surfaces as a typed code rather than the transport's own error shape.\n\t\tawait this.#writer.write(v).catch((err: unknown) => {\n\t\t\tthrow fromTransport(err, { version: this.version });\n\t\t});\n\t}\n\n\tasync string(str: string) {\n\t\tconst data = new TextEncoder().encode(str);\n\t\tawait this.u53(data.byteLength);\n\t\tawait this.write(data);\n\t}\n\n\tclose() {\n\t\tthis.#writer.close().catch(() => void 0);\n\t}\n\n\t// Mirrors Reader.closed: a STOP_SENDING reaches a caller racing this with the same\n\t// typed code it would get from a write.\n\tget closed(): Promise<void> {\n\t\tthis.#closed ??= this.#writer.closed.catch((err: unknown) => {\n\t\t\tthrow fromTransport(err, { version: this.version });\n\t\t});\n\t\treturn this.#closed;\n\t}\n\n\treset(reason: unknown) {\n\t\tthis.#writer.abort(withCode(reason, this.version)).catch(() => void 0);\n\t}\n\n\t/**\n\t * Open an outgoing unidirectional stream.\n\t * @param quic - The session to open it on\n\t * @param options - The version its varints encode with, and the send order ranking it\n\t * against the session's other streams\n\t */\n\tstatic async open(quic: WebTransport, options?: OpenOptions): Promise<Writer> {\n\t\tconst writable = await openWithin(\n\t\t\tquic.createUnidirectionalStream(sendOptions(options)) as Promise<WritableStream<Uint8Array>>,\n\t\t\toptions?.timeout ?? OPEN_TIMEOUT_MS,\n\t\t\t(stream) => void stream.abort().catch(() => void 0),\n\t\t);\n\n\t\treturn new Writer(writable, options?.version);\n\t}\n\n\t/**\n\t * Like {@link Writer.open}, but gives up when `cancel` settles or `timeout` elapses,\n\t * returning undefined so the caller can drop whatever it meant to send. A stream that\n\t * opens after that is reset rather than leaked. A real transport failure still throws.\n\t *\n\t * Worth using even with `waitUntilAvailable: false`, since an implementation may park\n\t * an over-limit open instead of rejecting it.\n\t */\n\tstatic async tryOpen(quic: WebTransport, options: TryOpenOptions): Promise<Writer | undefined> {\n\t\t// A rejected `cancel` (STOP_SENDING) means the peer is gone too, so both settle\n\t\t// paths mean \"give up\" and neither is left unhandled. Built before the open, and\n\t\t// raced ahead of it, so an already-cancelled caller wins even against a slot that\n\t\t// is free right now.\n\t\tconst cancelled = options.cancel.then(\n\t\t\t() => undefined,\n\t\t\t() => undefined,\n\t\t);\n\t\tconst open = Writer.open(quic, options);\n\n\t\ttry {\n\t\t\tconst stream = await Promise.race([cancelled, open]);\n\t\t\tif (stream) return stream;\n\t\t} catch (err: unknown) {\n\t\t\t// open already discarded the late stream on its way out.\n\t\t\tif (!(err instanceof TimeoutError)) throw err;\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst abandoned = new Error(\"abandoned waiting for a stream slot\");\n\t\topen.then((w) => w.reset(abandoned)).catch(() => void 0);\n\t\treturn undefined;\n\t}\n}\n\nfunction setUint8(dst: ArrayBuffer, v: number): Uint8Array {\n\tconst buffer = new Uint8Array(dst, 0, 1);\n\tbuffer[0] = v;\n\treturn buffer;\n}\n\nfunction setUint16(dst: ArrayBuffer, v: number): Uint8Array {\n\tconst view = new DataView(dst, 0, 2);\n\tview.setUint16(0, v);\n\treturn new Uint8Array(view.buffer, view.byteOffset, view.byteLength);\n}\n\nfunction setInt32(dst: ArrayBuffer, v: number): Uint8Array {\n\tconst view = new DataView(dst, 0, 4);\n\tview.setInt32(0, v);\n\treturn new Uint8Array(view.buffer, view.byteOffset, view.byteLength);\n}\n\n// Returns the next stream from the connection\nexport class Readers {\n\t#reader: ReadableStreamDefaultReader<ReadableStream<Uint8Array>>;\n\t#version?: IetfVersion;\n\n\tconstructor(quic: WebTransport, version?: IetfVersion) {\n\t\tthis.#reader = quic.incomingUnidirectionalStreams.getReader() as ReadableStreamDefaultReader<\n\t\t\tReadableStream<Uint8Array>\n\t\t>;\n\t\tthis.#version = version;\n\t}\n\n\tasync next(): Promise<Reader | undefined> {\n\t\tconst next = await this.#reader.read();\n\t\tif (next.done) return;\n\t\treturn new Reader(next.value, undefined, this.#version);\n\t}\n\n\tclose() {\n\t\tthis.#reader.cancel();\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE/F,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,kFA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,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzD,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;CACD","sourcesContent":["import { race } from \"@moq/signals\";\nimport { fromTransport, StreamCode, StreamError, toStreamCode, toTransport } from \"./error.ts\";\nimport type { IetfVersion } from \"./ietf/version.ts\";\nimport { Version } from \"./ietf/version.ts\";\nimport { TimeoutError, withTimeout } from \"./util/timeout.ts\";\nimport { decodeUtf8 } from \"./util/utf8.ts\";\nimport * as Varint from \"./varint.ts\";\n\n// Decode raw transport errors before mapping so they cannot bypass the negotiated\n// registry. Ordinary errors already send 0 and retain their local identity.\nfunction withCode(reason: unknown, version?: IetfVersion): unknown {\n\tconst decoded = fromTransport(reason, { version });\n\tconst code = toStreamCode(decoded, { version });\n\treturn code === StreamCode.Internal && decoded === reason ? reason : toTransport(code, decoded.message);\n}\n\nconst MAX_U31 = 2 ** 31 - 1;\nconst MAX_READ_SIZE = 1024 * 1024 * 64; // don't allocate more than 64MB for a message\n\n/**\n * Options handed to the transport for one outgoing stream.\n *\n * `waitUntilAvailable` waits for the peer's concurrent stream limit to free a slot instead\n * of rejecting with a `QuotaExceededError`, which is what we want for the streams a session\n * opens occasionally. `@types/web` doesn't declare it yet, hence the intersection.\n */\nexport function sendOptions(options?: OpenOptions): WebTransportSendStreamOptions & { waitUntilAvailable?: boolean } {\n\treturn { sendOrder: options?.sendOrder, waitUntilAvailable: options?.waitUntilAvailable ?? true };\n}\n\n// How long any open may wait for the peer to free a stream slot. Every open needs this,\n// whether or not it asked to wait: an implementation may park an over-limit open rather\n// than rejecting it, and a peer can advertise a stream limit of zero and never raise it.\n// Matches the subscribe budget.\nconst OPEN_TIMEOUT_MS = 10_000;\n\n/**\n * Bound an open that would otherwise park until the peer grants stream credit, restoring\n * the pre-waitUntilAvailable failure after a grace period. A stream arriving after the\n * deadline is discarded, since nobody is waiting for it any more.\n */\nasync function openWithin<T>(opening: Promise<T>, timeout: number, discard: (stream: T) => void): Promise<T> {\n\ttry {\n\t\treturn await withTimeout(opening, timeout, `stream open timed out after ${timeout}ms waiting for a slot`);\n\t} catch (err: unknown) {\n\t\topening.then(discard).catch(() => void 0);\n\t\tthrow err;\n\t}\n}\n\nfunction isLeadingOnes(version?: IetfVersion): boolean {\n\treturn (\n\t\tversion !== undefined &&\n\t\tversion !== Version.DRAFT_14 &&\n\t\tversion !== Version.DRAFT_15 &&\n\t\tversion !== Version.DRAFT_16\n\t);\n}\n\n/**\n * The `WebTransportSendStream` that every outgoing stream is, narrowed to the one attribute\n * this package uses. The DOM types available here still describe them as plain\n * `WritableStream`s, so the interface has to be named structurally.\n *\n * `sendOrder` is optional because it is absent until set, and stays absent on an\n * implementation that doesn't carry the interface at all.\n *\n * @see https://www.w3.org/TR/webtransport/#webtransportsendstream\n */\nexport type SendStream = WritableStream<Uint8Array> & { sendOrder?: number };\n\n/** Options for opening an outgoing stream. */\nexport interface OpenOptions {\n\t/** The negotiated IETF version, which selects the varint encoding. */\n\tversion?: IetfVersion;\n\n\t/**\n\t * The transport send order, where HIGHER values are transmitted first.\n\t * Left to the transport's default when unset.\n\t */\n\tsendOrder?: number;\n\n\t/**\n\t * Reject if the peer hasn't freed a stream slot within this many milliseconds. Defaults\n\t * to 10s. There is no way to wait indefinitely: a peer can advertise a stream limit of\n\t * zero and never raise it, so every open needs a way out.\n\t */\n\ttimeout?: number;\n\n\t/**\n\t * Ask the transport to wait for a stream slot rather than failing when the peer's\n\t * concurrent stream limit is exhausted. Defaults to true.\n\t *\n\t * Set it false on a path that opens streams faster than the peer can retire them. The\n\t * transport queues the opens it can't satisfy and serves them in order, with no way to\n\t * cancel one, so waiting there spends returning credit on whatever was requested first\n\t * rather than on what matters now.\n\t */\n\twaitUntilAvailable?: boolean;\n}\n\n/** Options for {@link Writer.tryOpen}. */\nexport interface TryOpenOptions extends OpenOptions {\n\t/** Give up once this resolves. */\n\tcancel: Promise<void>;\n}\n\nexport class Stream {\n\treader: Reader;\n\twriter: Writer;\n\n\t/** Wrap the two halves of a transport stream. */\n\tconstructor(props: {\n\t\twritable: WritableStream<Uint8Array>;\n\t\treadable: ReadableStream<Uint8Array>;\n\t\tversion?: IetfVersion;\n\t});\n\t/** Pair halves that were opened separately, as the SETUP exchange does. */\n\tconstructor(props: { writer: Writer; reader: Reader });\n\tconstructor(props: {\n\t\twritable?: WritableStream<Uint8Array>;\n\t\treadable?: ReadableStream<Uint8Array>;\n\t\twriter?: Writer;\n\t\treader?: Reader;\n\t\tversion?: IetfVersion;\n\t}) {\n\t\tconst writer = props.writer ?? (props.writable && new Writer(props.writable, props.version));\n\t\tconst reader = props.reader ?? (props.readable && new Reader(props.readable, undefined, props.version));\n\t\tif (!writer || !reader) throw new Error(\"stream needs both halves\");\n\n\t\tthis.writer = writer;\n\t\tthis.reader = reader;\n\t}\n\n\tstatic async accept(quic: WebTransport, version?: IetfVersion): Promise<Stream | undefined> {\n\t\tfor (;;) {\n\t\t\tconst reader =\n\t\t\t\tquic.incomingBidirectionalStreams.getReader() as ReadableStreamDefaultReader<WebTransportBidirectionalStream>;\n\t\t\tconst next = await reader.read();\n\t\t\treader.releaseLock();\n\n\t\t\tif (next.done) return;\n\t\t\tconst { readable, writable } = next.value;\n\t\t\treturn new Stream({ readable, writable, version });\n\t\t}\n\t}\n\n\t/**\n\t * Open an outgoing bidirectional stream.\n\t * @param quic - The session to open it on\n\t * @param options - The version its varints encode with, and the send order ranking it\n\t * against the session's other streams\n\t */\n\tstatic async open(quic: WebTransport, options?: OpenOptions): Promise<Stream> {\n\t\tconst { readable, writable } = await openWithin(\n\t\t\tquic.createBidirectionalStream(sendOptions(options)),\n\t\t\toptions?.timeout ?? OPEN_TIMEOUT_MS,\n\t\t\t(stream) => {\n\t\t\t\tvoid stream.writable.abort().catch(() => void 0);\n\t\t\t\tvoid stream.readable.cancel().catch(() => void 0);\n\t\t\t},\n\t\t);\n\t\treturn new Stream({ readable, writable, version: options?.version });\n\t}\n\n\tclose() {\n\t\tthis.writer.close();\n\t\t// A routine unsubscribe, so send CANCELLED. A bare Error would put 0 on the wire,\n\t\t// which the stream registry reads as INTERNAL_ERROR: the peer would log a failure\n\t\t// for every subscription we walk away from.\n\t\tthis.reader.stop(new StreamError(StreamCode.Cancel, { message: \"cancel\" }));\n\t}\n\n\tabort(reason: Error) {\n\t\tthis.writer.reset(reason);\n\t\tthis.reader.stop(reason);\n\t}\n}\n\n// Reader wraps a stream and provides convience methods for reading pieces from a stream\n// Unfortunately we can't use a BYOB reader because it's not supported with WebTransport+WebWorkers yet.\nexport class Reader {\n\t#buffer: Uint8Array;\n\t#stream?: ReadableStream<Uint8Array>; // if undefined, the buffer is consumed then EOF\n\t#reader?: ReadableStreamDefaultReader<Uint8Array>;\n\t#closed?: Promise<void>;\n\tversion?: IetfVersion;\n\n\t// Either stream or buffer MUST be provided.\n\tconstructor(stream: ReadableStream<Uint8Array>, buffer?: Uint8Array, version?: IetfVersion);\n\tconstructor(stream: undefined, buffer: Uint8Array, version?: IetfVersion);\n\tconstructor(stream?: ReadableStream<Uint8Array>, buffer?: Uint8Array, version?: IetfVersion) {\n\t\tthis.#buffer = buffer ?? new Uint8Array();\n\t\tthis.#stream = stream;\n\t\tthis.#reader = this.#stream?.getReader();\n\t\tthis.version = version;\n\t}\n\n\t// Adds more data to the buffer, returning true if more data was added.\n\tasync #fill(): Promise<boolean> {\n\t\tif (!this.#reader) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Every read of this stream funnels through here, so decoding the peer's reset code\n\t\t// once is enough to keep the raw transport error out of every caller (and every app).\n\t\tconst result = await this.#reader.read().catch((err: unknown) => {\n\t\t\tthrow fromTransport(err, { version: this.version });\n\t\t});\n\n\t\tif (result.done) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (result.value.byteLength === 0) {\n\t\t\tthrow new Error(\"unexpected empty chunk\");\n\t\t}\n\n\t\tconst buffer = result.value;\n\n\t\tif (this.#buffer.byteLength === 0) {\n\t\t\tthis.#buffer = new Uint8Array(buffer);\n\t\t} else {\n\t\t\tconst temp = new Uint8Array(this.#buffer.byteLength + buffer.byteLength);\n\t\t\ttemp.set(this.#buffer);\n\t\t\ttemp.set(buffer, this.#buffer.byteLength);\n\t\t\tthis.#buffer = temp;\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t// Add more data to the buffer until it's at least size bytes.\n\tasync #fillTo(size: number) {\n\t\tif (size > MAX_READ_SIZE) {\n\t\t\tthrow new Error(`read size ${size} exceeds max size ${MAX_READ_SIZE}`);\n\t\t}\n\n\t\twhile (this.#buffer.byteLength < size) {\n\t\t\tif (!(await this.#fill())) {\n\t\t\t\tthrow new Error(\"unexpected end of stream\");\n\t\t\t}\n\t\t}\n\t}\n\n\t// Consumes the first size bytes of the buffer.\n\t#slice(size: number): Uint8Array {\n\t\tconst result = new Uint8Array(this.#buffer.buffer, this.#buffer.byteOffset, size);\n\t\tthis.#buffer = new Uint8Array(\n\t\t\tthis.#buffer.buffer,\n\t\t\tthis.#buffer.byteOffset + size,\n\t\t\tthis.#buffer.byteLength - size,\n\t\t);\n\n\t\treturn result;\n\t}\n\n\tasync read(size: number): Promise<Uint8Array> {\n\t\tif (size === 0) return new Uint8Array();\n\n\t\tawait this.#fillTo(size);\n\t\treturn this.#slice(size);\n\t}\n\n\tasync readAll(): Promise<Uint8Array> {\n\t\twhile (await this.#fill()) {\n\t\t\t// keep going\n\t\t}\n\t\treturn this.#slice(this.#buffer.byteLength);\n\t}\n\n\tasync string(): Promise<string> {\n\t\tconst length = await this.u53();\n\t\tconst buffer = await this.read(length);\n\t\treturn decodeUtf8(buffer);\n\t}\n\n\tasync bool(): Promise<boolean> {\n\t\tconst v = await this.u8();\n\t\tif (v === 0) return false;\n\t\tif (v === 1) return true;\n\t\tthrow new Error(\"invalid bool value\");\n\t}\n\n\tasync u8(): Promise<number> {\n\t\tawait this.#fillTo(1);\n\t\treturn this.#slice(1)[0];\n\t}\n\n\tasync u16(): Promise<number> {\n\t\tawait this.#fillTo(2);\n\t\tconst view = new DataView(this.#buffer.buffer, this.#buffer.byteOffset, 2);\n\t\tconst result = view.getUint16(0);\n\t\tthis.#slice(2);\n\t\treturn result;\n\t}\n\n\t// Returns a Number using 53-bits, the max Javascript can use for integer math.\n\tasync u53(): Promise<number> {\n\t\tconst v = await this.u62();\n\t\tif (v > Varint.MAX_U53) {\n\t\t\tthrow new Error(`value larger than 53-bits: ${v.toString()}`);\n\t\t}\n\n\t\treturn Number(v);\n\t}\n\n\t// NOTE: Returns a bigint instead of a number since it may be larger than 53-bits\n\tasync u62(): Promise<bigint> {\n\t\tif (isLeadingOnes(this.version)) {\n\t\t\treturn this.#readLeadingOnes();\n\t\t}\n\t\treturn this.#readQuicVarint();\n\t}\n\n\tasync #readQuicVarint(): Promise<bigint> {\n\t\tawait this.#fillTo(1);\n\t\tconst size = (this.#buffer[0] & 0xc0) >> 6;\n\n\t\tif (size === 0) {\n\t\t\tconst first = this.#slice(1)[0];\n\t\t\treturn BigInt(first) & 0x3fn;\n\t\t}\n\t\tif (size === 1) {\n\t\t\tawait this.#fillTo(2);\n\t\t\tconst slice = this.#slice(2);\n\t\t\tconst view = new DataView(slice.buffer, slice.byteOffset, slice.byteLength);\n\n\t\t\treturn BigInt(view.getUint16(0)) & 0x3fffn;\n\t\t}\n\t\tif (size === 2) {\n\t\t\tawait this.#fillTo(4);\n\t\t\tconst slice = this.#slice(4);\n\t\t\tconst view = new DataView(slice.buffer, slice.byteOffset, slice.byteLength);\n\n\t\t\treturn BigInt(view.getUint32(0)) & 0x3fffffffn;\n\t\t}\n\t\tawait this.#fillTo(8);\n\t\tconst slice = this.#slice(8);\n\t\tconst view = new DataView(slice.buffer, slice.byteOffset, slice.byteLength);\n\n\t\treturn view.getBigUint64(0) & 0x3fffffffffffffffn;\n\t}\n\n\tasync #readLeadingOnes(): Promise<bigint> {\n\t\tawait this.#fillTo(1);\n\t\tconst b = this.#buffer[0];\n\n\t\t// Count leading 1-bits\n\t\tlet ones = 0;\n\t\tfor (let bit = 7; bit >= 0; bit--) {\n\t\t\tif (b & (1 << bit)) ones++;\n\t\t\telse break;\n\t\t}\n\n\t\t// 1111110x is a 7-byte form. Draft-17 rejects it; draft-18+ allows it per #1595.\n\t\tif (ones === 6 && this.version === Version.DRAFT_17) {\n\t\t\tthrow new Error(\"invalid leading-ones varint: 1111110x prefix is reserved on draft-17\");\n\t\t}\n\n\t\tlet totalSize: number;\n\t\tif (ones <= 5) totalSize = ones + 1;\n\t\telse if (ones === 6) totalSize = 7;\n\t\telse if (ones === 7) totalSize = 8;\n\t\telse totalSize = 9; // ones === 8\n\n\t\tawait this.#fillTo(totalSize);\n\t\tconst slice = this.#slice(totalSize);\n\n\t\tconst [value] = Varint.decodeLeadingOnes(slice);\n\t\treturn value;\n\t}\n\n\t// Returns false if there is more data to read, blocking if it hasn't been received yet.\n\tasync done(): Promise<boolean> {\n\t\tif (this.#buffer.byteLength > 0) return false;\n\t\treturn !(await this.#fill());\n\t}\n\n\tstop(reason: unknown) {\n\t\tthis.#reader?.cancel(withCode(reason, this.version)).catch(() => void 0);\n\t}\n\n\t// Decoded like #fill: a caller racing this against a read must not get a different error\n\t// shape depending on which one won. Derived once, so racing it per frame doesn't allocate.\n\tget closed(): Promise<void> {\n\t\tthis.#closed ??= (this.#reader?.closed ?? Promise.resolve()).catch((err: unknown) => {\n\t\t\tthrow fromTransport(err, { version: this.version });\n\t\t});\n\t\treturn this.#closed;\n\t}\n}\n\n// Writer wraps a stream and writes chunks of data\nexport class Writer {\n\t#writer: WritableStreamDefaultWriter<Uint8Array>;\n\t#stream: WritableStream<Uint8Array>;\n\t#closed?: Promise<void>;\n\n\t// Scratch buffer for writing varints.\n\t// Fixed at 9 bytes (leading-ones max).\n\t#scratch: ArrayBuffer;\n\n\tversion?: IetfVersion;\n\n\tconstructor(stream: WritableStream<Uint8Array>, version?: IetfVersion) {\n\t\tthis.#stream = stream;\n\t\tthis.#scratch = new ArrayBuffer(9);\n\t\tthis.#writer = this.#stream.getWriter();\n\t\tthis.version = version;\n\t}\n\n\t/**\n\t * Rank this stream against the session's others, where HIGHER values are sent first.\n\t *\n\t * A send order only schedules the local end, so a stream the peer opened has to be ranked\n\t * here rather than at the peer's {@link open}.\n\t *\n\t * The spec makes `sendOrder` a settable attribute on every {@link SendStream}. Where the\n\t * interface isn't implemented (Chrome as of writing, a mock, a polyfill) this just sets an\n\t * ignored property, the same way an ignored `sendOrder` option does at {@link open}.\n\t */\n\tsetPriority(sendOrder: number) {\n\t\t(this.#stream as SendStream).sendOrder = sendOrder;\n\t}\n\n\tasync bool(v: boolean) {\n\t\tawait this.write(setUint8(this.#scratch, v ? 1 : 0));\n\t}\n\n\tasync u8(v: number) {\n\t\tif (!Number.isInteger(v) || v < 0 || v > 255) {\n\t\t\tthrow new RangeError(`invalid u8: ${v}`);\n\t\t}\n\t\tawait this.write(setUint8(this.#scratch, v));\n\t}\n\n\tasync u16(v: number) {\n\t\tawait this.write(setUint16(this.#scratch, v));\n\t}\n\n\tasync i32(v: number) {\n\t\tif (Math.abs(v) > MAX_U31) {\n\t\t\tthrow new Error(`overflow, value larger than 32-bits: ${v.toString()}`);\n\t\t}\n\n\t\t// We don't use a VarInt, so it always takes 4 bytes.\n\t\t// This could be improved but nothing is standardized yet.\n\t\tawait this.write(setInt32(this.#scratch, v));\n\t}\n\n\tasync u53(v: number) {\n\t\tif (!Number.isSafeInteger(v) || v < 0) {\n\t\t\tthrow new RangeError(`invalid u53: ${v}`);\n\t\t}\n\t\tif (isLeadingOnes(this.version)) {\n\t\t\tawait this.write(Varint.encodeLeadingOnesTo(this.#scratch, v));\n\t\t} else {\n\t\t\tawait this.write(Varint.encodeTo(this.#scratch, v));\n\t\t}\n\t}\n\n\tasync u62(v: bigint) {\n\t\tif (isLeadingOnes(this.version)) {\n\t\t\tawait this.write(Varint.encodeLeadingOnesTo(this.#scratch, v));\n\t\t} else {\n\t\t\tawait this.write(Varint.encodeTo(this.#scratch, v));\n\t\t}\n\t}\n\n\tasync write(v: Uint8Array) {\n\t\t// Mirrors Reader.#fill: every write funnels through here, so a STOP_SENDING from the\n\t\t// peer surfaces as a typed code rather than the transport's own error shape.\n\t\tawait this.#writer.write(v).catch((err: unknown) => {\n\t\t\tthrow fromTransport(err, { version: this.version });\n\t\t});\n\t}\n\n\tasync string(str: string) {\n\t\tconst data = new TextEncoder().encode(str);\n\t\tawait this.u53(data.byteLength);\n\t\tawait this.write(data);\n\t}\n\n\tclose() {\n\t\tthis.#writer.close().catch(() => void 0);\n\t}\n\n\t// Mirrors Reader.closed: a STOP_SENDING reaches a caller racing this with the same\n\t// typed code it would get from a write.\n\tget closed(): Promise<void> {\n\t\tthis.#closed ??= this.#writer.closed.catch((err: unknown) => {\n\t\t\tthrow fromTransport(err, { version: this.version });\n\t\t});\n\t\treturn this.#closed;\n\t}\n\n\treset(reason: unknown) {\n\t\tthis.#writer.abort(withCode(reason, this.version)).catch(() => void 0);\n\t}\n\n\t/**\n\t * Open an outgoing unidirectional stream.\n\t * @param quic - The session to open it on\n\t * @param options - The version its varints encode with, and the send order ranking it\n\t * against the session's other streams\n\t */\n\tstatic async open(quic: WebTransport, options?: OpenOptions): Promise<Writer> {\n\t\tconst writable = await openWithin(\n\t\t\tquic.createUnidirectionalStream(sendOptions(options)) as Promise<WritableStream<Uint8Array>>,\n\t\t\toptions?.timeout ?? OPEN_TIMEOUT_MS,\n\t\t\t(stream) => void stream.abort().catch(() => void 0),\n\t\t);\n\n\t\treturn new Writer(writable, options?.version);\n\t}\n\n\t/**\n\t * Like {@link Writer.open}, but gives up when `cancel` settles or `timeout` elapses,\n\t * returning undefined so the caller can drop whatever it meant to send. A stream that\n\t * opens after that is reset rather than leaked. A real transport failure still throws.\n\t *\n\t * Worth using even with `waitUntilAvailable: false`, since an implementation may park\n\t * an over-limit open instead of rejecting it.\n\t */\n\tstatic async tryOpen(quic: WebTransport, options: TryOpenOptions): Promise<Writer | undefined> {\n\t\t// Raced ahead of the open, so an already-cancelled caller wins even against a slot\n\t\t// that is free right now. `race` rather than `Promise.race`: the caller shares one\n\t\t// `cancel` across every group of a subscription, which must not gain a reaction per call.\n\t\tconst open = Writer.open(quic, options);\n\n\t\t// Resets a stream that opens after we gave up; a no-op if the open itself failed.\n\t\tconst abandon = () => {\n\t\t\tconst abandoned = new Error(\"abandoned waiting for a stream slot\");\n\t\t\topen.then((w) => w.reset(abandoned)).catch(() => void 0);\n\t\t};\n\n\t\ttry {\n\t\t\tconst stream = await race([options.cancel, open]);\n\t\t\tif (stream) return stream;\n\t\t} catch (err: unknown) {\n\t\t\t// open already discarded the late stream on its way out.\n\t\t\tif (err instanceof TimeoutError) return undefined;\n\t\t\t// A rejected `cancel` still leaves the open pending.\n\t\t\tabandon();\n\t\t\tthrow err;\n\t\t}\n\n\t\tabandon();\n\t\treturn undefined;\n\t}\n}\n\nfunction setUint8(dst: ArrayBuffer, v: number): Uint8Array {\n\tconst buffer = new Uint8Array(dst, 0, 1);\n\tbuffer[0] = v;\n\treturn buffer;\n}\n\nfunction setUint16(dst: ArrayBuffer, v: number): Uint8Array {\n\tconst view = new DataView(dst, 0, 2);\n\tview.setUint16(0, v);\n\treturn new Uint8Array(view.buffer, view.byteOffset, view.byteLength);\n}\n\nfunction setInt32(dst: ArrayBuffer, v: number): Uint8Array {\n\tconst view = new DataView(dst, 0, 4);\n\tview.setInt32(0, v);\n\treturn new Uint8Array(view.buffer, view.byteOffset, view.byteLength);\n}\n\n// Returns the next stream from the connection\nexport class Readers {\n\t#reader: ReadableStreamDefaultReader<ReadableStream<Uint8Array>>;\n\t#version?: IetfVersion;\n\n\tconstructor(quic: WebTransport, version?: IetfVersion) {\n\t\tthis.#reader = quic.incomingUnidirectionalStreams.getReader() as ReadableStreamDefaultReader<\n\t\t\tReadableStream<Uint8Array>\n\t\t>;\n\t\tthis.#version = version;\n\t}\n\n\tasync next(): Promise<Reader | undefined> {\n\t\tconst next = await this.#reader.read();\n\t\tif (next.done) return;\n\t\treturn new Reader(next.value, undefined, this.#version);\n\t}\n\n\tclose() {\n\t\tthis.#reader.cancel();\n\t}\n}\n"]}
|
package/tail.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Milli } from "./time";
|
|
2
|
+
/**
|
|
3
|
+
* How long a subscriber waits for a group stream it cannot account for once the publisher
|
|
4
|
+
* has ended the subscription.
|
|
5
|
+
*
|
|
6
|
+
* A group reset before its header arrived leaves no trace, and QUIC does not order streams,
|
|
7
|
+
* so a stream opened before the end can still be in flight after it. This bounds the wait on
|
|
8
|
+
* IETF, and on moq-lite when the subscription has no max age to bound it with.
|
|
9
|
+
*/
|
|
10
|
+
export declare const TAIL_GRACE_MS: Milli;
|
|
11
|
+
//# sourceMappingURL=tail.d.ts.map
|
package/tail.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tail.d.ts","sourceRoot":"","sources":["../src/tail.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,OAAc,CAAC"}
|
package/tail.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/* @ts-self-types="./tail.d.ts" */
|
|
2
|
+
import { Signal } from "@moq/signals";
|
|
3
|
+
import { Milli } from "./time.js";
|
|
4
|
+
/**
|
|
5
|
+
* How long a subscriber waits for a group stream it cannot account for once the publisher
|
|
6
|
+
* has ended the subscription.
|
|
7
|
+
*
|
|
8
|
+
* A group reset before its header arrived leaves no trace, and QUIC does not order streams,
|
|
9
|
+
* so a stream opened before the end can still be in flight after it. This bounds the wait on
|
|
10
|
+
* IETF, and on moq-lite when the subscription has no max age to bound it with.
|
|
11
|
+
*/
|
|
12
|
+
export const TAIL_GRACE_MS = Milli(1000);
|
|
13
|
+
// setTimeout truncates a longer delay to a signed 32-bit int and fires at once.
|
|
14
|
+
const MAX_TIMEOUT_MS = 2 ** 31 - 1;
|
|
15
|
+
/**
|
|
16
|
+
* The group streams a subscription has received, so its end can wait for the ones still owed.
|
|
17
|
+
*
|
|
18
|
+
* A publisher ends a subscription before every group stream it opened has necessarily
|
|
19
|
+
* arrived. This records which sequences are accounted for (a stream's header arrived, or
|
|
20
|
+
* the publisher dropped them) and how many streams are still being read, and {@link settle}
|
|
21
|
+
* waits on them.
|
|
22
|
+
*
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export class Tail {
|
|
26
|
+
// Disjoint, sorted, exclusive-end ranges of accounted sequences. A gap splits a range, so
|
|
27
|
+
// this stays as small as the number of gaps rather than the number of groups.
|
|
28
|
+
#accounted = [];
|
|
29
|
+
// Group streams whose header arrived, and those still being read.
|
|
30
|
+
#streams = 0;
|
|
31
|
+
#active = 0;
|
|
32
|
+
#changed = new Signal(0);
|
|
33
|
+
/** Group streams whose header arrived, whether they finished or were reset. */
|
|
34
|
+
get streams() {
|
|
35
|
+
return this.#streams;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Record a group stream whose header arrived. Returns the call that marks it read to
|
|
39
|
+
* its end, which is idempotent.
|
|
40
|
+
*/
|
|
41
|
+
open(sequence) {
|
|
42
|
+
this.#streams += 1;
|
|
43
|
+
this.#active += 1;
|
|
44
|
+
this.#account(sequence, sequence + 1);
|
|
45
|
+
let closed = false;
|
|
46
|
+
return () => {
|
|
47
|
+
if (closed)
|
|
48
|
+
return;
|
|
49
|
+
closed = true;
|
|
50
|
+
this.#active -= 1;
|
|
51
|
+
this.#bump();
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** Record sequences `[start, end)` as accounted for without a stream: dropped, or a datagram. */
|
|
55
|
+
account(start, end) {
|
|
56
|
+
this.#account(start, end);
|
|
57
|
+
}
|
|
58
|
+
/** Whether every sequence in `[start, end)` is accounted for. */
|
|
59
|
+
covers(start, end) {
|
|
60
|
+
if (start >= end)
|
|
61
|
+
return true;
|
|
62
|
+
// Ranges are merged on insert, so one range covers the span or none does.
|
|
63
|
+
return this.#accounted.some(([lo, hi]) => lo <= start && end <= hi);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Wait until every stream is read to its end and `complete()` holds, or `grace`
|
|
67
|
+
* milliseconds pass with nothing left being read, or `closed` settles.
|
|
68
|
+
*
|
|
69
|
+
* A stream still being read is always waited for: a group ends on its own stream's FIN
|
|
70
|
+
* or reset, never because its track ended. The grace only gives up on streams that never
|
|
71
|
+
* arrived.
|
|
72
|
+
*/
|
|
73
|
+
async settle(complete, grace, closed) {
|
|
74
|
+
let expired = false;
|
|
75
|
+
const timer = setTimeout(() => {
|
|
76
|
+
expired = true;
|
|
77
|
+
this.#bump();
|
|
78
|
+
}, Math.min(grace, MAX_TIMEOUT_MS));
|
|
79
|
+
try {
|
|
80
|
+
while (closed.peek() === undefined) {
|
|
81
|
+
if (this.#active === 0 && (expired || complete()))
|
|
82
|
+
return;
|
|
83
|
+
await Signal.race(this.#changed, closed);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
clearTimeout(timer);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
#account(start, end) {
|
|
91
|
+
if (start >= end)
|
|
92
|
+
return;
|
|
93
|
+
const merged = [];
|
|
94
|
+
let lo = start;
|
|
95
|
+
let hi = end;
|
|
96
|
+
let placed = false;
|
|
97
|
+
for (const range of this.#accounted) {
|
|
98
|
+
if (range[1] < lo) {
|
|
99
|
+
merged.push(range);
|
|
100
|
+
}
|
|
101
|
+
else if (hi < range[0]) {
|
|
102
|
+
if (!placed)
|
|
103
|
+
merged.push([lo, hi]);
|
|
104
|
+
placed = true;
|
|
105
|
+
merged.push(range);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
lo = Math.min(lo, range[0]);
|
|
109
|
+
hi = Math.max(hi, range[1]);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (!placed)
|
|
113
|
+
merged.push([lo, hi]);
|
|
114
|
+
this.#accounted = merged;
|
|
115
|
+
this.#bump();
|
|
116
|
+
}
|
|
117
|
+
#bump() {
|
|
118
|
+
this.#changed.update((revision) => revision + 1);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=tail.js.map
|
package/tail.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tail.js","sourceRoot":"","sources":["../src/tail.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;AAEzC,gFAAgF;AAChF,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAEnC;;;;;;;;;GASG;AACH,MAAM,OAAO,IAAI;IAChB,0FAA0F;IAC1F,8EAA8E;IAC9E,UAAU,GAAuB,EAAE,CAAC;IACpC,kEAAkE;IAClE,QAAQ,GAAG,CAAC,CAAC;IACb,OAAO,GAAG,CAAC,CAAC;IACZ,QAAQ,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC;IAEzB,+EAA+E;IAC/E,IAAI,OAAO;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,IAAI,CAAC,QAAgB;QACpB,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC;QACnB,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;QAClB,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,CAAC,CAAC,CAAC;QAEtC,IAAI,MAAM,GAAG,KAAK,CAAC;QACnB,OAAO,GAAG,EAAE;YACX,IAAI,MAAM;gBAAE,OAAO;YACnB,MAAM,GAAG,IAAI,CAAC;YACd,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;Y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,GAAuB,EAAE,CAAC;QACtC,IAAI,EAAE,GAAG,KAAK,CAAC;QACf,IAAI,EAAE,GAAG,GAAG,CAAC;QACb,IAAI,MAAM,GAAG,KAAK,CAAC;QACnB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACrC,IAAI,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC;gBACnB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACpB,CAAC;iBAAM,IAAI,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC1B,IAAI,CAAC,MAAM;oBAAE,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;gBACnC,MAAM,GAAG,IAAI,CAAC;gBACd,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACpB,CAAC;iBAAM,CAAC;gBACP,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC5B,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7B,CAAC;QACF,CAAC;QACD,IAAI,CAAC,MAAM;YAAE,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;QACnC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC;QACzB,IAAI,CAAC,KAAK,EAAE,CAAC;IACd,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;IAClD,CAAC;CACD","sourcesContent":["import { type GetPromise, Signal } from \"@moq/signals\";\nimport { Milli } from \"./time.ts\";\n\n/**\n * How long a subscriber waits for a group stream it cannot account for once the publisher\n * has ended the subscription.\n *\n * A group reset before its header arrived leaves no trace, and QUIC does not order streams,\n * so a stream opened before the end can still be in flight after it. This bounds the wait on\n * IETF, and on moq-lite when the subscription has no max age to bound it with.\n */\nexport const TAIL_GRACE_MS = Milli(1000);\n\n// setTimeout truncates a longer delay to a signed 32-bit int and fires at once.\nconst MAX_TIMEOUT_MS = 2 ** 31 - 1;\n\n/**\n * The group streams a subscription has received, so its end can wait for the ones still owed.\n *\n * A publisher ends a subscription before every group stream it opened has necessarily\n * arrived. This records which sequences are accounted for (a stream's header arrived, or\n * the publisher dropped them) and how many streams are still being read, and {@link settle}\n * waits on them.\n *\n * @internal\n */\nexport class Tail {\n\t// Disjoint, sorted, exclusive-end ranges of accounted sequences. A gap splits a range, so\n\t// this stays as small as the number of gaps rather than the number of groups.\n\t#accounted: [number, number][] = [];\n\t// Group streams whose header arrived, and those still being read.\n\t#streams = 0;\n\t#active = 0;\n\t#changed = new Signal(0);\n\n\t/** Group streams whose header arrived, whether they finished or were reset. */\n\tget streams(): number {\n\t\treturn this.#streams;\n\t}\n\n\t/**\n\t * Record a group stream whose header arrived. Returns the call that marks it read to\n\t * its end, which is idempotent.\n\t */\n\topen(sequence: number): () => void {\n\t\tthis.#streams += 1;\n\t\tthis.#active += 1;\n\t\tthis.#account(sequence, sequence + 1);\n\n\t\tlet closed = false;\n\t\treturn () => {\n\t\t\tif (closed) return;\n\t\t\tclosed = true;\n\t\t\tthis.#active -= 1;\n\t\t\tthis.#bump();\n\t\t};\n\t}\n\n\t/** Record sequences `[start, end)` as accounted for without a stream: dropped, or a datagram. */\n\taccount(start: number, end: number): void {\n\t\tthis.#account(start, end);\n\t}\n\n\t/** Whether every sequence in `[start, end)` is accounted for. */\n\tcovers(start: number, end: number): boolean {\n\t\tif (start >= end) return true;\n\t\t// Ranges are merged on insert, so one range covers the span or none does.\n\t\treturn this.#accounted.some(([lo, hi]) => lo <= start && end <= hi);\n\t}\n\n\t/**\n\t * Wait until every stream is read to its end and `complete()` holds, or `grace`\n\t * milliseconds pass with nothing left being read, or `closed` settles.\n\t *\n\t * A stream still being read is always waited for: a group ends on its own stream's FIN\n\t * or reset, never because its track ended. The grace only gives up on streams that never\n\t * arrived.\n\t */\n\tasync settle(complete: () => boolean, grace: Milli, closed: GetPromise<unknown>): Promise<void> {\n\t\tlet expired = false;\n\t\tconst timer = setTimeout(\n\t\t\t() => {\n\t\t\t\texpired = true;\n\t\t\t\tthis.#bump();\n\t\t\t},\n\t\t\tMath.min(grace, MAX_TIMEOUT_MS),\n\t\t);\n\t\ttry {\n\t\t\twhile (closed.peek() === undefined) {\n\t\t\t\tif (this.#active === 0 && (expired || complete())) return;\n\t\t\t\tawait Signal.race(this.#changed, closed);\n\t\t\t}\n\t\t} finally {\n\t\t\tclearTimeout(timer);\n\t\t}\n\t}\n\n\t#account(start: number, end: number): void {\n\t\tif (start >= end) return;\n\n\t\tconst merged: [number, number][] = [];\n\t\tlet lo = start;\n\t\tlet hi = end;\n\t\tlet placed = false;\n\t\tfor (const range of this.#accounted) {\n\t\t\tif (range[1] < lo) {\n\t\t\t\tmerged.push(range);\n\t\t\t} else if (hi < range[0]) {\n\t\t\t\tif (!placed) merged.push([lo, hi]);\n\t\t\t\tplaced = true;\n\t\t\t\tmerged.push(range);\n\t\t\t} else {\n\t\t\t\tlo = Math.min(lo, range[0]);\n\t\t\t\thi = Math.max(hi, range[1]);\n\t\t\t}\n\t\t}\n\t\tif (!placed) merged.push([lo, hi]);\n\t\tthis.#accounted = merged;\n\t\tthis.#bump();\n\t}\n\n\t#bump(): void {\n\t\tthis.#changed.update((revision) => revision + 1);\n\t}\n}\n"]}
|
package/track.d.ts
CHANGED
|
@@ -226,7 +226,23 @@ export declare class Producer {
|
|
|
226
226
|
* apply. Most origin publishers want {@link appendDatagram} instead.
|
|
227
227
|
*/
|
|
228
228
|
insertDatagram(sequence: number, timestamp: Timestamp, payload: Uint8Array): void;
|
|
229
|
-
/**
|
|
229
|
+
/**
|
|
230
|
+
* Declare the track's exclusive end, possibly ahead of the live edge, mirroring the Rust
|
|
231
|
+
* `finish_at`.
|
|
232
|
+
*
|
|
233
|
+
* `final` is the first sequence that will never be produced, so a track whose last group
|
|
234
|
+
* is 89 finishes at 90. Groups and datagrams below it are still accepted; anything at or
|
|
235
|
+
* above it is refused. Unlike {@link close} it is not terminal: call `close()` once the
|
|
236
|
+
* remaining groups are written. Throws if the track is closed, already has an end, or
|
|
237
|
+
* `final` is at or below a sequence already produced.
|
|
238
|
+
*/
|
|
239
|
+
finishAt(final: number): void;
|
|
240
|
+
/**
|
|
241
|
+
* Close the track and every subscriber, mirroring the abort to their groups. Idempotent.
|
|
242
|
+
*
|
|
243
|
+
* A clean close keeps the end {@link finishAt} declared, or declares one past the highest
|
|
244
|
+
* sequence produced; an abort ends without one.
|
|
245
|
+
*/
|
|
230
246
|
close(abort?: Error): void;
|
|
231
247
|
/** Append a frame as its own single-frame group. */
|
|
232
248
|
writeFrame(frame: Frame): void;
|
|
@@ -264,12 +280,22 @@ export declare class Subscriber {
|
|
|
264
280
|
/** Return the latest group sequence observed on this track, if any. */
|
|
265
281
|
latest(): number | undefined;
|
|
266
282
|
/**
|
|
267
|
-
* The track's exclusive final boundary
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
* `latest() + 1`. Undefined
|
|
283
|
+
* The track's exclusive final boundary: the end {@link Producer.finishAt} declared, which
|
|
284
|
+
* can be ahead of the live edge, or one past the highest sequence produced once the
|
|
285
|
+
* producer closes cleanly (0 for a track that produced none). Groups and datagrams share
|
|
286
|
+
* the sequence namespace, so this can exceed `latest() + 1`. Undefined until declared,
|
|
287
|
+
* and after an abort that declared none.
|
|
271
288
|
*/
|
|
272
289
|
final(): number | undefined;
|
|
290
|
+
/**
|
|
291
|
+
* Resolve with the track's exclusive final boundary once it is known, mirroring the Rust
|
|
292
|
+
* `finished`.
|
|
293
|
+
*
|
|
294
|
+
* Resolves as soon as the end is declared, which may be ahead of the live edge, so it
|
|
295
|
+
* says nothing about every group having arrived: read until the cursor returns
|
|
296
|
+
* `undefined` for that. Rejects with the abort, or if the track closes without an end.
|
|
297
|
+
*/
|
|
298
|
+
finished(): Promise<number>;
|
|
273
299
|
/**
|
|
274
300
|
* The newest frame this track has produced, or `undefined` while it has none.
|
|
275
301
|
*
|
|
@@ -377,6 +403,8 @@ export declare class Ordered {
|
|
|
377
403
|
latest(): number | undefined;
|
|
378
404
|
/** The track's exclusive final boundary; see {@link Subscriber.final}. */
|
|
379
405
|
final(): number | undefined;
|
|
406
|
+
/** Resolve with the track's exclusive final boundary once known; see {@link Subscriber.finished}. */
|
|
407
|
+
finished(): Promise<number>;
|
|
380
408
|
/** Limit subsequent reads to these groups and return this reader for chaining. */
|
|
381
409
|
withGroups(groups: Groups): this;
|
|
382
410
|
/** Limit subsequent reads to these groups; see {@link Subscriber.setGroups}. */
|
package/track.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"track.d.ts","sourceRoot":"","sources":["../src/track.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAgB,KAAK,UAAU,EAAE,KAAK,MAAM,EAAgB,MAAM,cAAc,CAAC;AACxF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,QAAQ,IAAI,aAAa,EAAE,QAAQ,IAAI,aAAa,EAAE,MAAM,YAAY,CAAC;AASnG,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAG7D,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAM9C,6FAA6F;AAC7F,eAAO,MAAM,kBAAkB,OAAc,CAAC;AAY9C,mFAAmF;AACnF,MAAM,WAAW,QAAQ;IACxB,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;CACd;AAED;;;;;;GAMG;AACH,MAAM,WAAW,IAAI;IACpB;;;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AAM,IAAI,MAAM,GAAG,SAAS,CAE3B;IAED,0EAA0E;IAC1E,KAAK,IAAI,MAAM,GAAG,SAAS,CAE1B;IAED,qGAAqG;IACrG,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC,CAE1B;IAED,kFAAkF;IAClF,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAG/B;IAED,gFAAgF;IAChF,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAE9B;IAED,yEAAyE;IACzE,MAAM,CAAC,OAAO,EAAE,YAAY,QAE3B;IAED,0FAA0F;IAC1F,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,QAElB;IAED;;;;;;;OAOG;IACH,SAAS,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAE9C;IAED;;;;;;OAMG;IACH,SAAS,IAAI,OAAO,CAAC,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,KAAK,CAAC,GAAG,SAAS,CAAC,CAE3E;IAED,2DAA2D;IAC3D,UAAU,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAExC;IAED,gDAAgD;IAChD,QAAQ,IAAI,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAEvC;IAED,8FAA8F;IAC9F,QAAQ,IAAI,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAEvC;IAED;;;;;;;;OAQG;IACH,YAAY,IAAI,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAE5C;CACD"}
|
package/track.js
CHANGED
|
@@ -115,6 +115,7 @@ export class Request {
|
|
|
115
115
|
}
|
|
116
116
|
static {
|
|
117
117
|
hooks.makeRequest = (options) => new Request(options);
|
|
118
|
+
hooks.pendingTrackProducer = (request) => request.#producer;
|
|
118
119
|
}
|
|
119
120
|
/** The aggregate subscription requested for this track. */
|
|
120
121
|
get subscription() {
|
|
@@ -189,11 +190,12 @@ class TrackState {
|
|
|
189
190
|
datagrams = new Signal([]);
|
|
190
191
|
latest;
|
|
191
192
|
/**
|
|
192
|
-
* The exclusive final boundary,
|
|
193
|
-
* highest sequence produced. Groups and datagrams share the
|
|
194
|
-
* exceed `latest + 1` (which only tracks groups). Mirrors the
|
|
193
|
+
* The exclusive final boundary, declared by {@link Producer.finishAt} or stamped by a
|
|
194
|
+
* clean close as one past the highest sequence produced. Groups and datagrams share the
|
|
195
|
+
* namespace, so this can exceed `latest + 1` (which only tracks groups). Mirrors the
|
|
196
|
+
* Rust `final_sequence`.
|
|
195
197
|
*/
|
|
196
|
-
final;
|
|
198
|
+
final = new Signal(undefined);
|
|
197
199
|
closed = new Once();
|
|
198
200
|
update;
|
|
199
201
|
/** Resolved once the producer commits the immutable properties. */
|
|
@@ -403,10 +405,9 @@ export class Producer {
|
|
|
403
405
|
this.#prune();
|
|
404
406
|
for (const entry of this.#cache)
|
|
405
407
|
this.#mirror(entry, sink);
|
|
406
|
-
|
|
407
|
-
|
|
408
|
+
sink.final.set(this.#state.final.peek());
|
|
409
|
+
if (closed !== undefined)
|
|
408
410
|
closeTrackState(sink, closed instanceof Error ? closed : undefined);
|
|
409
|
-
}
|
|
410
411
|
}
|
|
411
412
|
// Recompute from every live sink because an update or close can narrow as well as widen
|
|
412
413
|
// the aggregate. The wire layer observes this signal and emits SUBSCRIBE_UPDATE.
|
|
@@ -521,11 +522,19 @@ export class Producer {
|
|
|
521
522
|
// so their latency guard can preserve a terminal expiry verdict.
|
|
522
523
|
this.#prune();
|
|
523
524
|
}
|
|
524
|
-
|
|
525
|
-
|
|
525
|
+
// Refuse a write once the track is closed, or at or past its declared end.
|
|
526
|
+
#writable(sequence) {
|
|
526
527
|
if (this.#state.closed.peek() !== undefined)
|
|
527
528
|
throw new Error("track is closed");
|
|
529
|
+
const final = this.#state.final.peek();
|
|
530
|
+
if (final !== undefined && sequence >= final) {
|
|
531
|
+
throw new Error(`sequence ${sequence} is at or past the track's end ${final}`);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
/** Append a new group with the next sequence number. */
|
|
535
|
+
appendGroup() {
|
|
528
536
|
const sequence = this.#sequence;
|
|
537
|
+
this.#writable(sequence.next);
|
|
529
538
|
const group = new GroupProducer(sequence.next);
|
|
530
539
|
sequence.next = group.sequence + 1;
|
|
531
540
|
this.#publish(group);
|
|
@@ -540,8 +549,7 @@ export class Producer {
|
|
|
540
549
|
* entry is already gone, so a long-evicted sequence is accepted as new.
|
|
541
550
|
*/
|
|
542
551
|
writeGroup(group) {
|
|
543
|
-
|
|
544
|
-
throw new Error("track is closed");
|
|
552
|
+
this.#writable(group.sequence);
|
|
545
553
|
const existing = this.#cache.findIndex((entry) => entry.group.sequence === group.sequence);
|
|
546
554
|
if (existing >= 0) {
|
|
547
555
|
const entry = this.#cache[existing];
|
|
@@ -582,12 +590,11 @@ export class Producer {
|
|
|
582
590
|
* relay preserving upstream numbering uses {@link insertDatagram}.
|
|
583
591
|
*/
|
|
584
592
|
appendDatagram(timestamp, payload) {
|
|
585
|
-
if (this.#state.closed.peek() !== undefined)
|
|
586
|
-
throw new Error("track is closed");
|
|
587
|
-
if (payload.byteLength > MAX_DATAGRAM_BYTES)
|
|
588
|
-
throw new Error("datagram payload too large");
|
|
589
593
|
const counter = this.#sequence;
|
|
590
594
|
const sequence = counter.next;
|
|
595
|
+
this.#writable(sequence);
|
|
596
|
+
if (payload.byteLength > MAX_DATAGRAM_BYTES)
|
|
597
|
+
throw new Error("datagram payload too large");
|
|
591
598
|
counter.next = sequence + 1;
|
|
592
599
|
this.#publishDatagram({ sequence, timestamp, payload });
|
|
593
600
|
return sequence;
|
|
@@ -600,8 +607,7 @@ export class Producer {
|
|
|
600
607
|
* apply. Most origin publishers want {@link appendDatagram} instead.
|
|
601
608
|
*/
|
|
602
609
|
insertDatagram(sequence, timestamp, payload) {
|
|
603
|
-
|
|
604
|
-
throw new Error("track is closed");
|
|
610
|
+
this.#writable(sequence);
|
|
605
611
|
if (payload.byteLength > MAX_DATAGRAM_BYTES)
|
|
606
612
|
throw new Error("datagram payload too large");
|
|
607
613
|
const counter = this.#sequence;
|
|
@@ -610,13 +616,43 @@ export class Producer {
|
|
|
610
616
|
}
|
|
611
617
|
this.#publishDatagram({ sequence, timestamp, payload });
|
|
612
618
|
}
|
|
613
|
-
/**
|
|
619
|
+
/**
|
|
620
|
+
* Declare the track's exclusive end, possibly ahead of the live edge, mirroring the Rust
|
|
621
|
+
* `finish_at`.
|
|
622
|
+
*
|
|
623
|
+
* `final` is the first sequence that will never be produced, so a track whose last group
|
|
624
|
+
* is 89 finishes at 90. Groups and datagrams below it are still accepted; anything at or
|
|
625
|
+
* above it is refused. Unlike {@link close} it is not terminal: call `close()` once the
|
|
626
|
+
* remaining groups are written. Throws if the track is closed, already has an end, or
|
|
627
|
+
* `final` is at or below a sequence already produced.
|
|
628
|
+
*/
|
|
629
|
+
finishAt(final) {
|
|
630
|
+
if (this.#state.closed.peek() !== undefined)
|
|
631
|
+
throw new Error("track is closed");
|
|
632
|
+
if (!Number.isSafeInteger(final) || final < 0)
|
|
633
|
+
throw new RangeError(`invalid track end: ${final}`);
|
|
634
|
+
const declared = this.#state.final.peek();
|
|
635
|
+
if (declared !== undefined)
|
|
636
|
+
throw new Error(`track already ends at ${declared}`);
|
|
637
|
+
if (final < this.#sequence.next) {
|
|
638
|
+
throw new Error(`track end ${final} is below the next sequence ${this.#sequence.next}`);
|
|
639
|
+
}
|
|
640
|
+
this.#declareFinal(final);
|
|
641
|
+
}
|
|
642
|
+
#declareFinal(final) {
|
|
643
|
+
this.#state.final.set(final);
|
|
644
|
+
for (const sink of this.#sinks)
|
|
645
|
+
sink.final.set(final);
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Close the track and every subscriber, mirroring the abort to their groups. Idempotent.
|
|
649
|
+
*
|
|
650
|
+
* A clean close keeps the end {@link finishAt} declared, or declares one past the highest
|
|
651
|
+
* sequence produced; an abort ends without one.
|
|
652
|
+
*/
|
|
614
653
|
close(abort) {
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
this.#state.final = this.#sequence.next;
|
|
618
|
-
for (const sink of this.#sinks)
|
|
619
|
-
sink.final = this.#state.final;
|
|
654
|
+
if (abort === undefined && this.#state.closed.peek() === undefined && this.#state.final.peek() === undefined) {
|
|
655
|
+
this.#declareFinal(this.#sequence.next);
|
|
620
656
|
}
|
|
621
657
|
closeTrackState(this.#state, abort);
|
|
622
658
|
clearTimeout(this.#pruneTimer);
|
|
@@ -826,13 +862,35 @@ export class Subscriber {
|
|
|
826
862
|
return this.#state.latest;
|
|
827
863
|
}
|
|
828
864
|
/**
|
|
829
|
-
* The track's exclusive final boundary
|
|
830
|
-
*
|
|
831
|
-
*
|
|
832
|
-
* `latest() + 1`. Undefined
|
|
865
|
+
* The track's exclusive final boundary: the end {@link Producer.finishAt} declared, which
|
|
866
|
+
* can be ahead of the live edge, or one past the highest sequence produced once the
|
|
867
|
+
* producer closes cleanly (0 for a track that produced none). Groups and datagrams share
|
|
868
|
+
* the sequence namespace, so this can exceed `latest() + 1`. Undefined until declared,
|
|
869
|
+
* and after an abort that declared none.
|
|
833
870
|
*/
|
|
834
871
|
final() {
|
|
835
|
-
return this.#state.final;
|
|
872
|
+
return this.#state.final.peek();
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* Resolve with the track's exclusive final boundary once it is known, mirroring the Rust
|
|
876
|
+
* `finished`.
|
|
877
|
+
*
|
|
878
|
+
* Resolves as soon as the end is declared, which may be ahead of the live edge, so it
|
|
879
|
+
* says nothing about every group having arrived: read until the cursor returns
|
|
880
|
+
* `undefined` for that. Rejects with the abort, or if the track closes without an end.
|
|
881
|
+
*/
|
|
882
|
+
async finished() {
|
|
883
|
+
for (;;) {
|
|
884
|
+
const final = this.#state.final.peek();
|
|
885
|
+
if (final !== undefined)
|
|
886
|
+
return final;
|
|
887
|
+
const closed = this.#state.closed.peek();
|
|
888
|
+
if (closed instanceof Error)
|
|
889
|
+
throw closed;
|
|
890
|
+
if (closed !== undefined)
|
|
891
|
+
throw new Error("track closed before its end was known");
|
|
892
|
+
await Signal.race(this.#state.final, this.#state.closed);
|
|
893
|
+
}
|
|
836
894
|
}
|
|
837
895
|
/**
|
|
838
896
|
* The newest frame this track has produced, or `undefined` while it has none.
|
|
@@ -980,9 +1038,15 @@ export class Subscriber {
|
|
|
980
1038
|
return group ? { kind: "boundary" } : { kind: "done" };
|
|
981
1039
|
}
|
|
982
1040
|
// Package-internal readiness half of recvGroup. Each registration fires at most once, and
|
|
983
|
-
// the caller disposes the losers after whichever source wakes it.
|
|
1041
|
+
// the caller disposes the losers after whichever source wakes it. A declared end wakes it
|
|
1042
|
+
// too, so a publisher can forward the end before the live edge reaches it.
|
|
984
1043
|
#groupChanged(fn) {
|
|
985
|
-
const dispose = [
|
|
1044
|
+
const dispose = [
|
|
1045
|
+
this.#state.groups.changed(fn),
|
|
1046
|
+
this.#cursor.changed(fn),
|
|
1047
|
+
this.#state.closed.changed(fn),
|
|
1048
|
+
this.#state.final.changed(fn),
|
|
1049
|
+
];
|
|
986
1050
|
return () => {
|
|
987
1051
|
for (const close of dispose)
|
|
988
1052
|
close();
|
|
@@ -1222,6 +1286,10 @@ export class Ordered {
|
|
|
1222
1286
|
final() {
|
|
1223
1287
|
return this.#subscriber.final();
|
|
1224
1288
|
}
|
|
1289
|
+
/** Resolve with the track's exclusive final boundary once known; see {@link Subscriber.finished}. */
|
|
1290
|
+
finished() {
|
|
1291
|
+
return this.#subscriber.finished();
|
|
1292
|
+
}
|
|
1225
1293
|
/** Limit subsequent reads to these groups and return this reader for chaining. */
|
|
1226
1294
|
withGroups(groups) {
|
|
1227
1295
|
this.setGroups(groups);
|