@moq/net 0.3.4 → 0.4.0
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/README.md +2 -2
- package/announce.d.ts +7 -0
- package/announce.d.ts.map +1 -0
- package/announce.js +8 -0
- package/announce.js.map +1 -0
- package/announced.d.ts +35 -91
- package/announced.d.ts.map +1 -1
- package/announced.js +21 -156
- package/announced.js.map +1 -1
- package/bandwidth.d.ts +163 -0
- package/bandwidth.d.ts.map +1 -0
- package/bandwidth.js +304 -0
- package/bandwidth.js.map +1 -0
- package/bandwidth_api.d.ts +7 -0
- package/bandwidth_api.d.ts.map +1 -0
- package/bandwidth_api.js +8 -0
- package/bandwidth_api.js.map +1 -0
- package/broadcast.d.ts +20 -28
- package/broadcast.d.ts.map +1 -1
- package/broadcast.js +60 -42
- package/broadcast.js.map +1 -1
- package/connection/accept.d.ts +16 -1
- package/connection/accept.d.ts.map +1 -1
- package/connection/accept.js +39 -24
- package/connection/accept.js.map +1 -1
- package/connection/browser.d.ts.map +1 -1
- package/connection/browser.js +9 -7
- package/connection/browser.js.map +1 -1
- package/connection/connect.d.ts +30 -6
- package/connection/connect.d.ts.map +1 -1
- package/connection/connect.js +97 -50
- package/connection/connect.js.map +1 -1
- package/connection/established.d.ts +16 -21
- package/connection/established.d.ts.map +1 -1
- package/connection/established.js.map +1 -1
- package/connection/forward.d.ts +2 -0
- package/connection/forward.d.ts.map +1 -0
- package/connection/forward.js +159 -0
- package/connection/forward.js.map +1 -0
- package/connection/handshake.d.ts.map +1 -1
- package/connection/handshake.js +2 -2
- package/connection/handshake.js.map +1 -1
- package/connection/index.d.ts +5 -5
- package/connection/index.d.ts.map +1 -1
- package/connection/index.js +4 -5
- package/connection/index.js.map +1 -1
- package/connection/pool.d.ts +188 -0
- package/connection/pool.d.ts.map +1 -0
- package/connection/pool.js +351 -0
- package/connection/pool.js.map +1 -0
- package/connection/reload.d.ts +14 -93
- package/connection/reload.d.ts.map +1 -1
- package/connection/reload.js +216 -80
- package/connection/reload.js.map +1 -1
- package/connection/stats.d.ts +3 -26
- package/connection/stats.d.ts.map +1 -1
- package/connection/stats.js.map +1 -1
- package/connection/transport.d.ts +0 -7
- package/connection/transport.d.ts.map +1 -1
- package/consume.d.ts +1 -43
- package/consume.d.ts.map +1 -1
- package/consume.js +1 -1
- package/consume.js.map +1 -1
- package/error.d.ts +180 -29
- package/error.d.ts.map +1 -1
- package/error.js +310 -16
- package/error.js.map +1 -1
- package/errors.d.ts +7 -0
- package/errors.d.ts.map +1 -0
- package/errors.js +8 -0
- package/errors.js.map +1 -0
- package/group.d.ts +9 -43
- package/group.d.ts.map +1 -1
- package/group.js +283 -69
- package/group.js.map +1 -1
- package/hop.d.ts +107 -0
- package/hop.d.ts.map +1 -0
- package/hop.js +103 -0
- package/hop.js.map +1 -0
- package/ietf/aliases.d.ts +1 -78
- package/ietf/aliases.d.ts.map +1 -1
- package/ietf/cluster.d.ts +6 -120
- package/ietf/cluster.d.ts.map +1 -1
- package/ietf/cluster.js +81 -41
- package/ietf/cluster.js.map +1 -1
- package/ietf/connection.d.ts +6 -72
- package/ietf/connection.d.ts.map +1 -1
- package/ietf/connection.js +11 -47
- package/ietf/connection.js.map +1 -1
- package/ietf/error.d.ts +11 -0
- package/ietf/error.d.ts.map +1 -0
- package/ietf/error.js +168 -0
- package/ietf/error.js.map +1 -0
- package/ietf/filter.d.ts.map +1 -1
- package/ietf/filter.js +6 -1
- package/ietf/filter.js.map +1 -1
- package/ietf/goaway.d.ts.map +1 -1
- package/ietf/goaway.js +22 -5
- package/ietf/goaway.js.map +1 -1
- package/ietf/parameters.d.ts +2 -2
- package/ietf/parameters.d.ts.map +1 -1
- package/ietf/parameters.js +15 -17
- package/ietf/parameters.js.map +1 -1
- package/ietf/publish_namespace.d.ts +25 -0
- package/ietf/publish_namespace.d.ts.map +1 -1
- package/ietf/publish_namespace.js +63 -0
- package/ietf/publish_namespace.js.map +1 -1
- package/ietf/publisher.d.ts +1 -82
- package/ietf/publisher.d.ts.map +1 -1
- package/ietf/publisher.js +219 -125
- package/ietf/publisher.js.map +1 -1
- package/ietf/solicit.d.ts +1 -40
- package/ietf/solicit.d.ts.map +1 -1
- package/ietf/subscribe.d.ts +1 -5
- package/ietf/subscribe.d.ts.map +1 -1
- package/ietf/subscribe.js +8 -9
- package/ietf/subscribe.js.map +1 -1
- package/ietf/subscriber.d.ts +1 -65
- package/ietf/subscriber.d.ts.map +1 -1
- package/ietf/subscriber.js +154 -73
- package/ietf/subscriber.js.map +1 -1
- package/ietf/version.d.ts +12 -1
- package/ietf/version.d.ts.map +1 -1
- package/ietf/version.js +13 -0
- package/ietf/version.js.map +1 -1
- package/index.d.ts +11 -6
- package/index.d.ts.map +1 -1
- package/index.js +10 -5
- package/index.js.map +1 -1
- package/internal.d.ts +99 -1
- package/internal.d.ts.map +1 -1
- package/internal.js +65 -0
- package/internal.js.map +1 -1
- package/lite/announce.d.ts +15 -9
- package/lite/announce.d.ts.map +1 -1
- package/lite/announce.js +47 -20
- package/lite/announce.js.map +1 -1
- package/lite/connection.d.ts +9 -59
- package/lite/connection.d.ts.map +1 -1
- package/lite/connection.js +20 -32
- package/lite/connection.js.map +1 -1
- package/lite/fetch.d.ts +15 -1
- package/lite/fetch.d.ts.map +1 -1
- package/lite/fetch.js +39 -7
- package/lite/fetch.js.map +1 -1
- package/lite/goaway.d.ts.map +1 -1
- package/lite/goaway.js +7 -1
- package/lite/goaway.js.map +1 -1
- package/lite/group.d.ts +18 -4
- package/lite/group.d.ts.map +1 -1
- package/lite/group.js +31 -10
- package/lite/group.js.map +1 -1
- package/lite/priority.d.ts +1 -61
- package/lite/priority.d.ts.map +1 -1
- package/lite/priority.js +4 -5
- package/lite/priority.js.map +1 -1
- package/lite/publisher.d.ts +1 -69
- package/lite/publisher.d.ts.map +1 -1
- package/lite/publisher.js +559 -232
- package/lite/publisher.js.map +1 -1
- package/lite/setup.d.ts +7 -7
- package/lite/setup.d.ts.map +1 -1
- package/lite/setup.js +13 -13
- package/lite/setup.js.map +1 -1
- package/lite/subscribe.d.ts +61 -13
- package/lite/subscribe.d.ts.map +1 -1
- package/lite/subscribe.js +186 -44
- package/lite/subscribe.js.map +1 -1
- package/lite/subscriber.d.ts +8 -57
- package/lite/subscriber.d.ts.map +1 -1
- package/lite/subscriber.js +179 -117
- package/lite/subscriber.js.map +1 -1
- package/lite/track.d.ts +4 -10
- package/lite/track.d.ts.map +1 -1
- package/lite/track.js +34 -29
- package/lite/track.js.map +1 -1
- package/lite/version.d.ts +31 -6
- package/lite/version.d.ts.map +1 -1
- package/lite/version.js +71 -11
- package/lite/version.js.map +1 -1
- package/origin.d.ts +229 -29
- package/origin.d.ts.map +1 -1
- package/origin.js +1087 -37
- package/origin.js.map +1 -1
- package/package.json +3 -2
- package/path.d.ts +25 -7
- package/path.d.ts.map +1 -1
- package/path.js +5 -3
- package/path.js.map +1 -1
- package/stream.d.ts.map +1 -1
- package/stream.js +25 -16
- package/stream.js.map +1 -1
- package/time.d.ts +15 -2
- package/time.d.ts.map +1 -1
- package/time.js +28 -9
- package/time.js.map +1 -1
- package/track.d.ts +171 -82
- package/track.d.ts.map +1 -1
- package/track.js +633 -184
- package/track.js.map +1 -1
- package/util/log.d.ts +5 -0
- package/util/log.d.ts.map +1 -0
- package/util/log.js +17 -0
- package/util/log.js.map +1 -0
- package/wire.d.ts +67 -0
- package/wire.d.ts.map +1 -0
- package/wire.js +32 -0
- package/wire.js.map +1 -0
- package/zod.d.ts +1 -1
- package/zod.d.ts.map +1 -1
- package/zod.js.map +1 -1
- package/mock.d.ts +0 -66
- package/mock.d.ts.map +0 -1
- package/mock.js +0 -243
- package/mock.js.map +0 -1
package/hop.d.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Endpoint identity within a hop chain, shared by both wire protocols.
|
|
3
|
+
*
|
|
4
|
+
* moq-lite carries these natively on every announcement; moq-transport carries them
|
|
5
|
+
* via the MoQ Cluster extension (see `ietf/cluster.ts`). Mirrors `Hop` in
|
|
6
|
+
* `rs/moq-net`.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import * as z from "zod/mini";
|
|
11
|
+
/**
|
|
12
|
+
* One relay's identity in a broadcast's hop chain, encoded as a 62-bit varint on the wire.
|
|
13
|
+
*
|
|
14
|
+
* Names a *hop*, not an {@link !Origin | Origin} routing table: this is the id a relay
|
|
15
|
+
* stamps into a chain as an announcement passes through, so a receiver can spot its own
|
|
16
|
+
* id and reject a loop. The SETUP parameter that carries it session-wide is `Hop` too.
|
|
17
|
+
*
|
|
18
|
+
* The {@link HopSchema} validates any incoming value and brands it so the type system
|
|
19
|
+
* enforces "only validated ids flow into hop chains." Internal code that synthesizes one
|
|
20
|
+
* (e.g. {@link randomHop}) uses `HopSchema.parse(...)` to brand a raw bigint.
|
|
21
|
+
*/
|
|
22
|
+
export declare const HopSchema: z.core.$ZodBranded<z.ZodMiniBigInt<bigint>, "Hop", "out">;
|
|
23
|
+
export type Hop = z.infer<typeof HopSchema>;
|
|
24
|
+
/**
|
|
25
|
+
* The reserved id 0, meaning "no identity".
|
|
26
|
+
*
|
|
27
|
+
* It stands in for an endpoint that never declared one, and any number of endpoints can
|
|
28
|
+
* be 0, so it identifies nothing: it is never a loop, never a publisher two chains have
|
|
29
|
+
* in common, and never excluded from an advertisement. A chain that holds a 0 anywhere
|
|
30
|
+
* is anonymous for route selection.
|
|
31
|
+
*/
|
|
32
|
+
export declare const UNKNOWN_HOP: Hop;
|
|
33
|
+
/**
|
|
34
|
+
* Maximum length of a hop chain. Must match `MAX_HOPS` in Rust's `model/origin.rs`.
|
|
35
|
+
*
|
|
36
|
+
* Broadcasts with longer chains are rejected, which bounds loop detection and rejects
|
|
37
|
+
* pathological announcements across clusters with unbounded forwarding.
|
|
38
|
+
*/
|
|
39
|
+
export declare const MAX_HOPS = 32;
|
|
40
|
+
/**
|
|
41
|
+
* Generate a fresh hop with a random non-zero id.
|
|
42
|
+
*
|
|
43
|
+
* `crypto.getRandomValues` is overkill for best-effort loop detection, but
|
|
44
|
+
* used for slightly better distribution than `Math.random` at negligible cost.
|
|
45
|
+
*
|
|
46
|
+
* TEMPORARY: the wire format allows 62 bits, but older `@moq/lite` JS clients
|
|
47
|
+
* decode `AnnounceInterest.exclude_hop` as a u53 (number) and throw on anything
|
|
48
|
+
* > 2^53-1. To keep those clients alive against fresh peers, we cap the random
|
|
49
|
+
* id at 53 bits. Restore to 62 bits once the u62 fix has propagated to deployed
|
|
50
|
+
* bundles. Mirrors `Hop::random` in rs/moq-net.
|
|
51
|
+
*/
|
|
52
|
+
export declare function randomHop(): Hop;
|
|
53
|
+
/**
|
|
54
|
+
* What pulling content via a route costs, in two magnitudes accumulated together
|
|
55
|
+
* and compared in that order: lower {@link Cost.warm} wins, and {@link Cost.cold}
|
|
56
|
+
* breaks the tie.
|
|
57
|
+
*
|
|
58
|
+
* Both price the same path against different cache states. `warm` is what one more
|
|
59
|
+
* subscription would cost the mesh right now, so it collapses to zero at any relay
|
|
60
|
+
* already carrying the broadcast. `cold` prices the identical path as if nothing were
|
|
61
|
+
* cached, so it keeps flowing through a warm relay unchanged and still says which of
|
|
62
|
+
* two warm relays sits closer to the publisher.
|
|
63
|
+
*/
|
|
64
|
+
export interface Cost {
|
|
65
|
+
/** The cost as the mesh stands today, discounted to zero at every carrying relay. */
|
|
66
|
+
warm: bigint;
|
|
67
|
+
/** The same path with every warm discount removed. */
|
|
68
|
+
cold: bigint;
|
|
69
|
+
}
|
|
70
|
+
/** Constructors for {@link Cost}. */
|
|
71
|
+
export declare const Cost: {
|
|
72
|
+
/** A free path in both magnitudes: what a live publisher seeds. */
|
|
73
|
+
zero: Cost;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* The path a route took through the mesh and what using it costs.
|
|
77
|
+
*
|
|
78
|
+
* The metadata half of an advertisement: an origin `dynamic()` pairs it with the
|
|
79
|
+
* pattern it covers, a broadcast `announce()` with the broadcast's exact path, and
|
|
80
|
+
* an announce event carries it so consumers can read it back.
|
|
81
|
+
*/
|
|
82
|
+
export interface Route {
|
|
83
|
+
/** The chain of hops the route has traversed, oldest first. */
|
|
84
|
+
hops: Hop[];
|
|
85
|
+
/** What pulling content via this route costs; lower wins. */
|
|
86
|
+
cost: Cost;
|
|
87
|
+
}
|
|
88
|
+
/** Constructors and helpers for {@link Route}. */
|
|
89
|
+
export declare const Route: {
|
|
90
|
+
/** An empty hop chain at zero cost: what a publisher seeds for a live broadcast. */
|
|
91
|
+
default: Route;
|
|
92
|
+
/** Normalize a partial route, treating a bare bigint cost as both magnitudes alike. */
|
|
93
|
+
normalize(route?: Route | {
|
|
94
|
+
hops?: readonly Hop[];
|
|
95
|
+
cost?: Cost | bigint;
|
|
96
|
+
}): Route;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Whether this route passed through an anonymous hop (id 0) at any depth.
|
|
100
|
+
*
|
|
101
|
+
* An empty chain is a local announcement, not the anonymous mark. Ingress fills a
|
|
102
|
+
* received empty list with {@link UNKNOWN_HOP} before yielding it.
|
|
103
|
+
*/
|
|
104
|
+
export declare function isAnonymous(route: Route): boolean;
|
|
105
|
+
/** Whether two routes name the same hop chain and cost. */
|
|
106
|
+
export declare function routesEqual(a: Route | undefined, b: Route | undefined): boolean;
|
|
107
|
+
//# sourceMappingURL=hop.d.ts.map
|
package/hop.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hop.d.ts","sourceRoot":"","sources":["../src/hop.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,2DAGR,CAAC;AAEf,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,SAAS,CAAC,CAAC;AAE5C;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,EAAE,GAAyB,CAAC;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,KAAK,CAAC;AAE3B;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,IAAI,GAAG,CAO/B;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,IAAI;IACpB,qFAAqF;IACrF,IAAI,EAAE,MAAM,CAAC;IACb,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;CACb;AAED,qCAAqC;AACrC,eAAO,MAAM,IAAI;IAChB,mEAAmE;IACnE,IAAI,EAA4B,IAAI;CACpC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,WAAW,KAAK;IACrB,+DAA+D;IAC/D,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,6DAA6D;IAC7D,IAAI,EAAE,IAAI,CAAC;CACX;AAED,kDAAkD;AAClD,eAAO,MAAM,KAAK;IACjB,oFAAoF;IACpF,OAAO,EAAmC,KAAK;IAE/C,uFAAuF;IACvF,SAAS,SAAQ,KAAK,GAAG;QAAE,IAAI,CAAC,EAAE,SAAS,GAAG,EAAE,CAAC;QAAC,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;KAAE,GAAQ,KAAK;CAOrF,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAEjD;AAED,2DAA2D;AAC3D,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,GAAG,SAAS,EAAE,CAAC,EAAE,KAAK,GAAG,SAAS,GAAG,OAAO,CAS/E"}
|
package/hop.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/* @ts-self-types="./hop.d.ts" */
|
|
2
|
+
/**
|
|
3
|
+
* Endpoint identity within a hop chain, shared by both wire protocols.
|
|
4
|
+
*
|
|
5
|
+
* moq-lite carries these natively on every announcement; moq-transport carries them
|
|
6
|
+
* via the MoQ Cluster extension (see `ietf/cluster.ts`). Mirrors `Hop` in
|
|
7
|
+
* `rs/moq-net`.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import * as z from "zod/mini";
|
|
12
|
+
/**
|
|
13
|
+
* One relay's identity in a broadcast's hop chain, encoded as a 62-bit varint on the wire.
|
|
14
|
+
*
|
|
15
|
+
* Names a *hop*, not an {@link !Origin | Origin} routing table: this is the id a relay
|
|
16
|
+
* stamps into a chain as an announcement passes through, so a receiver can spot its own
|
|
17
|
+
* id and reject a loop. The SETUP parameter that carries it session-wide is `Hop` too.
|
|
18
|
+
*
|
|
19
|
+
* The {@link HopSchema} validates any incoming value and brands it so the type system
|
|
20
|
+
* enforces "only validated ids flow into hop chains." Internal code that synthesizes one
|
|
21
|
+
* (e.g. {@link randomHop}) uses `HopSchema.parse(...)` to brand a raw bigint.
|
|
22
|
+
*/
|
|
23
|
+
export const HopSchema = z
|
|
24
|
+
.bigint()
|
|
25
|
+
.check(z.refine((value) => value >= 0n && value < 1n << 62n, "Hop must be a non-negative 62-bit integer"))
|
|
26
|
+
.brand("Hop");
|
|
27
|
+
/**
|
|
28
|
+
* The reserved id 0, meaning "no identity".
|
|
29
|
+
*
|
|
30
|
+
* It stands in for an endpoint that never declared one, and any number of endpoints can
|
|
31
|
+
* be 0, so it identifies nothing: it is never a loop, never a publisher two chains have
|
|
32
|
+
* in common, and never excluded from an advertisement. A chain that holds a 0 anywhere
|
|
33
|
+
* is anonymous for route selection.
|
|
34
|
+
*/
|
|
35
|
+
export const UNKNOWN_HOP = HopSchema.parse(0n);
|
|
36
|
+
/**
|
|
37
|
+
* Maximum length of a hop chain. Must match `MAX_HOPS` in Rust's `model/origin.rs`.
|
|
38
|
+
*
|
|
39
|
+
* Broadcasts with longer chains are rejected, which bounds loop detection and rejects
|
|
40
|
+
* pathological announcements across clusters with unbounded forwarding.
|
|
41
|
+
*/
|
|
42
|
+
export const MAX_HOPS = 32;
|
|
43
|
+
/**
|
|
44
|
+
* Generate a fresh hop with a random non-zero id.
|
|
45
|
+
*
|
|
46
|
+
* `crypto.getRandomValues` is overkill for best-effort loop detection, but
|
|
47
|
+
* used for slightly better distribution than `Math.random` at negligible cost.
|
|
48
|
+
*
|
|
49
|
+
* TEMPORARY: the wire format allows 62 bits, but older `@moq/lite` JS clients
|
|
50
|
+
* decode `AnnounceInterest.exclude_hop` as a u53 (number) and throw on anything
|
|
51
|
+
* > 2^53-1. To keep those clients alive against fresh peers, we cap the random
|
|
52
|
+
* id at 53 bits. Restore to 62 bits once the u62 fix has propagated to deployed
|
|
53
|
+
* bundles. Mirrors `Hop::random` in rs/moq-net.
|
|
54
|
+
*/
|
|
55
|
+
export function randomHop() {
|
|
56
|
+
const buf = new BigUint64Array(1);
|
|
57
|
+
crypto.getRandomValues(buf);
|
|
58
|
+
// Mask to 53 bits.
|
|
59
|
+
const raw = buf[0] & 0x1fffffffffffffn;
|
|
60
|
+
// Guard against the (astronomically unlikely) zero draw.
|
|
61
|
+
return HopSchema.parse(raw === 0n ? 1n : raw);
|
|
62
|
+
}
|
|
63
|
+
/** Constructors for {@link Cost}. */
|
|
64
|
+
export const Cost = {
|
|
65
|
+
/** A free path in both magnitudes: what a live publisher seeds. */
|
|
66
|
+
zero: { warm: 0n, cold: 0n },
|
|
67
|
+
};
|
|
68
|
+
/** Constructors and helpers for {@link Route}. */
|
|
69
|
+
export const Route = {
|
|
70
|
+
/** An empty hop chain at zero cost: what a publisher seeds for a live broadcast. */
|
|
71
|
+
default: { hops: [], cost: Cost.zero },
|
|
72
|
+
/** Normalize a partial route, treating a bare bigint cost as both magnitudes alike. */
|
|
73
|
+
normalize(route = {}) {
|
|
74
|
+
const hops = route.hops ? [...route.hops] : [];
|
|
75
|
+
const cost = route.cost;
|
|
76
|
+
if (cost === undefined)
|
|
77
|
+
return { hops, cost: Cost.zero };
|
|
78
|
+
if (typeof cost === "bigint")
|
|
79
|
+
return { hops, cost: { warm: cost, cold: cost } };
|
|
80
|
+
return { hops, cost: { warm: cost.warm, cold: cost.cold } };
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Whether this route passed through an anonymous hop (id 0) at any depth.
|
|
85
|
+
*
|
|
86
|
+
* An empty chain is a local announcement, not the anonymous mark. Ingress fills a
|
|
87
|
+
* received empty list with {@link UNKNOWN_HOP} before yielding it.
|
|
88
|
+
*/
|
|
89
|
+
export function isAnonymous(route) {
|
|
90
|
+
return route.hops.includes(UNKNOWN_HOP);
|
|
91
|
+
}
|
|
92
|
+
/** Whether two routes name the same hop chain and cost. */
|
|
93
|
+
export function routesEqual(a, b) {
|
|
94
|
+
if (a === b)
|
|
95
|
+
return true;
|
|
96
|
+
if (!a || !b)
|
|
97
|
+
return false;
|
|
98
|
+
return (a.cost.warm === b.cost.warm &&
|
|
99
|
+
a.cost.cold === b.cost.cold &&
|
|
100
|
+
a.hops.length === b.hops.length &&
|
|
101
|
+
a.hops.every((hop, i) => hop === b.hops[i]));
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=hop.js.map
|
package/hop.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hop.js","sourceRoot":"","sources":["../src/hop.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * Endpoint identity within a hop chain, shared by both wire protocols.\n *\n * moq-lite carries these natively on every announcement; moq-transport carries them\n * via the MoQ Cluster extension (see `ietf/cluster.ts`). Mirrors `Hop` in\n * `rs/moq-net`.\n *\n * @module\n */\nimport * as z from \"zod/mini\";\n\n/**\n * One relay's identity in a broadcast's hop chain, encoded as a 62-bit varint on the wire.\n *\n * Names a *hop*, not an {@link !Origin | Origin} routing table: this is the id a relay\n * stamps into a chain as an announcement passes through, so a receiver can spot its own\n * id and reject a loop. The SETUP parameter that carries it session-wide is `Hop` too.\n *\n * The {@link HopSchema} validates any incoming value and brands it so the type system\n * enforces \"only validated ids flow into hop chains.\" Internal code that synthesizes one\n * (e.g. {@link randomHop}) uses `HopSchema.parse(...)` to brand a raw bigint.\n */\nexport const HopSchema = z\n\t.bigint()\n\t.check(z.refine((value) => value >= 0n && value < 1n << 62n, \"Hop must be a non-negative 62-bit integer\"))\n\t.brand(\"Hop\");\n\nexport type Hop = z.infer<typeof HopSchema>;\n\n/**\n * The reserved id 0, meaning \"no identity\".\n *\n * It stands in for an endpoint that never declared one, and any number of endpoints can\n * be 0, so it identifies nothing: it is never a loop, never a publisher two chains have\n * in common, and never excluded from an advertisement. A chain that holds a 0 anywhere\n * is anonymous for route selection.\n */\nexport const UNKNOWN_HOP: Hop = HopSchema.parse(0n);\n\n/**\n * Maximum length of a hop chain. Must match `MAX_HOPS` in Rust's `model/origin.rs`.\n *\n * Broadcasts with longer chains are rejected, which bounds loop detection and rejects\n * pathological announcements across clusters with unbounded forwarding.\n */\nexport const MAX_HOPS = 32;\n\n/**\n * Generate a fresh hop with a random non-zero id.\n *\n * `crypto.getRandomValues` is overkill for best-effort loop detection, but\n * used for slightly better distribution than `Math.random` at negligible cost.\n *\n * TEMPORARY: the wire format allows 62 bits, but older `@moq/lite` JS clients\n * decode `AnnounceInterest.exclude_hop` as a u53 (number) and throw on anything\n * > 2^53-1. To keep those clients alive against fresh peers, we cap the random\n * id at 53 bits. Restore to 62 bits once the u62 fix has propagated to deployed\n * bundles. Mirrors `Hop::random` in rs/moq-net.\n */\nexport function randomHop(): Hop {\n\tconst buf = new BigUint64Array(1);\n\tcrypto.getRandomValues(buf);\n\t// Mask to 53 bits.\n\tconst raw = buf[0] & 0x1f_ffff_ffff_ffffn;\n\t// Guard against the (astronomically unlikely) zero draw.\n\treturn HopSchema.parse(raw === 0n ? 1n : raw);\n}\n\n/**\n * What pulling content via a route costs, in two magnitudes accumulated together\n * and compared in that order: lower {@link Cost.warm} wins, and {@link Cost.cold}\n * breaks the tie.\n *\n * Both price the same path against different cache states. `warm` is what one more\n * subscription would cost the mesh right now, so it collapses to zero at any relay\n * already carrying the broadcast. `cold` prices the identical path as if nothing were\n * cached, so it keeps flowing through a warm relay unchanged and still says which of\n * two warm relays sits closer to the publisher.\n */\nexport interface Cost {\n\t/** The cost as the mesh stands today, discounted to zero at every carrying relay. */\n\twarm: bigint;\n\t/** The same path with every warm discount removed. */\n\tcold: bigint;\n}\n\n/** Constructors for {@link Cost}. */\nexport const Cost = {\n\t/** A free path in both magnitudes: what a live publisher seeds. */\n\tzero: { warm: 0n, cold: 0n } as Cost,\n};\n\n/**\n * The path a route took through the mesh and what using it costs.\n *\n * The metadata half of an advertisement: an origin `dynamic()` pairs it with the\n * pattern it covers, a broadcast `announce()` with the broadcast's exact path, and\n * an announce event carries it so consumers can read it back.\n */\nexport interface Route {\n\t/** The chain of hops the route has traversed, oldest first. */\n\thops: Hop[];\n\t/** What pulling content via this route costs; lower wins. */\n\tcost: Cost;\n}\n\n/** Constructors and helpers for {@link Route}. */\nexport const Route = {\n\t/** An empty hop chain at zero cost: what a publisher seeds for a live broadcast. */\n\tdefault: { hops: [], cost: Cost.zero } as Route,\n\n\t/** Normalize a partial route, treating a bare bigint cost as both magnitudes alike. */\n\tnormalize(route: Route | { hops?: readonly Hop[]; cost?: Cost | bigint } = {}): Route {\n\t\tconst hops = route.hops ? [...route.hops] : [];\n\t\tconst cost = route.cost;\n\t\tif (cost === undefined) return { hops, cost: Cost.zero };\n\t\tif (typeof cost === \"bigint\") return { hops, cost: { warm: cost, cold: cost } };\n\t\treturn { hops, cost: { warm: cost.warm, cold: cost.cold } };\n\t},\n};\n\n/**\n * Whether this route passed through an anonymous hop (id 0) at any depth.\n *\n * An empty chain is a local announcement, not the anonymous mark. Ingress fills a\n * received empty list with {@link UNKNOWN_HOP} before yielding it.\n */\nexport function isAnonymous(route: Route): boolean {\n\treturn route.hops.includes(UNKNOWN_HOP);\n}\n\n/** Whether two routes name the same hop chain and cost. */\nexport function routesEqual(a: Route | undefined, b: Route | undefined): boolean {\n\tif (a === b) return true;\n\tif (!a || !b) return false;\n\treturn (\n\t\ta.cost.warm === b.cost.warm &&\n\t\ta.cost.cold === b.cost.cold &&\n\t\ta.hops.length === b.hops.length &&\n\t\ta.hops.every((hop, i) => hop === b.hops[i])\n\t);\n}\n"]}
|
package/ietf/aliases.d.ts
CHANGED
|
@@ -1,79 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* The full track name an alias is bound to.
|
|
3
|
-
*
|
|
4
|
-
* Kept as two components rather than one joined string: a track name may contain the same
|
|
5
|
-
* separator a broadcast path uses, so `a` + `b/c` and `a/b` + `c` would otherwise compare
|
|
6
|
-
* equal and turn a genuine collision into apparent sharing.
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
export type TrackIdentity = {
|
|
10
|
-
broadcast: string;
|
|
11
|
-
name: string;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Thrown when a group arrives for a subscription we already cancelled.
|
|
15
|
-
*
|
|
16
|
-
* The publisher only stops once our cancellation reaches it, so objects keep arriving for
|
|
17
|
-
* at least a round trip afterwards. Draft-19 section 11.1 asks us to keep enough state to
|
|
18
|
-
* discard them quickly "rather than treating them as belonging to an unknown Track Alias".
|
|
19
|
-
*
|
|
20
|
-
* This makes the window quiet, not safe. Once a publisher reassigns the alias the tombstone
|
|
21
|
-
* is reclaimed, and nothing on a group stream distinguishes the old subscription's objects
|
|
22
|
-
* from the new one's. Cancelling promptly is what bounds the exposure to a round trip.
|
|
23
|
-
* @internal
|
|
24
|
-
*/
|
|
25
|
-
export declare class RetiredTrackAlias extends Error {
|
|
26
|
-
constructor(alias: bigint);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Thrown when a publisher gives one alias to two subscriptions of the same track.
|
|
30
|
-
*
|
|
31
|
-
* Draft-19 section 5.1 permits this and expects the subscriber to demux by re-applying
|
|
32
|
-
* each subscription's filter. Ours are all LargestObject, so they are indistinguishable and
|
|
33
|
-
* we cannot, which costs the one subscription. It is not a protocol error, so it must not
|
|
34
|
-
* take the session down with it.
|
|
35
|
-
* @internal
|
|
36
|
-
*/
|
|
37
|
-
export declare class SharedTrackAlias extends Error {
|
|
38
|
-
constructor(alias: bigint);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Thrown when a publisher points one alias at two different tracks at once, which
|
|
42
|
-
* draft-19 section 11.1 makes fatal to the session.
|
|
43
|
-
* @internal
|
|
44
|
-
*/
|
|
45
|
-
export declare class DuplicateTrackAlias extends Error {
|
|
46
|
-
constructor(alias: bigint);
|
|
47
|
-
}
|
|
48
|
-
/** Resolves publisher-chosen track aliases after control/data stream reordering. @internal */
|
|
49
|
-
export declare class TrackAliases<T> {
|
|
50
|
-
#private;
|
|
51
|
-
/**
|
|
52
|
-
* Waits briefly for an alias to be established by SUBSCRIBE_OK or PUBLISH.
|
|
53
|
-
*
|
|
54
|
-
* Throws {@link RetiredTrackAlias} at once for an alias we cancelled, rather than
|
|
55
|
-
* waiting out the timeout for a binding that is never coming.
|
|
56
|
-
*/
|
|
57
|
-
get(alias: bigint): Promise<T>;
|
|
58
|
-
/**
|
|
59
|
-
* Establishes an alias and releases any data streams waiting for it.
|
|
60
|
-
*
|
|
61
|
-
* `track` is the full track name the alias was bound to, which is what decides whether a
|
|
62
|
-
* repeat is the legal sharing of an alias across subscriptions to one track
|
|
63
|
-
* ({@link SharedTrackAlias}) or the collision that must fail the session
|
|
64
|
-
* ({@link DuplicateTrackAlias}).
|
|
65
|
-
*/
|
|
66
|
-
set(alias: bigint, value: T, track: TrackIdentity): void;
|
|
67
|
-
/**
|
|
68
|
-
* Retires an alias whose subscription was cancelled, so groups still in flight for it
|
|
69
|
-
* are discarded promptly instead of reported as unknown.
|
|
70
|
-
*
|
|
71
|
-
* Only retires an alias that still belongs to the supplied value: a later subscription
|
|
72
|
-
* may already have reclaimed it, and that binding outranks a departing owner.
|
|
73
|
-
*
|
|
74
|
-
* Returns whether this caller still owned the binding, so metadata keyed by the alias is
|
|
75
|
-
* only torn down by the owner and never out from under whoever reclaimed it.
|
|
76
|
-
*/
|
|
77
|
-
retire(alias: bigint, value: T): boolean;
|
|
78
|
-
}
|
|
1
|
+
export {};
|
|
79
2
|
//# sourceMappingURL=aliases.d.ts.map
|
package/ietf/aliases.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aliases.d.ts","sourceRoot":"","sources":["../../src/ietf/aliases.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"aliases.d.ts","sourceRoot":"","sources":["../../src/ietf/aliases.ts"],"names":[],"mappings":""}
|
package/ietf/cluster.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The MoQ Cluster extension (draft-lcurley-moq-cluster-
|
|
2
|
+
* The MoQ Cluster extension (draft-lcurley-moq-cluster-01).
|
|
3
3
|
*
|
|
4
4
|
* moq-transport carries no routing information, so a peer cannot tell whether an
|
|
5
5
|
* advertisement already passed through us. This extension adds it:
|
|
6
6
|
*
|
|
7
|
-
* - each endpoint declares its own Hop ID via the
|
|
8
|
-
*
|
|
7
|
+
* - each endpoint declares its own Hop ID via the HOP_ID Setup Option, which is also what
|
|
8
|
+
* negotiates the extension;
|
|
9
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
|
|
10
|
+
* of that path, as Key-Value-Pair message parameters on PUBLISH_NAMESPACE and NAMESPACE,
|
|
11
|
+
* and a PUBLISH_NAMESPACE is repriced with the same parameters on a REQUEST_UPDATE.
|
|
11
12
|
*
|
|
12
13
|
* These are the semantics moq-lite carries natively on every announcement (see
|
|
13
14
|
* `lite/announce.ts`); this module is the moq-transport binding, negotiated on draft-17+
|
|
@@ -22,120 +23,5 @@
|
|
|
22
23
|
* @module
|
|
23
24
|
* @internal
|
|
24
25
|
*/
|
|
25
|
-
|
|
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;
|
|
26
|
+
export {};
|
|
141
27
|
//# sourceMappingURL=cluster.d.ts.map
|
package/ietf/cluster.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cluster.d.ts","sourceRoot":"","sources":["../../src/ietf/cluster.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"cluster.d.ts","sourceRoot":"","sources":["../../src/ietf/cluster.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG"}
|
package/ietf/cluster.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/* @ts-self-types="./cluster.d.ts" */
|
|
2
2
|
/**
|
|
3
|
-
* The MoQ Cluster extension (draft-lcurley-moq-cluster-
|
|
3
|
+
* The MoQ Cluster extension (draft-lcurley-moq-cluster-01).
|
|
4
4
|
*
|
|
5
5
|
* moq-transport carries no routing information, so a peer cannot tell whether an
|
|
6
6
|
* advertisement already passed through us. This extension adds it:
|
|
7
7
|
*
|
|
8
|
-
* - each endpoint declares its own Hop ID via the
|
|
9
|
-
*
|
|
8
|
+
* - each endpoint declares its own Hop ID via the HOP_ID Setup Option, which is also what
|
|
9
|
+
* negotiates the extension;
|
|
10
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
|
|
11
|
+
* of that path, as Key-Value-Pair message parameters on PUBLISH_NAMESPACE and NAMESPACE,
|
|
12
|
+
* and a PUBLISH_NAMESPACE is repriced with the same parameters on a REQUEST_UPDATE.
|
|
12
13
|
*
|
|
13
14
|
* These are the semantics moq-lite carries natively on every announcement (see
|
|
14
15
|
* `lite/announce.ts`); this module is the moq-transport binding, negotiated on draft-17+
|
|
@@ -24,7 +25,7 @@
|
|
|
24
25
|
* @internal
|
|
25
26
|
*/
|
|
26
27
|
import { ProtocolViolation, reason } from "../error.js";
|
|
27
|
-
import {
|
|
28
|
+
import { HopSchema, MAX_HOPS, UNKNOWN_HOP } from "../hop.js";
|
|
28
29
|
import * as Varint from "../varint.js";
|
|
29
30
|
import { Parameters, SetupOption } from "./parameters.js";
|
|
30
31
|
import { Version } from "./version.js";
|
|
@@ -48,16 +49,11 @@ export function supported(version) {
|
|
|
48
49
|
export function fromSetup(params, version) {
|
|
49
50
|
if (!supported(version))
|
|
50
51
|
return undefined;
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
// its identity.
|
|
54
|
-
const value = params.getBytes(SetupOption.RelayHops);
|
|
52
|
+
// 0 is legal: the peer speaks the extension but withholds its identity.
|
|
53
|
+
const value = params.getVarint(SetupOption.HopId);
|
|
55
54
|
if (value === undefined)
|
|
56
55
|
return undefined;
|
|
57
|
-
|
|
58
|
-
if (rest.length !== 0)
|
|
59
|
-
throw new Error("trailing bytes in RELAY_HOPS");
|
|
60
|
-
return OriginSchema.parse(origin);
|
|
56
|
+
return HopSchema.parse(value);
|
|
61
57
|
}
|
|
62
58
|
/**
|
|
63
59
|
* Declare our own Hop ID, which is also what negotiates the extension.
|
|
@@ -67,7 +63,7 @@ export function fromSetup(params, version) {
|
|
|
67
63
|
export function intoSetup(params, self, version) {
|
|
68
64
|
if (!supported(version))
|
|
69
65
|
return;
|
|
70
|
-
params.
|
|
66
|
+
params.setVarint(SetupOption.HopId, self);
|
|
71
67
|
}
|
|
72
68
|
/**
|
|
73
69
|
* Whether the session negotiated the extension, which is what decides whether an
|
|
@@ -104,7 +100,7 @@ export function advertise(ids) {
|
|
|
104
100
|
* @internal
|
|
105
101
|
*/
|
|
106
102
|
export function loops(advert, self) {
|
|
107
|
-
return self !==
|
|
103
|
+
return self !== UNKNOWN_HOP && advert.hops.includes(self);
|
|
108
104
|
}
|
|
109
105
|
/**
|
|
110
106
|
* Write an advertisement's parameters, ready to encode onto the wire.
|
|
@@ -112,23 +108,40 @@ export function loops(advert, self) {
|
|
|
112
108
|
* @internal
|
|
113
109
|
*/
|
|
114
110
|
export function intoParams(advert) {
|
|
115
|
-
validate(advert.hops);
|
|
116
111
|
const params = new Parameters();
|
|
117
|
-
|
|
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;
|
|
112
|
+
params.hopPath = encodeHops(advert.hops);
|
|
127
113
|
// Absent means 0, so a free path sends nothing.
|
|
128
114
|
if (advert.cost !== 0n)
|
|
129
115
|
params.routeCost = advert.cost;
|
|
130
116
|
return params;
|
|
131
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Write a REQUEST_UPDATE's parameters: only what changed, and a cost of 0 explicitly,
|
|
120
|
+
* since an omitted parameter keeps its value.
|
|
121
|
+
*
|
|
122
|
+
* @internal
|
|
123
|
+
*/
|
|
124
|
+
export function updateIntoParams(update) {
|
|
125
|
+
const params = new Parameters();
|
|
126
|
+
if (update.hops !== undefined)
|
|
127
|
+
params.hopPath = encodeHops(update.hops);
|
|
128
|
+
if (update.cost !== undefined)
|
|
129
|
+
params.routeCost = update.cost;
|
|
130
|
+
return params;
|
|
131
|
+
}
|
|
132
|
+
/** Write a HOP_PATH value: the entries fill it with no count of their own, framed by the
|
|
133
|
+
* parameter's own length prefix. */
|
|
134
|
+
function encodeHops(hops) {
|
|
135
|
+
validate(hops);
|
|
136
|
+
const encoded = hops.map((hop) => Varint.encodeLeadingOnes(hop));
|
|
137
|
+
const value = new Uint8Array(encoded.reduce((total, hop) => total + hop.length, 0));
|
|
138
|
+
let offset = 0;
|
|
139
|
+
for (const hop of encoded) {
|
|
140
|
+
value.set(hop, offset);
|
|
141
|
+
offset += hop.length;
|
|
142
|
+
}
|
|
143
|
+
return value;
|
|
144
|
+
}
|
|
132
145
|
/**
|
|
133
146
|
* Read the parameters a negotiated session puts on every advertisement.
|
|
134
147
|
*
|
|
@@ -163,25 +176,52 @@ export function fromParams(params) {
|
|
|
163
176
|
const value = params.hopPath;
|
|
164
177
|
if (value === undefined)
|
|
165
178
|
throw new Error("advertisement is missing HOP_PATH");
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
179
|
+
return { hops: decodeHops(value), cost: params.routeCost ?? 0n };
|
|
180
|
+
}
|
|
181
|
+
catch (err) {
|
|
182
|
+
throw new ProtocolViolation(reason(err), { cause: err });
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Read a REQUEST_UPDATE's parameters: each is optional, and a malformed HOP_PATH is the
|
|
187
|
+
* same violation it is on an advertisement.
|
|
188
|
+
*
|
|
189
|
+
* @internal
|
|
190
|
+
*/
|
|
191
|
+
export function updateFromParams(params) {
|
|
192
|
+
try {
|
|
193
|
+
const value = params.hopPath;
|
|
194
|
+
return { hops: value === undefined ? undefined : decodeHops(value), cost: params.routeCost };
|
|
180
195
|
}
|
|
181
196
|
catch (err) {
|
|
182
197
|
throw new ProtocolViolation(reason(err), { cause: err });
|
|
183
198
|
}
|
|
184
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* The advertisement after `update` lands on `held`: an omitted parameter keeps its value.
|
|
202
|
+
*
|
|
203
|
+
* @internal
|
|
204
|
+
*/
|
|
205
|
+
export function apply(held, update) {
|
|
206
|
+
return { hops: update.hops ?? held.hops, cost: update.cost ?? held.cost };
|
|
207
|
+
}
|
|
208
|
+
/** Read a HOP_PATH value: bare varints filling the parameter, with no count of their own. */
|
|
209
|
+
function decodeHops(value) {
|
|
210
|
+
const hops = [];
|
|
211
|
+
let rest = value;
|
|
212
|
+
while (rest.length > 0) {
|
|
213
|
+
// A short read here means the entries did not exactly fill the length.
|
|
214
|
+
const [hop, remain] = Varint.decodeLeadingOnes(rest);
|
|
215
|
+
hops.push(HopSchema.parse(hop));
|
|
216
|
+
rest = remain;
|
|
217
|
+
// Bail before the buffer does: a hostile length would otherwise cost us one
|
|
218
|
+
// allocation per entry all the way to 64KB of parameter value.
|
|
219
|
+
if (hops.length > MAX_HOPS)
|
|
220
|
+
throw new Error(`hop count exceeds maximum ${MAX_HOPS}`);
|
|
221
|
+
}
|
|
222
|
+
validate(hops);
|
|
223
|
+
return hops;
|
|
224
|
+
}
|
|
185
225
|
/**
|
|
186
226
|
* Reject a path that cannot have come from a conforming sender: an empty list, one longer
|
|
187
227
|
* than we accept, or a non-zero Hop ID appearing twice (a loop). Duplicate zeros are legal,
|
|
@@ -195,7 +235,7 @@ function validate(hops) {
|
|
|
195
235
|
// MAX_HOPS is 32, so the quadratic scan is cheaper than allocating a set.
|
|
196
236
|
for (let i = 0; i < hops.length; i++) {
|
|
197
237
|
const hop = hops[i];
|
|
198
|
-
if (hop ===
|
|
238
|
+
if (hop === UNKNOWN_HOP)
|
|
199
239
|
continue;
|
|
200
240
|
if (hops.indexOf(hop, i + 1) !== -1)
|
|
201
241
|
throw new Error(`hop ${hop} appears twice in the hop path`);
|