@moq/net 0.4.1 → 0.4.2
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/broadcast.d.ts +21 -7
- package/broadcast.d.ts.map +1 -1
- package/broadcast.js +38 -16
- package/broadcast.js.map +1 -1
- package/connection/accept.js +6 -4
- package/connection/accept.js.map +1 -1
- package/connection/connect.d.ts.map +1 -1
- package/connection/connect.js +5 -4
- package/connection/connect.js.map +1 -1
- package/connection/forward.js +54 -47
- package/connection/forward.js.map +1 -1
- package/connection/goaway.d.ts +34 -0
- package/connection/goaway.d.ts.map +1 -0
- package/connection/goaway.js +176 -0
- package/connection/goaway.js.map +1 -0
- package/connection/handshake.d.ts +4 -2
- package/connection/handshake.d.ts.map +1 -1
- package/connection/handshake.js +42 -10
- package/connection/handshake.js.map +1 -1
- package/connection/pool.d.ts +16 -1
- package/connection/pool.d.ts.map +1 -1
- package/connection/pool.js +32 -10
- package/connection/pool.js.map +1 -1
- package/connection/reload.d.ts.map +1 -1
- package/connection/reload.js +184 -30
- package/connection/reload.js.map +1 -1
- package/error.d.ts +11 -0
- package/error.d.ts.map +1 -1
- package/error.js +14 -0
- package/error.js.map +1 -1
- package/errors.d.ts +1 -1
- package/errors.d.ts.map +1 -1
- package/errors.js +1 -1
- package/errors.js.map +1 -1
- package/group.d.ts.map +1 -1
- package/group.js +5 -4
- package/group.js.map +1 -1
- package/hop.d.ts +8 -0
- package/hop.d.ts.map +1 -1
- package/hop.js +16 -0
- package/hop.js.map +1 -1
- package/ietf/adapter.d.ts +4 -0
- package/ietf/adapter.d.ts.map +1 -1
- package/ietf/adapter.js +19 -8
- package/ietf/adapter.js.map +1 -1
- package/ietf/cluster.d.ts +3 -3
- package/ietf/cluster.js +3 -3
- package/ietf/cluster.js.map +1 -1
- package/ietf/connection.d.ts.map +1 -1
- package/ietf/connection.js +110 -37
- package/ietf/connection.js.map +1 -1
- package/ietf/fetch.d.ts +7 -20
- package/ietf/fetch.d.ts.map +1 -1
- package/ietf/fetch.js +52 -22
- package/ietf/fetch.js.map +1 -1
- package/ietf/filter.d.ts +2 -0
- package/ietf/filter.d.ts.map +1 -1
- package/ietf/filter.js +4 -0
- package/ietf/filter.js.map +1 -1
- package/ietf/goaway.d.ts +9 -1
- package/ietf/goaway.d.ts.map +1 -1
- package/ietf/goaway.js +20 -0
- package/ietf/goaway.js.map +1 -1
- package/ietf/hidden.js +1 -1
- package/ietf/hidden.js.map +1 -1
- package/ietf/index.d.ts +1 -1
- package/ietf/index.d.ts.map +1 -1
- package/ietf/index.js +1 -1
- package/ietf/index.js.map +1 -1
- package/ietf/object.d.ts +7 -6
- package/ietf/object.d.ts.map +1 -1
- package/ietf/object.js +37 -33
- package/ietf/object.js.map +1 -1
- package/ietf/parameters.d.ts +7 -0
- package/ietf/parameters.d.ts.map +1 -1
- package/ietf/parameters.js +62 -12
- package/ietf/parameters.js.map +1 -1
- package/ietf/publish_namespace.d.ts +2 -2
- package/ietf/publish_namespace.js +2 -2
- package/ietf/publish_namespace.js.map +1 -1
- package/ietf/publisher.js +287 -172
- package/ietf/publisher.js.map +1 -1
- package/ietf/subscribe.d.ts +7 -1
- package/ietf/subscribe.d.ts.map +1 -1
- package/ietf/subscribe.js +22 -14
- package/ietf/subscribe.js.map +1 -1
- package/ietf/subscribe_namespace.d.ts.map +1 -1
- package/ietf/subscribe_namespace.js +2 -3
- package/ietf/subscribe_namespace.js.map +1 -1
- package/ietf/subscriber.js +57 -42
- package/ietf/subscriber.js.map +1 -1
- package/ietf/token.d.ts +2 -0
- package/ietf/token.d.ts.map +1 -0
- package/ietf/token.js +99 -0
- package/ietf/token.js.map +1 -0
- package/ietf/track.d.ts +4 -0
- package/ietf/track.d.ts.map +1 -1
- package/ietf/track.js +6 -20
- package/ietf/track.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.d.ts.map +1 -1
- package/index.js.map +1 -1
- package/internal.d.ts +12 -3
- package/internal.d.ts.map +1 -1
- package/internal.js +32 -0
- package/internal.js.map +1 -1
- package/lite/announce.d.ts.map +1 -1
- package/lite/announce.js +7 -4
- package/lite/announce.js.map +1 -1
- package/lite/connection.d.ts.map +1 -1
- package/lite/connection.js +22 -7
- package/lite/connection.js.map +1 -1
- package/lite/datagram.d.ts +3 -2
- package/lite/datagram.d.ts.map +1 -1
- package/lite/datagram.js +7 -8
- package/lite/datagram.js.map +1 -1
- package/lite/group.d.ts +12 -8
- package/lite/group.d.ts.map +1 -1
- package/lite/group.js +37 -16
- package/lite/group.js.map +1 -1
- package/lite/message.d.ts +2 -2
- package/lite/message.d.ts.map +1 -1
- package/lite/message.js +14 -5
- package/lite/message.js.map +1 -1
- package/lite/publisher.js +19 -37
- package/lite/publisher.js.map +1 -1
- package/lite/setup.d.ts +1 -1
- package/lite/setup.d.ts.map +1 -1
- package/lite/setup.js +22 -19
- package/lite/setup.js.map +1 -1
- package/lite/subscriber.d.ts.map +1 -1
- package/lite/subscriber.js +206 -127
- package/lite/subscriber.js.map +1 -1
- package/origin.d.ts +9 -1
- package/origin.d.ts.map +1 -1
- package/origin.js +341 -146
- package/origin.js.map +1 -1
- package/package.json +2 -2
- package/stream.d.ts +77 -12
- package/stream.d.ts.map +1 -1
- package/stream.js +359 -122
- package/stream.js.map +1 -1
- package/tail.d.ts +7 -0
- package/tail.d.ts.map +1 -1
- package/tail.js +68 -22
- package/tail.js.map +1 -1
- package/track.d.ts +14 -3
- package/track.d.ts.map +1 -1
- package/track.js +170 -76
- package/track.js.map +1 -1
- package/util/abort.d.ts +2 -0
- package/util/abort.d.ts.map +1 -0
- package/util/abort.js +20 -0
- package/util/abort.js.map +1 -0
- package/util/u64.d.ts +39 -0
- package/util/u64.d.ts.map +1 -0
- package/util/u64.js +83 -0
- package/util/u64.js.map +1 -0
- package/util/varint.d.ts +29 -0
- package/util/varint.d.ts.map +1 -0
- package/util/varint.js +198 -0
- package/util/varint.js.map +1 -0
- package/varint.d.ts +10 -6
- package/varint.d.ts.map +1 -1
- package/varint.js +40 -237
- package/varint.js.map +1 -1
- package/wire.d.ts +17 -3
- package/wire.d.ts.map +1 -1
- package/wire.js.map +1 -1
- package/ietf/control.d.ts +0 -135
- package/ietf/control.d.ts.map +0 -1
- package/ietf/control.js +0 -242
- package/ietf/control.js.map +0 -1
package/ietf/connection.js
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
/* @ts-self-types="./connection.d.ts" */
|
|
2
|
-
import { Signal } from "@moq/signals";
|
|
2
|
+
import { Once, Signal } from "@moq/signals";
|
|
3
3
|
import { transportStats } from "../connection/stats.js";
|
|
4
4
|
import { transportOf } from "../connection/transport.js";
|
|
5
|
-
import { error, fromClose, ProtocolViolation, StreamCode, StreamError } from "../error.js";
|
|
5
|
+
import { error, fromClose, ProtocolViolation, SessionCode, StreamCode, StreamError } from "../error.js";
|
|
6
6
|
import { Readers } from "../stream.js";
|
|
7
7
|
import { registerWire } from "../wire.js";
|
|
8
8
|
import { ControlStreamAdapter, NativeSession } from "./adapter.js";
|
|
9
9
|
import * as Cluster from "./cluster.js";
|
|
10
|
+
import { Fetch, FetchHeader } from "./fetch.js";
|
|
10
11
|
import { GoAway } from "./goaway.js";
|
|
11
12
|
import { Group } from "./object.js";
|
|
12
13
|
import { Publish } from "./publish.js";
|
|
13
14
|
import { PublishNamespace } from "./publish_namespace.js";
|
|
14
15
|
import { Publisher } from "./publisher.js";
|
|
15
16
|
import { Subscribe, SubscribeUpdate } from "./subscribe.js";
|
|
16
|
-
import { SubscribeNamespace, SubscribeNamespaceLegacy } from "./subscribe_namespace.js";
|
|
17
|
+
import { SUBSCRIBE_TRACKS_ID, SubscribeNamespace, SubscribeNamespaceLegacy } from "./subscribe_namespace.js";
|
|
17
18
|
import { Subscriber } from "./subscriber.js";
|
|
18
19
|
import { TrackStatusRequest } from "./track.js";
|
|
19
20
|
import { Version, versionName } from "./version.js";
|
|
21
|
+
// The PADDING stream type (draft-18+): bytes a peer sends to probe for bandwidth.
|
|
22
|
+
const PADDING = 0x132b3e28n;
|
|
20
23
|
/**
|
|
21
24
|
* Represents a connection to a MoQ server using moq-transport protocol.
|
|
22
25
|
*
|
|
@@ -35,6 +38,8 @@ export class Connection {
|
|
|
35
38
|
probe = new Signal({});
|
|
36
39
|
// The established WebTransport session.
|
|
37
40
|
#quic;
|
|
41
|
+
// Whether this side opened the session. Only a server may name a redirect.
|
|
42
|
+
#client;
|
|
38
43
|
// Session abstraction: adapter for v14-v16, native for v17.
|
|
39
44
|
#session;
|
|
40
45
|
// Module for contributing tracks.
|
|
@@ -45,6 +50,8 @@ export class Connection {
|
|
|
45
50
|
#solicit;
|
|
46
51
|
// The Hop IDs this session declared; see {@link Cluster}.
|
|
47
52
|
#cluster;
|
|
53
|
+
// The peer's GOAWAY: read here on v17+, by the control stream adapter before that.
|
|
54
|
+
#goaway;
|
|
48
55
|
// Just to avoid logging when `close()` is called.
|
|
49
56
|
#closed = false;
|
|
50
57
|
/**
|
|
@@ -56,29 +63,33 @@ export class Connection {
|
|
|
56
63
|
* @param version - The negotiated protocol version
|
|
57
64
|
* @param solicit - What the peer's SETUP declared (undefined when it declared nothing)
|
|
58
65
|
* @param cluster - The Hop IDs the SETUP exchange settled, on the versions that negotiate them
|
|
66
|
+
* @param early - Uni streams that arrived before the peer's SETUP
|
|
59
67
|
*
|
|
60
68
|
* @internal
|
|
61
69
|
*/
|
|
62
|
-
constructor({ url, quic, control, maxRequestId, version, client, discovery = true, publish, solicit, hidden = false, cluster, }) {
|
|
70
|
+
constructor({ url, quic, control, maxRequestId, version, client, discovery = true, publish, solicit, hidden = false, cluster, early = [], }) {
|
|
63
71
|
this.url = url;
|
|
64
72
|
this.discovery = discovery;
|
|
65
73
|
this.version = versionName(version);
|
|
66
74
|
this.transport = transportOf(quic);
|
|
67
75
|
this.#quic = quic;
|
|
76
|
+
this.#client = client;
|
|
68
77
|
// Two-path dispatch: v14-v16 uses adapter, v17+ uses native bidi streams
|
|
69
78
|
if (version >= Version.DRAFT_17) {
|
|
70
79
|
this.#session = new NativeSession(quic, version, client);
|
|
80
|
+
this.#goaway = new Once();
|
|
71
81
|
// v17+: control/setup stream only carries GoAway
|
|
72
82
|
void this.#runGoAway(control, version);
|
|
73
83
|
}
|
|
74
84
|
else {
|
|
75
85
|
const adapter = new ControlStreamAdapter(quic, control, version, maxRequestId, client);
|
|
76
86
|
this.#session = adapter;
|
|
87
|
+
this.#goaway = adapter.goaway;
|
|
77
88
|
// Start the adapter read loop (routes control messages to virtual streams)
|
|
78
89
|
void adapter.run().catch((err) => {
|
|
79
90
|
if (!this.#closed)
|
|
80
91
|
console.error("adapter error", err);
|
|
81
|
-
this
|
|
92
|
+
this.#close();
|
|
82
93
|
});
|
|
83
94
|
}
|
|
84
95
|
this.#publisher = new Publisher({
|
|
@@ -86,13 +97,14 @@ export class Connection {
|
|
|
86
97
|
session: this.#session,
|
|
87
98
|
publish,
|
|
88
99
|
requiresSolicitation: solicit ?? false,
|
|
100
|
+
hidden,
|
|
89
101
|
cluster,
|
|
90
102
|
});
|
|
91
103
|
this.#solicit = solicit;
|
|
92
104
|
this.#cluster = cluster;
|
|
93
105
|
this.#subscriber = new Subscriber({ session: this.#session, quic, cluster, hidden });
|
|
94
|
-
registerWire(this, { consume: (path) => this.#subscriber.consume(path) });
|
|
95
|
-
void this.#run();
|
|
106
|
+
registerWire(this, { consume: (path) => this.#subscriber.consume(path), goaway: this.#goaway });
|
|
107
|
+
void this.#run(early);
|
|
96
108
|
}
|
|
97
109
|
/** Snapshot the transport's counters; see {@link Established.stats}. */
|
|
98
110
|
async stats() {
|
|
@@ -102,20 +114,33 @@ export class Connection {
|
|
|
102
114
|
* Closes the connection.
|
|
103
115
|
*/
|
|
104
116
|
close() {
|
|
117
|
+
if (this.#closed)
|
|
118
|
+
return;
|
|
119
|
+
this.#subscriber.close();
|
|
120
|
+
this.#close();
|
|
121
|
+
}
|
|
122
|
+
// Close with the session code the peer should see, a clean close by default.
|
|
123
|
+
#close(info) {
|
|
105
124
|
if (this.#closed)
|
|
106
125
|
return;
|
|
107
126
|
this.#closed = true;
|
|
108
|
-
|
|
127
|
+
// Before the session, whose own close would send a clean code first.
|
|
109
128
|
try {
|
|
110
|
-
this.#quic.close();
|
|
129
|
+
this.#quic.close(info);
|
|
111
130
|
}
|
|
112
131
|
catch {
|
|
113
132
|
// ignore
|
|
114
133
|
}
|
|
134
|
+
this.#session.close();
|
|
135
|
+
}
|
|
136
|
+
// The peer broke the protocol, so losing the stream is not enough: nothing stops it
|
|
137
|
+
// repeating the violation on the next one.
|
|
138
|
+
#violated(err) {
|
|
139
|
+
this.#close({ closeCode: SessionCode.ProtocolViolation, reason: err.message });
|
|
115
140
|
}
|
|
116
|
-
async #run() {
|
|
141
|
+
async #run(early) {
|
|
117
142
|
try {
|
|
118
|
-
await Promise.all([this.#runBidis(), this.#runUnis(), this.#publisher.runPublishNamespaces()]);
|
|
143
|
+
await Promise.all([this.#runBidis(), this.#runUnis(early), this.#publisher.runPublishNamespaces()]);
|
|
119
144
|
}
|
|
120
145
|
catch (err) {
|
|
121
146
|
if (!this.#closed) {
|
|
@@ -123,7 +148,7 @@ export class Connection {
|
|
|
123
148
|
}
|
|
124
149
|
}
|
|
125
150
|
finally {
|
|
126
|
-
this
|
|
151
|
+
this.#close();
|
|
127
152
|
}
|
|
128
153
|
}
|
|
129
154
|
/** Gets an announced reader for `scope`; see {@link Established.announced}. */
|
|
@@ -141,10 +166,8 @@ export class Connection {
|
|
|
141
166
|
void this.#runBidi(stream).catch((err) => {
|
|
142
167
|
console.error("error processing bidi stream", err);
|
|
143
168
|
stream.abort(new Error("bidi stream error"));
|
|
144
|
-
// The peer broke the protocol, so losing the stream is not enough: nothing
|
|
145
|
-
// stops it repeating the violation on the next one.
|
|
146
169
|
if (err instanceof ProtocolViolation)
|
|
147
|
-
this
|
|
170
|
+
this.#violated(err);
|
|
148
171
|
});
|
|
149
172
|
}
|
|
150
173
|
}
|
|
@@ -183,11 +206,24 @@ export class Connection {
|
|
|
183
206
|
await this.#publisher.runSubscribe(msg, stream);
|
|
184
207
|
break;
|
|
185
208
|
}
|
|
209
|
+
case SUBSCRIBE_TRACKS_ID: {
|
|
210
|
+
// 0x51 is only a message from draft-18 on.
|
|
211
|
+
if (this.#session.version < Version.DRAFT_18) {
|
|
212
|
+
throw new ProtocolViolation("SUBSCRIBE_TRACKS before draft-18");
|
|
213
|
+
}
|
|
214
|
+
await this.#publisher.runSubscribeTracks(stream);
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
186
217
|
case TrackStatusRequest.id: {
|
|
187
218
|
const msg = await TrackStatusRequest.decode(stream.reader, this.#session.version);
|
|
188
219
|
await this.#publisher.runTrackStatusRequest(msg, stream);
|
|
189
220
|
break;
|
|
190
221
|
}
|
|
222
|
+
case Fetch.id: {
|
|
223
|
+
const msg = await Fetch.decode(stream.reader, this.#session.version);
|
|
224
|
+
await this.#publisher.runFetch(msg, stream);
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
191
227
|
// Subscriber handles incoming notifications
|
|
192
228
|
case PublishNamespace.id: {
|
|
193
229
|
const msg = await PublishNamespace.decode(stream.reader, this.#session.version, Cluster.negotiated(this.#cluster));
|
|
@@ -204,7 +240,7 @@ export class Connection {
|
|
|
204
240
|
const legacy = this.#session.version === Version.DRAFT_14 || this.#session.version === Version.DRAFT_15;
|
|
205
241
|
if (this.#solicit !== undefined && !legacy) {
|
|
206
242
|
console.error(`unsolicited publish_namespace from a peer that implements MoQ Solicit: broadcast=${msg.trackNamespace}`);
|
|
207
|
-
this
|
|
243
|
+
this.#close();
|
|
208
244
|
break;
|
|
209
245
|
}
|
|
210
246
|
await this.#subscriber.runPublishNamespace(msg, stream);
|
|
@@ -223,41 +259,78 @@ export class Connection {
|
|
|
223
259
|
/**
|
|
224
260
|
* Handles unidirectional streams for media delivery (groups).
|
|
225
261
|
*/
|
|
226
|
-
async #runUnis() {
|
|
262
|
+
async #runUnis(early) {
|
|
263
|
+
// Streams that beat the SETUP go first, in arrival order.
|
|
264
|
+
for (const stream of early)
|
|
265
|
+
this.#spawnUni(stream);
|
|
227
266
|
const readers = new Readers(this.#quic, this.#session.version);
|
|
228
267
|
for (;;) {
|
|
229
268
|
const stream = await readers.next();
|
|
230
269
|
if (!stream)
|
|
231
270
|
break;
|
|
232
|
-
this.#
|
|
233
|
-
.then(() => {
|
|
234
|
-
stream.stop(new StreamError(StreamCode.Cancel, { message: "cancel" }));
|
|
235
|
-
})
|
|
236
|
-
.catch((err) => {
|
|
237
|
-
console.error("error processing object stream", err);
|
|
238
|
-
stream.stop(err);
|
|
239
|
-
});
|
|
271
|
+
this.#spawnUni(stream);
|
|
240
272
|
}
|
|
241
273
|
}
|
|
274
|
+
#spawnUni(stream) {
|
|
275
|
+
this.#runUni(stream)
|
|
276
|
+
.then(() => {
|
|
277
|
+
stream.stop(new StreamError(StreamCode.Cancel, { message: "cancel" }));
|
|
278
|
+
})
|
|
279
|
+
.catch((err) => {
|
|
280
|
+
console.error("error processing object stream", err);
|
|
281
|
+
stream.stop(err);
|
|
282
|
+
// An unknown or invalid stream type MUST close the session, not just the stream.
|
|
283
|
+
if (err instanceof ProtocolViolation)
|
|
284
|
+
this.#violated(err);
|
|
285
|
+
});
|
|
286
|
+
}
|
|
242
287
|
async #runUni(stream) {
|
|
243
|
-
const
|
|
244
|
-
|
|
288
|
+
const version = this.#session.version;
|
|
289
|
+
// Full width, so an unknown type past 2^53 is still classified rather than thrown.
|
|
290
|
+
const type = await stream.u62();
|
|
291
|
+
// SUBGROUP_HEADER types match 0b0XX1XXXX; Group.decode validates the bits per draft.
|
|
292
|
+
if (type <= 0xffn && (type & 0x90n) === 0x10n) {
|
|
293
|
+
const header = await Group.decode(stream, version, Number(type));
|
|
294
|
+
await this.#subscriber.handleGroup(header, stream);
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
// The receiver MUST discard padding. We read it to the end rather than cancel,
|
|
298
|
+
// so a peer probing for bandwidth gets the throughput it is measuring.
|
|
299
|
+
if (type === PADDING && version >= Version.DRAFT_18) {
|
|
300
|
+
await stream.discard();
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
// We never FETCH, so a fetch response answers nothing of ours.
|
|
304
|
+
if (type === BigInt(FetchHeader.type))
|
|
305
|
+
throw new Error("unexpected fetch stream");
|
|
306
|
+
// Anything else is unknown, and a second SETUP is a violation too.
|
|
307
|
+
throw new ProtocolViolation(`unknown uni stream type: 0x${type.toString(16)}`);
|
|
245
308
|
}
|
|
246
309
|
/**
|
|
247
310
|
* v17+ only: reads GoAway from the setup/control stream.
|
|
311
|
+
*
|
|
312
|
+
* The session keeps serving after a GOAWAY so its groups in flight can finish while the
|
|
313
|
+
* caller migrates; only the stream ending, or a second GOAWAY, closes it here.
|
|
248
314
|
*/
|
|
249
315
|
async #runGoAway(controlStream, version) {
|
|
250
316
|
try {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
317
|
+
for (;;) {
|
|
318
|
+
const done = await controlStream.reader.done();
|
|
319
|
+
if (done)
|
|
320
|
+
return;
|
|
321
|
+
const typeId = await controlStream.reader.u53();
|
|
322
|
+
if (typeId !== GoAway.id) {
|
|
323
|
+
console.warn(`unexpected message on setup stream: 0x${typeId.toString(16)}`);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
256
326
|
const msg = await GoAway.decode(controlStream.reader, version);
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
327
|
+
if (this.#goaway.peek() !== undefined)
|
|
328
|
+
throw new ProtocolViolation("duplicate GOAWAY");
|
|
329
|
+
// A client may leave, but only the server may name where to go.
|
|
330
|
+
if (!this.#client && msg.newSessionUri !== "") {
|
|
331
|
+
throw new ProtocolViolation("client GOAWAY must not name a redirect");
|
|
332
|
+
}
|
|
333
|
+
this.#goaway.set(msg.drain());
|
|
261
334
|
}
|
|
262
335
|
}
|
|
263
336
|
catch (err) {
|
|
@@ -266,7 +339,7 @@ export class Connection {
|
|
|
266
339
|
}
|
|
267
340
|
}
|
|
268
341
|
finally {
|
|
269
|
-
this
|
|
342
|
+
this.#close();
|
|
270
343
|
}
|
|
271
344
|
}
|
|
272
345
|
/** Resolves when the session closes, decoding the peer's close code; see {@link Established.closed}. */
|
package/ietf/connection.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/ietf/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,EAAE,MAAM,cAAc,CAAC;AAGnD,OAAO,EAA0B,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAkB,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG3F,OAAO,EAAe,OAAO,EAAe,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAgB,MAAM,cAAc,CAAC;AACjF,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACxF,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAoB,OAAO,EAA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,SAAS,EAAE,CAAC,GAAY,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IACxE,CAAC;CACD","sourcesContent":["import { type Getter, Signal } from \"@moq/signals\";\nimport type * as announce from \"../announced.ts\";\nimport type { Established } from \"../connection/established.ts\";\nimport { type Probe, type Stats, transportStats } from \"../connection/stats.ts\";\nimport { type Transport, transportOf } from \"../connection/transport.ts\";\nimport { error, fromClose, ProtocolViolation, StreamCode, StreamError } from \"../error.ts\";\nimport type { Consumer as OriginConsumer } from \"../origin.ts\";\nimport type * as Path from \"../path.ts\";\nimport { type Reader, Readers, type Stream } from \"../stream.ts\";\nimport { registerWire } from \"../wire.ts\";\nimport { ControlStreamAdapter, NativeSession, type Session } from \"./adapter.ts\";\nimport * as Cluster from \"./cluster.ts\";\nimport { GoAway } from \"./goaway.ts\";\nimport { Group } from \"./object.ts\";\nimport { Publish } from \"./publish.ts\";\nimport { PublishNamespace } from \"./publish_namespace.ts\";\nimport { Publisher } from \"./publisher.ts\";\nimport { Subscribe, SubscribeUpdate } from \"./subscribe.ts\";\nimport { SubscribeNamespace, SubscribeNamespaceLegacy } from \"./subscribe_namespace.ts\";\nimport { Subscriber } from \"./subscriber.ts\";\nimport { TrackStatusRequest } from \"./track.ts\";\nimport { type IetfVersion, Version, versionName } from \"./version.ts\";\n\n/**\n * Represents a connection to a MoQ server using moq-transport protocol.\n *\n * @public\n */\nexport class Connection implements Established {\n\t// The URL of the connection.\n\treadonly url: URL;\n\n\t// The negotiated protocol version.\n\treadonly version: string;\n\n\t// The wire transport this session runs over.\n\treadonly transport: Transport;\n\n\t/** Whether the relay supports broadcast discovery; see {@link Established.discovery}. */\n\treadonly discovery: boolean;\n\n\t/** moq-transport has no PROBE, so this stays empty; see {@link Established.probe}. */\n\treadonly probe: Getter<Probe> = new Signal<Probe>({});\n\n\t// The established WebTransport session.\n\t#quic: WebTransport;\n\n\t// Session abstraction: adapter for v14-v16, native for v17.\n\t#session: Session;\n\n\t// Module for contributing tracks.\n\t#publisher: Publisher;\n\n\t// Module for distributing tracks.\n\t#subscriber: Subscriber;\n\n\t// What the peer declared about being solicited; see {@link Ietf.solicitFromSetup}.\n\t#solicit: boolean | undefined;\n\n\t// The Hop IDs this session declared; see {@link Cluster}.\n\t#cluster?: Cluster.Hops;\n\n\t// Just to avoid logging when `close()` is called.\n\t#closed = false;\n\n\t/**\n\t * Creates a new Connection instance.\n\t * @param url - The URL of the connection\n\t * @param quic - The WebTransport session\n\t * @param control - The control/setup stream\n\t * @param maxRequestId - The initial max request ID\n\t * @param version - The negotiated protocol version\n\t * @param solicit - What the peer's SETUP declared (undefined when it declared nothing)\n\t * @param cluster - The Hop IDs the SETUP exchange settled, on the versions that negotiate them\n\t *\n\t * @internal\n\t */\n\tconstructor({\n\t\turl,\n\t\tquic,\n\t\tcontrol,\n\t\tmaxRequestId,\n\t\tversion,\n\t\tclient,\n\t\tdiscovery = true,\n\t\tpublish,\n\t\tsolicit,\n\t\thidden = false,\n\t\tcluster,\n\t}: {\n\t\turl: URL;\n\t\tquic: WebTransport;\n\t\tcontrol: Stream;\n\t\tmaxRequestId: bigint;\n\t\tversion: IetfVersion;\n\t\t/** Whether this peer initiated the session, selecting the even request-ID space. */\n\t\tclient: boolean;\n\t\tdiscovery?: boolean;\n\t\t/** The origin whose broadcasts are served to the peer. Omit to publish nothing. */\n\t\tpublish?: OriginConsumer;\n\t\t/**\n\t\t * What the peer declared about being solicited. `undefined` means it declared\n\t\t * nothing, which is the one case where announcing at us unasked is not a bug.\n\t\t */\n\t\tsolicit?: boolean;\n\t\t/** Whether the peer understands the HIDDEN parameter (MoQ Hidden). */\n\t\thidden?: boolean;\n\t\t/**\n\t\t * The Hop IDs this session declared (MoQ Cluster). `undefined` on a version that\n\t\t * cannot negotiate the extension, as is a `peer` the peer never declared.\n\t\t */\n\t\tcluster?: Cluster.Hops;\n\t}) {\n\t\tthis.url = url;\n\t\tthis.discovery = discovery;\n\t\tthis.version = versionName(version);\n\t\tthis.transport = transportOf(quic);\n\t\tthis.#quic = quic;\n\n\t\t// Two-path dispatch: v14-v16 uses adapter, v17+ uses native bidi streams\n\t\tif (version >= Version.DRAFT_17) {\n\t\t\tthis.#session = new NativeSession(quic, version, client);\n\t\t\t// v17+: control/setup stream only carries GoAway\n\t\t\tvoid this.#runGoAway(control, version);\n\t\t} else {\n\t\t\tconst adapter = new ControlStreamAdapter(quic, control, version, maxRequestId, client);\n\t\t\tthis.#session = adapter;\n\t\t\t// Start the adapter read loop (routes control messages to virtual streams)\n\t\t\tvoid adapter.run().catch((err: unknown) => {\n\t\t\t\tif (!this.#closed) console.error(\"adapter error\", err);\n\t\t\t\tthis.close();\n\t\t\t});\n\t\t}\n\n\t\tthis.#publisher = new Publisher({\n\t\t\tquic: this.#quic,\n\t\t\tsession: this.#session,\n\t\t\tpublish,\n\t\t\trequiresSolicitation: solicit ?? false,\n\t\t\tcluster,\n\t\t});\n\t\tthis.#solicit = solicit;\n\t\tthis.#cluster = cluster;\n\t\tthis.#subscriber = new Subscriber({ session: this.#session, quic, cluster, hidden });\n\t\tregisterWire(this, { consume: (path) => this.#subscriber.consume(path) });\n\n\t\tvoid this.#run();\n\t}\n\n\t/** Snapshot the transport's counters; see {@link Established.stats}. */\n\tasync stats(): Promise<Stats> {\n\t\treturn transportStats(this.#quic);\n\t}\n\n\t/**\n\t * Closes the connection.\n\t */\n\tclose() {\n\t\tif (this.#closed) return;\n\n\t\tthis.#closed = true;\n\n\t\tthis.#session.close();\n\n\t\ttry {\n\t\t\tthis.#quic.close();\n\t\t} catch {\n\t\t\t// ignore\n\t\t}\n\t}\n\n\tasync #run(): Promise<void> {\n\t\ttry {\n\t\t\tawait Promise.all([this.#runBidis(), this.#runUnis(), this.#publisher.runPublishNamespaces()]);\n\t\t} catch (err) {\n\t\t\tif (!this.#closed) {\n\t\t\t\tconsole.error(\"fatal error running connection\", err);\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.close();\n\t\t}\n\t}\n\n\t/** Gets an announced reader for `scope`; see {@link Established.announced}. */\n\tannounced(scope?: Path.Pattern, options?: announce.Options): announce.Consumer {\n\t\treturn this.#subscriber.announced(scope, options);\n\t}\n\n\t/**\n\t * Accepts bidi streams (virtual for v14-v16, real for v17) and dispatches.\n\t */\n\tasync #runBidis() {\n\t\tfor (;;) {\n\t\t\tconst stream = await this.#session.acceptBi();\n\t\t\tif (!stream) break;\n\n\t\t\tvoid this.#runBidi(stream).catch((err: unknown) => {\n\t\t\t\tconsole.error(\"error processing bidi stream\", err);\n\t\t\t\tstream.abort(new Error(\"bidi stream error\"));\n\n\t\t\t\t// The peer broke the protocol, so losing the stream is not enough: nothing\n\t\t\t\t// stops it repeating the violation on the next one.\n\t\t\t\tif (err instanceof ProtocolViolation) this.close();\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Unified bidi stream dispatch. Reads typeId and routes to handler.\n\t * Matches the lite module's runBidi pattern.\n\t */\n\tasync #runBidi(stream: Stream) {\n\t\tconst typeId = await stream.reader.u53();\n\n\t\tswitch (typeId) {\n\t\t\t// Draft-18 SUBSCRIBE_NAMESPACE (0x50) and the legacy 0x11 message decode\n\t\t\t// to the same request_id + namespace; the legacy options field is ignored.\n\t\t\tcase SubscribeNamespace.id: {\n\t\t\t\tconst msg = await SubscribeNamespace.decode(stream.reader, this.#session.version);\n\t\t\t\tawait this.#publisher.runSubscribeNamespace(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SubscribeNamespaceLegacy.id: {\n\t\t\t\tconst legacy = await SubscribeNamespaceLegacy.decode(stream.reader, this.#session.version);\n\t\t\t\tconst msg = new SubscribeNamespace({\n\t\t\t\t\trequestId: legacy.requestId,\n\t\t\t\t\tnamespace: legacy.namespace,\n\t\t\t\t\thidden: legacy.hidden,\n\t\t\t\t});\n\t\t\t\tawait this.#publisher.runSubscribeNamespace(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SubscribeUpdate.id: {\n\t\t\t\t// REQUEST_UPDATE (0x02) is a follow-up, not a valid initial message\n\t\t\t\tstream.abort(new Error(\"unexpected REQUEST_UPDATE as initial message\"));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t// Publisher handles incoming requests\n\t\t\tcase Subscribe.id: {\n\t\t\t\tconst msg = await Subscribe.decode(stream.reader, this.#session.version);\n\t\t\t\tawait this.#publisher.runSubscribe(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase TrackStatusRequest.id: {\n\t\t\t\tconst msg = await TrackStatusRequest.decode(stream.reader, this.#session.version);\n\t\t\t\tawait this.#publisher.runTrackStatusRequest(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// Subscriber handles incoming notifications\n\t\t\tcase PublishNamespace.id: {\n\t\t\t\tconst msg = await PublishNamespace.decode(\n\t\t\t\t\tstream.reader,\n\t\t\t\t\tthis.#session.version,\n\t\t\t\t\tCluster.negotiated(this.#cluster),\n\t\t\t\t);\n\n\t\t\t\t// We always declare that advertisements to us must be solicited (MoQ\n\t\t\t\t// Solicit), and writing the option at all proves the peer implements the\n\t\t\t\t// extension, whichever value it chose. It also cannot have advertised\n\t\t\t\t// before reading our SETUP, since our SETUP is what says whether\n\t\t\t\t// advertising unasked is allowed. So this is a bug in the peer, and a\n\t\t\t\t// silent one on both sides if we tolerate it.\n\t\t\t\t//\n\t\t\t\t// Draft-14/15 are exempt: they have no inline NAMESPACE, so a\n\t\t\t\t// PUBLISH_NAMESPACE request is also how a peer answers our\n\t\t\t\t// SUBSCRIBE_NAMESPACE there, and the message alone does not say which.\n\t\t\t\tconst legacy = this.#session.version === Version.DRAFT_14 || this.#session.version === Version.DRAFT_15;\n\t\t\t\tif (this.#solicit !== undefined && !legacy) {\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`unsolicited publish_namespace from a peer that implements MoQ Solicit: broadcast=${msg.trackNamespace}`,\n\t\t\t\t\t);\n\t\t\t\t\tthis.close();\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tawait this.#subscriber.runPublishNamespace(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase Publish.id: {\n\t\t\t\tconst msg = await Publish.decode(stream.reader, this.#session.version);\n\t\t\t\tawait this.#subscriber.runPublish(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\tconsole.warn(`unexpected bidi stream type: 0x${typeId.toString(16)}`);\n\t\t\t\tstream.abort(new Error(\"unexpected stream type\"));\n\t\t}\n\t}\n\n\t/**\n\t * Handles unidirectional streams for media delivery (groups).\n\t */\n\tasync #runUnis() {\n\t\tconst readers = new Readers(this.#quic, this.#session.version);\n\n\t\tfor (;;) {\n\t\t\tconst stream = await readers.next();\n\t\t\tif (!stream) break;\n\n\t\t\tthis.#runUni(stream)\n\t\t\t\t.then(() => {\n\t\t\t\t\tstream.stop(new StreamError(StreamCode.Cancel, { message: \"cancel\" }));\n\t\t\t\t})\n\t\t\t\t.catch((err: unknown) => {\n\t\t\t\t\tconsole.error(\"error processing object stream\", err);\n\t\t\t\t\tstream.stop(err);\n\t\t\t\t});\n\t\t}\n\t}\n\n\tasync #runUni(stream: Reader) {\n\t\tconst header = await Group.decode(stream, this.#session.version);\n\t\tawait this.#subscriber.handleGroup(header, stream);\n\t}\n\n\t/**\n\t * v17+ only: reads GoAway from the setup/control stream.\n\t */\n\tasync #runGoAway(controlStream: Stream, version: IetfVersion) {\n\t\ttry {\n\t\t\tconst done = await controlStream.reader.done();\n\t\t\tif (done) return;\n\n\t\t\tconst typeId = await controlStream.reader.u53();\n\t\t\tif (typeId === GoAway.id) {\n\t\t\t\tconst msg = await GoAway.decode(controlStream.reader, version);\n\t\t\t\tconsole.warn(`received GOAWAY with redirect URI: ${msg.newSessionUri}`);\n\t\t\t} else {\n\t\t\t\tconsole.warn(`unexpected message on setup stream: 0x${typeId.toString(16)}`);\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tif (!this.#closed) {\n\t\t\t\tconsole.error(\"error reading setup stream\", err);\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.close();\n\t\t}\n\t}\n\n\t/** Resolves when the session closes, decoding the peer's close code; see {@link Established.closed}. */\n\tget closed(): Promise<Error | null> {\n\t\treturn this.#quic.closed.then(fromClose, (err: unknown) => error(err));\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/ietf/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAIzD,OAAO,EAA0B,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAkB,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAGxG,OAAO,EAAe,OAAO,EAAe,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAgB,MAAM,cAAc,CAAC;AACjF,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAC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OAAO,EAAE,CAAC;gBACnB,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAC;YAClD,CAAC;QACF,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,MAAM,EAAE,CAAC;QACf,CAAC;IACF,CAAC;IAED,wGAAwG;IACxG,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,GAAY,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IACxE,CAAC;CACD","sourcesContent":["import { type Getter, Once, Signal } from \"@moq/signals\";\nimport type * as announce from \"../announced.ts\";\nimport type { Established } from \"../connection/established.ts\";\nimport type { Drain } from \"../connection/goaway.ts\";\nimport { type Probe, type Stats, transportStats } from \"../connection/stats.ts\";\nimport { type Transport, transportOf } from \"../connection/transport.ts\";\nimport { error, fromClose, ProtocolViolation, SessionCode, StreamCode, StreamError } from \"../error.ts\";\nimport type { Consumer as OriginConsumer } from \"../origin.ts\";\nimport type * as Path from \"../path.ts\";\nimport { type Reader, Readers, type Stream } from \"../stream.ts\";\nimport { registerWire } from \"../wire.ts\";\nimport { ControlStreamAdapter, NativeSession, type Session } from \"./adapter.ts\";\nimport * as Cluster from \"./cluster.ts\";\nimport { Fetch, FetchHeader } from \"./fetch.ts\";\nimport { GoAway } from \"./goaway.ts\";\nimport { Group } from \"./object.ts\";\nimport { Publish } from \"./publish.ts\";\nimport { PublishNamespace } from \"./publish_namespace.ts\";\nimport { Publisher } from \"./publisher.ts\";\nimport { Subscribe, SubscribeUpdate } from \"./subscribe.ts\";\nimport { SUBSCRIBE_TRACKS_ID, SubscribeNamespace, SubscribeNamespaceLegacy } from \"./subscribe_namespace.ts\";\nimport { Subscriber } from \"./subscriber.ts\";\nimport { TrackStatusRequest } from \"./track.ts\";\nimport { type IetfVersion, Version, versionName } from \"./version.ts\";\n\n// The PADDING stream type (draft-18+): bytes a peer sends to probe for bandwidth.\nconst PADDING = 0x132b3e28n;\n\n/**\n * Represents a connection to a MoQ server using moq-transport protocol.\n *\n * @public\n */\nexport class Connection implements Established {\n\t// The URL of the connection.\n\treadonly url: URL;\n\n\t// The negotiated protocol version.\n\treadonly version: string;\n\n\t// The wire transport this session runs over.\n\treadonly transport: Transport;\n\n\t/** Whether the relay supports broadcast discovery; see {@link Established.discovery}. */\n\treadonly discovery: boolean;\n\n\t/** moq-transport has no PROBE, so this stays empty; see {@link Established.probe}. */\n\treadonly probe: Getter<Probe> = new Signal<Probe>({});\n\n\t// The established WebTransport session.\n\t#quic: WebTransport;\n\n\t// Whether this side opened the session. Only a server may name a redirect.\n\t#client: boolean;\n\n\t// Session abstraction: adapter for v14-v16, native for v17.\n\t#session: Session;\n\n\t// Module for contributing tracks.\n\t#publisher: Publisher;\n\n\t// Module for distributing tracks.\n\t#subscriber: Subscriber;\n\n\t// What the peer declared about being solicited; see {@link Ietf.solicitFromSetup}.\n\t#solicit: boolean | undefined;\n\n\t// The Hop IDs this session declared; see {@link Cluster}.\n\t#cluster?: Cluster.Hops;\n\n\t// The peer's GOAWAY: read here on v17+, by the control stream adapter before that.\n\t#goaway: Once<Drain>;\n\n\t// Just to avoid logging when `close()` is called.\n\t#closed = false;\n\n\t/**\n\t * Creates a new Connection instance.\n\t * @param url - The URL of the connection\n\t * @param quic - The WebTransport session\n\t * @param control - The control/setup stream\n\t * @param maxRequestId - The initial max request ID\n\t * @param version - The negotiated protocol version\n\t * @param solicit - What the peer's SETUP declared (undefined when it declared nothing)\n\t * @param cluster - The Hop IDs the SETUP exchange settled, on the versions that negotiate them\n\t * @param early - Uni streams that arrived before the peer's SETUP\n\t *\n\t * @internal\n\t */\n\tconstructor({\n\t\turl,\n\t\tquic,\n\t\tcontrol,\n\t\tmaxRequestId,\n\t\tversion,\n\t\tclient,\n\t\tdiscovery = true,\n\t\tpublish,\n\t\tsolicit,\n\t\thidden = false,\n\t\tcluster,\n\t\tearly = [],\n\t}: {\n\t\turl: URL;\n\t\tquic: WebTransport;\n\t\tcontrol: Stream;\n\t\tmaxRequestId: bigint;\n\t\tversion: IetfVersion;\n\t\t/** Whether this peer initiated the session, selecting the even request-ID space. */\n\t\tclient: boolean;\n\t\tdiscovery?: boolean;\n\t\t/** The origin whose broadcasts are served to the peer. Omit to publish nothing. */\n\t\tpublish?: OriginConsumer;\n\t\t/**\n\t\t * What the peer declared about being solicited. `undefined` means it declared\n\t\t * nothing, which is the one case where announcing at us unasked is not a bug.\n\t\t */\n\t\tsolicit?: boolean;\n\t\t/** Whether the peer understands the HIDDEN parameter (MoQ Hidden). */\n\t\thidden?: boolean;\n\t\t/**\n\t\t * The Hop IDs this session declared (MoQ Cluster). `undefined` on a version that\n\t\t * cannot negotiate the extension, as is a `peer` the peer never declared.\n\t\t */\n\t\tcluster?: Cluster.Hops;\n\t\t/** Uni streams that arrived before the peer's SETUP, type unread (v17+). */\n\t\tearly?: Reader[];\n\t}) {\n\t\tthis.url = url;\n\t\tthis.discovery = discovery;\n\t\tthis.version = versionName(version);\n\t\tthis.transport = transportOf(quic);\n\t\tthis.#quic = quic;\n\t\tthis.#client = client;\n\n\t\t// Two-path dispatch: v14-v16 uses adapter, v17+ uses native bidi streams\n\t\tif (version >= Version.DRAFT_17) {\n\t\t\tthis.#session = new NativeSession(quic, version, client);\n\t\t\tthis.#goaway = new Once();\n\t\t\t// v17+: control/setup stream only carries GoAway\n\t\t\tvoid this.#runGoAway(control, version);\n\t\t} else {\n\t\t\tconst adapter = new ControlStreamAdapter(quic, control, version, maxRequestId, client);\n\t\t\tthis.#session = adapter;\n\t\t\tthis.#goaway = adapter.goaway;\n\t\t\t// Start the adapter read loop (routes control messages to virtual streams)\n\t\t\tvoid adapter.run().catch((err: unknown) => {\n\t\t\t\tif (!this.#closed) console.error(\"adapter error\", err);\n\t\t\t\tthis.#close();\n\t\t\t});\n\t\t}\n\n\t\tthis.#publisher = new Publisher({\n\t\t\tquic: this.#quic,\n\t\t\tsession: this.#session,\n\t\t\tpublish,\n\t\t\trequiresSolicitation: solicit ?? false,\n\t\t\thidden,\n\t\t\tcluster,\n\t\t});\n\t\tthis.#solicit = solicit;\n\t\tthis.#cluster = cluster;\n\t\tthis.#subscriber = new Subscriber({ session: this.#session, quic, cluster, hidden });\n\t\tregisterWire(this, { consume: (path) => this.#subscriber.consume(path), goaway: this.#goaway });\n\n\t\tvoid this.#run(early);\n\t}\n\n\t/** Snapshot the transport's counters; see {@link Established.stats}. */\n\tasync stats(): Promise<Stats> {\n\t\treturn transportStats(this.#quic);\n\t}\n\n\t/**\n\t * Closes the connection.\n\t */\n\tclose() {\n\t\tif (this.#closed) return;\n\t\tthis.#subscriber.close();\n\t\tthis.#close();\n\t}\n\n\t// Close with the session code the peer should see, a clean close by default.\n\t#close(info?: WebTransportCloseInfo) {\n\t\tif (this.#closed) return;\n\n\t\tthis.#closed = true;\n\n\t\t// Before the session, whose own close would send a clean code first.\n\t\ttry {\n\t\t\tthis.#quic.close(info);\n\t\t} catch {\n\t\t\t// ignore\n\t\t}\n\n\t\tthis.#session.close();\n\t}\n\n\t// The peer broke the protocol, so losing the stream is not enough: nothing stops it\n\t// repeating the violation on the next one.\n\t#violated(err: ProtocolViolation) {\n\t\tthis.#close({ closeCode: SessionCode.ProtocolViolation, reason: err.message });\n\t}\n\n\tasync #run(early: Reader[]): Promise<void> {\n\t\ttry {\n\t\t\tawait Promise.all([this.#runBidis(), this.#runUnis(early), this.#publisher.runPublishNamespaces()]);\n\t\t} catch (err) {\n\t\t\tif (!this.#closed) {\n\t\t\t\tconsole.error(\"fatal error running connection\", err);\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.#close();\n\t\t}\n\t}\n\n\t/** Gets an announced reader for `scope`; see {@link Established.announced}. */\n\tannounced(scope?: Path.Pattern, options?: announce.Options): announce.Consumer {\n\t\treturn this.#subscriber.announced(scope, options);\n\t}\n\n\t/**\n\t * Accepts bidi streams (virtual for v14-v16, real for v17) and dispatches.\n\t */\n\tasync #runBidis() {\n\t\tfor (;;) {\n\t\t\tconst stream = await this.#session.acceptBi();\n\t\t\tif (!stream) break;\n\n\t\t\tvoid this.#runBidi(stream).catch((err: unknown) => {\n\t\t\t\tconsole.error(\"error processing bidi stream\", err);\n\t\t\t\tstream.abort(new Error(\"bidi stream error\"));\n\t\t\t\tif (err instanceof ProtocolViolation) this.#violated(err);\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Unified bidi stream dispatch. Reads typeId and routes to handler.\n\t * Matches the lite module's runBidi pattern.\n\t */\n\tasync #runBidi(stream: Stream) {\n\t\tconst typeId = await stream.reader.u53();\n\n\t\tswitch (typeId) {\n\t\t\t// Draft-18 SUBSCRIBE_NAMESPACE (0x50) and the legacy 0x11 message decode\n\t\t\t// to the same request_id + namespace; the legacy options field is ignored.\n\t\t\tcase SubscribeNamespace.id: {\n\t\t\t\tconst msg = await SubscribeNamespace.decode(stream.reader, this.#session.version);\n\t\t\t\tawait this.#publisher.runSubscribeNamespace(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SubscribeNamespaceLegacy.id: {\n\t\t\t\tconst legacy = await SubscribeNamespaceLegacy.decode(stream.reader, this.#session.version);\n\t\t\t\tconst msg = new SubscribeNamespace({\n\t\t\t\t\trequestId: legacy.requestId,\n\t\t\t\t\tnamespace: legacy.namespace,\n\t\t\t\t\thidden: legacy.hidden,\n\t\t\t\t});\n\t\t\t\tawait this.#publisher.runSubscribeNamespace(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SubscribeUpdate.id: {\n\t\t\t\t// REQUEST_UPDATE (0x02) is a follow-up, not a valid initial message\n\t\t\t\tstream.abort(new Error(\"unexpected REQUEST_UPDATE as initial message\"));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t// Publisher handles incoming requests\n\t\t\tcase Subscribe.id: {\n\t\t\t\tconst msg = await Subscribe.decode(stream.reader, this.#session.version);\n\t\t\t\tawait this.#publisher.runSubscribe(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SUBSCRIBE_TRACKS_ID: {\n\t\t\t\t// 0x51 is only a message from draft-18 on.\n\t\t\t\tif (this.#session.version < Version.DRAFT_18) {\n\t\t\t\t\tthrow new ProtocolViolation(\"SUBSCRIBE_TRACKS before draft-18\");\n\t\t\t\t}\n\t\t\t\tawait this.#publisher.runSubscribeTracks(stream);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase TrackStatusRequest.id: {\n\t\t\t\tconst msg = await TrackStatusRequest.decode(stream.reader, this.#session.version);\n\t\t\t\tawait this.#publisher.runTrackStatusRequest(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase Fetch.id: {\n\t\t\t\tconst msg = await Fetch.decode(stream.reader, this.#session.version);\n\t\t\t\tawait this.#publisher.runFetch(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// Subscriber handles incoming notifications\n\t\t\tcase PublishNamespace.id: {\n\t\t\t\tconst msg = await PublishNamespace.decode(\n\t\t\t\t\tstream.reader,\n\t\t\t\t\tthis.#session.version,\n\t\t\t\t\tCluster.negotiated(this.#cluster),\n\t\t\t\t);\n\n\t\t\t\t// We always declare that advertisements to us must be solicited (MoQ\n\t\t\t\t// Solicit), and writing the option at all proves the peer implements the\n\t\t\t\t// extension, whichever value it chose. It also cannot have advertised\n\t\t\t\t// before reading our SETUP, since our SETUP is what says whether\n\t\t\t\t// advertising unasked is allowed. So this is a bug in the peer, and a\n\t\t\t\t// silent one on both sides if we tolerate it.\n\t\t\t\t//\n\t\t\t\t// Draft-14/15 are exempt: they have no inline NAMESPACE, so a\n\t\t\t\t// PUBLISH_NAMESPACE request is also how a peer answers our\n\t\t\t\t// SUBSCRIBE_NAMESPACE there, and the message alone does not say which.\n\t\t\t\tconst legacy = this.#session.version === Version.DRAFT_14 || this.#session.version === Version.DRAFT_15;\n\t\t\t\tif (this.#solicit !== undefined && !legacy) {\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`unsolicited publish_namespace from a peer that implements MoQ Solicit: broadcast=${msg.trackNamespace}`,\n\t\t\t\t\t);\n\t\t\t\t\tthis.#close();\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tawait this.#subscriber.runPublishNamespace(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase Publish.id: {\n\t\t\t\tconst msg = await Publish.decode(stream.reader, this.#session.version);\n\t\t\t\tawait this.#subscriber.runPublish(msg, stream);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\tconsole.warn(`unexpected bidi stream type: 0x${typeId.toString(16)}`);\n\t\t\t\tstream.abort(new Error(\"unexpected stream type\"));\n\t\t}\n\t}\n\n\t/**\n\t * Handles unidirectional streams for media delivery (groups).\n\t */\n\tasync #runUnis(early: Reader[]) {\n\t\t// Streams that beat the SETUP go first, in arrival order.\n\t\tfor (const stream of early) this.#spawnUni(stream);\n\n\t\tconst readers = new Readers(this.#quic, this.#session.version);\n\t\tfor (;;) {\n\t\t\tconst stream = await readers.next();\n\t\t\tif (!stream) break;\n\t\t\tthis.#spawnUni(stream);\n\t\t}\n\t}\n\n\t#spawnUni(stream: Reader) {\n\t\tthis.#runUni(stream)\n\t\t\t.then(() => {\n\t\t\t\tstream.stop(new StreamError(StreamCode.Cancel, { message: \"cancel\" }));\n\t\t\t})\n\t\t\t.catch((err: unknown) => {\n\t\t\t\tconsole.error(\"error processing object stream\", err);\n\t\t\t\tstream.stop(err);\n\n\t\t\t\t// An unknown or invalid stream type MUST close the session, not just the stream.\n\t\t\t\tif (err instanceof ProtocolViolation) this.#violated(err);\n\t\t\t});\n\t}\n\n\tasync #runUni(stream: Reader) {\n\t\tconst version = this.#session.version;\n\t\t// Full width, so an unknown type past 2^53 is still classified rather than thrown.\n\t\tconst type = await stream.u62();\n\n\t\t// SUBGROUP_HEADER types match 0b0XX1XXXX; Group.decode validates the bits per draft.\n\t\tif (type <= 0xffn && (type & 0x90n) === 0x10n) {\n\t\t\tconst header = await Group.decode(stream, version, Number(type));\n\t\t\tawait this.#subscriber.handleGroup(header, stream);\n\t\t\treturn;\n\t\t}\n\n\t\t// The receiver MUST discard padding. We read it to the end rather than cancel,\n\t\t// so a peer probing for bandwidth gets the throughput it is measuring.\n\t\tif (type === PADDING && version >= Version.DRAFT_18) {\n\t\t\tawait stream.discard();\n\t\t\treturn;\n\t\t}\n\n\t\t// We never FETCH, so a fetch response answers nothing of ours.\n\t\tif (type === BigInt(FetchHeader.type)) throw new Error(\"unexpected fetch stream\");\n\n\t\t// Anything else is unknown, and a second SETUP is a violation too.\n\t\tthrow new ProtocolViolation(`unknown uni stream type: 0x${type.toString(16)}`);\n\t}\n\n\t/**\n\t * v17+ only: reads GoAway from the setup/control stream.\n\t *\n\t * The session keeps serving after a GOAWAY so its groups in flight can finish while the\n\t * caller migrates; only the stream ending, or a second GOAWAY, closes it here.\n\t */\n\tasync #runGoAway(controlStream: Stream, version: IetfVersion) {\n\t\ttry {\n\t\t\tfor (;;) {\n\t\t\t\tconst done = await controlStream.reader.done();\n\t\t\t\tif (done) return;\n\n\t\t\t\tconst typeId = await controlStream.reader.u53();\n\t\t\t\tif (typeId !== GoAway.id) {\n\t\t\t\t\tconsole.warn(`unexpected message on setup stream: 0x${typeId.toString(16)}`);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst msg = await GoAway.decode(controlStream.reader, version);\n\t\t\t\tif (this.#goaway.peek() !== undefined) throw new ProtocolViolation(\"duplicate GOAWAY\");\n\t\t\t\t// A client may leave, but only the server may name where to go.\n\t\t\t\tif (!this.#client && msg.newSessionUri !== \"\") {\n\t\t\t\t\tthrow new ProtocolViolation(\"client GOAWAY must not name a redirect\");\n\t\t\t\t}\n\t\t\t\tthis.#goaway.set(msg.drain());\n\t\t\t}\n\t\t} catch (err) {\n\t\t\tif (!this.#closed) {\n\t\t\t\tconsole.error(\"error reading setup stream\", err);\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.#close();\n\t\t}\n\t}\n\n\t/** Resolves when the session closes, decoding the peer's close code; see {@link Established.closed}. */\n\tget closed(): Promise<Error | null> {\n\t\treturn this.#quic.closed.then(fromClose, (err: unknown) => error(err));\n\t}\n}\n"]}
|
package/ietf/fetch.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type * as Path from "../path";
|
|
2
1
|
import type { Reader, Writer } from "../stream";
|
|
3
|
-
import type
|
|
2
|
+
import { type IetfVersion } from "./version";
|
|
4
3
|
/**
|
|
5
4
|
* The header that begins a fetch stream (draft-20 section 11.4.4), naming the request it
|
|
6
5
|
* answers. Written by the publisher when serving a subscription's fill.
|
|
@@ -18,31 +17,19 @@ export declare class FetchHeader {
|
|
|
18
17
|
/** Read the header, with the stream type already consumed. */
|
|
19
18
|
static decode(r: Reader, _version: IetfVersion): Promise<FetchHeader>;
|
|
20
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* A FETCH request. We serve none, so only what a refusal needs is kept; the rest is
|
|
22
|
+
* decoded so a legal request is refused rather than breaking the stream.
|
|
23
|
+
*/
|
|
21
24
|
export declare class Fetch {
|
|
22
25
|
#private;
|
|
23
26
|
static id: number;
|
|
24
27
|
requestId: bigint;
|
|
25
|
-
|
|
26
|
-
trackName: string;
|
|
27
|
-
subscriberPriority: number;
|
|
28
|
-
groupOrder: number;
|
|
29
|
-
startGroup: bigint;
|
|
30
|
-
startObject: bigint;
|
|
31
|
-
endGroup: bigint;
|
|
32
|
-
endObject: bigint;
|
|
33
|
-
constructor({ requestId, trackNamespace, trackName, subscriberPriority, groupOrder, startGroup, startObject, endGroup, endObject, }: {
|
|
28
|
+
constructor({ requestId }: {
|
|
34
29
|
requestId: bigint;
|
|
35
|
-
trackNamespace: Path.Valid;
|
|
36
|
-
trackName: string;
|
|
37
|
-
subscriberPriority: number;
|
|
38
|
-
groupOrder: number;
|
|
39
|
-
startGroup: bigint;
|
|
40
|
-
startObject: bigint;
|
|
41
|
-
endGroup: bigint;
|
|
42
|
-
endObject: bigint;
|
|
43
30
|
});
|
|
44
31
|
encode(w: Writer, _version: IetfVersion): Promise<void>;
|
|
45
|
-
static decode(r: Reader,
|
|
32
|
+
static decode(r: Reader, version: IetfVersion): Promise<Fetch>;
|
|
46
33
|
}
|
|
47
34
|
export declare class FetchOk {
|
|
48
35
|
#private;
|
package/ietf/fetch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/ietf/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/ietf/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAKnD,OAAO,EAAE,KAAK,WAAW,EAAW,MAAM,cAAc,CAAC;AAEzD;;;GAGG;AACH,qBAAa,WAAW;IACvB,qDAAqD;IACrD,MAAM,CAAC,IAAI,SAAO;IAElB,wEAAwE;IACxE,SAAS,EAAE,MAAM,CAAC;IAElB,YAAY,EAAE,SAAS,EAAE,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,EAE/C;IAED,oEAAoE;IAC9D,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAE5D;IAED,8DAA8D;IAC9D,OAAa,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAE1E;CACD;AAED;;;GAGG;AACH,qBAAa,KAAK;;IACjB,MAAM,CAAC,EAAE,SAAQ;IAEjB,SAAS,EAAE,MAAM,CAAC;IAElB,YAAY,EAAE,SAAS,EAAE,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,EAE/C;IAMK,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE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K,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAE5D;IAED,OAAa,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAE1E;CAKD"}
|
package/ietf/fetch.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
/* @ts-self-types="./fetch.d.ts" */
|
|
2
|
+
import { hasRangeFilters, isDraft20 } from "./filter.js";
|
|
2
3
|
import * as Message from "./message.js";
|
|
4
|
+
import * as Namespace from "./namespace.js";
|
|
5
|
+
import { Parameters } from "./parameters.js";
|
|
6
|
+
import { Version } from "./version.js";
|
|
3
7
|
/**
|
|
4
8
|
* The header that begins a fetch stream (draft-20 section 11.4.4), naming the request it
|
|
5
9
|
* answers. Written by the publisher when serving a subscription's fill.
|
|
@@ -21,27 +25,15 @@ export class FetchHeader {
|
|
|
21
25
|
return new FetchHeader({ requestId: await r.u62() });
|
|
22
26
|
}
|
|
23
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* A FETCH request. We serve none, so only what a refusal needs is kept; the rest is
|
|
30
|
+
* decoded so a legal request is refused rather than breaking the stream.
|
|
31
|
+
*/
|
|
24
32
|
export class Fetch {
|
|
25
33
|
static id = 0x16;
|
|
26
34
|
requestId;
|
|
27
|
-
|
|
28
|
-
trackName;
|
|
29
|
-
subscriberPriority;
|
|
30
|
-
groupOrder;
|
|
31
|
-
startGroup;
|
|
32
|
-
startObject;
|
|
33
|
-
endGroup;
|
|
34
|
-
endObject;
|
|
35
|
-
constructor({ requestId, trackNamespace, trackName, subscriberPriority, groupOrder, startGroup, startObject, endGroup, endObject, }) {
|
|
35
|
+
constructor({ requestId }) {
|
|
36
36
|
this.requestId = requestId;
|
|
37
|
-
this.trackNamespace = trackNamespace;
|
|
38
|
-
this.trackName = trackName;
|
|
39
|
-
this.subscriberPriority = subscriberPriority;
|
|
40
|
-
this.groupOrder = groupOrder;
|
|
41
|
-
this.startGroup = startGroup;
|
|
42
|
-
this.startObject = startObject;
|
|
43
|
-
this.endGroup = endGroup;
|
|
44
|
-
this.endObject = endObject;
|
|
45
37
|
}
|
|
46
38
|
async #encode(_w) {
|
|
47
39
|
throw new Error("FETCH messages are not supported");
|
|
@@ -49,11 +41,49 @@ export class Fetch {
|
|
|
49
41
|
async encode(w, _version) {
|
|
50
42
|
return Message.encode(w, this.#encode.bind(this));
|
|
51
43
|
}
|
|
52
|
-
static async decode(r,
|
|
53
|
-
return Message.decode(r, Fetch.#decode);
|
|
54
|
-
}
|
|
55
|
-
static async #decode(
|
|
56
|
-
|
|
44
|
+
static async decode(r, version) {
|
|
45
|
+
return Message.decode(r, (mr) => Fetch.#decode(mr, version));
|
|
46
|
+
}
|
|
47
|
+
static async #decode(r, version) {
|
|
48
|
+
const requestId = await r.u62();
|
|
49
|
+
if (version === Version.DRAFT_17) {
|
|
50
|
+
await r.u62(); // required_request_id_delta
|
|
51
|
+
}
|
|
52
|
+
if (version === Version.DRAFT_14) {
|
|
53
|
+
await r.u8(); // subscriber_priority
|
|
54
|
+
await r.u8(); // group_order
|
|
55
|
+
}
|
|
56
|
+
if (isDraft20(version)) {
|
|
57
|
+
// Draft-20 names the track up front and moves the range into LOCATION_FILTER.
|
|
58
|
+
await Namespace.decode(r);
|
|
59
|
+
await r.string();
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const fetchType = await r.u53();
|
|
63
|
+
switch (fetchType) {
|
|
64
|
+
case 0x1: // Standalone: namespace, name, start and end Locations
|
|
65
|
+
await Namespace.decode(r);
|
|
66
|
+
await r.string();
|
|
67
|
+
for (let i = 0; i < 4; i++)
|
|
68
|
+
await r.u62();
|
|
69
|
+
break;
|
|
70
|
+
case 0x2: // Relative Joining: subscription, group offset
|
|
71
|
+
case 0x3: // Absolute Joining: subscription, group
|
|
72
|
+
await r.u62();
|
|
73
|
+
await r.u62();
|
|
74
|
+
break;
|
|
75
|
+
default:
|
|
76
|
+
throw new Error(`unknown fetch type: ${fetchType}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const params = await Parameters.decode(r, version);
|
|
80
|
+
if (params.rangeFilters && !hasRangeFilters(version)) {
|
|
81
|
+
throw new Error("Range Filters need draft-19");
|
|
82
|
+
}
|
|
83
|
+
if (params.trackPropertyFilter) {
|
|
84
|
+
throw new Error("TRACK_PROPERTY_FILTER is not allowed on FETCH");
|
|
85
|
+
}
|
|
86
|
+
return new Fetch({ requestId });
|
|
57
87
|
}
|
|
58
88
|
}
|
|
59
89
|
export class FetchOk {
|
package/ietf/fetch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/ietf/fetch.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAGxC;;;GAGG;AACH,MAAM,OAAO,WAAW;IACvB,qDAAqD;IACrD,MAAM,CAAC,IAAI,GAAG,GAAG,CAAC;IAElB,wEAAwE;IACxE,SAAS,CAAS;IAElB,YAAY,EAAE,SAAS,EAAyB;QAC/C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC5B,CAAC;IAED,oEAAoE;IACpE,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,QAAqB;QAC5C,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC7B,CAAC;IAED,8DAA8D;IAC9D,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,QAAqB;QACnD,OAAO,IAAI,WAAW,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACtD,CAAC;CACD;AAED,MAAM,OAAO,KAAK;IACjB,MAAM,CAAC,EAAE,GAAG,IAAI,CAAC;IAEjB,SAAS,CAAS;IAClB,cAAc,CAAa;IAC3B,SAAS,CAAS;IAClB,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CAAC,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,QAAqB;QACnD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAU;QAC9B,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC3D,CAAC;CACD;AAED,iBAAiB;AACjB,MAAM,OAAO,WAAW;IACvB,MAAM,CAAC,EAAE,GAAG,IAAI,CAAC;IAEjB,SAAS,CAAS;IAElB,YAAY,EAAE,SAAS,EAAyB;QAC/C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,EAAU;QACvB,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,QAAqB;QAC5C,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,QAAqB;QACnD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAU;QAC9B,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC5D,CAAC;CACD","sourcesContent":["import type * as Path from \"../path.ts\";\nimport type { Reader, Writer } from \"../stream.ts\";\nimport * as Message from \"./message.ts\";\nimport type { IetfVersion } from \"./version.ts\";\n\n/**\n * The header that begins a fetch stream (draft-20 section 11.4.4), naming the request it\n * answers. Written by the publisher when serving a subscription's fill.\n */\nexport class FetchHeader {\n\t/** The uni stream type, not a control message id. */\n\tstatic type = 0x5;\n\n\t/** The SUBSCRIBE (or FETCH) request this stream carries objects for. */\n\trequestId: bigint;\n\n\tconstructor({ requestId }: { requestId: bigint }) {\n\t\tthis.requestId = requestId;\n\t}\n\n\t/** Write the header, which the stream type must already precede. */\n\tasync encode(w: Writer, _version: IetfVersion): Promise<void> {\n\t\tawait w.u62(this.requestId);\n\t}\n\n\t/** Read the header, with the stream type already consumed. */\n\tstatic async decode(r: Reader, _version: IetfVersion): Promise<FetchHeader> {\n\t\treturn new FetchHeader({ requestId: await r.u62() });\n\t}\n}\n\nexport class Fetch {\n\tstatic id = 0x16;\n\n\trequestId: bigint;\n\ttrackNamespace: Path.Valid;\n\ttrackName: string;\n\tsubscriberPriority: number;\n\tgroupOrder: number;\n\tstartGroup: bigint;\n\tstartObject: bigint;\n\tendGroup: bigint;\n\tendObject: bigint;\n\n\tconstructor({\n\t\trequestId,\n\t\ttrackNamespace,\n\t\ttrackName,\n\t\tsubscriberPriority,\n\t\tgroupOrder,\n\t\tstartGroup,\n\t\tstartObject,\n\t\tendGroup,\n\t\tendObject,\n\t}: {\n\t\trequestId: bigint;\n\t\ttrackNamespace: Path.Valid;\n\t\ttrackName: string;\n\t\tsubscriberPriority: number;\n\t\tgroupOrder: number;\n\t\tstartGroup: bigint;\n\t\tstartObject: bigint;\n\t\tendGroup: bigint;\n\t\tendObject: bigint;\n\t}) {\n\t\tthis.requestId = requestId;\n\t\tthis.trackNamespace = trackNamespace;\n\t\tthis.trackName = trackName;\n\t\tthis.subscriberPriority = subscriberPriority;\n\t\tthis.groupOrder = groupOrder;\n\t\tthis.startGroup = startGroup;\n\t\tthis.startObject = startObject;\n\t\tthis.endGroup = endGroup;\n\t\tthis.endObject = endObject;\n\t}\n\n\tasync #encode(_w: Writer): Promise<void> {\n\t\tthrow new Error(\"FETCH messages are not supported\");\n\t}\n\n\tasync encode(w: Writer, _version: IetfVersion): Promise<void> {\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, _version: IetfVersion): Promise<Fetch> {\n\t\treturn Message.decode(r, Fetch.#decode);\n\t}\n\n\tstatic async #decode(_r: Reader): Promise<Fetch> {\n\t\tthrow new Error(\"FETCH messages are not supported\");\n\t}\n}\n\nexport class FetchOk {\n\tstatic id = 0x18;\n\n\trequestId: bigint | undefined;\n\n\tconstructor({ requestId }: { requestId?: bigint }) {\n\t\tthis.requestId = requestId;\n\t}\n\n\tasync #encode(_w: Writer): Promise<void> {\n\t\tthrow new Error(\"FETCH_OK messages are not supported\");\n\t}\n\n\tasync encode(w: Writer, _version: IetfVersion): Promise<void> {\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, _version: IetfVersion): Promise<FetchOk> {\n\t\treturn Message.decode(r, FetchOk.#decode);\n\t}\n\n\tstatic async #decode(_r: Reader): Promise<FetchOk> {\n\t\tthrow new Error(\"FETCH_OK messages are not supported\");\n\t}\n}\n\nexport class FetchError {\n\tstatic id = 0x19;\n\n\trequestId: bigint;\n\terrorCode: number;\n\treasonPhrase: string;\n\n\tconstructor({\n\t\trequestId,\n\t\terrorCode,\n\t\treasonPhrase,\n\t}: { requestId: bigint; errorCode: number; reasonPhrase: string }) {\n\t\tthis.requestId = requestId;\n\t\tthis.errorCode = errorCode;\n\t\tthis.reasonPhrase = reasonPhrase;\n\t}\n\n\tasync #encode(_w: Writer): Promise<void> {\n\t\tthrow new Error(\"FETCH_ERROR messages are not supported\");\n\t}\n\n\tasync encode(w: Writer, _version: IetfVersion): Promise<void> {\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, _version: IetfVersion): Promise<FetchError> {\n\t\treturn Message.decode(r, FetchError.#decode);\n\t}\n\n\tstatic async #decode(_r: Reader): Promise<FetchError> {\n\t\tthrow new Error(\"FETCH_ERROR messages are not supported\");\n\t}\n}\n\n// Removed in d17\nexport class FetchCancel {\n\tstatic id = 0x17;\n\n\trequestId: bigint;\n\n\tconstructor({ requestId }: { requestId: bigint }) {\n\t\tthis.requestId = requestId;\n\t}\n\n\tasync #encode(_w: Writer): Promise<void> {\n\t\tthrow new Error(\"FETCH_CANCEL messages are not supported\");\n\t}\n\n\tasync encode(w: Writer, _version: IetfVersion): Promise<void> {\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, _version: IetfVersion): Promise<FetchCancel> {\n\t\treturn Message.decode(r, FetchCancel.#decode);\n\t}\n\n\tstatic async #decode(_r: Reader): Promise<FetchCancel> {\n\t\tthrow new Error(\"FETCH_CANCEL messages are not supported\");\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/ietf/fetch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAoB,OAAO,EAAE,MAAM,cAAc,CAAC;AAEzD;;;GAGG;AACH,MAAM,OAAO,WAAW;IACvB,qDAAqD;IACrD,MAAM,CAAC,IAAI,GAAG,GAAG,CAAC;IAElB,wEAAwE;IACxE,SAAS,CAAS;IAElB,YAAY,EAAE,SAAS,EAAyB;QAC/C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC5B,CAAC;IAED,oEAAoE;IACpE,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,QAAqB;QAC5C,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC7B,CAAC;IAED,8DAA8D;IAC9D,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,QAAqB;QACnD,OAAO,IAAI,WAAW,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IAC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,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAU;QAC9B,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC3D,CAAC;CACD;AAED,iBAAiB;AACjB,MAAM,OAAO,WAAW;IACvB,MAAM,CAAC,EAAE,GAAG,IAAI,CAAC;IAEjB,SAAS,CAAS;IAElB,YAAY,EAAE,SAAS,EAAyB;QAC/C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,EAAU;QACvB,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,QAAqB;QAC5C,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAS,EAAE,QAAqB;QACnD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAU;QAC9B,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC5D,CAAC;CACD","sourcesContent":["import type { Reader, Writer } from \"../stream.ts\";\nimport { hasRangeFilters, isDraft20 } from \"./filter.ts\";\nimport * as Message from \"./message.ts\";\nimport * as Namespace from \"./namespace.ts\";\nimport { Parameters } from \"./parameters.ts\";\nimport { type IetfVersion, Version } from \"./version.ts\";\n\n/**\n * The header that begins a fetch stream (draft-20 section 11.4.4), naming the request it\n * answers. Written by the publisher when serving a subscription's fill.\n */\nexport class FetchHeader {\n\t/** The uni stream type, not a control message id. */\n\tstatic type = 0x5;\n\n\t/** The SUBSCRIBE (or FETCH) request this stream carries objects for. */\n\trequestId: bigint;\n\n\tconstructor({ requestId }: { requestId: bigint }) {\n\t\tthis.requestId = requestId;\n\t}\n\n\t/** Write the header, which the stream type must already precede. */\n\tasync encode(w: Writer, _version: IetfVersion): Promise<void> {\n\t\tawait w.u62(this.requestId);\n\t}\n\n\t/** Read the header, with the stream type already consumed. */\n\tstatic async decode(r: Reader, _version: IetfVersion): Promise<FetchHeader> {\n\t\treturn new FetchHeader({ requestId: await r.u62() });\n\t}\n}\n\n/**\n * A FETCH request. We serve none, so only what a refusal needs is kept; the rest is\n * decoded so a legal request is refused rather than breaking the stream.\n */\nexport class Fetch {\n\tstatic id = 0x16;\n\n\trequestId: bigint;\n\n\tconstructor({ requestId }: { requestId: bigint }) {\n\t\tthis.requestId = requestId;\n\t}\n\n\tasync #encode(_w: Writer): Promise<void> {\n\t\tthrow new Error(\"FETCH messages are not supported\");\n\t}\n\n\tasync encode(w: Writer, _version: IetfVersion): Promise<void> {\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, version: IetfVersion): Promise<Fetch> {\n\t\treturn Message.decode(r, (mr) => Fetch.#decode(mr, version));\n\t}\n\n\tstatic async #decode(r: Reader, version: IetfVersion): Promise<Fetch> {\n\t\tconst requestId = await r.u62();\n\t\tif (version === Version.DRAFT_17) {\n\t\t\tawait r.u62(); // required_request_id_delta\n\t\t}\n\n\t\tif (version === Version.DRAFT_14) {\n\t\t\tawait r.u8(); // subscriber_priority\n\t\t\tawait r.u8(); // group_order\n\t\t}\n\n\t\tif (isDraft20(version)) {\n\t\t\t// Draft-20 names the track up front and moves the range into LOCATION_FILTER.\n\t\t\tawait Namespace.decode(r);\n\t\t\tawait r.string();\n\t\t} else {\n\t\t\tconst fetchType = await r.u53();\n\t\t\tswitch (fetchType) {\n\t\t\t\tcase 0x1: // Standalone: namespace, name, start and end Locations\n\t\t\t\t\tawait Namespace.decode(r);\n\t\t\t\t\tawait r.string();\n\t\t\t\t\tfor (let i = 0; i < 4; i++) await r.u62();\n\t\t\t\t\tbreak;\n\t\t\t\tcase 0x2: // Relative Joining: subscription, group offset\n\t\t\t\tcase 0x3: // Absolute Joining: subscription, group\n\t\t\t\t\tawait r.u62();\n\t\t\t\t\tawait r.u62();\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new Error(`unknown fetch type: ${fetchType}`);\n\t\t\t}\n\t\t}\n\n\t\tconst params = await Parameters.decode(r, version);\n\t\tif (params.rangeFilters && !hasRangeFilters(version)) {\n\t\t\tthrow new Error(\"Range Filters need draft-19\");\n\t\t}\n\t\tif (params.trackPropertyFilter) {\n\t\t\tthrow new Error(\"TRACK_PROPERTY_FILTER is not allowed on FETCH\");\n\t\t}\n\n\t\treturn new Fetch({ requestId });\n\t}\n}\n\nexport class FetchOk {\n\tstatic id = 0x18;\n\n\trequestId: bigint | undefined;\n\n\tconstructor({ requestId }: { requestId?: bigint }) {\n\t\tthis.requestId = requestId;\n\t}\n\n\tasync #encode(_w: Writer): Promise<void> {\n\t\tthrow new Error(\"FETCH_OK messages are not supported\");\n\t}\n\n\tasync encode(w: Writer, _version: IetfVersion): Promise<void> {\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, _version: IetfVersion): Promise<FetchOk> {\n\t\treturn Message.decode(r, FetchOk.#decode);\n\t}\n\n\tstatic async #decode(_r: Reader): Promise<FetchOk> {\n\t\tthrow new Error(\"FETCH_OK messages are not supported\");\n\t}\n}\n\nexport class FetchError {\n\tstatic id = 0x19;\n\n\trequestId: bigint;\n\terrorCode: number;\n\treasonPhrase: string;\n\n\tconstructor({\n\t\trequestId,\n\t\terrorCode,\n\t\treasonPhrase,\n\t}: { requestId: bigint; errorCode: number; reasonPhrase: string }) {\n\t\tthis.requestId = requestId;\n\t\tthis.errorCode = errorCode;\n\t\tthis.reasonPhrase = reasonPhrase;\n\t}\n\n\tasync #encode(_w: Writer): Promise<void> {\n\t\tthrow new Error(\"FETCH_ERROR messages are not supported\");\n\t}\n\n\tasync encode(w: Writer, _version: IetfVersion): Promise<void> {\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, _version: IetfVersion): Promise<FetchError> {\n\t\treturn Message.decode(r, FetchError.#decode);\n\t}\n\n\tstatic async #decode(_r: Reader): Promise<FetchError> {\n\t\tthrow new Error(\"FETCH_ERROR messages are not supported\");\n\t}\n}\n\n// Removed in d17\nexport class FetchCancel {\n\tstatic id = 0x17;\n\n\trequestId: bigint;\n\n\tconstructor({ requestId }: { requestId: bigint }) {\n\t\tthis.requestId = requestId;\n\t}\n\n\tasync #encode(_w: Writer): Promise<void> {\n\t\tthrow new Error(\"FETCH_CANCEL messages are not supported\");\n\t}\n\n\tasync encode(w: Writer, _version: IetfVersion): Promise<void> {\n\t\treturn Message.encode(w, this.#encode.bind(this));\n\t}\n\n\tstatic async decode(r: Reader, _version: IetfVersion): Promise<FetchCancel> {\n\t\treturn Message.decode(r, FetchCancel.#decode);\n\t}\n\n\tstatic async #decode(_r: Reader): Promise<FetchCancel> {\n\t\tthrow new Error(\"FETCH_CANCEL messages are not supported\");\n\t}\n}\n"]}
|
package/ietf/filter.d.ts
CHANGED
|
@@ -41,6 +41,8 @@ export type Filter =
|
|
|
41
41
|
* present selects the meaning.
|
|
42
42
|
*/
|
|
43
43
|
export declare function isDraft20(version: IetfVersion): boolean;
|
|
44
|
+
/** Whether the Range Filters (draft-19) exist on this draft. */
|
|
45
|
+
export declare function hasRangeFilters(version: IetfVersion): boolean;
|
|
44
46
|
/** Encode a filter as its raw parameter value. Unfiltered encodes to zero bytes. */
|
|
45
47
|
export declare function encode(filter: Filter, version: IetfVersion): Uint8Array;
|
|
46
48
|
/** Decode a filter from its raw parameter value. */
|
package/ietf/filter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../src/ietf/filter.ts"],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