@moq/net 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/announced.d.ts +14 -0
  2. package/announced.d.ts.map +1 -1
  3. package/announced.js.map +1 -1
  4. package/broadcast.d.ts +27 -10
  5. package/broadcast.d.ts.map +1 -1
  6. package/broadcast.js +47 -21
  7. package/broadcast.js.map +1 -1
  8. package/connection/accept.js +14 -4
  9. package/connection/accept.js.map +1 -1
  10. package/connection/connect.d.ts.map +1 -1
  11. package/connection/connect.js +14 -4
  12. package/connection/connect.js.map +1 -1
  13. package/connection/established.d.ts +2 -1
  14. package/connection/established.d.ts.map +1 -1
  15. package/connection/established.js.map +1 -1
  16. package/connection/forward.js +61 -47
  17. package/connection/forward.js.map +1 -1
  18. package/connection/goaway.d.ts +34 -0
  19. package/connection/goaway.d.ts.map +1 -0
  20. package/connection/goaway.js +176 -0
  21. package/connection/goaway.js.map +1 -0
  22. package/connection/handshake.d.ts +5 -2
  23. package/connection/handshake.d.ts.map +1 -1
  24. package/connection/handshake.js +45 -10
  25. package/connection/handshake.js.map +1 -1
  26. package/connection/pool.d.ts +24 -11
  27. package/connection/pool.d.ts.map +1 -1
  28. package/connection/pool.js +50 -18
  29. package/connection/pool.js.map +1 -1
  30. package/connection/reload.d.ts.map +1 -1
  31. package/connection/reload.js +189 -35
  32. package/connection/reload.js.map +1 -1
  33. package/error.d.ts +11 -0
  34. package/error.d.ts.map +1 -1
  35. package/error.js +35 -0
  36. package/error.js.map +1 -1
  37. package/errors.d.ts +1 -1
  38. package/errors.d.ts.map +1 -1
  39. package/errors.js +1 -1
  40. package/errors.js.map +1 -1
  41. package/group.d.ts.map +1 -1
  42. package/group.js +5 -4
  43. package/group.js.map +1 -1
  44. package/hop.d.ts +8 -0
  45. package/hop.d.ts.map +1 -1
  46. package/hop.js +16 -0
  47. package/hop.js.map +1 -1
  48. package/ietf/adapter.d.ts +9 -1
  49. package/ietf/adapter.d.ts.map +1 -1
  50. package/ietf/adapter.js +46 -17
  51. package/ietf/adapter.js.map +1 -1
  52. package/ietf/cluster.d.ts +3 -3
  53. package/ietf/cluster.js +3 -3
  54. package/ietf/cluster.js.map +1 -1
  55. package/ietf/connection.d.ts +1 -1
  56. package/ietf/connection.d.ts.map +1 -1
  57. package/ietf/connection.js +118 -41
  58. package/ietf/connection.js.map +1 -1
  59. package/ietf/error.js +27 -2
  60. package/ietf/error.js.map +1 -1
  61. package/ietf/fetch.d.ts +7 -20
  62. package/ietf/fetch.d.ts.map +1 -1
  63. package/ietf/fetch.js +52 -22
  64. package/ietf/fetch.js.map +1 -1
  65. package/ietf/filter.d.ts +2 -0
  66. package/ietf/filter.d.ts.map +1 -1
  67. package/ietf/filter.js +4 -0
  68. package/ietf/filter.js.map +1 -1
  69. package/ietf/goaway.d.ts +9 -1
  70. package/ietf/goaway.d.ts.map +1 -1
  71. package/ietf/goaway.js +20 -0
  72. package/ietf/goaway.js.map +1 -1
  73. package/ietf/hidden.d.ts +2 -0
  74. package/ietf/hidden.d.ts.map +1 -0
  75. package/ietf/hidden.js +30 -0
  76. package/ietf/hidden.js.map +1 -0
  77. package/ietf/index.d.ts +2 -1
  78. package/ietf/index.d.ts.map +1 -1
  79. package/ietf/index.js +2 -1
  80. package/ietf/index.js.map +1 -1
  81. package/ietf/object.d.ts +15 -8
  82. package/ietf/object.d.ts.map +1 -1
  83. package/ietf/object.js +54 -36
  84. package/ietf/object.js.map +1 -1
  85. package/ietf/parameters.d.ts +12 -0
  86. package/ietf/parameters.d.ts.map +1 -1
  87. package/ietf/parameters.js +82 -12
  88. package/ietf/parameters.js.map +1 -1
  89. package/ietf/properties.d.ts +1 -0
  90. package/ietf/properties.d.ts.map +1 -1
  91. package/ietf/properties.js +14 -0
  92. package/ietf/properties.js.map +1 -1
  93. package/ietf/publish.d.ts +19 -2
  94. package/ietf/publish.d.ts.map +1 -1
  95. package/ietf/publish.js +40 -6
  96. package/ietf/publish.js.map +1 -1
  97. package/ietf/publish_namespace.d.ts +2 -2
  98. package/ietf/publish_namespace.js +2 -2
  99. package/ietf/publish_namespace.js.map +1 -1
  100. package/ietf/publisher.js +383 -214
  101. package/ietf/publisher.js.map +1 -1
  102. package/ietf/subscribe.d.ts +7 -1
  103. package/ietf/subscribe.d.ts.map +1 -1
  104. package/ietf/subscribe.js +25 -18
  105. package/ietf/subscribe.js.map +1 -1
  106. package/ietf/subscribe_namespace.d.ts +8 -2
  107. package/ietf/subscribe_namespace.d.ts.map +1 -1
  108. package/ietf/subscribe_namespace.js +20 -11
  109. package/ietf/subscribe_namespace.js.map +1 -1
  110. package/ietf/subscriber.js +226 -88
  111. package/ietf/subscriber.js.map +1 -1
  112. package/ietf/token.d.ts +2 -0
  113. package/ietf/token.d.ts.map +1 -0
  114. package/ietf/token.js +99 -0
  115. package/ietf/token.js.map +1 -0
  116. package/ietf/track.d.ts +4 -0
  117. package/ietf/track.d.ts.map +1 -1
  118. package/ietf/track.js +6 -20
  119. package/ietf/track.js.map +1 -1
  120. package/index.d.ts +1 -1
  121. package/index.d.ts.map +1 -1
  122. package/index.js.map +1 -1
  123. package/internal.d.ts +19 -3
  124. package/internal.d.ts.map +1 -1
  125. package/internal.js +43 -0
  126. package/internal.js.map +1 -1
  127. package/lite/announce.d.ts +46 -2
  128. package/lite/announce.d.ts.map +1 -1
  129. package/lite/announce.js +133 -15
  130. package/lite/announce.js.map +1 -1
  131. package/lite/connection.d.ts +1 -1
  132. package/lite/connection.d.ts.map +1 -1
  133. package/lite/connection.js +30 -9
  134. package/lite/connection.js.map +1 -1
  135. package/lite/datagram.d.ts +3 -2
  136. package/lite/datagram.d.ts.map +1 -1
  137. package/lite/datagram.js +7 -8
  138. package/lite/datagram.js.map +1 -1
  139. package/lite/group.d.ts +12 -8
  140. package/lite/group.d.ts.map +1 -1
  141. package/lite/group.js +37 -16
  142. package/lite/group.js.map +1 -1
  143. package/lite/message.d.ts +2 -2
  144. package/lite/message.d.ts.map +1 -1
  145. package/lite/message.js +14 -5
  146. package/lite/message.js.map +1 -1
  147. package/lite/publisher.js +174 -133
  148. package/lite/publisher.js.map +1 -1
  149. package/lite/setup.d.ts +1 -1
  150. package/lite/setup.d.ts.map +1 -1
  151. package/lite/setup.js +22 -19
  152. package/lite/setup.js.map +1 -1
  153. package/lite/subscribe.d.ts +10 -4
  154. package/lite/subscribe.d.ts.map +1 -1
  155. package/lite/subscribe.js +20 -10
  156. package/lite/subscribe.js.map +1 -1
  157. package/lite/subscriber.d.ts +10 -2
  158. package/lite/subscriber.d.ts.map +1 -1
  159. package/lite/subscriber.js +333 -188
  160. package/lite/subscriber.js.map +1 -1
  161. package/lite/version.d.ts +11 -0
  162. package/lite/version.d.ts.map +1 -1
  163. package/lite/version.js +56 -0
  164. package/lite/version.js.map +1 -1
  165. package/origin.d.ts +46 -19
  166. package/origin.d.ts.map +1 -1
  167. package/origin.js +529 -189
  168. package/origin.js.map +1 -1
  169. package/package.json +8 -4
  170. package/stream.d.ts +79 -14
  171. package/stream.d.ts.map +1 -1
  172. package/stream.js +375 -133
  173. package/stream.js.map +1 -1
  174. package/tail.d.ts +18 -0
  175. package/tail.d.ts.map +1 -0
  176. package/tail.js +167 -0
  177. package/tail.js.map +1 -0
  178. package/track.d.ts +46 -7
  179. package/track.d.ts.map +1 -1
  180. package/track.js +263 -101
  181. package/track.js.map +1 -1
  182. package/util/abort.d.ts +2 -0
  183. package/util/abort.d.ts.map +1 -0
  184. package/util/abort.js +20 -0
  185. package/util/abort.js.map +1 -0
  186. package/util/u64.d.ts +39 -0
  187. package/util/u64.d.ts.map +1 -0
  188. package/util/u64.js +83 -0
  189. package/util/u64.js.map +1 -0
  190. package/util/varint.d.ts +29 -0
  191. package/util/varint.d.ts.map +1 -0
  192. package/util/varint.js +198 -0
  193. package/util/varint.js.map +1 -0
  194. package/varint.d.ts +10 -6
  195. package/varint.d.ts.map +1 -1
  196. package/varint.js +40 -237
  197. package/varint.js.map +1 -1
  198. package/wire.d.ts +19 -3
  199. package/wire.d.ts.map +1 -1
  200. package/wire.js.map +1 -1
  201. package/ietf/control.d.ts +0 -135
  202. package/ietf/control.d.ts.map +0 -1
  203. package/ietf/control.js +0 -242
  204. package/ietf/control.js.map +0 -1
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;2BAGsB,cAAc;sBAA3B,OAAO;4BAEO,eAAe;uBAA7B,QAAQ;6BAEO,oBAAoB;wBAAnC,SAAS;6BAEM,gBAAgB;wBAA/B,SAAS;AACrB,yDAAyD;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;yBAE9B,aAAa;oBAAxB,KAAK;yBAEM,YAAY;oBAAvB,KAAK;0BAEO,aAAa;qBAAzB,MAAM;wBAEI,WAAW;mBAArB,IAAI;wBAEM,WAAW;mBAArB,IAAI;yBAEO,YAAY;oBAAvB,KAAK;0BAEO,aAAa;qBAAzB,MAAM","sourcesContent":["/**\n * MoQ networking layer for browsers: connect to a relay, then publish and consume\n * broadcasts, tracks, groups, and frames over WebTransport (or a WebSocket fallback).\n *\n * @module\n */\n\n/** Re-export of {@link https://jsr.io/@moq/signals | @moq/signals}, the reactive primitives used throughout this package. */\nexport * as Signals from \"@moq/signals\";\n/** Broadcast announcement streams. */\nexport * as Announce from \"./announce.ts\";\n/** Send-side bandwidth estimates split among the tracks sharing a connection. */\nexport * as Bandwidth from \"./bandwidth_api.ts\";\n/** Broadcast role handles. */\nexport * as Broadcast from \"./broadcast.ts\";\n/** A reconnecting, shareable handle on a MoQ session. */\nexport { Connection } from \"./connection/index.ts\";\nexport { SessionCode, StreamCode } from \"./error.ts\";\n/** Session and stream errors, each carrying a code from its own registry. */\nexport * as Error from \"./errors.ts\";\n/** Group role handles and frame helpers. */\nexport * as Group from \"./group.ts\";\n/** Broadcast routing tables, independent of any connection. */\nexport * as Origin from \"./origin.ts\";\n/** Broadcast path utilities with delimiter-aware prefix matching. Path patterns are re-exported from `@moq/pattern`. */\nexport * as Path from \"./path.ts\";\n/** Branded time types (nanoseconds, microseconds, milliseconds, seconds) with conversions. */\nexport * as Time from \"./time.ts\";\n/** Track role handles. */\nexport * as Track from \"./track.ts\";\n/** QUIC variable-length integer encoding and decoding. */\nexport * as Varint from \"./varint.ts\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;2BAGsB,cAAc;sBAA3B,OAAO;4BAEO,eAAe;uBAA7B,QAAQ;6BAEO,oBAAoB;wBAAnC,SAAS;6BAEM,gBAAgB;wBAA/B,SAAS;AACrB,yDAAyD;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;yBAE9B,aAAa;oBAAxB,KAAK;yBAEM,YAAY;oBAAvB,KAAK;0BAEO,aAAa;qBAAzB,MAAM;wBAEI,WAAW;mBAArB,IAAI;wBAEM,WAAW;mBAArB,IAAI;yBAEO,YAAY;oBAAvB,KAAK;0BAEO,aAAa;qBAAzB,MAAM","sourcesContent":["/**\n * MoQ networking layer for browsers: connect to a relay, then publish and consume\n * broadcasts, tracks, groups, and frames over WebTransport (or a WebSocket fallback).\n *\n * @module\n */\n\n/** Re-export of {@link https://jsr.io/@moq/signals | @moq/signals}, the reactive primitives used throughout this package. */\nexport * as Signals from \"@moq/signals\";\n/** Broadcast announcement streams. */\nexport * as Announce from \"./announce.ts\";\n/** Send-side bandwidth estimates split among the tracks sharing a connection. */\nexport * as Bandwidth from \"./bandwidth_api.ts\";\n/** Broadcast role handles. */\nexport * as Broadcast from \"./broadcast.ts\";\n/** A reconnecting, shareable handle on a MoQ session. */\nexport { Connection } from \"./connection/index.ts\";\nexport { SessionCode, StreamCode } from \"./error.ts\";\n/** Session and stream errors, each carrying a code from its own registry. */\nexport * as Error from \"./errors.ts\";\n/** Group role handles and frame helpers. */\nexport * as Group from \"./group.ts\";\n/** Broadcast routing tables, independent of any connection. */\nexport * as Origin from \"./origin.ts\";\n/** Broadcast path utilities with delimiter-aware prefix matching. Path patterns are re-exported from `@moq/pattern`. */\nexport * as Path from \"./path.ts\";\n/** Branded time types (nanoseconds, microseconds, milliseconds, seconds) with conversions. */\nexport * as Time from \"./time.ts\";\n/** Track role handles. */\nexport * as Track from \"./track.ts\";\n/** Varint encoding and decoding, in QUIC's format and moq-transport's leading-ones format. */\nexport * as Varint from \"./varint.ts\";\n"]}
package/internal.d.ts CHANGED
@@ -6,12 +6,13 @@
6
6
  * @module
7
7
  */
8
8
  import type { Dispose, Getter } from "@moq/signals";
9
- import type { Producer as BroadcastProducer } from "./broadcast";
9
+ import type { Consumer as BroadcastConsumer, Producer as BroadcastProducer } from "./broadcast";
10
10
  import type { Frame, Consumer as GroupConsumer } from "./group";
11
11
  import type { Route } from "./hop";
12
12
  import * as Path from "./path";
13
13
  import type { Timestamp } from "./time";
14
14
  import type { Groups, Producer, Request, Subscriber } from "./track";
15
+ import type { Advertised, Advertisements } from "./wire";
15
16
  /** Normalize public group bounds into an inclusive start and exclusive end. */
16
17
  export declare function groupBounds(groups?: Groups): {
17
18
  start: number;
@@ -22,6 +23,17 @@ export declare function groupBounds(groups?: Groups): {
22
23
  * The peer echoes every suffix beneath it, and the caller filters what arrives.
23
24
  */
24
25
  export declare function scopeHead(scope: Path.Pattern): Path.Valid;
26
+ /**
27
+ * Whether a segment of `path` below `prefix` starts with `.`, which hides it from announce
28
+ * discovery unless the request opts in. A path at or above the prefix never hides.
29
+ */
30
+ export declare function hiddenBelow(prefix: Path.Valid, path: Path.Valid): boolean;
31
+ /**
32
+ * Where each carried route lands under the requested prefix: its suffix beneath the
33
+ * prefix, or the empty suffix for a route above it, where the most specific such route
34
+ * wins the way a request through the prefix would resolve.
35
+ */
36
+ export declare function presented(prefix: Path.Valid, table: Advertisements, carries: (covered: Path.Valid) => boolean): Map<Path.Valid, Advertised>;
25
37
  /** Whether the announced prefix's subtree overlaps `scope`. */
26
38
  export declare function scopeOverlaps(scope: Path.Pattern, prefix: Path.Valid): boolean;
27
39
  /** What `scope` captures from an exact announced prefix, if it pins every wildcard. */
@@ -83,6 +95,8 @@ export interface TrackRequestOptions {
83
95
  export declare const hooks: {
84
96
  /** Mint a track {@link Request}; assigned by `track.ts`. */
85
97
  makeRequest: (options: TrackRequestOptions) => Request;
98
+ /** Access the existing producer while a request awaits immutable wire metadata. */
99
+ pendingTrackProducer: (request: Request) => Producer;
86
100
  /**
87
101
  * Take the next group the subscriber's cursor allows, without waiting; assigned by `track.ts`.
88
102
  *
@@ -112,8 +126,8 @@ export declare const hooks: {
112
126
  expired: () => boolean;
113
127
  changed: readonly Getter<unknown>[];
114
128
  }) => void;
115
- /** Stop an in-flight group operation if the handed-out group expires. */
116
- guardGroup: <T>(group: GroupConsumer, operation: Promise<T>) => Promise<T>;
129
+ /** Start a group operation unless the handed-out group has expired, and stop it if the group expires mid-flight. */
130
+ guardGroup: <T>(group: GroupConsumer, operation: () => Promise<T>) => Promise<T>;
117
131
  /** Read a frame the wire publisher completes (or skips) once written. */
118
132
  readGroupFrame: (group: GroupConsumer, from?: number) => Promise<ReadGroupFrame | undefined>;
119
133
  /** Make an evicted mirror terminal while its track timeline still contains it. */
@@ -123,5 +137,7 @@ export declare const hooks: {
123
137
  announce(route: Route): void;
124
138
  unannounce(): void;
125
139
  }) => void;
140
+ /** Name a broadcast handle by the path an origin created or resolved it at. */
141
+ stampPath: (target: BroadcastProducer | BroadcastConsumer, path: Path.Valid) => void;
126
142
  };
127
143
  //# sourceMappingURL=internal.d.ts.map
package/internal.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAA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EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC;CA4CrF,CAAC"}
package/internal.js CHANGED
@@ -23,6 +23,43 @@ export function groupBounds(groups = {}) {
23
23
  export function scopeHead(scope) {
24
24
  return Path.from(scope.head);
25
25
  }
26
+ /**
27
+ * Whether a segment of `path` below `prefix` starts with `.`, which hides it from announce
28
+ * discovery unless the request opts in. A path at or above the prefix never hides.
29
+ */
30
+ export function hiddenBelow(prefix, path) {
31
+ const below = Path.stripPrefix(prefix, path);
32
+ return below !== null && Path.parts(below).some((part) => part.startsWith("."));
33
+ }
34
+ /**
35
+ * Where each carried route lands under the requested prefix: its suffix beneath the
36
+ * prefix, or the empty suffix for a route above it, where the most specific such route
37
+ * wins the way a request through the prefix would resolve.
38
+ */
39
+ export function presented(prefix, table, carries) {
40
+ const out = new Map();
41
+ let rootLen = -1;
42
+ const requested = Path.Pattern.subtree(prefix);
43
+ for (const [covered, candidates] of table) {
44
+ if (!carries(covered))
45
+ continue;
46
+ if (Path.hasPrefix(covered, prefix)) {
47
+ if (covered.length < rootLen)
48
+ continue;
49
+ // A scoped route covers only what it claims, so the best one that can serve the prefix wins.
50
+ const snap = candidates.find((candidate) => !candidate.claim || candidate.claim.overlaps(requested));
51
+ if (!snap)
52
+ continue;
53
+ rootLen = covered.length;
54
+ out.set(Path.empty(), snap);
55
+ continue;
56
+ }
57
+ const suffix = Path.stripPrefix(prefix, covered);
58
+ if (suffix !== null && candidates.length > 0)
59
+ out.set(suffix, candidates[0]);
60
+ }
61
+ return out;
62
+ }
26
63
  /** Whether the announced prefix's subtree overlaps `scope`. */
27
64
  export function scopeOverlaps(scope, prefix) {
28
65
  return scope.overlaps(Path.Pattern.subtree(prefix));
@@ -36,6 +73,9 @@ export const hooks = {
36
73
  makeRequest: () => {
37
74
  throw new Error("track.ts not loaded");
38
75
  },
76
+ pendingTrackProducer: () => {
77
+ throw new Error("track.ts not loaded");
78
+ },
39
79
  tryRecvGroup: () => {
40
80
  throw new Error("track.ts not loaded");
41
81
  },
@@ -69,5 +109,8 @@ export const hooks = {
69
109
  attachAnnouncer: () => {
70
110
  throw new Error("broadcast.ts not loaded");
71
111
  },
112
+ stampPath: () => {
113
+ throw new Error("broadcast.ts not loaded");
114
+ },
72
115
  };
73
116
  //# sourceMappingURL=internal.js.map
package/internal.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAIlC,+EAA+E;AAC/E,MAAM,UAAU,WAAW,CAAC,MAAM,GAAW,EAAE;IAC9C,MAAM,KAAK,GAAG,CAAC,KAAkC,EAAE,KAAc,EAAsB,EAAE;QACxF,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QAC1C,IAAI,CAAC,KAAK,CAAC,QAAQ,KAAK,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,KAAK,SAAS,CAAC,EAAE,CAAC;YACvE,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACtE,CAAC;QACD,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC;QAClD,IAAI,QAAQ,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;YAC/E,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACtE,CAAC;QACD,OAAO,QAAQ,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC;IACzG,CAAC,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAA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,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACxC,CAAC;IACD,WAAW,EAAE,GAAG,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACxC,CAAC;IACD,UAAU,EAAE,GAAG,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACxC,CAAC;IACD,cAAc,EAAE,GAAG,EAAE;QACpB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACxC,CAAC;IACD,UAAU,EAAE,GAAG,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACxC,CAAC;IACD,eAAe,EAAE,GAAG,EAAE;QACrB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;CACD,CAAC","sourcesContent":["/**\n * Package-internal constructor hooks. Classes keep their constructors private so consumers\n * can't mint detached handles; sibling modules create instances through these hooks instead.\n * Not exported from the package entrypoint.\n *\n * @module\n */\nimport type { Dispose, Getter } from \"@moq/signals\";\nimport type { Producer as BroadcastProducer } from \"./broadcast.ts\";\nimport type { Frame, Consumer as GroupConsumer } from \"./group.ts\";\nimport type { Route } from \"./hop.ts\";\nimport * as Path from \"./path.ts\";\nimport type { Timestamp } from \"./time.ts\";\nimport type { Groups, Producer, Request, Subscriber } from \"./track.ts\";\n\n/** Normalize public group bounds into an inclusive start and exclusive end. */\nexport function groupBounds(groups: Groups = {}): { start: number; end?: number } {\n\tconst bound = (value: Groups[\"start\"] | undefined, start: boolean): number | undefined => {\n\t\tif (value === undefined) return undefined;\n\t\tif ((value.included === undefined) === (value.excluded === undefined)) {\n\t\t\tthrow new Error(\"a group bound must be either included or excluded\");\n\t\t}\n\t\tconst sequence = value.included ?? value.excluded;\n\t\tif (sequence === undefined || !Number.isSafeInteger(sequence) || sequence < 0) {\n\t\t\tthrow new Error(\"a group bound must be a non-negative safe integer\");\n\t\t}\n\t\treturn sequence + (start ? Number(value.excluded !== undefined) : Number(value.included !== undefined));\n\t};\n\treturn { start: bound(groups.start, true) ?? 0, end: bound(groups.end, false) };\n}\n\n/**\n * The announce-interest prefix a scope needs on a prefix-shaped wire: its literal head.\n * The peer echoes every suffix beneath it, and the caller filters what arrives.\n */\nexport function scopeHead(scope: Path.Pattern): Path.Valid {\n\treturn Path.from(scope.head);\n}\n\n/** Whether the announced prefix's subtree overlaps `scope`. */\nexport function scopeOverlaps(scope: Path.Pattern, prefix: Path.Valid): boolean {\n\treturn scope.overlaps(Path.Pattern.subtree(prefix));\n}\n\n/** What `scope` captures from an exact announced prefix, if it pins every wildcard. */\nexport function scopeCaptures(scope: Path.Pattern, prefix: Path.Valid): Path.Pattern[] | undefined {\n\treturn scope.captures(Path.Pattern.literal(prefix));\n}\n\n/**\n * What a non-blocking group read found, which is everything the caller needs to decide what\n * to do next: no second look at the track's closed state, and no ordering rule to get wrong.\n */\nexport type Recv =\n\t/** A group to serve. It has already left the buffer, so dropping this is dropping the group. */\n\t| { kind: \"group\"; group: GroupConsumer }\n\t/** Nothing readable, but the track is live and may produce more. */\n\t| { kind: \"idle\" }\n\t/** The producer finished, yet groups above the cap are still held: raising it releases them. */\n\t| { kind: \"boundary\" }\n\t/** The producer finished and the buffer is drained. Nothing can follow. */\n\t| { kind: \"done\" }\n\t/** The track aborted. */\n\t| { kind: \"error\"; error: Error };\n\n/** A package-internal frame read the wire publisher completes once written. */\nexport interface ReadGroupFrame {\n\t/** Frame sequence within the group. */\n\tsequence: number;\n\t/** Frame returned to the publisher. */\n\tframe: Frame;\n\t/** Mark the frame delivered or deliberately skipped by the wire publisher. */\n\tcomplete(): void;\n}\n\n/** The next group or datagram sequence shared by dynamic producers of one broadcast track. */\nexport interface TrackSequence {\n\tnext: number;\n}\n\n/** Per-track sequence namespaces owned by one broadcast generation. */\nexport type TrackSequences = Map<string, TrackSequence>;\n\n/** Inputs for creating a package-internal track request. */\nexport interface TrackRequestOptions {\n\t/** The requested track name. */\n\tname: string;\n\t/** The producer that will serve the request. */\n\tproducer: Producer;\n\t/** Sequence namespaces shared by the broadcast generation. */\n\tsequences: TrackSequences;\n\t/** Requests not yet accepted or rejected by the publisher. */\n\tpending: Set<Request>;\n}\n\n/** Hooks assigned in static blocks by the owning class. */\nexport const hooks: {\n\t/** Mint a track {@link Request}; assigned by `track.ts`. */\n\tmakeRequest: (options: TrackRequestOptions) => Request;\n\t/**\n\t * Take the next group the subscriber's cursor allows, without waiting; assigned by `track.ts`.\n\t *\n\t * Synchronous so a caller can pop a group and act on it in the same turn. Park on\n\t * {@link groupChanged} when it reports `idle` or `boundary`.\n\t */\n\ttryRecvGroup: (subscriber: Subscriber) => Recv;\n\t/** Wake once a subscriber's group cursor may read differently; assigned by `track.ts`. */\n\tgroupChanged: (subscriber: Subscriber, fn: () => void) => Dispose;\n\t/**\n\t * Exempt a subscriber from live-delivery policy for a one-shot FETCH scan: it names one\n\t * old group explicitly, so it is neither late against the live edge nor bound by the start\n\t * a live subscription resolves to.\n\t */\n\texemptFetch: (subscriber: Subscriber) => void;\n\t/**\n\t * Replace a serving cursor. An omitted start keeps the current floor; a provided start\n\t * can lower it. Wire publishers apply SUBSCRIBE_UPDATE here rather than through\n\t * `setGroups`, which never rewinds.\n\t */\n\treplaceGroups: (subscriber: Subscriber, groups: Groups) => void;\n\t/** Return a group's first timestamp, retained even after its first frame is read. */\n\tgroupTimestamp: (group: GroupConsumer) => Timestamp | undefined;\n\tgroupLatest: (group: GroupConsumer) => Timestamp | undefined;\n\t/** Keep applying a subscription's drift policy after it hands a group out. */\n\texpireGroup: (\n\t\tgroup: GroupConsumer,\n\t\texpiry: { expired: () => boolean; changed: readonly Getter<unknown>[] },\n\t) => void;\n\t/** Stop an in-flight group operation if the handed-out group expires. */\n\tguardGroup: <T>(group: GroupConsumer, operation: Promise<T>) => Promise<T>;\n\t/** Read a frame the wire publisher completes (or skips) once written. */\n\treadGroupFrame: (group: GroupConsumer, from?: number) => Promise<ReadGroupFrame | undefined>;\n\t/** Make an evicted mirror terminal while its track timeline still contains it. */\n\tevictGroup: (group: GroupConsumer) => void;\n\t/** Attach the origin advertisement of a created broadcast. */\n\tattachAnnouncer: (\n\t\tproducer: BroadcastProducer,\n\t\tannouncer: { announce(route: Route): void; unannounce(): void },\n\t) => void;\n} = {\n\tmakeRequest: () => {\n\t\tthrow new Error(\"track.ts not loaded\");\n\t},\n\ttryRecvGroup: () => {\n\t\tthrow new Error(\"track.ts not loaded\");\n\t},\n\tgroupChanged: () => {\n\t\tthrow new Error(\"track.ts not loaded\");\n\t},\n\texemptFetch: () => {\n\t\tthrow new Error(\"track.ts not loaded\");\n\t},\n\treplaceGroups: () => {\n\t\tthrow new Error(\"track.ts not loaded\");\n\t},\n\tgroupTimestamp: () => {\n\t\tthrow new Error(\"group.ts not loaded\");\n\t},\n\tgroupLatest: () => {\n\t\tthrow new Error(\"group.ts not loaded\");\n\t},\n\texpireGroup: () => {\n\t\tthrow new Error(\"group.ts not loaded\");\n\t},\n\tguardGroup: () => {\n\t\tthrow new Error(\"group.ts not loaded\");\n\t},\n\treadGroupFrame: () => {\n\t\tthrow new Error(\"group.ts not loaded\");\n\t},\n\tevictGroup: () => {\n\t\tthrow new Error(\"group.ts not loaded\");\n\t},\n\tattachAnnouncer: () => {\n\t\tthrow new Error(\"broadcast.ts not loaded\");\n\t},\n};\n"]}
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAKlC,+EAA+E;AAC/E,MAAM,UAAU,WAAW,CAAC,MAAM,GAAW,EAAE;IAC9C,MAAM,KAAK,GAAG,CAAC,KAAkC,EAAE,KAAc,EAAsB,EAAE;QACxF,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QAC1C,IAAI,CAAC,KAAK,CAAC,QAAQ,KAAK,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,KAAK,SAAS,CAAC,EAA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,CAAC;IACxC,CAAC;IACD,UAAU,EAAE,GAAG,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACxC,CAAC;IACD,eAAe,EAAE,GAAG,EAAE;QACrB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;IACD,SAAS,EAAE,GAAG,EAAE;QACf,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;CACD,CAAC","sourcesContent":["/**\n * Package-internal constructor hooks. Classes keep their constructors private so consumers\n * can't mint detached handles; sibling modules create instances through these hooks instead.\n * Not exported from the package entrypoint.\n *\n * @module\n */\nimport type { Dispose, Getter } from \"@moq/signals\";\nimport type { Consumer as BroadcastConsumer, Producer as BroadcastProducer } from \"./broadcast.ts\";\nimport type { Frame, Consumer as GroupConsumer } from \"./group.ts\";\nimport type { Route } from \"./hop.ts\";\nimport * as Path from \"./path.ts\";\nimport type { Timestamp } from \"./time.ts\";\nimport type { Groups, Producer, Request, Subscriber } from \"./track.ts\";\nimport type { Advertised, Advertisements } from \"./wire.ts\";\n\n/** Normalize public group bounds into an inclusive start and exclusive end. */\nexport function groupBounds(groups: Groups = {}): { start: number; end?: number } {\n\tconst bound = (value: Groups[\"start\"] | undefined, start: boolean): number | undefined => {\n\t\tif (value === undefined) return undefined;\n\t\tif ((value.included === undefined) === (value.excluded === undefined)) {\n\t\t\tthrow new Error(\"a group bound must be either included or excluded\");\n\t\t}\n\t\tconst sequence = value.included ?? value.excluded;\n\t\tif (sequence === undefined || !Number.isSafeInteger(sequence) || sequence < 0) {\n\t\t\tthrow new Error(\"a group bound must be a non-negative safe integer\");\n\t\t}\n\t\treturn sequence + (start ? Number(value.excluded !== undefined) : Number(value.included !== undefined));\n\t};\n\treturn { start: bound(groups.start, true) ?? 0, end: bound(groups.end, false) };\n}\n\n/**\n * The announce-interest prefix a scope needs on a prefix-shaped wire: its literal head.\n * The peer echoes every suffix beneath it, and the caller filters what arrives.\n */\nexport function scopeHead(scope: Path.Pattern): Path.Valid {\n\treturn Path.from(scope.head);\n}\n\n/**\n * Whether a segment of `path` below `prefix` starts with `.`, which hides it from announce\n * discovery unless the request opts in. A path at or above the prefix never hides.\n */\nexport function hiddenBelow(prefix: Path.Valid, path: Path.Valid): boolean {\n\tconst below = Path.stripPrefix(prefix, path);\n\treturn below !== null && Path.parts(below).some((part) => part.startsWith(\".\"));\n}\n\n/**\n * Where each carried route lands under the requested prefix: its suffix beneath the\n * prefix, or the empty suffix for a route above it, where the most specific such route\n * wins the way a request through the prefix would resolve.\n */\nexport function presented(\n\tprefix: Path.Valid,\n\ttable: Advertisements,\n\tcarries: (covered: Path.Valid) => boolean,\n): Map<Path.Valid, Advertised> {\n\tconst out = new Map<Path.Valid, Advertised>();\n\tlet rootLen = -1;\n\tconst requested = Path.Pattern.subtree(prefix);\n\tfor (const [covered, candidates] of table) {\n\t\tif (!carries(covered)) continue;\n\t\tif (Path.hasPrefix(covered, prefix)) {\n\t\t\tif (covered.length < rootLen) continue;\n\t\t\t// A scoped route covers only what it claims, so the best one that can serve the prefix wins.\n\t\t\tconst snap = candidates.find((candidate) => !candidate.claim || candidate.claim.overlaps(requested));\n\t\t\tif (!snap) continue;\n\t\t\trootLen = covered.length;\n\t\t\tout.set(Path.empty(), snap);\n\t\t\tcontinue;\n\t\t}\n\t\tconst suffix = Path.stripPrefix(prefix, covered);\n\t\tif (suffix !== null && candidates.length > 0) out.set(suffix, candidates[0]);\n\t}\n\treturn out;\n}\n\n/** Whether the announced prefix's subtree overlaps `scope`. */\nexport function scopeOverlaps(scope: Path.Pattern, prefix: Path.Valid): boolean {\n\treturn scope.overlaps(Path.Pattern.subtree(prefix));\n}\n\n/** What `scope` captures from an exact announced prefix, if it pins every wildcard. */\nexport function scopeCaptures(scope: Path.Pattern, prefix: Path.Valid): Path.Pattern[] | undefined {\n\treturn scope.captures(Path.Pattern.literal(prefix));\n}\n\n/**\n * What a non-blocking group read found, which is everything the caller needs to decide what\n * to do next: no second look at the track's closed state, and no ordering rule to get wrong.\n */\nexport type Recv =\n\t/** A group to serve. It has already left the buffer, so dropping this is dropping the group. */\n\t| { kind: \"group\"; group: GroupConsumer }\n\t/** Nothing readable, but the track is live and may produce more. */\n\t| { kind: \"idle\" }\n\t/** The producer finished, yet groups above the cap are still held: raising it releases them. */\n\t| { kind: \"boundary\" }\n\t/** The producer finished and the buffer is drained. Nothing can follow. */\n\t| { kind: \"done\" }\n\t/** The track aborted. */\n\t| { kind: \"error\"; error: Error };\n\n/** A package-internal frame read the wire publisher completes once written. */\nexport interface ReadGroupFrame {\n\t/** Frame sequence within the group. */\n\tsequence: number;\n\t/** Frame returned to the publisher. */\n\tframe: Frame;\n\t/** Mark the frame delivered or deliberately skipped by the wire publisher. */\n\tcomplete(): void;\n}\n\n/** The next group or datagram sequence shared by dynamic producers of one broadcast track. */\nexport interface TrackSequence {\n\tnext: number;\n}\n\n/** Per-track sequence namespaces owned by one broadcast generation. */\nexport type TrackSequences = Map<string, TrackSequence>;\n\n/** Inputs for creating a package-internal track request. */\nexport interface TrackRequestOptions {\n\t/** The requested track name. */\n\tname: string;\n\t/** The producer that will serve the request. */\n\tproducer: Producer;\n\t/** Sequence namespaces shared by the broadcast generation. */\n\tsequences: TrackSequences;\n\t/** Requests not yet accepted or rejected by the publisher. */\n\tpending: Set<Request>;\n}\n\n/** Hooks assigned in static blocks by the owning class. */\nexport const hooks: {\n\t/** Mint a track {@link Request}; assigned by `track.ts`. */\n\tmakeRequest: (options: TrackRequestOptions) => Request;\n\t/** Access the existing producer while a request awaits immutable wire metadata. */\n\tpendingTrackProducer: (request: Request) => Producer;\n\t/**\n\t * Take the next group the subscriber's cursor allows, without waiting; assigned by `track.ts`.\n\t *\n\t * Synchronous so a caller can pop a group and act on it in the same turn. Park on\n\t * {@link groupChanged} when it reports `idle` or `boundary`.\n\t */\n\ttryRecvGroup: (subscriber: Subscriber) => Recv;\n\t/** Wake once a subscriber's group cursor may read differently; assigned by `track.ts`. */\n\tgroupChanged: (subscriber: Subscriber, fn: () => void) => Dispose;\n\t/**\n\t * Exempt a subscriber from live-delivery policy for a one-shot FETCH scan: it names one\n\t * old group explicitly, so it is neither late against the live edge nor bound by the start\n\t * a live subscription resolves to.\n\t */\n\texemptFetch: (subscriber: Subscriber) => void;\n\t/**\n\t * Replace a serving cursor. An omitted start keeps the current floor; a provided start\n\t * can lower it. Wire publishers apply SUBSCRIBE_UPDATE here rather than through\n\t * `setGroups`, which never rewinds.\n\t */\n\treplaceGroups: (subscriber: Subscriber, groups: Groups) => void;\n\t/** Return a group's first timestamp, retained even after its first frame is read. */\n\tgroupTimestamp: (group: GroupConsumer) => Timestamp | undefined;\n\tgroupLatest: (group: GroupConsumer) => Timestamp | undefined;\n\t/** Keep applying a subscription's drift policy after it hands a group out. */\n\texpireGroup: (\n\t\tgroup: GroupConsumer,\n\t\texpiry: { expired: () => boolean; changed: readonly Getter<unknown>[] },\n\t) => void;\n\t/** Start a group operation unless the handed-out group has expired, and stop it if the group expires mid-flight. */\n\tguardGroup: <T>(group: GroupConsumer, operation: () => Promise<T>) => Promise<T>;\n\t/** Read a frame the wire publisher completes (or skips) once written. */\n\treadGroupFrame: (group: GroupConsumer, from?: number) => Promise<ReadGroupFrame | undefined>;\n\t/** Make an evicted mirror terminal while its track timeline still contains it. */\n\tevictGroup: (group: GroupConsumer) => void;\n\t/** Attach the origin advertisement of a created broadcast. */\n\tattachAnnouncer: (\n\t\tproducer: BroadcastProducer,\n\t\tannouncer: { announce(route: Route): void; unannounce(): void },\n\t) => void;\n\t/** Name a broadcast handle by the path an origin created or resolved it at. */\n\tstampPath: (target: BroadcastProducer | BroadcastConsumer, path: Path.Valid) => void;\n} = {\n\tmakeRequest: () => {\n\t\tthrow new Error(\"track.ts not loaded\");\n\t},\n\tpendingTrackProducer: () => {\n\t\tthrow new Error(\"track.ts not loaded\");\n\t},\n\ttryRecvGroup: () => {\n\t\tthrow new Error(\"track.ts not loaded\");\n\t},\n\tgroupChanged: () => {\n\t\tthrow new Error(\"track.ts not loaded\");\n\t},\n\texemptFetch: () => {\n\t\tthrow new Error(\"track.ts not loaded\");\n\t},\n\treplaceGroups: () => {\n\t\tthrow new Error(\"track.ts not loaded\");\n\t},\n\tgroupTimestamp: () => {\n\t\tthrow new Error(\"group.ts not loaded\");\n\t},\n\tgroupLatest: () => {\n\t\tthrow new Error(\"group.ts not loaded\");\n\t},\n\texpireGroup: () => {\n\t\tthrow new Error(\"group.ts not loaded\");\n\t},\n\tguardGroup: () => {\n\t\tthrow new Error(\"group.ts not loaded\");\n\t},\n\treadGroupFrame: () => {\n\t\tthrow new Error(\"group.ts not loaded\");\n\t},\n\tevictGroup: () => {\n\t\tthrow new Error(\"group.ts not loaded\");\n\t},\n\tattachAnnouncer: () => {\n\t\tthrow new Error(\"broadcast.ts not loaded\");\n\t},\n\tstampPath: () => {\n\t\tthrow new Error(\"broadcast.ts not loaded\");\n\t},\n};\n"]}
@@ -3,6 +3,15 @@ import * as Path from "../path";
3
3
  import type { Reader, Writer } from "../stream";
4
4
  import { Version } from "./version";
5
5
  export type { Cost };
6
+ /**
7
+ * Lite-07: copy `keep` path segments (from the head) or hops (from the tail) of the
8
+ * live announcement `distance` back from the stream's next Announce ID, where 1 is the
9
+ * latest ANNOUNCE_START. Resolved by {@link AnnounceHistory}.
10
+ */
11
+ export type Base = {
12
+ distance: bigint;
13
+ keep: number;
14
+ };
6
15
  /**
7
16
  * An announcement on the Announce Stream, advertising or retracting a broadcast.
8
17
  *
@@ -16,12 +25,15 @@ export type { Cost };
16
25
  export type AnnounceBroadcast =
17
26
  /** A broadcast is now available, carrying the path suffix, the hop chain, and
18
27
  * (lite-06+) the route cost. An absent cost encodes as zero; it decodes as
19
- * `undefined` on a wire with no room for one. */
28
+ * `undefined` on a wire with no room for one. On lite-07, `suffix` follows the
29
+ * segments `pathBase` copies and `hops` precede the ones `hopBase` copies. */
20
30
  {
21
31
  status: "active";
22
32
  suffix: Path.Valid;
23
33
  hops: Hop[];
24
34
  cost?: Cost;
35
+ pathBase?: Base;
36
+ hopBase?: Base;
25
37
  }
26
38
  /** Pre-lite-06: a broadcast is no longer available, retracted by path. */
27
39
  | {
@@ -41,6 +53,7 @@ export type AnnounceBroadcast =
41
53
  id: bigint;
42
54
  hops: Hop[];
43
55
  cost?: Cost;
56
+ hopBase?: Base;
44
57
  }
45
58
  /** An unknown lite-06+ announce type, skipped by length. Does not assign an id. */
46
59
  | {
@@ -52,6 +65,33 @@ export declare function encodeAnnounceBroadcast(w: Writer, msg: AnnounceBroadcas
52
65
  export declare function decodeAnnounceBroadcast(r: Reader, version: Version): Promise<AnnounceBroadcast>;
53
66
  /** Like {@link decodeAnnounceBroadcast} but resolves `undefined` on a clean FIN. */
54
67
  export declare function decodeAnnounceBroadcastMaybe(r: Reader, version: Version): Promise<AnnounceBroadcast | undefined>;
68
+ type Advertised = {
69
+ suffix: Path.Valid;
70
+ hops: Hop[];
71
+ };
72
+ /**
73
+ * The live announcements on one lite-06+ announce stream, by Announce ID: what
74
+ * ANNOUNCE_END and ANNOUNCE_UPDATE reference, and what a lite-07 base copies from.
75
+ * Every violation throws {@link ProtocolViolation}.
76
+ */
77
+ export declare class AnnounceHistory {
78
+ #private;
79
+ /** An ANNOUNCE_START: resolve it and assign it the next id. */
80
+ start(msg: {
81
+ suffix: Path.Valid;
82
+ hops: Hop[];
83
+ pathBase?: Base;
84
+ hopBase?: Base;
85
+ }): Advertised;
86
+ /** An ANNOUNCE_UPDATE: resolve its chain before replacing the old one, which it may be based on. */
87
+ update(msg: {
88
+ id: bigint;
89
+ hops: Hop[];
90
+ hopBase?: Base;
91
+ }): Advertised;
92
+ /** An ANNOUNCE_END: retire the id, returning its suffix. */
93
+ end(id: bigint): Path.Valid;
94
+ }
55
95
  /**
56
96
  * ANNOUNCE_REQUEST: sent by the subscriber to request ANNOUNCE_BROADCAST messages
57
97
  * for a path prefix. Renamed from `AnnounceInterest` in lite-05.
@@ -66,7 +106,11 @@ export declare class AnnounceRequest {
66
106
  *
67
107
  * Must be a bigint: peer origins are up to 62 bits and overflow u53. */
68
108
  excludeHop: bigint;
69
- constructor(prefix: Path.Valid, excludeHop?: bigint);
109
+ /** Lite07+: also announce routes with a `.`-prefixed segment below the prefix. Not on
110
+ * the wire earlier, so a value set here is ignored when encoding for an older version
111
+ * and decodes as false. */
112
+ hidden: boolean;
113
+ constructor(prefix: Path.Valid, excludeHop?: bigint, hidden?: boolean);
70
114
  encode(w: Writer, version: Version): Promise<void>;
71
115
  static decode(r: Reader, version: Version): Promise<AnnounceRequest>;
72
116
  }
@@ -1 +1 @@
1
- {"version":3,"file":"announce.d.ts","sourceRoot":"","sources":["../../src/lite/announce.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,GAAG,EAAoC,MAAM,WAAW,CAAC;AAClF,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAA6D,OAAO,EAAE,MAAM,cAAc,CAAC;AAclG,YAAY,EAAE,IAAI,EAAE,CAAC;AAErB;;;;;;;;;GASG;AACH,MAAM,MAAM,iBAAiB;AAC5B;;iDAEiD;AAC/C;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC;IAAC,IAAI,EAAE,GAAG,EAAE,CAAC;IAAC,IAAI,CAAC,EAAE,IAAI,CAAA;CAAE;AACpE,0EAA0E;GACxE;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAA;CAAE;AACzC;sEACsE;GACpE;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE;AACnC;oFACoF;GAClF;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,GAAG,E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EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAGpE;CACD"}
package/lite/announce.js CHANGED
@@ -3,7 +3,7 @@ import { ProtocolViolation } from "../error.js";
3
3
  import { HopSchema, MAX_HOPS, UNKNOWN_HOP } from "../hop.js";
4
4
  import * as Path from "../path.js";
5
5
  import * as Message from "./message.js";
6
- import { hasAnnounceId, hasAnnounceOk, hasExcludeHop, hasRouteCost, Version } from "./version.js";
6
+ import { hasAnnounceCompression, hasAnnounceId, hasAnnounceOk, hasExcludeHop, hasHidden, hasRouteCost, Version, } from "./version.js";
7
7
  // Pre-lite-06 inner status values, carried inside the single ANNOUNCE_BROADCAST body.
8
8
  const STATUS_ENDED = 0;
9
9
  const STATUS_ACTIVE = 1;
@@ -80,25 +80,74 @@ async function decodeHops(r, version) {
80
80
  }
81
81
  }
82
82
  }
83
+ // Lite-07 carries a base around a path and a hop list. A distance of 0 names
84
+ // nothing, and a keep without a base is a violation. Other versions have no room for
85
+ // a base at all.
86
+ function checkBase(version, base) {
87
+ if (base && !hasAnnounceCompression(version)) {
88
+ throw new Error("announce compression not supported for this version");
89
+ }
90
+ }
91
+ function toBase(distance, keep) {
92
+ if (distance !== 0n)
93
+ return { distance, keep };
94
+ if (keep !== 0)
95
+ throw new ProtocolViolation("announce keep without a base");
96
+ return undefined;
97
+ }
98
+ async function encodePath(w, version, suffix, base) {
99
+ checkBase(version, base);
100
+ if (hasAnnounceCompression(version)) {
101
+ await w.u62(base?.distance ?? 0n);
102
+ await w.u53(base?.keep ?? 0);
103
+ }
104
+ await w.string(Path.encode(suffix));
105
+ }
106
+ async function decodePath(r, version) {
107
+ if (!hasAnnounceCompression(version))
108
+ return { suffix: Path.decode(await r.string()) };
109
+ const pathBase = toBase(await r.u62(), await r.u53());
110
+ const suffix = Path.decode(await r.string());
111
+ return pathBase ? { suffix, pathBase } : { suffix };
112
+ }
113
+ async function encodeHopsBlock(w, version, hops, base) {
114
+ checkBase(version, base);
115
+ if (!hasAnnounceCompression(version))
116
+ return encodeHops(w, version, hops);
117
+ await w.u62(base?.distance ?? 0n);
118
+ await encodeHops(w, version, hops);
119
+ await w.u53(base?.keep ?? 0);
120
+ }
121
+ async function decodeHopsBlock(r, version) {
122
+ if (!hasAnnounceCompression(version))
123
+ return { hops: await decodeHops(r, version) };
124
+ const distance = await r.u62();
125
+ const hops = await decodeHops(r, version);
126
+ const hopBase = toBase(distance, await r.u53());
127
+ return hopBase ? { hops, hopBase } : { hops };
128
+ }
83
129
  // The route cost rides lite-06+ announcements as two varints, warm then cold; older
84
- // versions carry neither.
130
+ // versions carry neither. Costs saturate at 2^62-1 on every version, even where lite-07's
131
+ // varints could carry more, so a cost always forwards to a peer on an older version.
132
+ const MAX_COST = 2n ** 62n - 1n;
133
+ const saturate = (v) => (v > MAX_COST ? MAX_COST : v);
85
134
  async function encodeRouteCost(w, version, cost) {
86
135
  if (!hasRouteCost(version))
87
136
  return;
88
- await w.u62(cost?.warm ?? 0n);
89
- await w.u62(cost?.cold ?? 0n);
137
+ await w.u62(saturate(cost?.warm ?? 0n));
138
+ await w.u62(saturate(cost?.cold ?? 0n));
90
139
  }
91
140
  async function decodeRouteCost(r, version) {
92
141
  if (!hasRouteCost(version))
93
142
  return undefined;
94
- return { warm: await r.u62(), cold: await r.u62() };
143
+ return { warm: saturate(await r.u62()), cold: saturate(await r.u62()) };
95
144
  }
96
145
  // lite-06 message body (no discriminator; the type is carried outside the length prefix).
97
146
  async function encodeAnnounce06Body(w, msg, version) {
98
147
  switch (msg.status) {
99
148
  case "active":
100
- await w.string(Path.encode(msg.suffix));
101
- await encodeHops(w, version, msg.hops);
149
+ await encodePath(w, version, msg.suffix, msg.pathBase);
150
+ await encodeHopsBlock(w, version, msg.hops, msg.hopBase);
102
151
  await encodeRouteCost(w, version, msg.cost);
103
152
  break;
104
153
  case "endedId":
@@ -106,7 +155,7 @@ async function encodeAnnounce06Body(w, msg, version) {
106
155
  break;
107
156
  case "restart":
108
157
  await w.u62(msg.id);
109
- await encodeHops(w, version, msg.hops);
158
+ await encodeHopsBlock(w, version, msg.hops, msg.hopBase);
110
159
  await encodeRouteCost(w, version, msg.cost);
111
160
  break;
112
161
  case "ended":
@@ -134,16 +183,16 @@ function announce06Type(msg) {
134
183
  async function decodeAnnounce06Body(r, typ, version) {
135
184
  switch (typ) {
136
185
  case ANNOUNCE_START: {
137
- const suffix = Path.decode(await r.string());
138
- const hops = await decodeHops(r, version);
139
- return { status: "active", suffix, hops, cost: await decodeRouteCost(r, version) };
186
+ const path = await decodePath(r, version);
187
+ const hops = await decodeHopsBlock(r, version);
188
+ return { status: "active", ...path, ...hops, cost: await decodeRouteCost(r, version) };
140
189
  }
141
190
  case ANNOUNCE_END:
142
191
  return { status: "endedId", id: await r.u62() };
143
192
  case ANNOUNCE_RESTART: {
144
193
  const id = await r.u62();
145
- const hops = await decodeHops(r, version);
146
- return { status: "restart", id, hops, cost: await decodeRouteCost(r, version) };
194
+ const hops = await decodeHopsBlock(r, version);
195
+ return { status: "restart", id, ...hops, cost: await decodeRouteCost(r, version) };
147
196
  }
148
197
  default:
149
198
  // Skip the length-prefixed body so an earlier Lite06 build negotiating
@@ -156,6 +205,7 @@ async function decodeAnnounce06Body(r, typ, version) {
156
205
  async function encodeLegacyBody(w, msg, version) {
157
206
  switch (msg.status) {
158
207
  case "active":
208
+ checkBase(version, msg.pathBase ?? msg.hopBase);
159
209
  await w.u8(STATUS_ACTIVE);
160
210
  await w.string(Path.encode(msg.suffix));
161
211
  await encodeHops(w, version, msg.hops);
@@ -211,6 +261,65 @@ export async function decodeAnnounceBroadcastMaybe(r, version) {
211
261
  }
212
262
  return Message.decodeMaybe(r, (r) => decodeLegacyBody(r, version));
213
263
  }
264
+ /**
265
+ * The live announcements on one lite-06+ announce stream, by Announce ID: what
266
+ * ANNOUNCE_END and ANNOUNCE_UPDATE reference, and what a lite-07 base copies from.
267
+ * Every violation throws {@link ProtocolViolation}.
268
+ */
269
+ export class AnnounceHistory {
270
+ #next = 0n;
271
+ #live = new Map();
272
+ #base(base) {
273
+ const live = this.#live.get(this.#next - base.distance);
274
+ if (!live)
275
+ throw new ProtocolViolation(`announce base ${base.distance} is not live`);
276
+ return live;
277
+ }
278
+ #hops(hops, base) {
279
+ if (!base)
280
+ return hops;
281
+ const tail = this.#base(base).hops;
282
+ if (base.keep > tail.length)
283
+ throw new ProtocolViolation(`announce keeps ${base.keep} of ${tail.length} hops`);
284
+ const resolved = [...hops, ...tail.slice(tail.length - base.keep)];
285
+ checkHops(resolved);
286
+ return resolved;
287
+ }
288
+ /** An ANNOUNCE_START: resolve it and assign it the next id. */
289
+ start(msg) {
290
+ let suffix = msg.suffix;
291
+ if (msg.pathBase) {
292
+ const head = Path.parts(this.#base(msg.pathBase).suffix);
293
+ const keep = msg.pathBase.keep;
294
+ if (keep > head.length)
295
+ throw new ProtocolViolation(`announce keeps ${keep} of ${head.length} segments`);
296
+ suffix = Path.join(Path.from(...head.slice(0, keep)), suffix);
297
+ if (Path.parts(suffix).length > Path.MAX_PARTS) {
298
+ throw new ProtocolViolation(`path exceeds ${Path.MAX_PARTS} parts`);
299
+ }
300
+ }
301
+ const hops = this.#hops(msg.hops, msg.hopBase);
302
+ this.#live.set(this.#next++, { suffix, hops });
303
+ return { suffix, hops };
304
+ }
305
+ /** An ANNOUNCE_UPDATE: resolve its chain before replacing the old one, which it may be based on. */
306
+ update(msg) {
307
+ const hops = this.#hops(msg.hops, msg.hopBase);
308
+ const live = this.#live.get(msg.id);
309
+ if (!live)
310
+ throw new ProtocolViolation(`unknown announce id: ${msg.id}`);
311
+ this.#live.set(msg.id, { suffix: live.suffix, hops });
312
+ return { suffix: live.suffix, hops };
313
+ }
314
+ /** An ANNOUNCE_END: retire the id, returning its suffix. */
315
+ end(id) {
316
+ const live = this.#live.get(id);
317
+ if (!live)
318
+ throw new ProtocolViolation(`unknown announce id: ${id}`);
319
+ this.#live.delete(id);
320
+ return live.suffix;
321
+ }
322
+ }
214
323
  /**
215
324
  * ANNOUNCE_REQUEST: sent by the subscriber to request ANNOUNCE_BROADCAST messages
216
325
  * for a path prefix. Renamed from `AnnounceInterest` in lite-05.
@@ -224,20 +333,29 @@ export class AnnounceRequest {
224
333
  *
225
334
  * Must be a bigint: peer origins are up to 62 bits and overflow u53. */
226
335
  excludeHop;
227
- constructor(prefix, excludeHop = 0n) {
336
+ /** Lite07+: also announce routes with a `.`-prefixed segment below the prefix. Not on
337
+ * the wire earlier, so a value set here is ignored when encoding for an older version
338
+ * and decodes as false. */
339
+ hidden;
340
+ constructor(prefix, excludeHop = 0n, hidden = false) {
228
341
  this.prefix = prefix;
229
342
  this.excludeHop = excludeHop;
343
+ this.hidden = hidden;
230
344
  }
231
345
  async #encode(w, version) {
232
346
  await w.string(Path.encode(this.prefix));
233
347
  if (hasExcludeHop(version)) {
234
348
  await w.u62(this.excludeHop);
235
349
  }
350
+ if (hasHidden(version)) {
351
+ await w.bool(this.hidden);
352
+ }
236
353
  }
237
354
  static async #decode(r, version) {
238
355
  const prefix = Path.decode(await r.string());
239
356
  const excludeHop = hasExcludeHop(version) ? await r.u62() : 0n;
240
- return new AnnounceRequest(prefix, excludeHop);
357
+ const hidden = hasHidden(version) ? await r.bool() : false;
358
+ return new AnnounceRequest(prefix, excludeHop, hidden);
241
359
  }
242
360
  async encode(w, version) {
243
361
  return Message.encode(w, (w) => this.#encode(w, version));