@moq/net 0.3.0 → 0.3.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.
Files changed (91) hide show
  1. package/connection/accept.js +2 -1
  2. package/connection/accept.js.map +1 -1
  3. package/connection/browser.d.ts.map +1 -1
  4. package/connection/browser.js +15 -12
  5. package/connection/browser.js.map +1 -1
  6. package/connection/connect.d.ts.map +1 -1
  7. package/connection/connect.js +2 -1
  8. package/connection/connect.js.map +1 -1
  9. package/connection/handshake.d.ts +7 -4
  10. package/connection/handshake.d.ts.map +1 -1
  11. package/connection/handshake.js +17 -5
  12. package/connection/handshake.js.map +1 -1
  13. package/error.d.ts +14 -0
  14. package/error.d.ts.map +1 -1
  15. package/error.js +15 -0
  16. package/error.js.map +1 -1
  17. package/ietf/cluster.d.ts +141 -0
  18. package/ietf/cluster.d.ts.map +1 -0
  19. package/ietf/cluster.js +204 -0
  20. package/ietf/cluster.js.map +1 -0
  21. package/ietf/connection.d.ts +8 -1
  22. package/ietf/connection.d.ts.map +1 -1
  23. package/ietf/connection.js +19 -4
  24. package/ietf/connection.js.map +1 -1
  25. package/ietf/index.d.ts +1 -0
  26. package/ietf/index.d.ts.map +1 -1
  27. package/ietf/index.js +2 -0
  28. package/ietf/index.js.map +1 -1
  29. package/ietf/parameters.d.ts +20 -8
  30. package/ietf/parameters.d.ts.map +1 -1
  31. package/ietf/parameters.js +185 -40
  32. package/ietf/parameters.js.map +1 -1
  33. package/ietf/publish_namespace.d.ts +16 -2
  34. package/ietf/publish_namespace.d.ts.map +1 -1
  35. package/ietf/publish_namespace.js +25 -6
  36. package/ietf/publish_namespace.js.map +1 -1
  37. package/ietf/publisher.d.ts +11 -4
  38. package/ietf/publisher.d.ts.map +1 -1
  39. package/ietf/publisher.js +9 -6
  40. package/ietf/publisher.js.map +1 -1
  41. package/ietf/subscribe_namespace.d.ts +21 -3
  42. package/ietf/subscribe_namespace.d.ts.map +1 -1
  43. package/ietf/subscribe_namespace.js +31 -9
  44. package/ietf/subscribe_namespace.js.map +1 -1
  45. package/ietf/subscriber.d.ts +8 -3
  46. package/ietf/subscriber.d.ts.map +1 -1
  47. package/ietf/subscriber.js +98 -9
  48. package/ietf/subscriber.js.map +1 -1
  49. package/lite/announce.d.ts +1 -2
  50. package/lite/announce.d.ts.map +1 -1
  51. package/lite/announce.js +4 -9
  52. package/lite/announce.js.map +1 -1
  53. package/lite/connection.d.ts +18 -2
  54. package/lite/connection.d.ts.map +1 -1
  55. package/lite/connection.js +36 -5
  56. package/lite/connection.js.map +1 -1
  57. package/lite/probe.d.ts +18 -2
  58. package/lite/probe.d.ts.map +1 -1
  59. package/lite/probe.js +24 -22
  60. package/lite/probe.js.map +1 -1
  61. package/lite/publisher.d.ts +1 -1
  62. package/lite/publisher.d.ts.map +1 -1
  63. package/lite/publisher.js +43 -13
  64. package/lite/publisher.js.map +1 -1
  65. package/lite/setup.d.ts +1 -1
  66. package/lite/setup.d.ts.map +1 -1
  67. package/lite/setup.js +1 -1
  68. package/lite/setup.js.map +1 -1
  69. package/lite/subscriber.d.ts +1 -1
  70. package/lite/subscriber.d.ts.map +1 -1
  71. package/lite/subscriber.js +10 -5
  72. package/lite/subscriber.js.map +1 -1
  73. package/lite/version.d.ts +7 -0
  74. package/lite/version.d.ts.map +1 -1
  75. package/lite/version.js +17 -0
  76. package/lite/version.js.map +1 -1
  77. package/{lite/origin.d.ts → origin.d.ts} +24 -0
  78. package/origin.d.ts.map +1 -0
  79. package/{lite/origin.js → origin.js} +24 -0
  80. package/origin.js.map +1 -0
  81. package/package.json +4 -3
  82. package/path.d.ts +29 -0
  83. package/path.d.ts.map +1 -1
  84. package/path.js +51 -0
  85. package/path.js.map +1 -1
  86. package/varint.d.ts +8 -3
  87. package/varint.d.ts.map +1 -1
  88. package/varint.js +17 -10
  89. package/varint.js.map +1 -1
  90. package/lite/origin.d.ts.map +0 -1
  91. package/lite/origin.js.map +0 -1
@@ -0,0 +1,141 @@
1
+ /**
2
+ * The MoQ Cluster extension (draft-lcurley-moq-cluster-00).
3
+ *
4
+ * moq-transport carries no routing information, so a peer cannot tell whether an
5
+ * advertisement already passed through us. This extension adds it:
6
+ *
7
+ * - each endpoint declares its own Hop ID via the RELAY_HOPS Setup Option, which is also
8
+ * what negotiates the extension;
9
+ * - every advertisement carries the HOP_PATH it traversed and the accumulated ROUTE_COST
10
+ * of that path, as Key-Value-Pair message parameters on PUBLISH_NAMESPACE and NAMESPACE.
11
+ *
12
+ * These are the semantics moq-lite carries natively on every announcement (see
13
+ * `lite/announce.ts`); this module is the moq-transport binding, negotiated on draft-17+
14
+ * only, where SETUP is a Key-Value-Pair block.
15
+ *
16
+ * We are a leaf, never a relay: the only path we can advertise is our own, so we stamp a
17
+ * single-entry HOP_PATH and seed the cost at 0. What we get out of declaring is the other
18
+ * direction. A relay that knows our Hop ID withholds the advertisements that already flowed
19
+ * through us, so publishing a broadcast no longer announces it back to us, which is what
20
+ * moq-lite has always done with its own hop chain.
21
+ *
22
+ * @module
23
+ * @internal
24
+ */
25
+ import { type Origin } from "../origin";
26
+ import type { Reader } from "../stream";
27
+ import { Parameters, type SetupOptions } from "./parameters";
28
+ import { type IetfVersion } from "./version";
29
+ /**
30
+ * Whether a version can negotiate the extension.
31
+ *
32
+ * Draft-17 is the first with the unified SETUP: a bare Key-Value-Pair block that a new
33
+ * option slots into without touching the message shape. Earlier drafts exchange SETUP over
34
+ * the legacy control stream, which this extension does not cover.
35
+ *
36
+ * @internal
37
+ */
38
+ export declare function supported(version: IetfVersion): boolean;
39
+ /**
40
+ * The Hop IDs this session declared, one per direction.
41
+ *
42
+ * @internal
43
+ */
44
+ export interface Hops {
45
+ /** Our own Hop ID, declared in SETUP and stamped onto every advertisement we send. */
46
+ self: Origin;
47
+ /**
48
+ * The peer's Hop ID, or `undefined` when it declared no RELAY_HOPS.
49
+ *
50
+ * This is what decides whether advertisements carry the parameters at all, in both
51
+ * directions: a peer that declared nothing has not read ours either, so sending it a
52
+ * HOP_PATH would be a protocol violation and expecting one back would reject a legal
53
+ * message. A peer that declared the reserved 0 negotiated the extension but withheld its
54
+ * identity, so the parameters flow and there is simply nothing to exclude.
55
+ */
56
+ peer?: Origin;
57
+ }
58
+ /**
59
+ * The cluster parameters carried on one advertisement.
60
+ *
61
+ * Present on every PUBLISH_NAMESPACE and NAMESPACE of a session that negotiated the
62
+ * extension, and on none of a session that did not.
63
+ *
64
+ * @internal
65
+ */
66
+ export interface Advert {
67
+ /** HOP_PATH: the path this advertisement traversed, publisher first, sender last. */
68
+ hops: Origin[];
69
+ /** ROUTE_COST: the marginal cost of subscribing via this advertisement. Absent on the
70
+ * wire means 0, so an endpoint that prices nothing sends nothing. */
71
+ cost: bigint;
72
+ }
73
+ /**
74
+ * Read the peer's Hop ID out of its SETUP, or `undefined` when it did not negotiate.
75
+ *
76
+ * @internal
77
+ */
78
+ export declare function fromSetup(params: SetupOptions, version: IetfVersion): Origin | undefined;
79
+ /**
80
+ * Declare our own Hop ID, which is also what negotiates the extension.
81
+ *
82
+ * @internal
83
+ */
84
+ export declare function intoSetup(params: SetupOptions, self: Origin, version: IetfVersion): void;
85
+ /**
86
+ * Whether the session negotiated the extension, which is what decides whether an
87
+ * advertisement carries the parameters in either direction.
88
+ *
89
+ * @internal
90
+ */
91
+ export declare function negotiated(ids: Hops | undefined): boolean;
92
+ /**
93
+ * The advertisement to send for one of our own broadcasts, or `undefined` on a session
94
+ * that negotiated nothing.
95
+ *
96
+ * The sender's own Hop ID is always the last entry, so a receiver reconstructs the full
97
+ * path without the sender restating it. We originate everything we advertise, so the path
98
+ * is just us and the cost is 0: a subscription costs the peer nothing but the transfer,
99
+ * since we are already producing the content.
100
+ *
101
+ * @internal
102
+ */
103
+ export declare function advertise(ids: Hops | undefined): Advert | undefined;
104
+ /**
105
+ * Whether this advertisement looped back through `self`.
106
+ *
107
+ * A receiver discards such an advertisement: forwarding it would extend the loop, and
108
+ * subscribing through it would route the receiver back to itself. Hop ID 0 identifies
109
+ * nothing, so a receiver that withheld its own identity detects nothing.
110
+ *
111
+ * @internal
112
+ */
113
+ export declare function loops(advert: Advert, self: Origin): boolean;
114
+ /**
115
+ * Write an advertisement's parameters, ready to encode onto the wire.
116
+ *
117
+ * @internal
118
+ */
119
+ export declare function intoParams(advert: Advert): Parameters;
120
+ /**
121
+ * Read the parameters a negotiated session puts on every advertisement.
122
+ *
123
+ * The parameter block is mandatory there, so a message that ends before it (the base form)
124
+ * or one whose block does not parse is the peer's violation, same as a block that parses but
125
+ * carries no HOP_PATH.
126
+ *
127
+ * @internal
128
+ */
129
+ export declare function decodeParams(r: Reader, version: IetfVersion): Promise<Advert>;
130
+ /**
131
+ * Read an advertisement out of a decoded parameter block.
132
+ *
133
+ * Every way this fails is one the draft says to close the session over: a negotiated session
134
+ * that omits HOP_PATH, entries that do not exactly fill the parameter, an empty list, or a
135
+ * non-zero Hop ID appearing twice. So they all surface as one {@link ProtocolViolation},
136
+ * which the session dispatch acts on.
137
+ *
138
+ * @internal
139
+ */
140
+ export declare function fromParams(params: Parameters): Advert;
141
+ //# sourceMappingURL=cluster.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cluster.d.ts","sourceRoot":"","sources":["../../src/ietf/cluster.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,EAAY,KAAK,MAAM,EAAgC,MAAM,cAAc,CAAC;AACnF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAe,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAAE,KAAK,WAAW,EAAW,MAAM,cAAc,CAAC;AAEzD;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAEvD;AAED;;;;GAIG;AACH,MAAM,WAAW,IAAI;IACpB,sFAAsF;IACtF,IAAI,EAAE,MAAM,CAAC;IAEb;;;;;;;;OAQG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,MAAM;IACtB,qFAAqF;IACrF,IAAI,EAAE,MAAM,EAAE,CAAC;IAEf;yEACqE;IACrE,IAAI,EAAE,MAAM,CAAC;CACb;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,CAYxF;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,QAGjF;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,IAAI,GAAG,SAAS,GAAG,OAAO,CAEzD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAGnE;AAED;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAE3D;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAoBrD;AAED;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CASnF;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAuBrD"}
@@ -0,0 +1,204 @@
1
+ /* @ts-self-types="./cluster.d.ts" */
2
+ /**
3
+ * The MoQ Cluster extension (draft-lcurley-moq-cluster-00).
4
+ *
5
+ * moq-transport carries no routing information, so a peer cannot tell whether an
6
+ * advertisement already passed through us. This extension adds it:
7
+ *
8
+ * - each endpoint declares its own Hop ID via the RELAY_HOPS Setup Option, which is also
9
+ * what negotiates the extension;
10
+ * - every advertisement carries the HOP_PATH it traversed and the accumulated ROUTE_COST
11
+ * of that path, as Key-Value-Pair message parameters on PUBLISH_NAMESPACE and NAMESPACE.
12
+ *
13
+ * These are the semantics moq-lite carries natively on every announcement (see
14
+ * `lite/announce.ts`); this module is the moq-transport binding, negotiated on draft-17+
15
+ * only, where SETUP is a Key-Value-Pair block.
16
+ *
17
+ * We are a leaf, never a relay: the only path we can advertise is our own, so we stamp a
18
+ * single-entry HOP_PATH and seed the cost at 0. What we get out of declaring is the other
19
+ * direction. A relay that knows our Hop ID withholds the advertisements that already flowed
20
+ * through us, so publishing a broadcast no longer announces it back to us, which is what
21
+ * moq-lite has always done with its own hop chain.
22
+ *
23
+ * @module
24
+ * @internal
25
+ */
26
+ import { ProtocolViolation, reason } from "../error.js";
27
+ import { MAX_HOPS, OriginSchema, UNKNOWN_ORIGIN } from "../origin.js";
28
+ import * as Varint from "../varint.js";
29
+ import { Parameters, SetupOption } from "./parameters.js";
30
+ import { Version } from "./version.js";
31
+ /**
32
+ * Whether a version can negotiate the extension.
33
+ *
34
+ * Draft-17 is the first with the unified SETUP: a bare Key-Value-Pair block that a new
35
+ * option slots into without touching the message shape. Earlier drafts exchange SETUP over
36
+ * the legacy control stream, which this extension does not cover.
37
+ *
38
+ * @internal
39
+ */
40
+ export function supported(version) {
41
+ return version !== Version.DRAFT_14 && version !== Version.DRAFT_15 && version !== Version.DRAFT_16;
42
+ }
43
+ /**
44
+ * Read the peer's Hop ID out of its SETUP, or `undefined` when it did not negotiate.
45
+ *
46
+ * @internal
47
+ */
48
+ export function fromSetup(params, version) {
49
+ if (!supported(version))
50
+ return undefined;
51
+ // RELAY_HOPS is odd, so its value is a length-prefixed byte string holding the sender's
52
+ // Hop ID as a single varint. 0 is legal: the peer speaks the extension but withholds
53
+ // its identity.
54
+ const value = params.getBytes(SetupOption.RelayHops);
55
+ if (value === undefined)
56
+ return undefined;
57
+ const [origin, rest] = Varint.decodeLeadingOnes(value);
58
+ if (rest.length !== 0)
59
+ throw new Error("trailing bytes in RELAY_HOPS");
60
+ return OriginSchema.parse(origin);
61
+ }
62
+ /**
63
+ * Declare our own Hop ID, which is also what negotiates the extension.
64
+ *
65
+ * @internal
66
+ */
67
+ export function intoSetup(params, self, version) {
68
+ if (!supported(version))
69
+ return;
70
+ params.setBytes(SetupOption.RelayHops, Varint.encodeLeadingOnes(self));
71
+ }
72
+ /**
73
+ * Whether the session negotiated the extension, which is what decides whether an
74
+ * advertisement carries the parameters in either direction.
75
+ *
76
+ * @internal
77
+ */
78
+ export function negotiated(ids) {
79
+ return ids?.peer !== undefined;
80
+ }
81
+ /**
82
+ * The advertisement to send for one of our own broadcasts, or `undefined` on a session
83
+ * that negotiated nothing.
84
+ *
85
+ * The sender's own Hop ID is always the last entry, so a receiver reconstructs the full
86
+ * path without the sender restating it. We originate everything we advertise, so the path
87
+ * is just us and the cost is 0: a subscription costs the peer nothing but the transfer,
88
+ * since we are already producing the content.
89
+ *
90
+ * @internal
91
+ */
92
+ export function advertise(ids) {
93
+ if (ids === undefined || ids.peer === undefined)
94
+ return undefined;
95
+ return { hops: [ids.self], cost: 0n };
96
+ }
97
+ /**
98
+ * Whether this advertisement looped back through `self`.
99
+ *
100
+ * A receiver discards such an advertisement: forwarding it would extend the loop, and
101
+ * subscribing through it would route the receiver back to itself. Hop ID 0 identifies
102
+ * nothing, so a receiver that withheld its own identity detects nothing.
103
+ *
104
+ * @internal
105
+ */
106
+ export function loops(advert, self) {
107
+ return self !== UNKNOWN_ORIGIN && advert.hops.includes(self);
108
+ }
109
+ /**
110
+ * Write an advertisement's parameters, ready to encode onto the wire.
111
+ *
112
+ * @internal
113
+ */
114
+ export function intoParams(advert) {
115
+ validate(advert.hops);
116
+ const params = new Parameters();
117
+ // The entries fill the value, so they are written with no count of their own and framed
118
+ // by the parameter's own length prefix.
119
+ const hops = advert.hops.map((hop) => Varint.encodeLeadingOnes(hop));
120
+ const value = new Uint8Array(hops.reduce((total, hop) => total + hop.length, 0));
121
+ let offset = 0;
122
+ for (const hop of hops) {
123
+ value.set(hop, offset);
124
+ offset += hop.length;
125
+ }
126
+ params.hopPath = value;
127
+ // Absent means 0, so a free path sends nothing.
128
+ if (advert.cost !== 0n)
129
+ params.routeCost = advert.cost;
130
+ return params;
131
+ }
132
+ /**
133
+ * Read the parameters a negotiated session puts on every advertisement.
134
+ *
135
+ * The parameter block is mandatory there, so a message that ends before it (the base form)
136
+ * or one whose block does not parse is the peer's violation, same as a block that parses but
137
+ * carries no HOP_PATH.
138
+ *
139
+ * @internal
140
+ */
141
+ export async function decodeParams(r, version) {
142
+ let params;
143
+ try {
144
+ params = await Parameters.decode(r, version);
145
+ }
146
+ catch (err) {
147
+ throw new ProtocolViolation(reason(err), { cause: err });
148
+ }
149
+ return fromParams(params);
150
+ }
151
+ /**
152
+ * Read an advertisement out of a decoded parameter block.
153
+ *
154
+ * Every way this fails is one the draft says to close the session over: a negotiated session
155
+ * that omits HOP_PATH, entries that do not exactly fill the parameter, an empty list, or a
156
+ * non-zero Hop ID appearing twice. So they all surface as one {@link ProtocolViolation},
157
+ * which the session dispatch acts on.
158
+ *
159
+ * @internal
160
+ */
161
+ export function fromParams(params) {
162
+ try {
163
+ const value = params.hopPath;
164
+ if (value === undefined)
165
+ throw new Error("advertisement is missing HOP_PATH");
166
+ const hops = [];
167
+ let rest = value;
168
+ while (rest.length > 0) {
169
+ // A short read here means the entries did not exactly fill the length.
170
+ const [hop, remain] = Varint.decodeLeadingOnes(rest);
171
+ hops.push(OriginSchema.parse(hop));
172
+ rest = remain;
173
+ // Bail before the buffer does: a hostile length would otherwise cost us one
174
+ // allocation per entry all the way to 64KB of parameter value.
175
+ if (hops.length > MAX_HOPS)
176
+ throw new Error(`hop count exceeds maximum ${MAX_HOPS}`);
177
+ }
178
+ validate(hops);
179
+ return { hops, cost: params.routeCost ?? 0n };
180
+ }
181
+ catch (err) {
182
+ throw new ProtocolViolation(reason(err), { cause: err });
183
+ }
184
+ }
185
+ /**
186
+ * Reject a path that cannot have come from a conforming sender: an empty list, one longer
187
+ * than we accept, or a non-zero Hop ID appearing twice (a loop). Duplicate zeros are legal,
188
+ * since 0 identifies nothing.
189
+ */
190
+ function validate(hops) {
191
+ if (hops.length === 0)
192
+ throw new Error("hop path is empty");
193
+ if (hops.length > MAX_HOPS)
194
+ throw new Error(`hop count ${hops.length} exceeds maximum ${MAX_HOPS}`);
195
+ // MAX_HOPS is 32, so the quadratic scan is cheaper than allocating a set.
196
+ for (let i = 0; i < hops.length; i++) {
197
+ const hop = hops[i];
198
+ if (hop === UNKNOWN_ORIGIN)
199
+ continue;
200
+ if (hops.indexOf(hop, i + 1) !== -1)
201
+ throw new Error(`hop ${hop} appears twice in the hop path`);
202
+ }
203
+ }
204
+ //# sourceMappingURL=cluster.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cluster.js","sourceRoot":"","sources":["../../src/ietf/cluster.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAe,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnF,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAqB,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAAoB,OAAO,EAAE,MAAM,cAAc,CAAC;AAEzD;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CAAC,OAAoB;IAC7C,OAAO,OAAO,KAAK,OAAO,CAAC,QAAQ,IAAI,OAAO,KAAK,OAAO,CAAC,QAAQ,IAAI,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC;AACrG,CAAC;AAwCD;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,MAAoB,EAAE,OAAoB;IACnE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;QA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QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,aAAa,IAAI,CAAC,MAAM,oBAAoB,QAAQ,EAAE,CAAC,CAAC;IAEpG,0EAA0E;IAC1E,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,GAAG,KAAK,cAAc;YAAE,SAAS;QACrC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,OAAO,GAAG,gCAAgC,CAAC,CAAC;IAClG,CAAC;AACF,CAAC","sourcesContent":["/**\n * The MoQ Cluster extension (draft-lcurley-moq-cluster-00).\n *\n * moq-transport carries no routing information, so a peer cannot tell whether an\n * advertisement already passed through us. This extension adds it:\n *\n * - each endpoint declares its own Hop ID via the RELAY_HOPS Setup Option, which is also\n * what negotiates the extension;\n * - every advertisement carries the HOP_PATH it traversed and the accumulated ROUTE_COST\n * of that path, as Key-Value-Pair message parameters on PUBLISH_NAMESPACE and NAMESPACE.\n *\n * These are the semantics moq-lite carries natively on every announcement (see\n * `lite/announce.ts`); this module is the moq-transport binding, negotiated on draft-17+\n * only, where SETUP is a Key-Value-Pair block.\n *\n * We are a leaf, never a relay: the only path we can advertise is our own, so we stamp a\n * single-entry HOP_PATH and seed the cost at 0. What we get out of declaring is the other\n * direction. A relay that knows our Hop ID withholds the advertisements that already flowed\n * through us, so publishing a broadcast no longer announces it back to us, which is what\n * moq-lite has always done with its own hop chain.\n *\n * @module\n * @internal\n */\n\nimport { ProtocolViolation, reason } from \"../error.ts\";\nimport { MAX_HOPS, type Origin, OriginSchema, UNKNOWN_ORIGIN } from \"../origin.ts\";\nimport type { Reader } from \"../stream.ts\";\nimport * as Varint from \"../varint.ts\";\nimport { Parameters, SetupOption, type SetupOptions } from \"./parameters.ts\";\nimport { type IetfVersion, Version } from \"./version.ts\";\n\n/**\n * Whether a version can negotiate the extension.\n *\n * Draft-17 is the first with the unified SETUP: a bare Key-Value-Pair block that a new\n * option slots into without touching the message shape. Earlier drafts exchange SETUP over\n * the legacy control stream, which this extension does not cover.\n *\n * @internal\n */\nexport function supported(version: IetfVersion): boolean {\n\treturn version !== Version.DRAFT_14 && version !== Version.DRAFT_15 && version !== Version.DRAFT_16;\n}\n\n/**\n * The Hop IDs this session declared, one per direction.\n *\n * @internal\n */\nexport interface Hops {\n\t/** Our own Hop ID, declared in SETUP and stamped onto every advertisement we send. */\n\tself: Origin;\n\n\t/**\n\t * The peer's Hop ID, or `undefined` when it declared no RELAY_HOPS.\n\t *\n\t * This is what decides whether advertisements carry the parameters at all, in both\n\t * directions: a peer that declared nothing has not read ours either, so sending it a\n\t * HOP_PATH would be a protocol violation and expecting one back would reject a legal\n\t * message. A peer that declared the reserved 0 negotiated the extension but withheld its\n\t * identity, so the parameters flow and there is simply nothing to exclude.\n\t */\n\tpeer?: Origin;\n}\n\n/**\n * The cluster parameters carried on one advertisement.\n *\n * Present on every PUBLISH_NAMESPACE and NAMESPACE of a session that negotiated the\n * extension, and on none of a session that did not.\n *\n * @internal\n */\nexport interface Advert {\n\t/** HOP_PATH: the path this advertisement traversed, publisher first, sender last. */\n\thops: Origin[];\n\n\t/** ROUTE_COST: the marginal cost of subscribing via this advertisement. Absent on the\n\t * wire means 0, so an endpoint that prices nothing sends nothing. */\n\tcost: bigint;\n}\n\n/**\n * Read the peer's Hop ID out of its SETUP, or `undefined` when it did not negotiate.\n *\n * @internal\n */\nexport function fromSetup(params: SetupOptions, version: IetfVersion): Origin | undefined {\n\tif (!supported(version)) return undefined;\n\n\t// RELAY_HOPS is odd, so its value is a length-prefixed byte string holding the sender's\n\t// Hop ID as a single varint. 0 is legal: the peer speaks the extension but withholds\n\t// its identity.\n\tconst value = params.getBytes(SetupOption.RelayHops);\n\tif (value === undefined) return undefined;\n\n\tconst [origin, rest] = Varint.decodeLeadingOnes(value);\n\tif (rest.length !== 0) throw new Error(\"trailing bytes in RELAY_HOPS\");\n\treturn OriginSchema.parse(origin);\n}\n\n/**\n * Declare our own Hop ID, which is also what negotiates the extension.\n *\n * @internal\n */\nexport function intoSetup(params: SetupOptions, self: Origin, version: IetfVersion) {\n\tif (!supported(version)) return;\n\tparams.setBytes(SetupOption.RelayHops, Varint.encodeLeadingOnes(self));\n}\n\n/**\n * Whether the session negotiated the extension, which is what decides whether an\n * advertisement carries the parameters in either direction.\n *\n * @internal\n */\nexport function negotiated(ids: Hops | undefined): boolean {\n\treturn ids?.peer !== undefined;\n}\n\n/**\n * The advertisement to send for one of our own broadcasts, or `undefined` on a session\n * that negotiated nothing.\n *\n * The sender's own Hop ID is always the last entry, so a receiver reconstructs the full\n * path without the sender restating it. We originate everything we advertise, so the path\n * is just us and the cost is 0: a subscription costs the peer nothing but the transfer,\n * since we are already producing the content.\n *\n * @internal\n */\nexport function advertise(ids: Hops | undefined): Advert | undefined {\n\tif (ids === undefined || ids.peer === undefined) return undefined;\n\treturn { hops: [ids.self], cost: 0n };\n}\n\n/**\n * Whether this advertisement looped back through `self`.\n *\n * A receiver discards such an advertisement: forwarding it would extend the loop, and\n * subscribing through it would route the receiver back to itself. Hop ID 0 identifies\n * nothing, so a receiver that withheld its own identity detects nothing.\n *\n * @internal\n */\nexport function loops(advert: Advert, self: Origin): boolean {\n\treturn self !== UNKNOWN_ORIGIN && advert.hops.includes(self);\n}\n\n/**\n * Write an advertisement's parameters, ready to encode onto the wire.\n *\n * @internal\n */\nexport function intoParams(advert: Advert): Parameters {\n\tvalidate(advert.hops);\n\n\tconst params = new Parameters();\n\n\t// The entries fill the value, so they are written with no count of their own and framed\n\t// by the parameter's own length prefix.\n\tconst hops = advert.hops.map((hop) => Varint.encodeLeadingOnes(hop));\n\tconst value = new Uint8Array(hops.reduce((total, hop) => total + hop.length, 0));\n\tlet offset = 0;\n\tfor (const hop of hops) {\n\t\tvalue.set(hop, offset);\n\t\toffset += hop.length;\n\t}\n\tparams.hopPath = value;\n\n\t// Absent means 0, so a free path sends nothing.\n\tif (advert.cost !== 0n) params.routeCost = advert.cost;\n\n\treturn params;\n}\n\n/**\n * Read the parameters a negotiated session puts on every advertisement.\n *\n * The parameter block is mandatory there, so a message that ends before it (the base form)\n * or one whose block does not parse is the peer's violation, same as a block that parses but\n * carries no HOP_PATH.\n *\n * @internal\n */\nexport async function decodeParams(r: Reader, version: IetfVersion): Promise<Advert> {\n\tlet params: Parameters;\n\ttry {\n\t\tparams = await Parameters.decode(r, version);\n\t} catch (err) {\n\t\tthrow new ProtocolViolation(reason(err), { cause: err });\n\t}\n\n\treturn fromParams(params);\n}\n\n/**\n * Read an advertisement out of a decoded parameter block.\n *\n * Every way this fails is one the draft says to close the session over: a negotiated session\n * that omits HOP_PATH, entries that do not exactly fill the parameter, an empty list, or a\n * non-zero Hop ID appearing twice. So they all surface as one {@link ProtocolViolation},\n * which the session dispatch acts on.\n *\n * @internal\n */\nexport function fromParams(params: Parameters): Advert {\n\ttry {\n\t\tconst value = params.hopPath;\n\t\tif (value === undefined) throw new Error(\"advertisement is missing HOP_PATH\");\n\n\t\tconst hops: Origin[] = [];\n\t\tlet rest = value;\n\t\twhile (rest.length > 0) {\n\t\t\t// A short read here means the entries did not exactly fill the length.\n\t\t\tconst [hop, remain] = Varint.decodeLeadingOnes(rest);\n\t\t\thops.push(OriginSchema.parse(hop));\n\t\t\trest = remain;\n\n\t\t\t// Bail before the buffer does: a hostile length would otherwise cost us one\n\t\t\t// allocation per entry all the way to 64KB of parameter value.\n\t\t\tif (hops.length > MAX_HOPS) throw new Error(`hop count exceeds maximum ${MAX_HOPS}`);\n\t\t}\n\n\t\tvalidate(hops);\n\t\treturn { hops, cost: params.routeCost ?? 0n };\n\t} catch (err) {\n\t\tthrow new ProtocolViolation(reason(err), { cause: err });\n\t}\n}\n\n/**\n * Reject a path that cannot have come from a conforming sender: an empty list, one longer\n * than we accept, or a non-zero Hop ID appearing twice (a loop). Duplicate zeros are legal,\n * since 0 identifies nothing.\n */\nfunction validate(hops: Origin[]) {\n\tif (hops.length === 0) throw new Error(\"hop path is empty\");\n\tif (hops.length > MAX_HOPS) throw new Error(`hop count ${hops.length} exceeds maximum ${MAX_HOPS}`);\n\n\t// MAX_HOPS is 32, so the quadratic scan is cheaper than allocating a set.\n\tfor (let i = 0; i < hops.length; i++) {\n\t\tconst hop = hops[i];\n\t\tif (hop === UNKNOWN_ORIGIN) continue;\n\t\tif (hops.indexOf(hop, i + 1) !== -1) throw new Error(`hop ${hop} appears twice in the hop path`);\n\t}\n}\n"]}
@@ -6,6 +6,7 @@ import { type Probe, type Stats } from "../connection/stats";
6
6
  import { type Transport } from "../connection/transport";
7
7
  import * as Path from "../path";
8
8
  import { type Stream } from "../stream";
9
+ import * as Cluster from "./cluster";
9
10
  import { type IetfVersion } from "./version";
10
11
  /**
11
12
  * Represents a connection to a MoQ server using moq-transport protocol.
@@ -29,10 +30,11 @@ export declare class Connection implements Established {
29
30
  * @param maxRequestId - The initial max request ID
30
31
  * @param version - The negotiated protocol version
31
32
  * @param solicit - What the peer's SETUP declared (undefined when it declared nothing)
33
+ * @param cluster - The Hop IDs the SETUP exchange settled, on the versions that negotiate them
32
34
  *
33
35
  * @internal
34
36
  */
35
- constructor({ url, quic, control, maxRequestId, version, client, discovery, solicit, }: {
37
+ constructor({ url, quic, control, maxRequestId, version, client, discovery, solicit, cluster, }: {
36
38
  url: URL;
37
39
  quic: WebTransport;
38
40
  control: Stream;
@@ -46,6 +48,11 @@ export declare class Connection implements Established {
46
48
  * nothing, which is the one case where announcing at us unasked is not a bug.
47
49
  */
48
50
  solicit?: boolean;
51
+ /**
52
+ * The Hop IDs this session declared (MoQ Cluster). `undefined` on a version that
53
+ * cannot negotiate the extension, as is a `peer` the peer never declared.
54
+ */
55
+ cluster?: Cluster.Hops;
49
56
  });
50
57
  /** Snapshot the transport's counters; see {@link Established.stats}. */
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AAQ,CAE5C;IAED;;;;;OAKG;IACH,kBAAkB,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,SAAS,CAEvD;IAuJD;;;OAGG;IACH,IAAI,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAE1B;CACD"}
@@ -3,9 +3,11 @@ import { Signal } from "@moq/signals";
3
3
  import * as announce from "../announced.js";
4
4
  import { transportStats } from "../connection/stats.js";
5
5
  import { transportOf } from "../connection/transport.js";
6
+ import { ProtocolViolation } from "../error.js";
6
7
  import * as Path from "../path.js";
7
8
  import { Readers } from "../stream.js";
8
9
  import { ControlStreamAdapter, NativeSession } from "./adapter.js";
10
+ import * as Cluster from "./cluster.js";
9
11
  import { GoAway } from "./goaway.js";
10
12
  import { Group } from "./object.js";
11
13
  import { Publish } from "./publish.js";
@@ -42,6 +44,8 @@ export class Connection {
42
44
  #subscriber;
43
45
  // What the peer declared about being solicited; see {@link Ietf.solicitFromSetup}.
44
46
  #solicit;
47
+ // The Hop IDs this session declared; see {@link Cluster}.
48
+ #cluster;
45
49
  // Just to avoid logging when `close()` is called.
46
50
  #closed = false;
47
51
  /**
@@ -52,10 +56,11 @@ export class Connection {
52
56
  * @param maxRequestId - The initial max request ID
53
57
  * @param version - The negotiated protocol version
54
58
  * @param solicit - What the peer's SETUP declared (undefined when it declared nothing)
59
+ * @param cluster - The Hop IDs the SETUP exchange settled, on the versions that negotiate them
55
60
  *
56
61
  * @internal
57
62
  */
58
- constructor({ url, quic, control, maxRequestId, version, client, discovery = true, solicit, }) {
63
+ constructor({ url, quic, control, maxRequestId, version, client, discovery = true, solicit, cluster, }) {
59
64
  this.url = url;
60
65
  this.discovery = discovery;
61
66
  this.version = versionName(version);
@@ -77,9 +82,15 @@ export class Connection {
77
82
  this.close();
78
83
  });
79
84
  }
80
- this.#publisher = new Publisher(this.#quic, this.#session, solicit ?? false);
85
+ this.#publisher = new Publisher({
86
+ quic: this.#quic,
87
+ session: this.#session,
88
+ requiresSolicitation: solicit ?? false,
89
+ cluster,
90
+ });
81
91
  this.#solicit = solicit;
82
- this.#subscriber = new Subscriber(this.#session);
92
+ this.#cluster = cluster;
93
+ this.#subscriber = new Subscriber({ session: this.#session, cluster });
83
94
  void this.#run();
84
95
  }
85
96
  /** Snapshot the transport's counters; see {@link Established.stats}. */
@@ -163,6 +174,10 @@ export class Connection {
163
174
  void this.#runBidi(stream).catch((err) => {
164
175
  console.error("error processing bidi stream", err);
165
176
  stream.abort(new Error("bidi stream error"));
177
+ // The peer broke the protocol, so losing the stream is not enough: nothing
178
+ // stops it repeating the violation on the next one.
179
+ if (err instanceof ProtocolViolation)
180
+ this.close();
166
181
  });
167
182
  }
168
183
  }
@@ -204,7 +219,7 @@ export class Connection {
204
219
  }
205
220
  // Subscriber handles incoming notifications
206
221
  case PublishNamespace.id: {
207
- const msg = await PublishNamespace.decode(stream.reader, this.#session.version);
222
+ const msg = await PublishNamespace.decode(stream.reader, this.#session.version, Cluster.negotiated(this.#cluster));
208
223
  // We always declare that advertisements to us must be solicited (MoQ
209
224
  // Solicit), and writing the option at all proves the peer implements the
210
225
  // extension, whichever value it chose. It also cannot have advertised
@@ -1 +1 @@
1
- {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/ietf/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAA0B,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAkB,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAe,OAAO,EAAe,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAgB,MAAM,cAAc,CAAC;AACjF,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAA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,CAAC;gBACnB,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAC;YAClD,CAAC;QACF,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,KAAK,EAAE,CAAC;QACd,CAAC;IACF,CAAC;IAED;;;OAGG;IACH,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAChD,CAAC;CACD","sourcesContent":["import { type Getter, Signal } from \"@moq/signals\";\nimport * as announce from \"../announced.ts\";\nimport type * as broadcast from \"../broadcast.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 * as Path from \"../path.ts\";\nimport { type Reader, Readers, type Stream } from \"../stream.ts\";\nimport { ControlStreamAdapter, NativeSession, type Session } from \"./adapter.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// 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 *\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\tsolicit,\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/**\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}) {\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(this.#quic, this.#session, solicit ?? false);\n\t\tthis.#solicit = solicit;\n\t\tthis.#subscriber = new Subscriber(this.#session);\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.#publisher.close();\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/**\n\t * Publishes a broadcast to the connection.\n\t * @param name - The broadcast path to publish\n\t * @param broadcast - The broadcast to publish\n\t */\n\tpublish(path: Path.Valid, producer: broadcast.Producer) {\n\t\tthis.#publisher.publish(path, producer);\n\t}\n\n\t/**\n\t * Gets an announced reader for the specified prefix.\n\t * @param prefix - The prefix for announcements\n\t * @returns An Announced instance\n\t */\n\tannounced(prefix = Path.empty()): announce.Consumer {\n\t\treturn this.#subscriber.announced(prefix);\n\t}\n\n\t/**\n\t * Consumes a broadcast from the connection.\n\t *\n\t * @remarks\n\t * If the broadcast is not found, a \"not found\" error will be thrown when requesting any tracks.\n\t *\n\t * @param broadcast - The path of the broadcast to consume\n\t * @returns A Broadcast instance\n\t */\n\tconsume(path: Path.Valid): broadcast.Consumer {\n\t\treturn this.#subscriber.consume(path);\n\t}\n\n\t/**\n\t * Watches a broadcast, live only while it is announced.\n\t *\n\t * @param path - The path of the broadcast to watch\n\t * @returns A reactive handle to the broadcast\n\t */\n\tannouncedBroadcast(path: Path.Valid): announce.Broadcast {\n\t\treturn new announce.Broadcast({ connection: this, path });\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});\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({ requestId: legacy.requestId, namespace: legacy.namespace });\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(stream.reader, this.#session.version);\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 Error(\"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/**\n\t * Returns a promise that resolves when the connection is closed.\n\t * @returns A promise that resolves when closed\n\t */\n\tget closed(): Promise<void> {\n\t\treturn this.#quic.closed.then(() => undefined);\n\t}\n}\n"]}
1
+ {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/ietf/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAA0B,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAkB,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAe,OAAO,EAAe,MAAM,cAAc,CAAC;AACjE,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,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEtE;;;;GAIG;AACH,MAAM,OAAO,UAAU;IACtB,6BAA6B;IACpB,GAAG,CAAM;IAElB,mCAAmC;IAC1B,OAAO,CAAS;IAEz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CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAChD,CAAC;CACD","sourcesContent":["import { type Getter, Signal } from \"@moq/signals\";\nimport * as announce from \"../announced.ts\";\nimport type * as broadcast from \"../broadcast.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 { ProtocolViolation } from \"../error.ts\";\nimport * as Path from \"../path.ts\";\nimport { type Reader, Readers, type Stream } from \"../stream.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\tsolicit,\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/**\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/**\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\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, cluster });\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.#publisher.close();\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/**\n\t * Publishes a broadcast to the connection.\n\t * @param name - The broadcast path to publish\n\t * @param broadcast - The broadcast to publish\n\t */\n\tpublish(path: Path.Valid, producer: broadcast.Producer) {\n\t\tthis.#publisher.publish(path, producer);\n\t}\n\n\t/**\n\t * Gets an announced reader for the specified prefix.\n\t * @param prefix - The prefix for announcements\n\t * @returns An Announced instance\n\t */\n\tannounced(prefix = Path.empty()): announce.Consumer {\n\t\treturn this.#subscriber.announced(prefix);\n\t}\n\n\t/**\n\t * Consumes a broadcast from the connection.\n\t *\n\t * @remarks\n\t * If the broadcast is not found, a \"not found\" error will be thrown when requesting any tracks.\n\t *\n\t * @param broadcast - The path of the broadcast to consume\n\t * @returns A Broadcast instance\n\t */\n\tconsume(path: Path.Valid): broadcast.Consumer {\n\t\treturn this.#subscriber.consume(path);\n\t}\n\n\t/**\n\t * Watches a broadcast, live only while it is announced.\n\t *\n\t * @param path - The path of the broadcast to watch\n\t * @returns A reactive handle to the broadcast\n\t */\n\tannouncedBroadcast(path: Path.Valid): announce.Broadcast {\n\t\treturn new announce.Broadcast({ connection: this, path });\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({ requestId: legacy.requestId, namespace: legacy.namespace });\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 Error(\"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/**\n\t * Returns a promise that resolves when the connection is closed.\n\t * @returns A promise that resolves when closed\n\t */\n\tget closed(): Promise<void> {\n\t\treturn this.#quic.closed.then(() => undefined);\n\t}\n}\n"]}
package/ietf/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./adapter";
2
+ export * as Cluster from "./cluster";
2
3
  export * from "./connection";
3
4
  export * from "./control";
4
5
  export * from "./fetch";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ietf/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ietf/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
package/ietf/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  /* @ts-self-types="./index.d.ts" */
2
2
  export * from "./adapter.js";
3
+ import * as Cluster_1 from "./cluster.js";
4
+ export { Cluster_1 as Cluster };
3
5
  export * from "./connection.js";
4
6
  export * from "./control.js";
5
7
  export * from "./fetch.js";
package/ietf/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ietf/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC","sourcesContent":["export * from \"./adapter.ts\";\nexport * from \"./connection.ts\";\nexport * from \"./control.ts\";\nexport * from \"./fetch.ts\";\nexport * from \"./goaway.ts\";\nexport * from \"./object.ts\";\nexport * from \"./parameters.ts\";\nexport * from \"./publish.ts\";\nexport * from \"./publish_namespace.ts\";\nexport * from \"./publisher.ts\";\nexport * from \"./request.ts\";\nexport * from \"./setup.ts\";\nexport * from \"./solicit.ts\";\nexport * from \"./subscribe.ts\";\nexport * from \"./subscribe_namespace.ts\";\nexport * from \"./subscriber.ts\";\nexport * from \"./track.ts\";\nexport * from \"./version.ts\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ietf/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;2BACJ,cAAc;sBAA3B,OAAO;AACnB,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC","sourcesContent":["export * from \"./adapter.ts\";\nexport * as Cluster from \"./cluster.ts\";\nexport * from \"./connection.ts\";\nexport * from \"./control.ts\";\nexport * from \"./fetch.ts\";\nexport * from \"./goaway.ts\";\nexport * from \"./object.ts\";\nexport * from \"./parameters.ts\";\nexport * from \"./publish.ts\";\nexport * from \"./publish_namespace.ts\";\nexport * from \"./publisher.ts\";\nexport * from \"./request.ts\";\nexport * from \"./setup.ts\";\nexport * from \"./solicit.ts\";\nexport * from \"./subscribe.ts\";\nexport * from \"./subscribe_namespace.ts\";\nexport * from \"./subscriber.ts\";\nexport * from \"./track.ts\";\nexport * from \"./version.ts\";\n"]}