@moq/net 0.4.7 → 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 (664) 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 -2
  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 -32
  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 -139
  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 -2
  33. package/bandwidth_api.js.map +1 -1
  34. package/broadcast.d.ts +64 -38
  35. package/broadcast.d.ts.map +1 -1
  36. package/broadcast.js +556 -173
  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 +21 -13
  47. package/connection/accept.d.ts.map +1 -1
  48. package/connection/accept.js +97 -130
  49. package/connection/accept.js.map +1 -1
  50. package/connection/browser.d.ts.map +1 -1
  51. package/connection/browser.js +28 -20
  52. package/connection/browser.js.map +1 -1
  53. package/connection/connect.d.ts +120 -24
  54. package/connection/connect.d.ts.map +1 -1
  55. package/connection/connect.js +535 -217
  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 -81
  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 -95
  72. package/connection/goaway.js.map +1 -1
  73. package/connection/handshake.d.ts +34 -8
  74. package/connection/handshake.d.ts.map +1 -1
  75. package/connection/handshake.js +97 -21
  76. package/connection/handshake.js.map +1 -1
  77. package/connection/index.d.ts +4 -7
  78. package/connection/index.d.ts.map +1 -1
  79. package/connection/index.js +1 -3
  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 +142 -63
  86. package/connection/pool.d.ts.map +1 -1
  87. package/connection/pool.js +281 -118
  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 -234
  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 -9
  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 -5
  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 -47
  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 -2
  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 -38
  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 -3
  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 -308
  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 -65
  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 -36
  199. package/ietf/aliases.js.map +1 -1
  200. package/ietf/cluster.d.ts +3 -3
  201. package/ietf/cluster.js +14 -55
  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 -144
  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 -101
  213. package/ietf/error.js.map +1 -1
  214. package/ietf/fetch.d.ts +93 -37
  215. package/ietf/fetch.d.ts.map +1 -1
  216. package/ietf/fetch.js +172 -94
  217. package/ietf/fetch.js.map +1 -1
  218. package/ietf/filter.d.ts +21 -31
  219. package/ietf/filter.d.ts.map +1 -1
  220. package/ietf/filter.js +140 -172
  221. package/ietf/filter.js.map +1 -1
  222. package/ietf/goaway.d.ts +12 -10
  223. package/ietf/goaway.d.ts.map +1 -1
  224. package/ietf/goaway.js +22 -36
  225. package/ietf/goaway.js.map +1 -1
  226. package/ietf/hidden.js +1 -2
  227. package/ietf/hidden.js.map +1 -1
  228. package/ietf/index.d.ts +8 -20
  229. package/ietf/index.d.ts.map +1 -1
  230. package/ietf/index.js +4 -15
  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 -41
  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 +19 -5
  245. package/ietf/namespace.d.ts.map +1 -1
  246. package/ietf/namespace.js +78 -27
  247. package/ietf/namespace.js.map +1 -1
  248. package/ietf/object.d.ts +195 -33
  249. package/ietf/object.d.ts.map +1 -1
  250. package/ietf/object.js +405 -179
  251. package/ietf/object.js.map +1 -1
  252. package/ietf/parameters.d.ts +25 -45
  253. package/ietf/parameters.d.ts.map +1 -1
  254. package/ietf/parameters.js +260 -473
  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 -5
  259. package/ietf/priority.js.map +1 -1
  260. package/ietf/properties.d.ts +6 -5
  261. package/ietf/properties.d.ts.map +1 -1
  262. package/ietf/properties.js +78 -49
  263. package/ietf/properties.js.map +1 -1
  264. package/ietf/publish.d.ts +25 -33
  265. package/ietf/publish.d.ts.map +1 -1
  266. package/ietf/publish.js +45 -140
  267. package/ietf/publish.js.map +1 -1
  268. package/ietf/publish_namespace.d.ts +49 -72
  269. package/ietf/publish_namespace.d.ts.map +1 -1
  270. package/ietf/publish_namespace.js +66 -185
  271. package/ietf/publish_namespace.js.map +1 -1
  272. package/ietf/publisher.js +1800 -601
  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 +6 -30
  279. package/ietf/request.d.ts.map +1 -1
  280. package/ietf/request.js +41 -79
  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 -17
  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 +5 -30
  291. package/ietf/setup.d.ts.map +1 -1
  292. package/ietf/setup.js +6 -118
  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 -15
  299. package/ietf/solicit.js.map +1 -1
  300. package/ietf/subscribe.d.ts +52 -45
  301. package/ietf/subscribe.d.ts.map +1 -1
  302. package/ietf/subscribe.js +118 -240
  303. package/ietf/subscribe.js.map +1 -1
  304. package/ietf/subscribe_namespace.d.ts +16 -79
  305. package/ietf/subscribe_namespace.d.ts.map +1 -1
  306. package/ietf/subscribe_namespace.js +30 -202
  307. package/ietf/subscribe_namespace.js.map +1 -1
  308. package/ietf/subscriber.js +1839 -537
  309. package/ietf/subscriber.js.map +1 -1
  310. package/ietf/token.js +105 -28
  311. package/ietf/token.js.map +1 -1
  312. package/ietf/track.d.ts +27 -24
  313. package/ietf/track.d.ts.map +1 -1
  314. package/ietf/track.js +48 -62
  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 -49
  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 +34 -19
  325. package/index.d.ts.map +1 -1
  326. package/index.js +19 -7
  327. package/index.js.map +1 -1
  328. package/internal.d.ts +1515 -67
  329. package/internal.d.ts.map +1 -1
  330. package/internal.js +557 -80
  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 +127 -66
  341. package/lite/announce.d.ts.map +1 -1
  342. package/lite/announce.js +384 -159
  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 -78
  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 -10
  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 +2 -2
  389. package/lite/goaway.d.ts.map +1 -1
  390. package/lite/goaway.js +5 -14
  391. package/lite/goaway.js.map +1 -1
  392. package/lite/group.d.ts +67 -16
  393. package/lite/group.d.ts.map +1 -1
  394. package/lite/group.js +108 -31
  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 +14 -13
  401. package/lite/index.d.ts.map +1 -1
  402. package/lite/index.js +2 -2
  403. package/lite/index.js.map +1 -1
  404. package/lite/message.d.ts +10 -2
  405. package/lite/message.d.ts.map +1 -1
  406. package/lite/message.js +28 -45
  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 -106
  411. package/lite/priority.js.map +1 -1
  412. package/lite/probe.d.ts +2 -2
  413. package/lite/probe.d.ts.map +1 -1
  414. package/lite/probe.js +9 -1
  415. package/lite/probe.js.map +1 -1
  416. package/lite/publisher.d.ts +10 -1
  417. package/lite/publisher.d.ts.map +1 -1
  418. package/lite/publisher.js +2548 -438
  419. package/lite/publisher.js.map +1 -1
  420. package/lite/routed.d.ts +59 -0
  421. package/lite/routed.d.ts.map +1 -0
  422. package/lite/routed.js +564 -0
  423. package/lite/routed.js.map +1 -0
  424. package/lite/session.d.ts +2 -28
  425. package/lite/session.d.ts.map +1 -1
  426. package/lite/session.js +0 -100
  427. package/lite/session.js.map +1 -1
  428. package/lite/setup.d.ts +32 -5
  429. package/lite/setup.d.ts.map +1 -1
  430. package/lite/setup.js +95 -22
  431. package/lite/setup.js.map +1 -1
  432. package/lite/stream.d.ts +5 -11
  433. package/lite/stream.d.ts.map +1 -1
  434. package/lite/stream.js +5 -2
  435. package/lite/stream.js.map +1 -1
  436. package/lite/subscribe.d.ts +478 -78
  437. package/lite/subscribe.d.ts.map +1 -1
  438. package/lite/subscribe.js +1373 -143
  439. package/lite/subscribe.js.map +1 -1
  440. package/lite/subscriber.d.ts +7 -44
  441. package/lite/subscriber.d.ts.map +1 -1
  442. package/lite/subscriber.js +3290 -516
  443. package/lite/subscriber.js.map +1 -1
  444. package/lite/track.d.ts +27 -12
  445. package/lite/track.d.ts.map +1 -1
  446. package/lite/track.js +116 -38
  447. package/lite/track.js.map +1 -1
  448. package/lite/tracks.d.ts +55 -0
  449. package/lite/tracks.d.ts.map +1 -0
  450. package/lite/tracks.js +114 -0
  451. package/lite/tracks.js.map +1 -0
  452. package/lite/version.d.ts +132 -24
  453. package/lite/version.d.ts.map +1 -1
  454. package/lite/version.js +378 -34
  455. package/lite/version.js.map +1 -1
  456. package/meta.d.ts +77 -0
  457. package/meta.d.ts.map +1 -0
  458. package/meta.js +130 -0
  459. package/meta.js.map +1 -0
  460. package/meta_api.d.ts +7 -0
  461. package/meta_api.d.ts.map +1 -0
  462. package/meta_api.js +7 -0
  463. package/meta_api.js.map +1 -0
  464. package/mint.d.ts +28 -0
  465. package/mint.d.ts.map +1 -0
  466. package/mint.js +66 -0
  467. package/mint.js.map +1 -0
  468. package/open.d.ts +63 -0
  469. package/open.d.ts.map +1 -0
  470. package/open.js +250 -0
  471. package/open.js.map +1 -0
  472. package/origin.d.ts +394 -142
  473. package/origin.d.ts.map +1 -1
  474. package/origin.js +2533 -687
  475. package/origin.js.map +1 -1
  476. package/package.json +8 -13
  477. package/path.d.ts +51 -51
  478. package/path.d.ts.map +1 -1
  479. package/path.js +210 -58
  480. package/path.js.map +1 -1
  481. package/payload.d.ts +33 -0
  482. package/payload.d.ts.map +1 -0
  483. package/payload.js +65 -0
  484. package/payload.js.map +1 -0
  485. package/prefix.d.ts +152 -0
  486. package/prefix.d.ts.map +1 -0
  487. package/prefix.js +349 -0
  488. package/prefix.js.map +1 -0
  489. package/priority.d.ts +8 -0
  490. package/priority.d.ts.map +1 -0
  491. package/priority.js +185 -0
  492. package/priority.js.map +1 -0
  493. package/queue.d.ts +2 -0
  494. package/queue.d.ts.map +1 -0
  495. package/queue.js +46 -0
  496. package/queue.js.map +1 -0
  497. package/ranges.d.ts +36 -0
  498. package/ranges.d.ts.map +1 -0
  499. package/ranges.js +312 -0
  500. package/ranges.js.map +1 -0
  501. package/rescale.d.ts +24 -0
  502. package/rescale.d.ts.map +1 -0
  503. package/rescale.js +39 -0
  504. package/rescale.js.map +1 -0
  505. package/resume.d.ts +55 -0
  506. package/resume.d.ts.map +1 -0
  507. package/resume.js +4173 -0
  508. package/resume.js.map +1 -0
  509. package/resume.test-util.d.ts +2 -0
  510. package/resume.test-util.d.ts.map +1 -0
  511. package/resume.test-util.js +25 -0
  512. package/resume.test-util.js.map +1 -0
  513. package/skips.d.ts +48 -0
  514. package/skips.d.ts.map +1 -0
  515. package/skips.js +182 -0
  516. package/skips.js.map +1 -0
  517. package/stream.d.ts +78 -40
  518. package/stream.d.ts.map +1 -1
  519. package/stream.js +236 -93
  520. package/stream.js.map +1 -1
  521. package/subscription.test-util.d.ts +2 -0
  522. package/subscription.test-util.d.ts.map +1 -0
  523. package/subscription.test-util.js +49 -0
  524. package/subscription.test-util.js.map +1 -0
  525. package/tail.d.ts +23 -14
  526. package/tail.d.ts.map +1 -1
  527. package/tail.js +224 -98
  528. package/tail.js.map +1 -1
  529. package/time.d.ts +41 -102
  530. package/time.d.ts.map +1 -1
  531. package/time.js +129 -92
  532. package/time.js.map +1 -1
  533. package/timed.d.ts +21 -0
  534. package/timed.d.ts.map +1 -0
  535. package/timed.js +2 -0
  536. package/timed.js.map +1 -0
  537. package/track.d.ts +578 -246
  538. package/track.d.ts.map +1 -1
  539. package/track.js +7306 -772
  540. package/track.js.map +1 -1
  541. package/track_api.d.ts +7 -0
  542. package/track_api.d.ts.map +1 -0
  543. package/track_api.js +7 -0
  544. package/track_api.js.map +1 -0
  545. package/util/abort.d.ts +1 -0
  546. package/util/abort.d.ts.map +1 -1
  547. package/util/abort.js +23 -2
  548. package/util/abort.js.map +1 -1
  549. package/util/announce.d.ts +4 -0
  550. package/util/announce.d.ts.map +1 -0
  551. package/util/announce.js +11 -0
  552. package/util/announce.js.map +1 -0
  553. package/util/bigint.d.ts +3 -0
  554. package/util/bigint.d.ts.map +1 -0
  555. package/util/bigint.js +8 -0
  556. package/util/bigint.js.map +1 -0
  557. package/util/change.d.ts +12 -0
  558. package/util/change.d.ts.map +1 -0
  559. package/util/change.js +18 -0
  560. package/util/change.js.map +1 -0
  561. package/util/deadline.d.ts +2 -0
  562. package/util/deadline.d.ts.map +1 -0
  563. package/util/deadline.js +108 -0
  564. package/util/deadline.js.map +1 -0
  565. package/util/decode_error.d.ts +3 -0
  566. package/util/decode_error.d.ts.map +1 -0
  567. package/util/decode_error.js +11 -0
  568. package/util/decode_error.js.map +1 -0
  569. package/util/demand.d.ts +8 -0
  570. package/util/demand.d.ts.map +1 -0
  571. package/util/demand.js +24 -0
  572. package/util/demand.js.map +1 -0
  573. package/util/given_up.d.ts +2 -0
  574. package/util/given_up.d.ts.map +1 -0
  575. package/util/given_up.js +101 -0
  576. package/util/given_up.js.map +1 -0
  577. package/util/hex.d.ts +6 -0
  578. package/util/hex.d.ts.map +1 -1
  579. package/util/hex.js +19 -5
  580. package/util/hex.js.map +1 -1
  581. package/util/key.d.ts +15 -0
  582. package/util/key.d.ts.map +1 -0
  583. package/util/key.js +38 -0
  584. package/util/key.js.map +1 -0
  585. package/util/limits.d.ts +2 -0
  586. package/util/limits.d.ts.map +1 -0
  587. package/util/limits.js +76 -0
  588. package/util/limits.js.map +1 -0
  589. package/util/observed.d.ts +23 -0
  590. package/util/observed.d.ts.map +1 -0
  591. package/util/observed.js +122 -0
  592. package/util/observed.js.map +1 -0
  593. package/util/sorted.d.ts +2 -0
  594. package/util/sorted.d.ts.map +1 -0
  595. package/util/sorted.js +149 -0
  596. package/util/sorted.js.map +1 -0
  597. package/util/timeout.d.ts +2 -1
  598. package/util/timeout.d.ts.map +1 -1
  599. package/util/timeout.js +13 -10
  600. package/util/timeout.js.map +1 -1
  601. package/util/timer.d.ts +2 -0
  602. package/util/timer.d.ts.map +1 -0
  603. package/util/timer.js +19 -0
  604. package/util/timer.js.map +1 -0
  605. package/util/u64.js +0 -1
  606. package/util/utf8.d.ts +2 -0
  607. package/util/utf8.d.ts.map +1 -1
  608. package/util/utf8.js +7 -2
  609. package/util/utf8.js.map +1 -1
  610. package/util/varint.d.ts.map +1 -1
  611. package/util/varint.js +8 -2
  612. package/util/varint.js.map +1 -1
  613. package/util/watch.d.ts +8 -0
  614. package/util/watch.d.ts.map +1 -0
  615. package/util/watch.js +38 -0
  616. package/util/watch.js.map +1 -0
  617. package/util/yield.d.ts +2 -0
  618. package/util/yield.d.ts.map +1 -0
  619. package/util/yield.js +31 -0
  620. package/util/yield.js.map +1 -0
  621. package/varint.d.ts +0 -29
  622. package/varint.d.ts.map +1 -1
  623. package/varint.js +7 -29
  624. package/varint.js.map +1 -1
  625. package/varint_api.d.ts +7 -0
  626. package/varint_api.d.ts.map +1 -0
  627. package/varint_api.js +7 -0
  628. package/varint_api.js.map +1 -0
  629. package/version.d.ts +2 -0
  630. package/version.d.ts.map +1 -0
  631. package/version.js +4 -0
  632. package/version.js.map +1 -0
  633. package/window.d.ts +570 -0
  634. package/window.d.ts.map +1 -0
  635. package/window.js +1677 -0
  636. package/window.js.map +1 -0
  637. package/wire.d.ts +150 -35
  638. package/wire.d.ts.map +1 -1
  639. package/wire.js +27 -1
  640. package/wire.js.map +1 -1
  641. package/connection/established.d.ts +0 -53
  642. package/connection/established.d.ts.map +0 -1
  643. package/connection/established.js +0 -3
  644. package/connection/established.js.map +0 -1
  645. package/ietf/adapter.d.ts +0 -75
  646. package/ietf/adapter.d.ts.map +0 -1
  647. package/ietf/adapter.js +0 -700
  648. package/ietf/adapter.js.map +0 -1
  649. package/lite/datagram_stream.d.ts +0 -8
  650. package/lite/datagram_stream.d.ts.map +0 -1
  651. package/lite/datagram_stream.js +0 -44
  652. package/lite/datagram_stream.js.map +0 -1
  653. package/lite/fetch.d.ts +0 -28
  654. package/lite/fetch.d.ts.map +0 -1
  655. package/lite/fetch.js +0 -79
  656. package/lite/fetch.js.map +0 -1
  657. package/util/log.d.ts +0 -5
  658. package/util/log.d.ts.map +0 -1
  659. package/util/log.js +0 -17
  660. package/util/log.js.map +0 -1
  661. package/zod.d.ts +0 -13
  662. package/zod.d.ts.map +0 -1
  663. package/zod.js +0 -19
  664. package/zod.js.map +0 -1
package/lite/announce.js CHANGED
@@ -1,19 +1,57 @@
1
- /* @ts-self-types="./announce.d.ts" */
2
1
  import { ProtocolViolation } from "../error.js";
3
- import { HopSchema, MAX_HOPS, UNKNOWN_HOP } from "../hop.js";
2
+ import { MAX_HOPS, toHop, UNKNOWN_HOP, wireHop } from "../hop.js";
4
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";
5
7
  import * as Message from "./message.js";
6
- 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";
7
11
  // Pre-lite-06 inner status values, carried inside the single ANNOUNCE_BROADCAST body.
8
12
  const STATUS_ENDED = 0;
9
13
  const STATUS_ACTIVE = 1;
10
- const STATUS_RESTART = 2;
14
+ // The lite-05 draft's explicit `restart` status: a metadata update.
15
+ const STATUS_UPDATE = 2;
11
16
  // lite-06 announce message types: an outer discriminator carried before the length
12
17
  // prefix, so each announcement is an independently-typed, length-delimited message
13
18
  // (mirroring SUBSCRIBE_START/END/DROP on the subscribe stream).
14
19
  const ANNOUNCE_START = 0;
15
20
  const ANNOUNCE_END = 1;
16
- 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
+ }
17
55
  // Both wire rules on a hop chain, applied to what we send and to what we receive: a
18
56
  // chain that revisits a hop looped, so neither forwarding it nor subscribing through it
19
57
  // is safe, and a receiver must end the session over one. `UNKNOWN_HOP` identifies
@@ -35,7 +73,7 @@ function checkHops(hops) {
35
73
  }
36
74
  }
37
75
  }
38
- async function encodeHops(w, version, hops) {
76
+ async function encodeHops(w, version, hops = []) {
39
77
  checkHops(hops);
40
78
  switch (version) {
41
79
  case Version.DRAFT_01:
@@ -48,7 +86,7 @@ async function encodeHops(w, version, hops) {
48
86
  // Lite04+: hop count + individual Hop varints.
49
87
  await w.u53(hops.length);
50
88
  for (const origin of hops) {
51
- await w.u62(origin);
89
+ await w.u62(wireHop(origin, version));
52
90
  }
53
91
  break;
54
92
  }
@@ -73,91 +111,227 @@ async function decodeHops(r, version) {
73
111
  throw new Error(`hop count ${count} exceeds maximum ${MAX_HOPS}`);
74
112
  const hops = [];
75
113
  for (let i = 0; i < count; i++) {
76
- hops.push(HopSchema.parse(await r.u62()));
114
+ hops.push(toHop(await r.u62()));
77
115
  }
78
116
  checkHops(hops);
79
117
  return hops;
80
118
  }
81
119
  }
82
120
  }
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
121
  async function encodePath(w, version, suffix, base) {
99
- checkBase(version, base);
100
122
  if (hasAnnounceCompression(version)) {
101
123
  await w.u62(base?.distance ?? 0n);
102
124
  await w.u53(base?.keep ?? 0);
103
125
  }
126
+ else if (base) {
127
+ throw new Error("announce compression not supported for this version");
128
+ }
104
129
  await w.string(Path.encode(suffix));
105
130
  }
106
131
  async function decodePath(r, version) {
107
132
  if (!hasAnnounceCompression(version))
108
133
  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
134
  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 };
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 } };
128
141
  }
129
- // The route cost rides lite-06+ announcements as two varints, warm then cold; older
130
- // 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
131
144
  // varints could carry more, so a cost always forwards to a peer on an older version.
132
145
  const MAX_COST = 2n ** 62n - 1n;
133
146
  const saturate = (v) => (v > MAX_COST ? MAX_COST : v);
134
147
  async function encodeRouteCost(w, version, cost) {
135
148
  if (!hasRouteCost(version))
136
149
  return;
137
- await w.u62(saturate(cost?.warm ?? 0n));
138
- 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);
139
153
  }
140
154
  async function decodeRouteCost(r, version) {
141
155
  if (!hasRouteCost(version))
142
156
  return undefined;
143
- 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 }));
144
289
  }
145
290
  // lite-06 message body (no discriminator; the type is carried outside the length prefix).
146
291
  async function encodeAnnounce06Body(w, msg, version) {
147
292
  switch (msg.status) {
148
293
  case "active":
149
- await encodePath(w, version, msg.suffix, msg.pathBase);
150
- 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);
151
299
  await encodeRouteCost(w, version, msg.cost);
152
300
  break;
153
301
  case "endedId":
154
302
  await w.u62(msg.id);
303
+ if (hasRoutes(version))
304
+ await w.bool(msg.lost ?? false);
155
305
  break;
156
- case "restart":
306
+ case "update":
307
+ if (hasRoutes(version))
308
+ throw new Error("a lite-07 update carries its claim");
157
309
  await w.u62(msg.id);
158
- await encodeHopsBlock(w, version, msg.hops, msg.hopBase);
310
+ await encodeHops(w, version, msg.hops);
159
311
  await encodeRouteCost(w, version, msg.cost);
160
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;
161
335
  case "ended":
162
336
  // The pre-lite-06 path-form retraction has no place on lite-06.
163
337
  throw new Error("ended-by-path not supported for this version");
@@ -166,14 +340,28 @@ async function encodeAnnounce06Body(w, msg, version) {
166
340
  }
167
341
  }
168
342
  // lite-06 outer message type for a given announcement.
169
- function announce06Type(msg) {
343
+ function announce06Type(msg, version) {
170
344
  switch (msg.status) {
171
345
  case "active":
346
+ case "start":
172
347
  return ANNOUNCE_START;
173
348
  case "endedId":
174
349
  return ANNOUNCE_END;
175
- case "restart":
176
- 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;
177
365
  case "ended":
178
366
  throw new Error("ended-by-path not supported for this version");
179
367
  case "skipped":
@@ -184,28 +372,62 @@ async function decodeAnnounce06Body(r, typ, version) {
184
372
  switch (typ) {
185
373
  case ANNOUNCE_START: {
186
374
  const path = await decodePath(r, version);
187
- const hops = await decodeHopsBlock(r, version);
188
- 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) };
189
385
  }
190
- case ANNOUNCE_END:
191
- return { status: "endedId", id: await r.u62() };
192
- case ANNOUNCE_RESTART: {
386
+ case ANNOUNCE_END: {
193
387
  const id = await r.u62();
194
- const hops = await decodeHopsBlock(r, version);
195
- return { status: "restart", id, ...hops, cost: await decodeRouteCost(r, version) };
388
+ return hasRoutes(version) ? { status: "endedId", id, lost: await r.bool() } : { status: "endedId", id };
196
389
  }
197
- default:
198
- // Skip the length-prefixed body so an earlier Lite06 build negotiating
199
- // the same ALPN does not kill the announce stream.
200
- await r.readAll();
201
- return { status: "skipped" };
202
- }
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" };
203
426
  }
204
427
  // Pre-lite-06 single ANNOUNCE_BROADCAST body: an inner status byte, then path + hops.
205
428
  async function encodeLegacyBody(w, msg, version) {
206
429
  switch (msg.status) {
207
430
  case "active":
208
- checkBase(version, msg.pathBase ?? msg.hopBase);
209
431
  await w.u8(STATUS_ACTIVE);
210
432
  await w.string(Path.encode(msg.suffix));
211
433
  await encodeHops(w, version, msg.hops);
@@ -215,18 +437,16 @@ async function encodeLegacyBody(w, msg, version) {
215
437
  await w.string(Path.encode(msg.suffix));
216
438
  await encodeHops(w, version, []);
217
439
  break;
218
- case "endedId":
219
- case "restart":
220
- case "skipped":
440
+ default:
221
441
  // The id-referencing forms only exist on lite-06+.
222
442
  throw new Error("announce ids not supported for this version");
223
443
  }
224
444
  }
225
445
  async function decodeLegacyBody(r, version) {
226
446
  const status = await r.u8();
227
- // On lite-05 a restart travels as a duplicate `active`, but the explicit restart
228
- // status is accepted on decode and treated the same. Older versions never defined it.
229
- 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));
230
450
  if (status !== STATUS_ENDED && !active) {
231
451
  throw new Error("invalid announce status");
232
452
  }
@@ -238,8 +458,7 @@ async function decodeLegacyBody(r, version) {
238
458
  export async function encodeAnnounceBroadcast(w, msg, version) {
239
459
  if (hasAnnounceId(version)) {
240
460
  // lite-06+: outer type discriminator, then a size-prefixed body (like the subscribe stream).
241
- await w.u53(announce06Type(msg));
242
- return Message.encode(w, (w) => encodeAnnounce06Body(w, msg, version));
461
+ return Message.encode(w, (w) => encodeAnnounce06Body(w, msg, version), { id: announce06Type(msg, version) });
243
462
  }
244
463
  return Message.encode(w, (w) => encodeLegacyBody(w, msg, version));
245
464
  }
@@ -262,105 +481,104 @@ export async function decodeAnnounceBroadcastMaybe(r, version) {
262
481
  return Message.decodeMaybe(r, (r) => decodeLegacyBody(r, version));
263
482
  }
264
483
  /**
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}.
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}.
268
487
  */
269
488
  export class AnnounceHistory {
270
489
  #next = 0n;
271
490
  #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. */
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. */
289
499
  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) {
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) {
316
531
  const live = this.#live.get(id);
317
- if (!live)
532
+ if (live === undefined)
318
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);
319
541
  this.#live.delete(id);
320
- return live.suffix;
542
+ return live;
321
543
  }
322
544
  }
323
545
  /**
324
- * ANNOUNCE_REQUEST: sent by the subscriber to request ANNOUNCE_BROADCAST messages
325
- * 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).
326
549
  */
327
550
  export class AnnounceRequest {
328
551
  prefix;
329
- /** Lite04/05 only: the 62-bit Hop id of the peer asking for announces, which the
330
- * publisher uses to skip announces that already passed through it. Zero means "no
331
- * exclusion". Not on the wire elsewhere, so a value set here is ignored when encoding
332
- * for another version and decodes as zero.
333
- *
334
- * 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. */
335
556
  excludeHop;
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) {
557
+ constructor(prefix, excludeHop = UNKNOWN_HOP) {
341
558
  this.prefix = prefix;
342
559
  this.excludeHop = excludeHop;
343
- this.hidden = hidden;
560
+ }
561
+ static #guard(version) {
562
+ if (hasRoutes(version))
563
+ throw new Error("announce request streams not supported for this version");
344
564
  }
345
565
  async #encode(w, version) {
346
566
  await w.string(Path.encode(this.prefix));
347
567
  if (hasExcludeHop(version)) {
348
- await w.u62(this.excludeHop);
349
- }
350
- if (hasHidden(version)) {
351
- await w.bool(this.hidden);
568
+ await w.u62(wireHop(this.excludeHop, version));
352
569
  }
353
570
  }
354
571
  static async #decode(r, version) {
355
572
  const prefix = Path.decode(await r.string());
356
- const excludeHop = hasExcludeHop(version) ? await r.u62() : 0n;
357
- const hidden = hasHidden(version) ? await r.bool() : false;
358
- return new AnnounceRequest(prefix, excludeHop, hidden);
573
+ const excludeHop = hasExcludeHop(version) ? toHop(await r.u62()) : UNKNOWN_HOP;
574
+ return new AnnounceRequest(prefix, excludeHop);
359
575
  }
360
576
  async encode(w, version) {
577
+ AnnounceRequest.#guard(version);
361
578
  return Message.encode(w, (w) => this.#encode(w, version));
362
579
  }
363
580
  static async decode(r, version) {
581
+ AnnounceRequest.#guard(version);
364
582
  return Message.decode(r, (r) => AnnounceRequest.#decode(r, version));
365
583
  }
366
584
  }
@@ -387,30 +605,38 @@ export class AnnounceInit {
387
605
  await w.string(Path.encode(path));
388
606
  }
389
607
  }
390
- static async #decode(r) {
608
+ static async #decode(r, budget) {
391
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`);
392
613
  const suffixes = [];
393
614
  for (let i = 0; i < count; i++) {
394
615
  suffixes.push(Path.decode(await r.string()));
395
616
  }
396
617
  return new AnnounceInit(suffixes);
397
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;
398
622
  async encode(w, version) {
399
623
  AnnounceInit.#guard(version);
400
- return Message.encode(w, this.#encode.bind(this));
624
+ return Message.encode(w, this.#encode.bind(this), { max: AnnounceInit.MAX_SIZE });
401
625
  }
402
- 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) {
403
628
  AnnounceInit.#guard(version);
404
- return Message.decode(r, AnnounceInit.#decode);
629
+ return Message.decode(r, (r) => AnnounceInit.#decode(r, budget), AnnounceInit.MAX_SIZE);
405
630
  }
406
631
  }
407
632
  /// Sent by the publisher as the first message on an announce stream, before any
408
- /// 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).
409
635
  ///
410
636
  /// `origin` is the responder's Hop ID, which the subscriber stamps onto each
411
637
  /// announce's hop chain (the publisher no longer stamps itself), or the reserved
412
- /// {@link UNKNOWN_HOP} when the responder has no identity to give. `active` is
413
- /// 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.
414
640
  export class AnnounceOk {
415
641
  hop;
416
642
  active;
@@ -419,25 +645,24 @@ export class AnnounceOk {
419
645
  this.active = active;
420
646
  }
421
647
  static #guard(version) {
422
- if (!hasAnnounceOk(version)) {
648
+ if (!hasAnnounceOk(version) || hasRoutes(version)) {
423
649
  throw new Error("announce ok not supported for this version");
424
650
  }
425
651
  }
426
- async #encode(w) {
427
- await w.u62(this.hop);
652
+ async #encode(w, version) {
653
+ await w.u62(wireHop(this.hop, version));
428
654
  await w.u53(this.active);
429
655
  }
430
656
  static async #decode(r) {
431
657
  // The draft reserves 0 for "unknown": the responder was never assigned an id, or
432
658
  // withholds it to obscure its routing. It names nobody, so callers must not stamp
433
659
  // it onto a hop chain, but it is a legal message and not grounds to drop the stream.
434
- const origin = HopSchema.parse(await r.u62());
435
- const active = await r.u53();
436
- return new AnnounceOk(origin, active);
660
+ const origin = toHop(await r.u62());
661
+ return new AnnounceOk(origin, await r.u53());
437
662
  }
438
663
  async encode(w, version) {
439
664
  AnnounceOk.#guard(version);
440
- return Message.encode(w, this.#encode.bind(this));
665
+ return Message.encode(w, (w) => this.#encode(w, version));
441
666
  }
442
667
  static async decode(r, version) {
443
668
  AnnounceOk.#guard(version);