@moq/net 0.4.8 → 0.22.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.
Files changed (662) hide show
  1. package/README.md +7 -1
  2. package/announce.d.ts +1 -1
  3. package/announce.d.ts.map +1 -1
  4. package/announce.js +1 -1
  5. package/announce.js.map +1 -1
  6. package/announced.d.ts +51 -47
  7. package/announced.d.ts.map +1 -1
  8. package/announced.js +183 -31
  9. package/announced.js.map +1 -1
  10. package/announced.test-util.d.ts +2 -0
  11. package/announced.test-util.d.ts.map +1 -0
  12. package/announced.test-util.js +27 -0
  13. package/announced.test-util.js.map +1 -0
  14. package/auth.d.ts +64 -0
  15. package/auth.d.ts.map +1 -0
  16. package/auth.js +20 -0
  17. package/auth.js.map +1 -0
  18. package/auth_gate.d.ts +2 -0
  19. package/auth_gate.d.ts.map +1 -0
  20. package/auth_gate.js +24 -0
  21. package/auth_gate.js.map +1 -0
  22. package/auth_session.d.ts +49 -0
  23. package/auth_session.d.ts.map +1 -0
  24. package/auth_session.js +1097 -0
  25. package/auth_session.js.map +1 -0
  26. package/bandwidth.d.ts +129 -25
  27. package/bandwidth.d.ts.map +1 -1
  28. package/bandwidth.js +410 -138
  29. package/bandwidth.js.map +1 -1
  30. package/bandwidth_api.d.ts +1 -1
  31. package/bandwidth_api.d.ts.map +1 -1
  32. package/bandwidth_api.js +1 -1
  33. package/bandwidth_api.js.map +1 -1
  34. package/broadcast.d.ts +62 -36
  35. package/broadcast.d.ts.map +1 -1
  36. package/broadcast.js +556 -172
  37. package/broadcast.js.map +1 -1
  38. package/cache.d.ts +103 -0
  39. package/cache.d.ts.map +1 -0
  40. package/cache.js +254 -0
  41. package/cache.js.map +1 -0
  42. package/claim.test-util.d.ts +5 -0
  43. package/claim.test-util.d.ts.map +1 -0
  44. package/claim.test-util.js +13 -0
  45. package/claim.test-util.js.map +1 -0
  46. package/connection/accept.d.ts +20 -12
  47. package/connection/accept.d.ts.map +1 -1
  48. package/connection/accept.js +97 -129
  49. package/connection/accept.js.map +1 -1
  50. package/connection/browser.d.ts.map +1 -1
  51. package/connection/browser.js +28 -19
  52. package/connection/browser.js.map +1 -1
  53. package/connection/connect.d.ts +119 -23
  54. package/connection/connect.d.ts.map +1 -1
  55. package/connection/connect.js +535 -216
  56. package/connection/connect.js.map +1 -1
  57. package/connection/dials.d.ts +45 -0
  58. package/connection/dials.d.ts.map +1 -0
  59. package/connection/dials.js +109 -0
  60. package/connection/dials.js.map +1 -0
  61. package/connection/endpoint.d.ts +60 -0
  62. package/connection/endpoint.d.ts.map +1 -0
  63. package/connection/endpoint.js +114 -0
  64. package/connection/endpoint.js.map +1 -0
  65. package/connection/forward.d.ts +7 -1
  66. package/connection/forward.d.ts.map +1 -1
  67. package/connection/forward.js +265 -80
  68. package/connection/forward.js.map +1 -1
  69. package/connection/goaway.d.ts +16 -9
  70. package/connection/goaway.d.ts.map +1 -1
  71. package/connection/goaway.js +22 -108
  72. package/connection/goaway.js.map +1 -1
  73. package/connection/handshake.d.ts +32 -6
  74. package/connection/handshake.d.ts.map +1 -1
  75. package/connection/handshake.js +97 -20
  76. package/connection/handshake.js.map +1 -1
  77. package/connection/index.d.ts +3 -6
  78. package/connection/index.d.ts.map +1 -1
  79. package/connection/index.js +1 -2
  80. package/connection/index.js.map +1 -1
  81. package/connection/liveness.d.ts +14 -0
  82. package/connection/liveness.d.ts.map +1 -0
  83. package/connection/liveness.js +30 -0
  84. package/connection/liveness.js.map +1 -0
  85. package/connection/pool.d.ts +137 -58
  86. package/connection/pool.d.ts.map +1 -1
  87. package/connection/pool.js +281 -117
  88. package/connection/pool.js.map +1 -1
  89. package/connection/reload.d.ts +60 -12
  90. package/connection/reload.d.ts.map +1 -1
  91. package/connection/reload.js +859 -233
  92. package/connection/reload.js.map +1 -1
  93. package/connection/session.d.ts +91 -0
  94. package/connection/session.d.ts.map +1 -0
  95. package/connection/session.js +2 -0
  96. package/connection/session.js.map +1 -0
  97. package/connection/stats.d.ts +20 -11
  98. package/connection/stats.d.ts.map +1 -1
  99. package/connection/stats.js +64 -8
  100. package/connection/stats.js.map +1 -1
  101. package/connection/ticker.d.ts +4 -0
  102. package/connection/ticker.d.ts.map +1 -0
  103. package/connection/ticker.js +66 -0
  104. package/connection/ticker.js.map +1 -0
  105. package/connection/tokens.d.ts +2 -0
  106. package/connection/tokens.d.ts.map +1 -0
  107. package/connection/tokens.js +404 -0
  108. package/connection/tokens.js.map +1 -0
  109. package/connection/transport.d.ts.map +1 -1
  110. package/connection/transport.js +4 -4
  111. package/connection/transport.js.map +1 -1
  112. package/connection/withdrawal.d.ts +2 -0
  113. package/connection/withdrawal.d.ts.map +1 -0
  114. package/connection/withdrawal.js +23 -0
  115. package/connection/withdrawal.js.map +1 -0
  116. package/consume.js +213 -46
  117. package/consume.js.map +1 -1
  118. package/cover.d.ts +59 -0
  119. package/cover.d.ts.map +1 -0
  120. package/cover.js +375 -0
  121. package/cover.js.map +1 -0
  122. package/datagram.d.ts +70 -11
  123. package/datagram.d.ts.map +1 -1
  124. package/datagram.js +317 -1
  125. package/datagram.js.map +1 -1
  126. package/datagram_stream.d.ts +18 -0
  127. package/datagram_stream.d.ts.map +1 -0
  128. package/datagram_stream.js +67 -0
  129. package/datagram_stream.js.map +1 -0
  130. package/defined.test-util.d.ts +2 -0
  131. package/defined.test-util.d.ts.map +1 -0
  132. package/defined.test-util.js +7 -0
  133. package/defined.test-util.js.map +1 -0
  134. package/delivered.d.ts +75 -0
  135. package/delivered.d.ts.map +1 -0
  136. package/delivered.js +228 -0
  137. package/delivered.js.map +1 -0
  138. package/demand.d.ts +173 -0
  139. package/demand.d.ts.map +1 -0
  140. package/demand.js +582 -0
  141. package/demand.js.map +1 -0
  142. package/drops.d.ts +93 -0
  143. package/drops.d.ts.map +1 -0
  144. package/drops.js +283 -0
  145. package/drops.js.map +1 -0
  146. package/error.d.ts +120 -21
  147. package/error.d.ts.map +1 -1
  148. package/error.js +230 -37
  149. package/error.js.map +1 -1
  150. package/errors.d.ts +2 -2
  151. package/errors.d.ts.map +1 -1
  152. package/errors.js +2 -2
  153. package/errors.js.map +1 -1
  154. package/fill.d.ts +174 -0
  155. package/fill.d.ts.map +1 -0
  156. package/fill.js +760 -0
  157. package/fill.js.map +1 -0
  158. package/flate/decoder.d.ts +2 -0
  159. package/flate/decoder.d.ts.map +1 -0
  160. package/flate/decoder.js +63 -0
  161. package/flate/decoder.js.map +1 -0
  162. package/flate/encoder.d.ts +2 -0
  163. package/flate/encoder.d.ts.map +1 -0
  164. package/flate/encoder.js +64 -0
  165. package/flate/encoder.js.map +1 -0
  166. package/flate/group.d.ts +34 -0
  167. package/flate/group.d.ts.map +1 -0
  168. package/flate/group.js +140 -0
  169. package/flate/group.js.map +1 -0
  170. package/frame.d.ts +80 -0
  171. package/frame.d.ts.map +1 -0
  172. package/frame.js +296 -0
  173. package/frame.js.map +1 -0
  174. package/frame.test-util.d.ts +5 -0
  175. package/frame.test-util.d.ts.map +1 -0
  176. package/frame.test-util.js +9 -0
  177. package/frame.test-util.js.map +1 -0
  178. package/group.d.ts +108 -45
  179. package/group.d.ts.map +1 -1
  180. package/group.js +1616 -307
  181. package/group.js.map +1 -1
  182. package/group_api.d.ts +7 -0
  183. package/group_api.d.ts.map +1 -0
  184. package/group_api.js +7 -0
  185. package/group_api.js.map +1 -0
  186. package/hop.d.ts +62 -76
  187. package/hop.d.ts.map +1 -1
  188. package/hop.js +92 -64
  189. package/hop.js.map +1 -1
  190. package/identity.d.ts +39 -0
  191. package/identity.d.ts.map +1 -0
  192. package/identity.js +47 -0
  193. package/identity.js.map +1 -0
  194. package/ietf/active_count.d.ts +2 -0
  195. package/ietf/active_count.d.ts.map +1 -0
  196. package/ietf/active_count.js +30 -0
  197. package/ietf/active_count.js.map +1 -0
  198. package/ietf/aliases.js +69 -35
  199. package/ietf/aliases.js.map +1 -1
  200. package/ietf/cluster.d.ts +3 -3
  201. package/ietf/cluster.js +14 -62
  202. package/ietf/cluster.js.map +1 -1
  203. package/ietf/connection.d.ts +1 -31
  204. package/ietf/connection.d.ts.map +1 -1
  205. package/ietf/connection.js +305 -143
  206. package/ietf/connection.js.map +1 -1
  207. package/ietf/datagram.d.ts +60 -0
  208. package/ietf/datagram.d.ts.map +1 -0
  209. package/ietf/datagram.js +152 -0
  210. package/ietf/datagram.js.map +1 -0
  211. package/ietf/error.d.ts +3 -3
  212. package/ietf/error.js +82 -100
  213. package/ietf/error.js.map +1 -1
  214. package/ietf/fetch.d.ts +91 -35
  215. package/ietf/fetch.d.ts.map +1 -1
  216. package/ietf/fetch.js +172 -93
  217. package/ietf/fetch.js.map +1 -1
  218. package/ietf/filter.d.ts +20 -30
  219. package/ietf/filter.d.ts.map +1 -1
  220. package/ietf/filter.js +140 -171
  221. package/ietf/filter.js.map +1 -1
  222. package/ietf/goaway.d.ts +11 -9
  223. package/ietf/goaway.d.ts.map +1 -1
  224. package/ietf/goaway.js +22 -35
  225. package/ietf/goaway.js.map +1 -1
  226. package/ietf/hidden.js +1 -1
  227. package/ietf/hidden.js.map +1 -1
  228. package/ietf/index.d.ts +2 -14
  229. package/ietf/index.d.ts.map +1 -1
  230. package/ietf/index.js +4 -14
  231. package/ietf/index.js.map +1 -1
  232. package/ietf/join.d.ts +7 -0
  233. package/ietf/join.d.ts.map +1 -0
  234. package/ietf/join.js +234 -0
  235. package/ietf/join.js.map +1 -0
  236. package/ietf/message.d.ts +18 -2
  237. package/ietf/message.d.ts.map +1 -1
  238. package/ietf/message.js +60 -40
  239. package/ietf/message.js.map +1 -1
  240. package/ietf/message.test-util.d.ts +6 -0
  241. package/ietf/message.test-util.d.ts.map +1 -0
  242. package/ietf/message.test-util.js +13 -0
  243. package/ietf/message.test-util.js.map +1 -0
  244. package/ietf/namespace.d.ts +17 -3
  245. package/ietf/namespace.d.ts.map +1 -1
  246. package/ietf/namespace.js +78 -26
  247. package/ietf/namespace.js.map +1 -1
  248. package/ietf/object.d.ts +194 -32
  249. package/ietf/object.d.ts.map +1 -1
  250. package/ietf/object.js +405 -178
  251. package/ietf/object.js.map +1 -1
  252. package/ietf/parameters.d.ts +22 -42
  253. package/ietf/parameters.d.ts.map +1 -1
  254. package/ietf/parameters.js +260 -472
  255. package/ietf/parameters.js.map +1 -1
  256. package/ietf/priority.d.ts +17 -2
  257. package/ietf/priority.d.ts.map +1 -1
  258. package/ietf/priority.js +19 -4
  259. package/ietf/priority.js.map +1 -1
  260. package/ietf/properties.d.ts +5 -4
  261. package/ietf/properties.d.ts.map +1 -1
  262. package/ietf/properties.js +78 -48
  263. package/ietf/properties.js.map +1 -1
  264. package/ietf/publish.d.ts +22 -30
  265. package/ietf/publish.d.ts.map +1 -1
  266. package/ietf/publish.js +45 -139
  267. package/ietf/publish.js.map +1 -1
  268. package/ietf/publish_namespace.d.ts +46 -69
  269. package/ietf/publish_namespace.d.ts.map +1 -1
  270. package/ietf/publish_namespace.js +66 -184
  271. package/ietf/publish_namespace.js.map +1 -1
  272. package/ietf/publisher.js +1800 -600
  273. package/ietf/publisher.js.map +1 -1
  274. package/ietf/range.d.ts +2 -0
  275. package/ietf/range.d.ts.map +1 -0
  276. package/ietf/range.js +222 -0
  277. package/ietf/range.js.map +1 -0
  278. package/ietf/request.d.ts +3 -27
  279. package/ietf/request.d.ts.map +1 -1
  280. package/ietf/request.js +41 -78
  281. package/ietf/request.js.map +1 -1
  282. package/ietf/request_stream.d.ts +1 -6
  283. package/ietf/request_stream.d.ts.map +1 -1
  284. package/ietf/request_stream.js +306 -16
  285. package/ietf/request_stream.js.map +1 -1
  286. package/ietf/session.d.ts +41 -0
  287. package/ietf/session.d.ts.map +1 -0
  288. package/ietf/session.js +65 -0
  289. package/ietf/session.js.map +1 -0
  290. package/ietf/setup.d.ts +4 -29
  291. package/ietf/setup.d.ts.map +1 -1
  292. package/ietf/setup.js +6 -117
  293. package/ietf/setup.js.map +1 -1
  294. package/ietf/setup_options.d.ts +31 -0
  295. package/ietf/setup_options.d.ts.map +1 -0
  296. package/ietf/setup_options.js +138 -0
  297. package/ietf/setup_options.js.map +1 -0
  298. package/ietf/solicit.js +4 -14
  299. package/ietf/solicit.js.map +1 -1
  300. package/ietf/subscribe.d.ts +48 -41
  301. package/ietf/subscribe.d.ts.map +1 -1
  302. package/ietf/subscribe.js +118 -239
  303. package/ietf/subscribe.js.map +1 -1
  304. package/ietf/subscribe_namespace.d.ts +13 -76
  305. package/ietf/subscribe_namespace.d.ts.map +1 -1
  306. package/ietf/subscribe_namespace.js +30 -201
  307. package/ietf/subscribe_namespace.js.map +1 -1
  308. package/ietf/subscriber.js +1839 -536
  309. package/ietf/subscriber.js.map +1 -1
  310. package/ietf/token.js +105 -27
  311. package/ietf/token.js.map +1 -1
  312. package/ietf/track.d.ts +25 -22
  313. package/ietf/track.d.ts.map +1 -1
  314. package/ietf/track.js +48 -61
  315. package/ietf/track.js.map +1 -1
  316. package/ietf/version.d.ts +13 -42
  317. package/ietf/version.d.ts.map +1 -1
  318. package/ietf/version.js +22 -48
  319. package/ietf/version.js.map +1 -1
  320. package/implementation.d.ts +2 -0
  321. package/implementation.d.ts.map +1 -0
  322. package/implementation.js +5 -0
  323. package/implementation.js.map +1 -0
  324. package/index.d.ts +25 -10
  325. package/index.d.ts.map +1 -1
  326. package/index.js +19 -6
  327. package/index.js.map +1 -1
  328. package/internal.d.ts +1512 -64
  329. package/internal.d.ts.map +1 -1
  330. package/internal.js +557 -79
  331. package/internal.js.map +1 -1
  332. package/ledger.d.ts +23 -0
  333. package/ledger.d.ts.map +1 -0
  334. package/ledger.js +247 -0
  335. package/ledger.js.map +1 -0
  336. package/listing.d.ts +132 -0
  337. package/listing.d.ts.map +1 -0
  338. package/listing.js +486 -0
  339. package/listing.js.map +1 -0
  340. package/lite/announce.d.ts +124 -63
  341. package/lite/announce.d.ts.map +1 -1
  342. package/lite/announce.js +384 -158
  343. package/lite/announce.js.map +1 -1
  344. package/lite/announce_stream.d.ts +2 -0
  345. package/lite/announce_stream.d.ts.map +1 -0
  346. package/lite/announce_stream.js +92 -0
  347. package/lite/announce_stream.js.map +1 -0
  348. package/lite/answer.d.ts +22 -0
  349. package/lite/answer.d.ts.map +1 -0
  350. package/lite/answer.js +301 -0
  351. package/lite/answer.js.map +1 -0
  352. package/lite/auth.d.ts +45 -0
  353. package/lite/auth.d.ts.map +1 -0
  354. package/lite/auth.js +204 -0
  355. package/lite/auth.js.map +1 -0
  356. package/lite/compat.d.ts +31 -0
  357. package/lite/compat.d.ts.map +1 -0
  358. package/lite/compat.js +86 -0
  359. package/lite/compat.js.map +1 -0
  360. package/lite/connection.d.ts +1 -45
  361. package/lite/connection.d.ts.map +1 -1
  362. package/lite/connection.js +360 -77
  363. package/lite/connection.js.map +1 -1
  364. package/lite/datagram-end.d.ts +26 -0
  365. package/lite/datagram-end.d.ts.map +1 -0
  366. package/lite/datagram-end.js +30 -0
  367. package/lite/datagram-end.js.map +1 -0
  368. package/lite/datagram.d.ts +73 -8
  369. package/lite/datagram.d.ts.map +1 -1
  370. package/lite/datagram.js +144 -9
  371. package/lite/datagram.js.map +1 -1
  372. package/lite/duration.d.ts +6 -0
  373. package/lite/duration.d.ts.map +1 -0
  374. package/lite/duration.js +14 -0
  375. package/lite/duration.js.map +1 -0
  376. package/lite/error.d.ts +9 -0
  377. package/lite/error.d.ts.map +1 -0
  378. package/lite/error.js +24 -0
  379. package/lite/error.js.map +1 -0
  380. package/lite/fills.d.ts +162 -0
  381. package/lite/fills.d.ts.map +1 -0
  382. package/lite/fills.js +486 -0
  383. package/lite/fills.js.map +1 -0
  384. package/lite/fit.d.ts +49 -0
  385. package/lite/fit.d.ts.map +1 -0
  386. package/lite/fit.js +305 -0
  387. package/lite/fit.js.map +1 -0
  388. package/lite/goaway.d.ts +1 -1
  389. package/lite/goaway.d.ts.map +1 -1
  390. package/lite/goaway.js +5 -13
  391. package/lite/goaway.js.map +1 -1
  392. package/lite/group.d.ts +64 -13
  393. package/lite/group.d.ts.map +1 -1
  394. package/lite/group.js +108 -30
  395. package/lite/group.js.map +1 -1
  396. package/lite/identity.d.ts +25 -0
  397. package/lite/identity.d.ts.map +1 -0
  398. package/lite/identity.js +79 -0
  399. package/lite/identity.js.map +1 -0
  400. package/lite/index.d.ts +2 -1
  401. package/lite/index.d.ts.map +1 -1
  402. package/lite/index.js +2 -1
  403. package/lite/index.js.map +1 -1
  404. package/lite/message.d.ts +9 -1
  405. package/lite/message.d.ts.map +1 -1
  406. package/lite/message.js +28 -44
  407. package/lite/message.js.map +1 -1
  408. package/lite/priority.d.ts +9 -2
  409. package/lite/priority.d.ts.map +1 -1
  410. package/lite/priority.js +11 -105
  411. package/lite/priority.js.map +1 -1
  412. package/lite/probe.d.ts.map +1 -1
  413. package/lite/probe.js +9 -0
  414. package/lite/probe.js.map +1 -1
  415. package/lite/publisher.d.ts +10 -1
  416. package/lite/publisher.d.ts.map +1 -1
  417. package/lite/publisher.js +2548 -437
  418. package/lite/publisher.js.map +1 -1
  419. package/lite/routed.d.ts +59 -0
  420. package/lite/routed.d.ts.map +1 -0
  421. package/lite/routed.js +564 -0
  422. package/lite/routed.js.map +1 -0
  423. package/lite/session.d.ts +1 -27
  424. package/lite/session.d.ts.map +1 -1
  425. package/lite/session.js +0 -99
  426. package/lite/session.js.map +1 -1
  427. package/lite/setup.d.ts +29 -2
  428. package/lite/setup.d.ts.map +1 -1
  429. package/lite/setup.js +95 -21
  430. package/lite/setup.js.map +1 -1
  431. package/lite/stream.d.ts +5 -11
  432. package/lite/stream.d.ts.map +1 -1
  433. package/lite/stream.js +5 -1
  434. package/lite/stream.js.map +1 -1
  435. package/lite/subscribe.d.ts +475 -75
  436. package/lite/subscribe.d.ts.map +1 -1
  437. package/lite/subscribe.js +1373 -142
  438. package/lite/subscribe.js.map +1 -1
  439. package/lite/subscriber.d.ts +7 -44
  440. package/lite/subscriber.d.ts.map +1 -1
  441. package/lite/subscriber.js +3290 -515
  442. package/lite/subscriber.js.map +1 -1
  443. package/lite/track.d.ts +24 -9
  444. package/lite/track.d.ts.map +1 -1
  445. package/lite/track.js +116 -37
  446. package/lite/track.js.map +1 -1
  447. package/lite/tracks.d.ts +55 -0
  448. package/lite/tracks.d.ts.map +1 -0
  449. package/lite/tracks.js +114 -0
  450. package/lite/tracks.js.map +1 -0
  451. package/lite/version.d.ts +132 -24
  452. package/lite/version.d.ts.map +1 -1
  453. package/lite/version.js +378 -33
  454. package/lite/version.js.map +1 -1
  455. package/meta.d.ts +77 -0
  456. package/meta.d.ts.map +1 -0
  457. package/meta.js +130 -0
  458. package/meta.js.map +1 -0
  459. package/meta_api.d.ts +7 -0
  460. package/meta_api.d.ts.map +1 -0
  461. package/meta_api.js +7 -0
  462. package/meta_api.js.map +1 -0
  463. package/mint.d.ts +28 -0
  464. package/mint.d.ts.map +1 -0
  465. package/mint.js +66 -0
  466. package/mint.js.map +1 -0
  467. package/open.d.ts +63 -0
  468. package/open.d.ts.map +1 -0
  469. package/open.js +250 -0
  470. package/open.js.map +1 -0
  471. package/origin.d.ts +392 -140
  472. package/origin.d.ts.map +1 -1
  473. package/origin.js +2533 -686
  474. package/origin.js.map +1 -1
  475. package/package.json +8 -13
  476. package/path.d.ts +51 -51
  477. package/path.d.ts.map +1 -1
  478. package/path.js +210 -57
  479. package/path.js.map +1 -1
  480. package/payload.d.ts +33 -0
  481. package/payload.d.ts.map +1 -0
  482. package/payload.js +65 -0
  483. package/payload.js.map +1 -0
  484. package/prefix.d.ts +152 -0
  485. package/prefix.d.ts.map +1 -0
  486. package/prefix.js +349 -0
  487. package/prefix.js.map +1 -0
  488. package/priority.d.ts +8 -0
  489. package/priority.d.ts.map +1 -0
  490. package/priority.js +185 -0
  491. package/priority.js.map +1 -0
  492. package/queue.d.ts +2 -0
  493. package/queue.d.ts.map +1 -0
  494. package/queue.js +46 -0
  495. package/queue.js.map +1 -0
  496. package/ranges.d.ts +36 -0
  497. package/ranges.d.ts.map +1 -0
  498. package/ranges.js +312 -0
  499. package/ranges.js.map +1 -0
  500. package/rescale.d.ts +24 -0
  501. package/rescale.d.ts.map +1 -0
  502. package/rescale.js +39 -0
  503. package/rescale.js.map +1 -0
  504. package/resume.d.ts +55 -0
  505. package/resume.d.ts.map +1 -0
  506. package/resume.js +4173 -0
  507. package/resume.js.map +1 -0
  508. package/resume.test-util.d.ts +2 -0
  509. package/resume.test-util.d.ts.map +1 -0
  510. package/resume.test-util.js +25 -0
  511. package/resume.test-util.js.map +1 -0
  512. package/skips.d.ts +48 -0
  513. package/skips.d.ts.map +1 -0
  514. package/skips.js +182 -0
  515. package/skips.js.map +1 -0
  516. package/stream.d.ts +75 -37
  517. package/stream.d.ts.map +1 -1
  518. package/stream.js +236 -92
  519. package/stream.js.map +1 -1
  520. package/subscription.test-util.d.ts +2 -0
  521. package/subscription.test-util.d.ts.map +1 -0
  522. package/subscription.test-util.js +49 -0
  523. package/subscription.test-util.js.map +1 -0
  524. package/tail.d.ts +23 -14
  525. package/tail.d.ts.map +1 -1
  526. package/tail.js +224 -97
  527. package/tail.js.map +1 -1
  528. package/time.d.ts +41 -102
  529. package/time.d.ts.map +1 -1
  530. package/time.js +129 -91
  531. package/time.js.map +1 -1
  532. package/timed.d.ts +21 -0
  533. package/timed.d.ts.map +1 -0
  534. package/timed.js +2 -0
  535. package/timed.js.map +1 -0
  536. package/track.d.ts +577 -245
  537. package/track.d.ts.map +1 -1
  538. package/track.js +7306 -771
  539. package/track.js.map +1 -1
  540. package/track_api.d.ts +7 -0
  541. package/track_api.d.ts.map +1 -0
  542. package/track_api.js +7 -0
  543. package/track_api.js.map +1 -0
  544. package/util/abort.d.ts +1 -0
  545. package/util/abort.d.ts.map +1 -1
  546. package/util/abort.js +23 -1
  547. package/util/abort.js.map +1 -1
  548. package/util/announce.d.ts +4 -0
  549. package/util/announce.d.ts.map +1 -0
  550. package/util/announce.js +11 -0
  551. package/util/announce.js.map +1 -0
  552. package/util/bigint.d.ts +3 -0
  553. package/util/bigint.d.ts.map +1 -0
  554. package/util/bigint.js +8 -0
  555. package/util/bigint.js.map +1 -0
  556. package/util/change.d.ts +12 -0
  557. package/util/change.d.ts.map +1 -0
  558. package/util/change.js +18 -0
  559. package/util/change.js.map +1 -0
  560. package/util/deadline.d.ts +2 -0
  561. package/util/deadline.d.ts.map +1 -0
  562. package/util/deadline.js +108 -0
  563. package/util/deadline.js.map +1 -0
  564. package/util/decode_error.d.ts +3 -0
  565. package/util/decode_error.d.ts.map +1 -0
  566. package/util/decode_error.js +11 -0
  567. package/util/decode_error.js.map +1 -0
  568. package/util/demand.d.ts +8 -0
  569. package/util/demand.d.ts.map +1 -0
  570. package/util/demand.js +24 -0
  571. package/util/demand.js.map +1 -0
  572. package/util/given_up.d.ts +2 -0
  573. package/util/given_up.d.ts.map +1 -0
  574. package/util/given_up.js +101 -0
  575. package/util/given_up.js.map +1 -0
  576. package/util/hex.d.ts +6 -0
  577. package/util/hex.d.ts.map +1 -1
  578. package/util/hex.js +19 -4
  579. package/util/hex.js.map +1 -1
  580. package/util/key.d.ts +15 -0
  581. package/util/key.d.ts.map +1 -0
  582. package/util/key.js +38 -0
  583. package/util/key.js.map +1 -0
  584. package/util/limits.d.ts +2 -0
  585. package/util/limits.d.ts.map +1 -0
  586. package/util/limits.js +76 -0
  587. package/util/limits.js.map +1 -0
  588. package/util/observed.d.ts +23 -0
  589. package/util/observed.d.ts.map +1 -0
  590. package/util/observed.js +122 -0
  591. package/util/observed.js.map +1 -0
  592. package/util/sorted.d.ts +2 -0
  593. package/util/sorted.d.ts.map +1 -0
  594. package/util/sorted.js +149 -0
  595. package/util/sorted.js.map +1 -0
  596. package/util/timeout.d.ts +2 -1
  597. package/util/timeout.d.ts.map +1 -1
  598. package/util/timeout.js +13 -9
  599. package/util/timeout.js.map +1 -1
  600. package/util/timer.d.ts +2 -0
  601. package/util/timer.d.ts.map +1 -0
  602. package/util/timer.js +19 -0
  603. package/util/timer.js.map +1 -0
  604. package/util/utf8.d.ts +2 -0
  605. package/util/utf8.d.ts.map +1 -1
  606. package/util/utf8.js +7 -1
  607. package/util/utf8.js.map +1 -1
  608. package/util/varint.d.ts.map +1 -1
  609. package/util/varint.js +8 -1
  610. package/util/varint.js.map +1 -1
  611. package/util/watch.d.ts +8 -0
  612. package/util/watch.d.ts.map +1 -0
  613. package/util/watch.js +38 -0
  614. package/util/watch.js.map +1 -0
  615. package/util/yield.d.ts +2 -0
  616. package/util/yield.d.ts.map +1 -0
  617. package/util/yield.js +31 -0
  618. package/util/yield.js.map +1 -0
  619. package/varint.d.ts +0 -29
  620. package/varint.d.ts.map +1 -1
  621. package/varint.js +7 -28
  622. package/varint.js.map +1 -1
  623. package/varint_api.d.ts +7 -0
  624. package/varint_api.d.ts.map +1 -0
  625. package/varint_api.js +7 -0
  626. package/varint_api.js.map +1 -0
  627. package/version.d.ts +2 -0
  628. package/version.d.ts.map +1 -0
  629. package/version.js +4 -0
  630. package/version.js.map +1 -0
  631. package/window.d.ts +570 -0
  632. package/window.d.ts.map +1 -0
  633. package/window.js +1677 -0
  634. package/window.js.map +1 -0
  635. package/wire.d.ts +145 -30
  636. package/wire.d.ts.map +1 -1
  637. package/wire.js +27 -0
  638. package/wire.js.map +1 -1
  639. package/connection/established.d.ts +0 -53
  640. package/connection/established.d.ts.map +0 -1
  641. package/connection/established.js +0 -2
  642. package/connection/established.js.map +0 -1
  643. package/ietf/adapter.d.ts +0 -75
  644. package/ietf/adapter.d.ts.map +0 -1
  645. package/ietf/adapter.js +0 -699
  646. package/ietf/adapter.js.map +0 -1
  647. package/lite/datagram_stream.d.ts +0 -8
  648. package/lite/datagram_stream.d.ts.map +0 -1
  649. package/lite/datagram_stream.js +0 -43
  650. package/lite/datagram_stream.js.map +0 -1
  651. package/lite/fetch.d.ts +0 -28
  652. package/lite/fetch.d.ts.map +0 -1
  653. package/lite/fetch.js +0 -78
  654. package/lite/fetch.js.map +0 -1
  655. package/util/log.d.ts +0 -5
  656. package/util/log.d.ts.map +0 -1
  657. package/util/log.js +0 -16
  658. package/util/log.js.map +0 -1
  659. package/zod.d.ts +0 -13
  660. package/zod.d.ts.map +0 -1
  661. package/zod.js +0 -18
  662. package/zod.js.map +0 -1
package/lite/announce.js CHANGED
@@ -1,18 +1,57 @@
1
1
  import { ProtocolViolation } from "../error.js";
2
- import { HopSchema, MAX_HOPS, UNKNOWN_HOP } from "../hop.js";
2
+ import { MAX_HOPS, toHop, UNKNOWN_HOP, wireHop } from "../hop.js";
3
3
  import * as Path from "../path.js";
4
+ import { encodeVarint } from "../stream.js";
5
+ import { SEGMENT_BYTES } from "../util/limits.js";
6
+ import { decodeRoute, encodeRoute } from "./identity.js";
4
7
  import * as Message from "./message.js";
5
- import { hasAnnounceCompression, hasAnnounceId, hasAnnounceOk, hasExcludeHop, hasHidden, hasRouteCost, Version, } from "./version.js";
8
+ import { MAX_MESSAGE_SIZE } from "./message.js";
9
+ import { fromWire, toWire } from "./priority.js";
10
+ import { hasAnnounceCompression, hasAnnounceId, hasAnnounceOk, hasExcludeHop, hasRouteCost, hasRoutes, hasSynced, Version, } from "./version.js";
6
11
  // Pre-lite-06 inner status values, carried inside the single ANNOUNCE_BROADCAST body.
7
12
  const STATUS_ENDED = 0;
8
13
  const STATUS_ACTIVE = 1;
9
- const STATUS_RESTART = 2;
14
+ // The lite-05 draft's explicit `restart` status: a metadata update.
15
+ const STATUS_UPDATE = 2;
10
16
  // lite-06 announce message types: an outer discriminator carried before the length
11
17
  // prefix, so each announcement is an independently-typed, length-delimited message
12
18
  // (mirroring SUBSCRIBE_START/END/DROP on the subscribe stream).
13
19
  const ANNOUNCE_START = 0;
14
20
  const ANNOUNCE_END = 1;
15
- const ANNOUNCE_RESTART = 2;
21
+ const ANNOUNCE_UPDATE = 2;
22
+ // lite-07: what only two nodes that both declared a Node ID exchange. An endpoint declares none,
23
+ // so receiving one is a protocol violation.
24
+ const ANNOUNCE_FLOOR = 3;
25
+ const SYNCED = 4;
26
+ // lite-07: an edit of the prefixes the sender wants, and the marker answering one.
27
+ const ANNOUNCE_REQUEST = 5;
28
+ const ANNOUNCE_OK = 6;
29
+ const ROUTE = 7;
30
+ const ROUTE_END = 8;
31
+ const DEAD = 9;
32
+ const DRAIN = 10;
33
+ /** The most nodes a lite-07 claim's chain may name: one that would reach 32 is never taken. */
34
+ export const CHAIN_MAX = 31;
35
+ // Claim flags.
36
+ const UNAVAILABLE = 0x1;
37
+ const DRAINING = 0x2;
38
+ const MARKED = 0x4;
39
+ /** A claim this origin publishes itself: no cost, at the top priority, announced again by no one. */
40
+ export function ownClaim(epoch, above = 0n) {
41
+ return { epoch, cost: 0n, above, unavailable: false, draining: false, marked: false, priority: 127, chain: [] };
42
+ }
43
+ /** Whether two claims say the same. */
44
+ export function claimsEqual(a, b) {
45
+ return (a.epoch === b.epoch &&
46
+ a.cost === b.cost &&
47
+ a.above === b.above &&
48
+ a.unavailable === b.unavailable &&
49
+ a.draining === b.draining &&
50
+ a.marked === b.marked &&
51
+ a.priority === b.priority &&
52
+ a.chain.length === b.chain.length &&
53
+ a.chain.every((node, i) => node === b.chain[i]));
54
+ }
16
55
  // Both wire rules on a hop chain, applied to what we send and to what we receive: a
17
56
  // chain that revisits a hop looped, so neither forwarding it nor subscribing through it
18
57
  // is safe, and a receiver must end the session over one. `UNKNOWN_HOP` identifies
@@ -34,7 +73,7 @@ function checkHops(hops) {
34
73
  }
35
74
  }
36
75
  }
37
- async function encodeHops(w, version, hops) {
76
+ async function encodeHops(w, version, hops = []) {
38
77
  checkHops(hops);
39
78
  switch (version) {
40
79
  case Version.DRAFT_01:
@@ -47,7 +86,7 @@ async function encodeHops(w, version, hops) {
47
86
  // Lite04+: hop count + individual Hop varints.
48
87
  await w.u53(hops.length);
49
88
  for (const origin of hops) {
50
- await w.u62(origin);
89
+ await w.u62(wireHop(origin, version));
51
90
  }
52
91
  break;
53
92
  }
@@ -72,91 +111,227 @@ async function decodeHops(r, version) {
72
111
  throw new Error(`hop count ${count} exceeds maximum ${MAX_HOPS}`);
73
112
  const hops = [];
74
113
  for (let i = 0; i < count; i++) {
75
- hops.push(HopSchema.parse(await r.u62()));
114
+ hops.push(toHop(await r.u62()));
76
115
  }
77
116
  checkHops(hops);
78
117
  return hops;
79
118
  }
80
119
  }
81
120
  }
82
- // Lite-07 carries a base around a path and a hop list. A distance of 0 names
83
- // nothing, and a keep without a base is a violation. Other versions have no room for
84
- // a base at all.
85
- function checkBase(version, base) {
86
- if (base && !hasAnnounceCompression(version)) {
87
- throw new Error("announce compression not supported for this version");
88
- }
89
- }
90
- function toBase(distance, keep) {
91
- if (distance !== 0n)
92
- return { distance, keep };
93
- if (keep !== 0)
94
- throw new ProtocolViolation("announce keep without a base");
95
- return undefined;
96
- }
97
121
  async function encodePath(w, version, suffix, base) {
98
- checkBase(version, base);
99
122
  if (hasAnnounceCompression(version)) {
100
123
  await w.u62(base?.distance ?? 0n);
101
124
  await w.u53(base?.keep ?? 0);
102
125
  }
126
+ else if (base) {
127
+ throw new Error("announce compression not supported for this version");
128
+ }
103
129
  await w.string(Path.encode(suffix));
104
130
  }
105
131
  async function decodePath(r, version) {
106
132
  if (!hasAnnounceCompression(version))
107
133
  return { suffix: Path.decode(await r.string()) };
108
- const pathBase = toBase(await r.u62(), await r.u53());
109
- const suffix = Path.decode(await r.string());
110
- return pathBase ? { suffix, pathBase } : { suffix };
111
- }
112
- async function encodeHopsBlock(w, version, hops, base) {
113
- checkBase(version, base);
114
- if (!hasAnnounceCompression(version))
115
- return encodeHops(w, version, hops);
116
- await w.u62(base?.distance ?? 0n);
117
- await encodeHops(w, version, hops);
118
- await w.u53(base?.keep ?? 0);
119
- }
120
- async function decodeHopsBlock(r, version) {
121
- if (!hasAnnounceCompression(version))
122
- return { hops: await decodeHops(r, version) };
123
134
  const distance = await r.u62();
124
- const hops = await decodeHops(r, version);
125
- const hopBase = toBase(distance, await r.u53());
126
- return hopBase ? { hops, hopBase } : { hops };
135
+ const keep = await r.u53();
136
+ // A distance of 0 names nothing, so a keep without a base is a violation.
137
+ if (distance === 0n && keep !== 0)
138
+ throw new ProtocolViolation("announce keep without a base");
139
+ const suffix = Path.decode(await r.string());
140
+ return distance === 0n ? { suffix } : { suffix, pathBase: { distance, keep } };
127
141
  }
128
- // The route cost rides lite-06+ announcements as two varints, warm then cold; older
129
- // versions carry neither. Costs saturate at 2^62-1 on every version, even where lite-07's
142
+ // Lite07 carries one static cost. Lite06 retains its second field at the ceiling;
143
+ // older versions carry neither. Costs saturate at 2^62-1 on every version, even where lite-07's
130
144
  // varints could carry more, so a cost always forwards to a peer on an older version.
131
145
  const MAX_COST = 2n ** 62n - 1n;
132
146
  const saturate = (v) => (v > MAX_COST ? MAX_COST : v);
133
147
  async function encodeRouteCost(w, version, cost) {
134
148
  if (!hasRouteCost(version))
135
149
  return;
136
- await w.u62(saturate(cost?.warm ?? 0n));
137
- await w.u62(saturate(cost?.cold ?? 0n));
150
+ await w.u62(saturate(cost ?? 0n));
151
+ if (version === Version.DRAFT_06)
152
+ await w.u62(MAX_COST);
138
153
  }
139
154
  async function decodeRouteCost(r, version) {
140
155
  if (!hasRouteCost(version))
141
156
  return undefined;
142
- return { warm: saturate(await r.u62()), cold: saturate(await r.u62()) };
157
+ const cost = saturate(await r.u62());
158
+ if (version === Version.DRAFT_06)
159
+ await r.u62();
160
+ return cost;
161
+ }
162
+ /** Encode what a lite-07 claim says after its epoch: cost, above, flags, priority, and chain. */
163
+ async function encodeClaim(w, claim) {
164
+ if (claim.chain.length > CHAIN_MAX || claim.chain.some((node) => node === 0n))
165
+ throw new Error("no node sends that chain");
166
+ await w.u62(saturate(claim.cost));
167
+ await w.u62(claim.above);
168
+ await w.u8((claim.unavailable ? UNAVAILABLE : 0) | (claim.draining ? DRAINING : 0) | (claim.marked ? MARKED : 0));
169
+ await w.u8(toWire(claim.priority));
170
+ await w.u53(claim.chain.length);
171
+ for (const node of claim.chain)
172
+ await w.u62(node);
173
+ }
174
+ /** Decode a lite-07 claim of `epoch`. A chain past the limit or naming Node ID 0, and a flag this
175
+ * version does not define, fail the stream: no sender builds one. Mirrors rs/moq-net. */
176
+ async function decodeClaim(r, epoch) {
177
+ // Costs saturate at 2^62-1 on every version, so a larger one reads as the ceiling.
178
+ const cost = saturate(await r.u62());
179
+ const above = await r.u62();
180
+ const flags = await r.u8();
181
+ if (flags & ~(UNAVAILABLE | DRAINING | MARKED))
182
+ throw new ProtocolViolation(`unknown claim flags ${flags}`);
183
+ const priority = fromWire(await r.u8());
184
+ const count = await r.u62();
185
+ if (count > BigInt(CHAIN_MAX))
186
+ throw new ProtocolViolation(`claim chain of ${count} nodes`);
187
+ const chain = [];
188
+ for (let i = 0n; i < count; i++) {
189
+ const node = await r.u62();
190
+ if (node === 0n)
191
+ throw new ProtocolViolation("Node ID 0 names no node");
192
+ chain.push(node);
193
+ }
194
+ return {
195
+ epoch,
196
+ cost,
197
+ above,
198
+ unavailable: (flags & UNAVAILABLE) !== 0,
199
+ draining: (flags & DRAINING) !== 0,
200
+ marked: (flags & MARKED) !== 0,
201
+ priority,
202
+ chain,
203
+ };
204
+ }
205
+ /** Encode an ANNOUNCE_REQUEST body: `More`, the Prefix IDs to remove, then the prefixes to add,
206
+ * each with its `Hidden`. */
207
+ async function encodeRequest(w, more, remove, add) {
208
+ await w.bool(more);
209
+ await w.u53(remove.length);
210
+ for (const id of remove)
211
+ await w.u62(id);
212
+ await w.u53(add.length);
213
+ for (const { prefix, hidden } of add) {
214
+ await w.string(Path.encode(prefix));
215
+ await w.bool(hidden);
216
+ }
217
+ }
218
+ /** Decode an ANNOUNCE_REQUEST body. The prefixes are the sender's own, so one that is no path
219
+ * fails the message rather than being refused. Each entry takes bytes, so the body bounds both
220
+ * counts before either loop runs out. */
221
+ async function decodeRequest(r) {
222
+ const more = await r.bool();
223
+ const remove = [];
224
+ for (let left = await r.u62(); left > 0n; left--)
225
+ remove.push(await r.u62());
226
+ const add = [];
227
+ for (let left = await r.u62(); left > 0n; left--) {
228
+ add.push({ prefix: Path.decode(await r.string()), hidden: await r.bool() });
229
+ }
230
+ return { status: "request", more, remove, add };
231
+ }
232
+ /** The bytes one Add of `prefix` takes: its length, its bytes, and its flag. */
233
+ function addSize(prefix, version) {
234
+ const length = new TextEncoder().encode(Path.encode(prefix)).byteLength;
235
+ return encodeVarint(length, version).byteLength + length + 1;
236
+ }
237
+ /** The bytes an ANNOUNCE_REQUEST body takes with `removes` Prefix IDs totalling `ids` bytes and
238
+ * `adds` Adds totalling `added` bytes. */
239
+ function requestSize(removes, ids, adds, added, version) {
240
+ return 1 + encodeVarint(removes, version).byteLength + encodeVarint(adds, version).byteLength + ids + added;
241
+ }
242
+ /** Whether the prefixes `set` fit the Adds of one ANNOUNCE_REQUEST, as a subscriber's whole set
243
+ * must. */
244
+ export function requestFits(set, version) {
245
+ let adds = 0;
246
+ let added = 0;
247
+ for (const prefix of set) {
248
+ adds++;
249
+ added += addSize(prefix, version);
250
+ }
251
+ return requestSize(0, 0, adds, added, version) <= MAX_MESSAGE_SIZE;
252
+ }
253
+ /**
254
+ * The ANNOUNCE_REQUESTs of one edit removing the Prefix IDs `remove` and adding `add`: as many as
255
+ * it takes for each to fit one message, every one but the last with `more`. The receiver applies
256
+ * them together at the last, so how they split changes nothing. Mirrors `request_parts` in
257
+ * rs/moq-net.
258
+ *
259
+ * @internal
260
+ */
261
+ export function requestParts(remove, add, version) {
262
+ const parts = [];
263
+ let part = { remove: [], add: [] };
264
+ let ids = 0;
265
+ let added = 0;
266
+ const fits = (id, adding) => requestSize(part.remove.length + (id > 0 ? 1 : 0), ids + id, part.add.length + (adding > 0 ? 1 : 0), added + adding, version) <= MAX_MESSAGE_SIZE;
267
+ const next = () => {
268
+ parts.push(part);
269
+ part = { remove: [], add: [] };
270
+ ids = 0;
271
+ added = 0;
272
+ };
273
+ for (const id of remove) {
274
+ const bytes = encodeVarint(id, version).byteLength;
275
+ if (!fits(bytes, 0))
276
+ next();
277
+ part.remove.push(id);
278
+ ids += bytes;
279
+ }
280
+ for (const one of add) {
281
+ const bytes = addSize(one.prefix, version);
282
+ if (!fits(0, bytes))
283
+ next();
284
+ part.add.push(one);
285
+ added += bytes;
286
+ }
287
+ parts.push(part);
288
+ return parts.map((part, i) => ({ status: "request", more: i + 1 < parts.length, ...part }));
143
289
  }
144
290
  // lite-06 message body (no discriminator; the type is carried outside the length prefix).
145
291
  async function encodeAnnounce06Body(w, msg, version) {
146
292
  switch (msg.status) {
147
293
  case "active":
148
- await encodePath(w, version, msg.suffix, msg.pathBase);
149
- await encodeHopsBlock(w, version, msg.hops, msg.hopBase);
294
+ if (hasRoutes(version))
295
+ throw new Error("a lite-07 claim names its identity");
296
+ await encodePath(w, version, msg.suffix, undefined);
297
+ await encodeRoute(w, version, undefined, undefined);
298
+ await encodeHops(w, version, msg.hops);
150
299
  await encodeRouteCost(w, version, msg.cost);
151
300
  break;
152
301
  case "endedId":
153
302
  await w.u62(msg.id);
303
+ if (hasRoutes(version))
304
+ await w.bool(msg.lost ?? false);
154
305
  break;
155
- case "restart":
306
+ case "update":
307
+ if (hasRoutes(version))
308
+ throw new Error("a lite-07 update carries its claim");
156
309
  await w.u62(msg.id);
157
- await encodeHopsBlock(w, version, msg.hops, msg.hopBase);
310
+ await encodeHops(w, version, msg.hops);
158
311
  await encodeRouteCost(w, version, msg.cost);
159
312
  break;
313
+ case "start":
314
+ if (!hasRoutes(version))
315
+ throw new Error("claims not supported for this version");
316
+ await encodePath(w, version, msg.suffix, msg.pathBase);
317
+ await encodeRoute(w, version, msg.identity, msg.claim.epoch);
318
+ await encodeClaim(w, msg.claim);
319
+ break;
320
+ case "change":
321
+ if (!hasRoutes(version))
322
+ throw new Error("claims not supported for this version");
323
+ await w.u62(msg.id);
324
+ await w.u62(msg.claim.epoch);
325
+ await encodeClaim(w, msg.claim);
326
+ break;
327
+ case "synced":
328
+ await w.u62(msg.prefix);
329
+ break;
330
+ case "request":
331
+ await encodeRequest(w, msg.more, msg.remove, msg.add);
332
+ break;
333
+ case "ok":
334
+ break;
160
335
  case "ended":
161
336
  // The pre-lite-06 path-form retraction has no place on lite-06.
162
337
  throw new Error("ended-by-path not supported for this version");
@@ -165,14 +340,28 @@ async function encodeAnnounce06Body(w, msg, version) {
165
340
  }
166
341
  }
167
342
  // lite-06 outer message type for a given announcement.
168
- function announce06Type(msg) {
343
+ function announce06Type(msg, version) {
169
344
  switch (msg.status) {
170
345
  case "active":
346
+ case "start":
171
347
  return ANNOUNCE_START;
172
348
  case "endedId":
173
349
  return ANNOUNCE_END;
174
- case "restart":
175
- return ANNOUNCE_RESTART;
350
+ case "update":
351
+ case "change":
352
+ return ANNOUNCE_UPDATE;
353
+ case "synced":
354
+ if (!hasSynced(version))
355
+ throw new Error("synced not supported for this version");
356
+ return SYNCED;
357
+ case "request":
358
+ if (!hasRoutes(version))
359
+ throw new Error("announce edits not supported for this version");
360
+ return ANNOUNCE_REQUEST;
361
+ case "ok":
362
+ if (!hasRoutes(version))
363
+ throw new Error("announce edits not supported for this version");
364
+ return ANNOUNCE_OK;
176
365
  case "ended":
177
366
  throw new Error("ended-by-path not supported for this version");
178
367
  case "skipped":
@@ -183,28 +372,62 @@ async function decodeAnnounce06Body(r, typ, version) {
183
372
  switch (typ) {
184
373
  case ANNOUNCE_START: {
185
374
  const path = await decodePath(r, version);
186
- const hops = await decodeHopsBlock(r, version);
187
- return { status: "active", ...path, ...hops, cost: await decodeRouteCost(r, version) };
375
+ const served = await decodeRoute(r, version);
376
+ if (hasRoutes(version)) {
377
+ // Every lite-07 claim names its identity.
378
+ if (served.identity === undefined)
379
+ throw new ProtocolViolation("a claim without an identity");
380
+ const claim = await decodeClaim(r, served.epoch ?? 0n);
381
+ return { status: "start", ...path, identity: served.identity, claim };
382
+ }
383
+ const hops = await decodeHops(r, version);
384
+ return { status: "active", suffix: path.suffix, hops, cost: await decodeRouteCost(r, version) };
188
385
  }
189
- case ANNOUNCE_END:
190
- return { status: "endedId", id: await r.u62() };
191
- case ANNOUNCE_RESTART: {
386
+ case ANNOUNCE_END: {
192
387
  const id = await r.u62();
193
- const hops = await decodeHopsBlock(r, version);
194
- return { status: "restart", id, ...hops, cost: await decodeRouteCost(r, version) };
388
+ return hasRoutes(version) ? { status: "endedId", id, lost: await r.bool() } : { status: "endedId", id };
195
389
  }
196
- default:
197
- // Skip the length-prefixed body so an earlier Lite06 build negotiating
198
- // the same ALPN does not kill the announce stream.
199
- await r.readAll();
200
- return { status: "skipped" };
201
- }
390
+ case ANNOUNCE_UPDATE: {
391
+ const id = await r.u62();
392
+ if (hasRoutes(version))
393
+ return { status: "change", id, claim: await decodeClaim(r, await r.u62()) };
394
+ const hops = await decodeHops(r, version);
395
+ return { status: "update", id, hops, cost: await decodeRouteCost(r, version) };
396
+ }
397
+ case SYNCED:
398
+ if (!hasSynced(version))
399
+ break;
400
+ return { status: "synced", prefix: await r.u62() };
401
+ case ANNOUNCE_REQUEST:
402
+ if (!hasRoutes(version))
403
+ break;
404
+ return decodeRequest(r);
405
+ case ANNOUNCE_OK:
406
+ if (!hasRoutes(version))
407
+ break;
408
+ return { status: "ok" };
409
+ case ANNOUNCE_FLOOR:
410
+ case ROUTE:
411
+ case ROUTE_END:
412
+ case DEAD:
413
+ case DRAIN:
414
+ if (!hasRoutes(version))
415
+ break;
416
+ // Only two nodes that both declared a Node ID exchange routes, and this one declares none.
417
+ throw new ProtocolViolation(`route message ${typ} to a node that declared no Node ID`);
418
+ }
419
+ // lite-07 defines every type its streams carry, so an unknown one is a violation.
420
+ if (hasRoutes(version))
421
+ throw new ProtocolViolation(`unknown announce message type ${typ}`);
422
+ // Lite06 skips the length-prefixed body so a build that predates a type negotiating
423
+ // the same ALPN does not kill the announce stream.
424
+ await r.readAll();
425
+ return { status: "skipped" };
202
426
  }
203
427
  // Pre-lite-06 single ANNOUNCE_BROADCAST body: an inner status byte, then path + hops.
204
428
  async function encodeLegacyBody(w, msg, version) {
205
429
  switch (msg.status) {
206
430
  case "active":
207
- checkBase(version, msg.pathBase ?? msg.hopBase);
208
431
  await w.u8(STATUS_ACTIVE);
209
432
  await w.string(Path.encode(msg.suffix));
210
433
  await encodeHops(w, version, msg.hops);
@@ -214,18 +437,16 @@ async function encodeLegacyBody(w, msg, version) {
214
437
  await w.string(Path.encode(msg.suffix));
215
438
  await encodeHops(w, version, []);
216
439
  break;
217
- case "endedId":
218
- case "restart":
219
- case "skipped":
440
+ default:
220
441
  // The id-referencing forms only exist on lite-06+.
221
442
  throw new Error("announce ids not supported for this version");
222
443
  }
223
444
  }
224
445
  async function decodeLegacyBody(r, version) {
225
446
  const status = await r.u8();
226
- // On lite-05 a restart travels as a duplicate `active`, but the explicit restart
227
- // status is accepted on decode and treated the same. Older versions never defined it.
228
- const active = status === STATUS_ACTIVE || (status === STATUS_RESTART && hasAnnounceOk(version));
447
+ // On lite-05 an update travels as a duplicate `active`, but the explicit update status
448
+ // is accepted on decode and treated the same. Older versions never defined it.
449
+ const active = status === STATUS_ACTIVE || (status === STATUS_UPDATE && hasAnnounceOk(version));
229
450
  if (status !== STATUS_ENDED && !active) {
230
451
  throw new Error("invalid announce status");
231
452
  }
@@ -237,8 +458,7 @@ async function decodeLegacyBody(r, version) {
237
458
  export async function encodeAnnounceBroadcast(w, msg, version) {
238
459
  if (hasAnnounceId(version)) {
239
460
  // lite-06+: outer type discriminator, then a size-prefixed body (like the subscribe stream).
240
- await w.u53(announce06Type(msg));
241
- return Message.encode(w, (w) => encodeAnnounce06Body(w, msg, version));
461
+ return Message.encode(w, (w) => encodeAnnounce06Body(w, msg, version), { id: announce06Type(msg, version) });
242
462
  }
243
463
  return Message.encode(w, (w) => encodeLegacyBody(w, msg, version));
244
464
  }
@@ -261,105 +481,104 @@ export async function decodeAnnounceBroadcastMaybe(r, version) {
261
481
  return Message.decodeMaybe(r, (r) => decodeLegacyBody(r, version));
262
482
  }
263
483
  /**
264
- * The live announcements on one lite-06+ announce stream, by Announce ID: what
265
- * ANNOUNCE_END and ANNOUNCE_UPDATE reference, and what a lite-07 base copies from.
266
- * Every violation throws {@link ProtocolViolation}.
484
+ * The live announcements on one lite-06+ announce stream, by Announce ID: what ANNOUNCE_END
485
+ * and ANNOUNCE_UPDATE reference, and what a lite-07 base copies from. Every
486
+ * violation throws {@link ProtocolViolation}.
267
487
  */
268
488
  export class AnnounceHistory {
269
489
  #next = 0n;
270
490
  #live = new Map();
271
- #base(base) {
272
- const live = this.#live.get(this.#next - base.distance);
273
- if (!live)
274
- throw new ProtocolViolation(`announce base ${base.distance} is not live`);
275
- return live;
276
- }
277
- #hops(hops, base) {
278
- if (!base)
279
- return hops;
280
- const tail = this.#base(base).hops;
281
- if (base.keep > tail.length)
282
- throw new ProtocolViolation(`announce keeps ${base.keep} of ${tail.length} hops`);
283
- const resolved = [...hops, ...tail.slice(tail.length - base.keep)];
284
- checkHops(resolved);
285
- return resolved;
286
- }
287
- /** An ANNOUNCE_START: resolve it and assign it the next id. */
491
+ // The live ids whose path was refused, which a base names only to be refused too.
492
+ #refused = new Set();
493
+ /** The Announce ID the next ANNOUNCE_START is assigned. */
494
+ get next() {
495
+ return this.#next;
496
+ }
497
+ /** An ANNOUNCE_START: assign it the next id, and resolve its suffix, or undefined when that
498
+ * suffix, or the base it names, is no path this node can hold. */
288
499
  start(msg) {
289
- let suffix = msg.suffix;
290
- if (msg.pathBase) {
291
- const head = Path.parts(this.#base(msg.pathBase).suffix);
292
- const keep = msg.pathBase.keep;
293
- if (keep > head.length)
294
- throw new ProtocolViolation(`announce keeps ${keep} of ${head.length} segments`);
295
- suffix = Path.join(Path.from(...head.slice(0, keep)), suffix);
296
- if (Path.parts(suffix).length > Path.MAX_PARTS) {
297
- throw new ProtocolViolation(`path exceeds ${Path.MAX_PARTS} parts`);
298
- }
299
- }
300
- const hops = this.#hops(msg.hops, msg.hopBase);
301
- this.#live.set(this.#next++, { suffix, hops });
302
- return { suffix, hops };
303
- }
304
- /** An ANNOUNCE_UPDATE: resolve its chain before replacing the old one, which it may be based on. */
305
- update(msg) {
306
- const hops = this.#hops(msg.hops, msg.hopBase);
307
- const live = this.#live.get(msg.id);
308
- if (!live)
309
- throw new ProtocolViolation(`unknown announce id: ${msg.id}`);
310
- this.#live.set(msg.id, { suffix: live.suffix, hops });
311
- return { suffix: live.suffix, hops };
312
- }
313
- /** An ANNOUNCE_END: retire the id, returning its suffix. */
314
- end(id) {
500
+ const suffix = msg && this.#resolve(msg);
501
+ const id = this.#next++;
502
+ if (suffix === undefined)
503
+ this.#refused.add(id);
504
+ else
505
+ this.#live.set(id, suffix);
506
+ return suffix;
507
+ }
508
+ #resolve(msg) {
509
+ const suffix = msg.suffix;
510
+ if (!msg.pathBase)
511
+ return suffix;
512
+ const id = this.#next - msg.pathBase.distance;
513
+ if (this.#refused.has(id))
514
+ return undefined;
515
+ const base = this.#live.get(id);
516
+ if (base === undefined)
517
+ throw new ProtocolViolation(`announce base ${msg.pathBase.distance} is not live`);
518
+ // A keep counts whole parts, so a kept head never ends inside an escape.
519
+ const head = Path.parts(base);
520
+ const keep = msg.pathBase.keep;
521
+ if (keep > head.length)
522
+ throw new ProtocolViolation(`announce keeps ${keep} of ${head.length} parts`);
523
+ // A path that does not resolve, such as one too deep, is refused as content, as rs/moq-net does.
524
+ const kept = head.slice(0, keep);
525
+ if (suffix !== Path.empty())
526
+ kept.push(suffix);
527
+ return Path.tryDecode(kept.join("/"));
528
+ }
529
+ /** The suffix of the live announcement `id`, which an update references. */
530
+ get(id) {
315
531
  const live = this.#live.get(id);
316
- if (!live)
532
+ if (live === undefined)
317
533
  throw new ProtocolViolation(`unknown announce id: ${id}`);
534
+ return live;
535
+ }
536
+ /** An ANNOUNCE_END: retire the id, returning its suffix, or undefined if it was refused. */
537
+ end(id) {
538
+ if (this.#refused.delete(id))
539
+ return undefined;
540
+ const live = this.get(id);
318
541
  this.#live.delete(id);
319
- return live.suffix;
542
+ return live;
320
543
  }
321
544
  }
322
545
  /**
323
- * ANNOUNCE_REQUEST: sent by the subscriber to request ANNOUNCE_BROADCAST messages
324
- * for a path prefix. Renamed from `AnnounceInterest` in lite-05.
546
+ * ANNOUNCE_REQUEST before lite-07: sent by the subscriber to request ANNOUNCE_BROADCAST messages
547
+ * for a path prefix, opening a bidirectional Announce Stream. Renamed from `AnnounceInterest` in
548
+ * lite-05. Lite-07 edits a set of prefixes on its one stream instead (the `request` message).
325
549
  */
326
550
  export class AnnounceRequest {
327
551
  prefix;
328
- /** Lite04/05 only: the 62-bit Hop id of the peer asking for announces, which the
329
- * publisher uses to skip announces that already passed through it. Zero means "no
330
- * exclusion". Not on the wire elsewhere, so a value set here is ignored when encoding
331
- * for another version and decodes as zero.
332
- *
333
- * Must be a bigint: peer origins are up to 62 bits and overflow u53. */
552
+ /** Lite04/05 only: the Hop id of the peer asking for announces, which the publisher
553
+ * uses to skip announces that already passed through it. {@link UNKNOWN_HOP} means
554
+ * "no exclusion". Not on the wire elsewhere, so a value set here is ignored when
555
+ * encoding for another version and decodes as unknown. */
334
556
  excludeHop;
335
- /** Lite07+: also announce routes with a `.`-prefixed segment below the prefix. Not on
336
- * the wire earlier, so a value set here is ignored when encoding for an older version
337
- * and decodes as false. */
338
- hidden;
339
- constructor(prefix, excludeHop = 0n, hidden = false) {
557
+ constructor(prefix, excludeHop = UNKNOWN_HOP) {
340
558
  this.prefix = prefix;
341
559
  this.excludeHop = excludeHop;
342
- this.hidden = hidden;
560
+ }
561
+ static #guard(version) {
562
+ if (hasRoutes(version))
563
+ throw new Error("announce request streams not supported for this version");
343
564
  }
344
565
  async #encode(w, version) {
345
566
  await w.string(Path.encode(this.prefix));
346
567
  if (hasExcludeHop(version)) {
347
- await w.u62(this.excludeHop);
348
- }
349
- if (hasHidden(version)) {
350
- await w.bool(this.hidden);
568
+ await w.u62(wireHop(this.excludeHop, version));
351
569
  }
352
570
  }
353
571
  static async #decode(r, version) {
354
572
  const prefix = Path.decode(await r.string());
355
- const excludeHop = hasExcludeHop(version) ? await r.u62() : 0n;
356
- const hidden = hasHidden(version) ? await r.bool() : false;
357
- return new AnnounceRequest(prefix, excludeHop, hidden);
573
+ const excludeHop = hasExcludeHop(version) ? toHop(await r.u62()) : UNKNOWN_HOP;
574
+ return new AnnounceRequest(prefix, excludeHop);
358
575
  }
359
576
  async encode(w, version) {
577
+ AnnounceRequest.#guard(version);
360
578
  return Message.encode(w, (w) => this.#encode(w, version));
361
579
  }
362
580
  static async decode(r, version) {
581
+ AnnounceRequest.#guard(version);
363
582
  return Message.decode(r, (r) => AnnounceRequest.#decode(r, version));
364
583
  }
365
584
  }
@@ -386,30 +605,38 @@ export class AnnounceInit {
386
605
  await w.string(Path.encode(path));
387
606
  }
388
607
  }
389
- static async #decode(r) {
608
+ static async #decode(r, budget) {
390
609
  const count = await r.u53();
610
+ // Refused before decoding any, so the set grows no larger than what may be announced.
611
+ if (count > budget)
612
+ throw new Error(`announce init lists ${count} broadcasts with ${budget} slots left`);
391
613
  const suffixes = [];
392
614
  for (let i = 0; i < count; i++) {
393
615
  suffixes.push(Path.decode(await r.string()));
394
616
  }
395
617
  return new AnnounceInit(suffixes);
396
618
  }
619
+ // The whole initial set in one message, capped like Rust's so it fits one storage segment
620
+ // (1 MiB) with its type and size prefixes. A larger set is refused on both ends.
621
+ static MAX_SIZE = SEGMENT_BYTES - 16;
397
622
  async encode(w, version) {
398
623
  AnnounceInit.#guard(version);
399
- return Message.encode(w, this.#encode.bind(this));
624
+ return Message.encode(w, this.#encode.bind(this), { max: AnnounceInit.MAX_SIZE });
400
625
  }
401
- static async decode(r, version) {
626
+ /** Decode the initial set, refusing one that lists more than `budget` broadcasts. */
627
+ static async decode(r, version, budget) {
402
628
  AnnounceInit.#guard(version);
403
- return Message.decode(r, AnnounceInit.#decode);
629
+ return Message.decode(r, (r) => AnnounceInit.#decode(r, budget), AnnounceInit.MAX_SIZE);
404
630
  }
405
631
  }
406
632
  /// Sent by the publisher as the first message on an announce stream, before any
407
- /// individual Announce messages. Lite05+ only; the successor to AnnounceInit.
633
+ /// individual Announce messages. Lite05/06 only; the successor to AnnounceInit. Lite-07 answers
634
+ /// on its one stream instead (the `ok` message).
408
635
  ///
409
636
  /// `origin` is the responder's Hop ID, which the subscriber stamps onto each
410
637
  /// announce's hop chain (the publisher no longer stamps itself), or the reserved
411
- /// {@link UNKNOWN_HOP} when the responder has no identity to give. `active` is
412
- /// the number of initial Announce messages that follow immediately.
638
+ /// {@link UNKNOWN_HOP} when the responder has no identity to give. `active` is the
639
+ /// initial start count.
413
640
  export class AnnounceOk {
414
641
  hop;
415
642
  active;
@@ -418,25 +645,24 @@ export class AnnounceOk {
418
645
  this.active = active;
419
646
  }
420
647
  static #guard(version) {
421
- if (!hasAnnounceOk(version)) {
648
+ if (!hasAnnounceOk(version) || hasRoutes(version)) {
422
649
  throw new Error("announce ok not supported for this version");
423
650
  }
424
651
  }
425
- async #encode(w) {
426
- await w.u62(this.hop);
652
+ async #encode(w, version) {
653
+ await w.u62(wireHop(this.hop, version));
427
654
  await w.u53(this.active);
428
655
  }
429
656
  static async #decode(r) {
430
657
  // The draft reserves 0 for "unknown": the responder was never assigned an id, or
431
658
  // withholds it to obscure its routing. It names nobody, so callers must not stamp
432
659
  // it onto a hop chain, but it is a legal message and not grounds to drop the stream.
433
- const origin = HopSchema.parse(await r.u62());
434
- const active = await r.u53();
435
- return new AnnounceOk(origin, active);
660
+ const origin = toHop(await r.u62());
661
+ return new AnnounceOk(origin, await r.u53());
436
662
  }
437
663
  async encode(w, version) {
438
664
  AnnounceOk.#guard(version);
439
- return Message.encode(w, this.#encode.bind(this));
665
+ return Message.encode(w, (w) => this.#encode(w, version));
440
666
  }
441
667
  static async decode(r, version) {
442
668
  AnnounceOk.#guard(version);