@moq/net 0.4.1 → 0.4.3
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 +20 -4
- package/ietf/filter.d.ts.map +1 -1
- package/ietf/filter.js +165 -17
- 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 +9 -6
- package/ietf/object.d.ts.map +1 -1
- package/ietf/object.js +47 -38
- package/ietf/object.js.map +1 -1
- package/ietf/parameters.d.ts +13 -8
- package/ietf/parameters.d.ts.map +1 -1
- package/ietf/parameters.js +177 -30
- package/ietf/parameters.js.map +1 -1
- package/ietf/publish.d.ts +1 -0
- package/ietf/publish.d.ts.map +1 -1
- package/ietf/publish.js +1 -0
- package/ietf/publish.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 +404 -202
- package/ietf/publisher.js.map +1 -1
- package/ietf/request_stream.d.ts +7 -0
- package/ietf/request_stream.d.ts.map +1 -0
- package/ietf/request_stream.js +20 -0
- package/ietf/request_stream.js.map +1 -0
- package/ietf/subscribe.d.ts +7 -1
- package/ietf/subscribe.d.ts.map +1 -1
- package/ietf/subscribe.js +24 -17
- package/ietf/subscribe.js.map +1 -1
- package/ietf/subscribe_namespace.d.ts.map +1 -1
- package/ietf/subscribe_namespace.js +7 -3
- package/ietf/subscribe_namespace.js.map +1 -1
- package/ietf/subscriber.js +83 -56
- 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 +39 -45
- 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/subscribe.d.ts.map +1 -1
- package/lite/subscribe.js +4 -5
- package/lite/subscribe.js.map +1 -1
- package/lite/subscriber.d.ts.map +1 -1
- package/lite/subscriber.js +210 -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/subscriber.js
CHANGED
|
@@ -5,17 +5,18 @@ import * as broadcast from "../broadcast.js";
|
|
|
5
5
|
import { BroadcastCache } from "../consume.js";
|
|
6
6
|
import { closeError, controlTimeout, error, ProtocolViolation, reason, sessionCause } from "../error.js";
|
|
7
7
|
import * as netGroup from "../group.js";
|
|
8
|
-
import { Cost, routesEqual, UNKNOWN_HOP } from "../hop.js";
|
|
8
|
+
import { Cost, randomHop, routesEqual, stampHops, UNKNOWN_HOP } from "../hop.js";
|
|
9
9
|
import { hiddenBelow, hooks, scopeCaptures, scopeHead, scopeOverlaps } from "../internal.js";
|
|
10
10
|
import * as Path from "../path.js";
|
|
11
|
-
import {
|
|
11
|
+
import { UnexpectedEnd } from "../stream.js";
|
|
12
|
+
import { Tail } from "../tail.js";
|
|
12
13
|
import { Timestamp } from "../time.js";
|
|
13
14
|
import { TimeoutError, withTimeout } from "../util/timeout.js";
|
|
14
15
|
import { overrideBroadcastWire, wireOf } from "../wire.js";
|
|
15
16
|
import { DuplicateTrackAlias, RetiredTrackAlias, TrackAliases } from "./aliases.js";
|
|
16
17
|
import * as Cluster from "./cluster.js";
|
|
17
18
|
import { requestReason, toRequestCode } from "./error.js";
|
|
18
|
-
import { Frame } from "./object.js";
|
|
19
|
+
import { Frame, hasFirstObjectBit } from "./object.js";
|
|
19
20
|
import { fromWire, toWire } from "./priority.js";
|
|
20
21
|
import { PublishDone, PublishError, publishDoneClean } from "./publish.js";
|
|
21
22
|
import { PublishNamespaceDone, PublishNamespaceError, PublishNamespaceOk, PublishNamespaceUpdate, } from "./publish_namespace.js";
|
|
@@ -39,6 +40,7 @@ function sees(filter, path) {
|
|
|
39
40
|
*/
|
|
40
41
|
export class Subscriber {
|
|
41
42
|
#session;
|
|
43
|
+
#localClose = false;
|
|
42
44
|
// The transport, so a request cut off by the session's close ends with the session's
|
|
43
45
|
// error. Optional for tests that drive a bare session.
|
|
44
46
|
#quic;
|
|
@@ -54,6 +56,9 @@ export class Subscriber {
|
|
|
54
56
|
#timescales = new Map();
|
|
55
57
|
// Dedup consumed broadcasts per path: repeat consume() calls share one subscription.
|
|
56
58
|
#consumes = new BroadcastCache();
|
|
59
|
+
// A random Hop ID of this connection's own, written as the first hop of any path that
|
|
60
|
+
// names no publisher, so a publisher that reconnects reads as a new one.
|
|
61
|
+
#stamp = randomHop();
|
|
57
62
|
// Paths with a legacy PUBLISH_NAMESPACE request in flight, reserved synchronously.
|
|
58
63
|
// The count below is only taken once the OK is written, and two requests that both
|
|
59
64
|
// got past the duplicate check before either attached would both take one.
|
|
@@ -70,6 +75,10 @@ export class Subscriber {
|
|
|
70
75
|
#announcedConsumers = new Map();
|
|
71
76
|
// Whether the peer understands the HIDDEN parameter (MoQ Hidden).
|
|
72
77
|
#hidden;
|
|
78
|
+
/** Marks this subscriber's deliberate local session close. @internal */
|
|
79
|
+
close() {
|
|
80
|
+
this.#localClose = true;
|
|
81
|
+
}
|
|
73
82
|
/**
|
|
74
83
|
* Creates a new Subscriber instance.
|
|
75
84
|
*
|
|
@@ -92,11 +101,17 @@ export class Subscriber {
|
|
|
92
101
|
#reflected(advert) {
|
|
93
102
|
return advert !== undefined && this.#cluster !== undefined && Cluster.loops(advert, this.#cluster.self);
|
|
94
103
|
}
|
|
95
|
-
/**
|
|
104
|
+
/**
|
|
105
|
+
* The route an advertisement carries; one without a path is free. A path that names no
|
|
106
|
+
* publisher, or none at all, gets this connection's stamp in front of a 0.
|
|
107
|
+
*/
|
|
96
108
|
#route(advert) {
|
|
97
109
|
if (advert === undefined)
|
|
98
|
-
return { hops: [UNKNOWN_HOP], cost: Cost.zero };
|
|
99
|
-
|
|
110
|
+
return { hops: [this.#stamp, UNKNOWN_HOP], cost: Cost.zero };
|
|
111
|
+
// A full chain, or a stamp colliding with an entry (a 1-in-2^53 draw), keeps the
|
|
112
|
+
// path as sent.
|
|
113
|
+
const hops = stampHops(advert.hops, this.#stamp) ?? [...advert.hops];
|
|
114
|
+
return { hops, cost: { warm: advert.cost, cold: advert.cost } };
|
|
100
115
|
}
|
|
101
116
|
/**
|
|
102
117
|
* Gets an announced reader matching `scope`. Paths are relative to the session,
|
|
@@ -156,11 +171,16 @@ export class Subscriber {
|
|
|
156
171
|
* Replace the stored route for a path that is already announced. A no-op when the
|
|
157
172
|
* hops and cost did not change; otherwise consumers hear `updated` so a forwarder
|
|
158
173
|
* can reprice without retracting.
|
|
174
|
+
*
|
|
175
|
+
* A new first hop is a new publisher: holders keep their broadcast to drain, but the
|
|
176
|
+
* next consume starts fresh rather than reusing the old publisher's cached track info.
|
|
159
177
|
*/
|
|
160
178
|
#updateAnnounce(path, route) {
|
|
161
179
|
const existing = this.#announced.get(path);
|
|
162
180
|
if (existing === undefined || routesEqual(existing.route, route))
|
|
163
181
|
return;
|
|
182
|
+
if (existing.route.hops[0] !== route.hops[0])
|
|
183
|
+
this.#consumes.evict(path);
|
|
164
184
|
existing.route = route;
|
|
165
185
|
console.debug(`announced: broadcast=${path} rerouted`);
|
|
166
186
|
for (const [consumer, filter] of this.#announcedConsumers) {
|
|
@@ -515,7 +535,7 @@ export class Subscriber {
|
|
|
515
535
|
}
|
|
516
536
|
catch (err) {
|
|
517
537
|
const e = await sessionCause(this.#quic, err);
|
|
518
|
-
producer.close(e);
|
|
538
|
+
producer.close(this.#localClose ? undefined : e);
|
|
519
539
|
stream.abort(e);
|
|
520
540
|
console.warn(`subscribe error: id=${requestId} broadcast=${broadcast} track=${request.name} error=${reason(e)}`);
|
|
521
541
|
}
|
|
@@ -532,26 +552,25 @@ export class Subscriber {
|
|
|
532
552
|
* An error status aborts the track with it. A clean one leaves streams in flight, since
|
|
533
553
|
* QUIC does not order them, so wait until the Stream Count many have been read, or a
|
|
534
554
|
* bounded grace for the ones that never arrive (the draft says to use a timeout). The count
|
|
535
|
-
* is only a hint: a peer may send 0 regardless, so 0 waits out the grace. A request
|
|
536
|
-
* that
|
|
555
|
+
* is only a hint: a peer may send 0 regardless, so 0 waits out the grace. A request
|
|
556
|
+
* stream that FINs without PUBLISH_DONE is a protocol violation.
|
|
537
557
|
*/
|
|
538
558
|
async #runPublishDone(stream, subscription) {
|
|
539
559
|
const version = this.#session.version;
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
}
|
|
550
|
-
count = done.streamCount;
|
|
560
|
+
if (await stream.reader.done())
|
|
561
|
+
throw new ProtocolViolation("subscribe stream ended without PUBLISH_DONE");
|
|
562
|
+
const typeId = await stream.reader.u53();
|
|
563
|
+
if (typeId !== PublishDone.id) {
|
|
564
|
+
throw new ProtocolViolation(`unexpected message on a subscription: 0x${typeId.toString(16)}`);
|
|
565
|
+
}
|
|
566
|
+
const done = await PublishDone.decode(stream.reader, version);
|
|
567
|
+
if (!publishDoneClean(done.statusCode, version)) {
|
|
568
|
+
throw new Error(`publish done: status=0x${done.statusCode.toString(16)} reason=${done.reasonPhrase}`);
|
|
551
569
|
}
|
|
570
|
+
const count = done.streamCount;
|
|
552
571
|
const { tail, track } = subscription;
|
|
553
|
-
const complete = () => count
|
|
554
|
-
await tail.settle(complete,
|
|
572
|
+
const complete = () => count > 0n && BigInt(tail.streams) >= count;
|
|
573
|
+
await tail.settle(complete, track.closed);
|
|
555
574
|
}
|
|
556
575
|
/**
|
|
557
576
|
* Tell the publisher to stop serving a subscription we are walking away from.
|
|
@@ -756,20 +775,7 @@ export class Subscriber {
|
|
|
756
775
|
}
|
|
757
776
|
}
|
|
758
777
|
else {
|
|
759
|
-
// A different original publisher
|
|
760
|
-
// draft has withdrawn and made again: its content is not continuous with
|
|
761
|
-
// what is held. Refusing the update closes the stream, which is that
|
|
762
|
-
// withdrawal.
|
|
763
|
-
if (update.update.hops !== undefined && update.update.hops[0] !== held.hops[0]) {
|
|
764
|
-
console.warn(`publish_namespace update changes the publisher: broadcast=${path}`);
|
|
765
|
-
await stream.writer.u53(RequestError.id);
|
|
766
|
-
await new RequestError({
|
|
767
|
-
errorCode: toRequestCode("not_supported", "publish_namespace", version),
|
|
768
|
-
reasonPhrase: "a new publisher is a new advertisement",
|
|
769
|
-
}).encode(stream.writer, version);
|
|
770
|
-
stream.close();
|
|
771
|
-
return;
|
|
772
|
-
}
|
|
778
|
+
// A different original publisher applies in place too, as it does inline.
|
|
773
779
|
held = Cluster.apply(held, update.update);
|
|
774
780
|
}
|
|
775
781
|
// A path that now runs through us is unusable, so give it back. The update
|
|
@@ -857,7 +863,7 @@ export class Subscriber {
|
|
|
857
863
|
subscription = await this.#aliases.get(group.trackAlias);
|
|
858
864
|
}
|
|
859
865
|
catch (err) {
|
|
860
|
-
const e =
|
|
866
|
+
const e = await sessionCause(this.#quic, err);
|
|
861
867
|
// Ours: we cancelled the subscription and the publisher has not stopped yet.
|
|
862
868
|
// Anything else on this alias is the publisher sending data for a track it never
|
|
863
869
|
// acknowledged, which is worth seeing.
|
|
@@ -875,38 +881,58 @@ export class Subscriber {
|
|
|
875
881
|
let producer;
|
|
876
882
|
const open = () => {
|
|
877
883
|
if (!producer) {
|
|
884
|
+
// The publisher contradicted its own end, which no later group can repair.
|
|
885
|
+
if (subscription.end !== undefined && group.groupId >= subscription.end) {
|
|
886
|
+
throw new ProtocolViolation(`group ${group.groupId} is at or past the declared end ${subscription.end}`);
|
|
887
|
+
}
|
|
878
888
|
producer = new netGroup.Producer(group.groupId);
|
|
879
889
|
track.writeGroup(producer);
|
|
880
890
|
}
|
|
881
891
|
return producer;
|
|
882
892
|
};
|
|
883
893
|
try {
|
|
884
|
-
// FIRST_OBJECT clear
|
|
885
|
-
//
|
|
886
|
-
//
|
|
887
|
-
//
|
|
888
|
-
//
|
|
894
|
+
// FIRST_OBJECT clear is the publisher's claim that the stream starts partway
|
|
895
|
+
// through the group. The first Object ID is absolute either way, and IDs start
|
|
896
|
+
// at 0, so a clear bit on object 0 is still the whole group. Any other first ID,
|
|
897
|
+
// or a stream with no object, has a hole at the front: drop it and pick up at
|
|
898
|
+
// the next group.
|
|
889
899
|
//
|
|
890
|
-
//
|
|
891
|
-
//
|
|
892
|
-
//
|
|
893
|
-
//
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
900
|
+
// Drafts before the bit cannot say this in the header, so the first ID is the only
|
|
901
|
+
// signal: a non-zero one is the same hole and is dropped the same way, but an empty
|
|
902
|
+
// stream there is still a group. A later gap, or a header that claimed the group
|
|
903
|
+
// starts at object 0, still fails it: `Frame.decode` refuses every non-zero delta.
|
|
904
|
+
const legacy = !hasFirstObjectBit(this.#session.version);
|
|
905
|
+
if (!group.flags.firstObject || legacy) {
|
|
906
|
+
let id;
|
|
907
|
+
try {
|
|
908
|
+
id = await stream.peekU62();
|
|
909
|
+
}
|
|
910
|
+
catch (err) {
|
|
911
|
+
if (!(err instanceof UnexpectedEnd))
|
|
912
|
+
throw err;
|
|
913
|
+
}
|
|
914
|
+
if (id !== 0n && !(legacy && id === undefined)) {
|
|
915
|
+
console.debug(`dropping a group with no head: alias=${group.trackAlias} group=${group.groupId}`);
|
|
916
|
+
stream.stop(new Error("a group must start at object 0"));
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
898
919
|
}
|
|
899
920
|
// The alias binds after SUBSCRIBE_OK commits the track property; an omitted
|
|
900
921
|
// header priority inherits it (draft-21 section 10.4).
|
|
901
922
|
if (!group.flags.hasPriority)
|
|
902
923
|
group.publisherPriority = toWire((await track.info()).priority);
|
|
924
|
+
const decode = (c) => Frame.decode(c, group.flags, this.#timescales.get(group.trackAlias));
|
|
903
925
|
for (;;) {
|
|
904
|
-
//
|
|
905
|
-
//
|
|
906
|
-
|
|
907
|
-
|
|
926
|
+
// Every object already buffered is written without an await, so the reader wakes
|
|
927
|
+
// once per batch rather than once per object. Only the group's own stream ends it:
|
|
928
|
+
// a track that closes first has already closed (or aborted) this group through its
|
|
929
|
+
// cache.
|
|
930
|
+
const frame = stream.tryDecode(decode) ??
|
|
931
|
+
(await (producer
|
|
932
|
+
? race([stream.decodeMaybe(decode), producer.closed])
|
|
933
|
+
: stream.decodeMaybe(decode)));
|
|
934
|
+
if (!frame || frame instanceof Error)
|
|
908
935
|
break;
|
|
909
|
-
const frame = await Frame.decode(stream, group.flags, this.#timescales.get(group.trackAlias), this.#session.version);
|
|
910
936
|
if (frame.endOfTrack) {
|
|
911
937
|
// No object at or past this location exists: after the group's last object
|
|
912
938
|
// the track ends with it, and at object 0 it ends before it.
|
|
@@ -918,6 +944,7 @@ export class Subscriber {
|
|
|
918
944
|
catch (err) {
|
|
919
945
|
throw new ProtocolViolation(`invalid END_OF_TRACK: ${reason(error(err))}`);
|
|
920
946
|
}
|
|
947
|
+
subscription.end ??= end;
|
|
921
948
|
return;
|
|
922
949
|
}
|
|
923
950
|
if (frame.payload === undefined)
|
|
@@ -928,7 +955,7 @@ export class Subscriber {
|
|
|
928
955
|
open().close();
|
|
929
956
|
}
|
|
930
957
|
catch (err) {
|
|
931
|
-
const e =
|
|
958
|
+
const e = await sessionCause(this.#quic, err);
|
|
932
959
|
if (e instanceof ProtocolViolation) {
|
|
933
960
|
// The publisher broke the track's end, which no later group can repair.
|
|
934
961
|
producer?.close(e);
|