@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
@@ -1,64 +1,86 @@
1
- import { Once, Signal } from "@moq/signals";
2
- import { transportStats } from "../connection/stats.js";
1
+ import { Duration } from "@moq/clock";
2
+ import { Once, race, Signal } from "@moq/signals";
3
+ import * as announce from "../announced.js";
4
+ import { AuthSession } from "../auth_session.js";
5
+ import { detect, transportStats } from "../connection/stats.js";
3
6
  import { transportOf } from "../connection/transport.js";
4
- import { error, fromClose, ProtocolViolation, SessionCode, StreamCode, StreamError } from "../error.js";
7
+ import { closeReason, error, fromClose, ProtocolViolation, StreamCode, StreamError, sessionClosed } from "../error.js";
8
+ import { Cost } from "../hop.js";
9
+ import * as Path from "../path.js";
5
10
  import { Readers } from "../stream.js";
11
+ import { withTimeout } from "../util/timeout.js";
6
12
  import { registerWire } from "../wire.js";
7
- import { ControlStreamAdapter, NativeSession } from "./adapter.js";
8
13
  import * as Cluster from "./cluster.js";
14
+ import { IetfSessionCode } from "./error.js";
9
15
  import { Fetch, FetchHeader } from "./fetch.js";
10
16
  import { GoAway } from "./goaway.js";
17
+ import * as Message from "./message.js";
11
18
  import { Group } from "./object.js";
12
19
  import { Publish } from "./publish.js";
13
20
  import { PublishNamespace } from "./publish_namespace.js";
14
21
  import { Publisher } from "./publisher.js";
22
+ import { malformed, refuse } from "./request_stream.js";
23
+ import { NativeSession } from "./session.js";
15
24
  import { Subscribe, SubscribeUpdate } from "./subscribe.js";
16
- import { SUBSCRIBE_TRACKS_ID, SubscribeNamespace, SubscribeNamespaceLegacy } from "./subscribe_namespace.js";
25
+ import { SUBSCRIBE_TRACKS_ID, SubscribeNamespace } from "./subscribe_namespace.js";
17
26
  import { Subscriber } from "./subscriber.js";
27
+ import { MalformedAuthToken } from "./token.js";
18
28
  import { TrackStatusRequest } from "./track.js";
19
29
  import { Version, versionName } from "./version.js";
20
30
  // The PADDING stream type (draft-18+): bytes a peer sends to probe for bandwidth.
21
31
  const PADDING = 0x132b3e28n;
32
+ // A handler owns its request stream, and ending the request (closing the session over a
33
+ // violation) is its job: closing again here could only send a competing code.
34
+ function handed(task) {
35
+ return task.catch((err) => console.error("error processing bidi stream", err));
36
+ }
22
37
  /**
23
38
  * Represents a connection to a MoQ server using moq-transport protocol.
24
39
  *
25
- * @public
40
+ * @internal
26
41
  */
27
42
  export class Connection {
43
+ #phase = { kind: "open" };
28
44
  // The URL of the connection.
29
45
  url;
30
46
  // The negotiated protocol version.
31
47
  version;
32
48
  // The wire transport this session runs over.
33
49
  transport;
34
- /** Whether the relay supports broadcast discovery; see {@link Established.discovery}. */
35
- discovery;
36
- /** moq-transport has no PROBE, so this stays empty; see {@link Established.probe}. */
50
+ /** moq-transport has no PROBE, so this stays empty; see {@link Session.probe}. */
37
51
  probe = new Signal({});
52
+ /** The peer's liveness, on a transport that probes it; see {@link Session.liveness}. */
53
+ liveness;
54
+ /** Our tokens, which requests carry; see {@link Session.auth}. */
55
+ get auth() {
56
+ return this.#auth.handle;
57
+ }
58
+ // Our tokens, for the requests that carry them.
59
+ #auth;
38
60
  // The established WebTransport session.
39
61
  #quic;
40
- // Whether this side opened the session. Only a server may name a redirect.
62
+ // Whether this side opened the session. Only a server may name a redirect, and only
63
+ // the dialing side fails loud on a publication its grant does not cover.
41
64
  #client;
42
- // Session abstraction: adapter for v14-v16, native for v17.
65
+ // Opens request streams and allocates request IDs.
43
66
  #session;
44
67
  // Module for contributing tracks.
45
68
  #publisher;
46
69
  // Module for distributing tracks.
47
70
  #subscriber;
48
- // What the peer declared about being solicited; see {@link Ietf.solicitFromSetup}.
49
- #solicit;
50
71
  // The Hop IDs this session declared; see {@link Cluster}.
51
72
  #cluster;
52
- // The peer's GOAWAY: read here on v17+, by the control stream adapter before that.
53
- #goaway;
54
- // Just to avoid logging when `close()` is called.
55
- #closed = false;
73
+ // The peer's GOAWAY, read off its SETUP stream.
74
+ #goaway = new Once();
75
+ // How the session ended: `fromClose` of the transport's close, settled after auth lets go of it.
76
+ #closed = new Once();
77
+ /** The implementation the peer advertised; see {@link Session.peerImplementation}. */
78
+ peerImplementation;
56
79
  /**
57
80
  * Creates a new Connection instance.
58
81
  * @param url - The URL of the connection
59
82
  * @param quic - The WebTransport session
60
- * @param control - The control/setup stream
61
- * @param maxRequestId - The initial max request ID
83
+ * @param control - The SETUP stream, which then carries GOAWAY
62
84
  * @param version - The negotiated protocol version
63
85
  * @param solicit - What the peer's SETUP declared (undefined when it declared nothing)
64
86
  * @param cluster - The Hop IDs the SETUP exchange settled, on the versions that negotiate them
@@ -66,63 +88,106 @@ export class Connection {
66
88
  *
67
89
  * @internal
68
90
  */
69
- constructor({ url, quic, control, maxRequestId, version, client, discovery = true, publish, solicit, hidden = false, cluster, early = [], }) {
91
+ constructor({ url, quic, control, version, client, publish, solicit, hidden = false, activeCount = false, cluster, handle, early = [], peerImplementation, liveness, linkCost, priority = 0, }) {
92
+ this.liveness = liveness;
70
93
  this.url = url;
71
- this.discovery = discovery;
72
94
  this.version = versionName(version);
73
95
  this.transport = transportOf(quic);
96
+ detect(this, quic);
74
97
  this.#quic = quic;
75
98
  this.#client = client;
76
- // Two-path dispatch: v14-v16 uses adapter, v17+ uses native bidi streams
77
- if (version >= Version.DRAFT_17) {
78
- this.#session = new NativeSession(quic, version, client);
79
- this.#goaway = new Once();
80
- // v17+: control/setup stream only carries GoAway
81
- void this.#runGoAway(control, version);
82
- }
83
- else {
84
- const adapter = new ControlStreamAdapter(quic, control, version, maxRequestId, client);
85
- this.#session = adapter;
86
- this.#goaway = adapter.goaway;
87
- // Start the adapter read loop (routes control messages to virtual streams)
88
- void adapter.run().catch((err) => {
89
- if (!this.#closed)
90
- console.error("adapter error", err);
91
- this.#close();
92
- });
93
- }
99
+ this.peerImplementation = Promise.resolve(peerImplementation);
100
+ this.#session = new NativeSession(quic, version, client);
101
+ // The SETUP stream only carries GOAWAY from here on.
102
+ void this.#runGoAway(control, version);
103
+ // What the peer's connection credential earns by default: publishing anything to us,
104
+ // since we consume on demand, and subscribing to whatever we publish.
105
+ this.#auth = new AuthSession({
106
+ requests: true,
107
+ peerGrant: {
108
+ publish: Path.Prefixes.all(),
109
+ subscribe: publish ? Path.Prefixes.all() : new Path.Prefixes(),
110
+ },
111
+ handle,
112
+ draining: () => this.#goaway.peek() !== undefined || this.#phase.kind !== "open",
113
+ });
114
+ // Left before anything observes the close, so a successor on the same handle never
115
+ // finds this session still active.
116
+ const leave = () => this.#auth.close();
117
+ void quic.closed.then(leave, leave);
118
+ void quic.closed.then((info) => this.#closed.set(fromClose(info)), (err) => this.#closed.set(error(err)));
119
+ this.#client = client;
120
+ this.#auth.violated.subscribe((err) => {
121
+ if (err)
122
+ this.#violated(err);
123
+ });
94
124
  this.#publisher = new Publisher({
95
125
  quic: this.#quic,
96
126
  session: this.#session,
97
127
  publish,
98
128
  requiresSolicitation: solicit ?? false,
99
129
  hidden,
130
+ activeCount,
100
131
  cluster,
132
+ grant: this.#auth.scope,
133
+ auth: this.#auth,
101
134
  });
102
- this.#solicit = solicit;
103
135
  this.#cluster = cluster;
104
- this.#subscriber = new Subscriber({ session: this.#session, quic, cluster, hidden });
105
- registerWire(this, { consume: (path) => this.#subscriber.consume(path), goaway: this.#goaway });
136
+ this.#subscriber = new Subscriber({
137
+ session: this.#session,
138
+ quic,
139
+ cluster,
140
+ hidden,
141
+ activeCount,
142
+ goaway: this.#goaway,
143
+ grant: this.#auth.scope,
144
+ auth: this.#auth,
145
+ link: { cost: linkCost ?? Cost.zero, priority },
146
+ });
147
+ registerWire(this, {
148
+ consume: (path) => this.#subscriber.consume(path),
149
+ // The drafts refuse overlapping SUBSCRIBE_NAMESPACEs (PREFIX_OVERLAP). A peer that
150
+ // declared MoQ Solicit is ours and holds both; any other may enforce it.
151
+ exclusive: solicit === undefined,
152
+ // Drained locally only: this compatibility layer sends no client GOAWAY.
153
+ leave: () => {
154
+ if (this.#phase.kind === "open")
155
+ this.#phase = { kind: "leaving" };
156
+ },
157
+ auth: this.#auth,
158
+ });
106
159
  void this.#run(early);
107
160
  }
108
- /** Snapshot the transport's counters; see {@link Established.stats}. */
161
+ /** Snapshot the transport's counters; see {@link Session.stats}. */
109
162
  async stats() {
110
163
  return transportStats(this.#quic);
111
164
  }
112
- /**
113
- * Closes the connection.
114
- */
165
+ /** Withdraw announcements and wait up to one second for delivery before closing. */
115
166
  close() {
116
- if (this.#closed)
117
- return;
118
- this.#subscriber.close();
167
+ switch (this.#phase.kind) {
168
+ case "open":
169
+ case "leaving": {
170
+ const done = withTimeout(this.#publisher.withdraw(), Duration.secs(1), "session close timed out").finally(() => this.abort());
171
+ this.#phase = { kind: "closing", done };
172
+ return done;
173
+ }
174
+ case "closing":
175
+ return this.#phase.done;
176
+ case "closed":
177
+ return Promise.resolve();
178
+ }
179
+ }
180
+ /** End the session immediately without waiting for delivery. */
181
+ abort() {
119
182
  this.#close();
120
183
  }
121
184
  // Close with the session code the peer should see, a clean close by default.
122
185
  #close(info) {
123
- if (this.#closed)
186
+ if (this.#phase.kind === "closed")
124
187
  return;
125
- this.#closed = true;
188
+ this.#phase = { kind: "closed" };
189
+ this.#publisher.close();
190
+ this.#auth.close();
126
191
  // Before the session, whose own close would send a clean code first.
127
192
  try {
128
193
  this.#quic.close(info);
@@ -135,28 +200,49 @@ export class Connection {
135
200
  // The peer broke the protocol, so losing the stream is not enough: nothing stops it
136
201
  // repeating the violation on the next one.
137
202
  #violated(err) {
138
- this.#close({ closeCode: SessionCode.ProtocolViolation, reason: err.message });
203
+ this.#close({ closeCode: err.code, reason: closeReason(err.message) });
139
204
  }
140
205
  async #run(early) {
141
206
  try {
142
- await Promise.all([this.#runBidis(), this.#runUnis(early), this.#publisher.runPublishNamespaces()]);
207
+ // All run together. runPublishNamespaces is a no-op when the peer asked to be
208
+ // solicited; otherwise it pushes PUBLISH_NAMESPACE. A SUBSCRIBE_NAMESPACE stream
209
+ // is filled either way. A NAMESPACE is discovery,
210
+ // not a second route.
211
+ const tasks = [
212
+ this.#runBidis(),
213
+ this.#runUnis(early),
214
+ this.#runDatagrams(),
215
+ this.#publisher.runPublishNamespaces(),
216
+ ];
217
+ // Fail loud on a publication our grant never covers, once the peer has answered the
218
+ // credential we presented at setup.
219
+ if (this.#client)
220
+ tasks.push(this.#publisher.runEnforce(this.#auth.setupAnswered(), this.#auth));
221
+ await Promise.all(tasks);
143
222
  }
144
223
  catch (err) {
145
- if (!this.#closed) {
224
+ if (this.#phase.kind !== "closed") {
146
225
  console.error("fatal error running connection", err);
147
226
  }
148
227
  }
149
228
  finally {
150
- this.#close();
229
+ // A graceful close owns the teardown while it drains. runPublishNamespaces is
230
+ // a tracked withdrawal, so a failure in it ends this driver while close() is
231
+ // still waiting on the sibling loops; closing here would drop their
232
+ // withdrawals. close() aborts once its barrier settles or the deadline hits.
233
+ if (this.#phase.kind !== "closing")
234
+ this.#close();
151
235
  }
152
236
  }
153
- /** Gets an announced reader for `scope`; see {@link Established.announced}. */
154
- announced(scope, options) {
155
- return this.#subscriber.announced(scope, options);
237
+ /** The paths announced at or beneath `prefix`, each present or absent; see {@link Session.announced}. */
238
+ announced(prefix, options) {
239
+ return announce.list(this.#subscriber.routes(prefix, options));
156
240
  }
157
- /**
158
- * Accepts bidi streams (virtual for v14-v16, real for v17) and dispatches.
159
- */
241
+ /** Every route change at or beneath `prefix`, for code that forwards routes. @internal */
242
+ routes(prefix, options) {
243
+ return this.#subscriber.routes(prefix, options);
244
+ }
245
+ /** Accepts request streams and dispatches them. */
160
246
  async #runBidis() {
161
247
  for (;;) {
162
248
  const stream = await this.#session.acceptBi();
@@ -175,81 +261,125 @@ export class Connection {
175
261
  * Matches the lite module's runBidi pattern.
176
262
  */
177
263
  async #runBidi(stream) {
178
- const typeId = await stream.reader.u53();
264
+ // Full width, so unknown types above 2^53 still reach protocol classification.
265
+ const typeId = await stream.reader.u62();
179
266
  switch (typeId) {
180
- // Draft-18 SUBSCRIBE_NAMESPACE (0x50) and the legacy 0x11 message decode
181
- // to the same request_id + namespace; the legacy options field is ignored.
182
- case SubscribeNamespace.id: {
183
- const msg = await SubscribeNamespace.decode(stream.reader, this.#session.version);
184
- await this.#publisher.runSubscribeNamespace(msg, stream);
267
+ case BigInt(SubscribeNamespace.id): {
268
+ const decoded = SubscribeNamespace.decode(stream.reader, this.#session.version);
269
+ const msg = await this.#request(stream, "subscribe_namespace", decoded);
270
+ if (msg)
271
+ await handed(this.#publisher.runSubscribeNamespace(msg, stream));
185
272
  break;
186
273
  }
187
- case SubscribeNamespaceLegacy.id: {
188
- const legacy = await SubscribeNamespaceLegacy.decode(stream.reader, this.#session.version);
189
- const msg = new SubscribeNamespace({
190
- requestId: legacy.requestId,
191
- namespace: legacy.namespace,
192
- hidden: legacy.hidden,
193
- });
194
- await this.#publisher.runSubscribeNamespace(msg, stream);
195
- break;
196
- }
197
- case SubscribeUpdate.id: {
274
+ case BigInt(SubscribeUpdate.id): {
198
275
  // REQUEST_UPDATE (0x02) is a follow-up, not a valid initial message
199
276
  throw new ProtocolViolation("unexpected REQUEST_UPDATE as initial message");
200
277
  }
201
278
  // Publisher handles incoming requests
202
- case Subscribe.id: {
203
- const msg = await Subscribe.decode(stream.reader, this.#session.version);
204
- await this.#publisher.runSubscribe(msg, stream);
279
+ case BigInt(Subscribe.id): {
280
+ const decoded = Subscribe.decode(stream.reader, this.#session.version);
281
+ const msg = await this.#request(stream, "subscribe", decoded);
282
+ if (msg)
283
+ await handed(this.#publisher.runSubscribe(msg, stream));
205
284
  break;
206
285
  }
207
- case SUBSCRIBE_TRACKS_ID: {
208
- // 0x51 is only a message from draft-18 on.
209
- if (this.#session.version < Version.DRAFT_18) {
210
- throw new ProtocolViolation("SUBSCRIBE_TRACKS before draft-18");
211
- }
212
- await this.#publisher.runSubscribeTracks(stream);
286
+ case BigInt(SUBSCRIBE_TRACKS_ID): {
287
+ // We list no tracks by PUBLISH, so each listing is refused on its own. Only its
288
+ // Request ID is read; the rest of the body goes unread.
289
+ const requestId = await Message.decode(stream.reader, async (body) => {
290
+ const id = await body.u62();
291
+ await body.discard();
292
+ return id;
293
+ }).catch((err) => {
294
+ throw malformed(err, "subscribe_tracks");
295
+ });
296
+ this.#spend(requestId);
297
+ await handed(this.#refuseUnsupported(stream, "subscribe_namespace", "SUBSCRIBE_TRACKS is not supported"));
213
298
  break;
214
299
  }
215
- case TrackStatusRequest.id: {
216
- const msg = await TrackStatusRequest.decode(stream.reader, this.#session.version);
217
- await this.#publisher.runTrackStatusRequest(msg, stream);
300
+ case BigInt(TrackStatusRequest.id): {
301
+ const decoded = TrackStatusRequest.decode(stream.reader, this.#session.version);
302
+ const msg = await this.#request(stream, "track_status", decoded);
303
+ if (msg)
304
+ await handed(this.#publisher.runTrackStatusRequest(msg, stream));
218
305
  break;
219
306
  }
220
- case Fetch.id: {
221
- const msg = await Fetch.decode(stream.reader, this.#session.version);
222
- await this.#publisher.runFetch(msg, stream);
307
+ case BigInt(Fetch.id): {
308
+ const decoded = Fetch.decode(stream.reader, this.#session.version);
309
+ const msg = await this.#request(stream, "fetch", decoded);
310
+ // Only a relay answers a FETCH, from its cache.
311
+ if (msg)
312
+ await handed(this.#refuseUnsupported(stream, "fetch", "FETCH is not supported"));
223
313
  break;
224
314
  }
225
315
  // Subscriber handles incoming notifications
226
- case PublishNamespace.id: {
227
- const msg = await PublishNamespace.decode(stream.reader, this.#session.version, Cluster.negotiated(this.#cluster));
228
- // We always declare that advertisements to us must be solicited (MoQ
229
- // Solicit), and writing the option at all proves the peer implements the
230
- // extension, whichever value it chose. It also cannot have advertised
231
- // before reading our SETUP, since our SETUP is what says whether
232
- // advertising unasked is allowed. So this is a bug in the peer, and a
233
- // silent one on both sides if we tolerate it.
234
- //
235
- // Draft-14/15 are exempt: they have no inline NAMESPACE, so a
236
- // PUBLISH_NAMESPACE request is also how a peer answers our
237
- // SUBSCRIBE_NAMESPACE there, and the message alone does not say which.
238
- const legacy = this.#session.version === Version.DRAFT_14 || this.#session.version === Version.DRAFT_15;
239
- if (this.#solicit !== undefined && !legacy) {
240
- throw new ProtocolViolation(`unsolicited publish_namespace from a peer that implements MoQ Solicit: broadcast=${msg.trackNamespace}`);
241
- }
242
- await this.#subscriber.runPublishNamespace(msg, stream);
316
+ case BigInt(PublishNamespace.id): {
317
+ const decoded = PublishNamespace.decode(stream.reader, this.#session.version, {
318
+ cluster: Cluster.negotiated(this.#cluster),
319
+ });
320
+ const msg = await this.#request(stream, "publish_namespace", decoded);
321
+ if (!msg)
322
+ break;
323
+ await handed(this.#subscriber.runPublishNamespace(msg, stream));
243
324
  break;
244
325
  }
245
- case Publish.id: {
246
- const msg = await Publish.decode(stream.reader, this.#session.version);
247
- await this.#subscriber.runPublish(msg, stream);
326
+ case BigInt(Publish.id): {
327
+ const decoded = Publish.decode(stream.reader, this.#session.version);
328
+ const msg = await this.#request(stream, "publish", decoded);
329
+ if (msg)
330
+ await handed(this.#subscriber.runPublish(msg, stream));
248
331
  break;
249
332
  }
250
333
  default:
251
- console.warn(`unexpected bidi stream type: 0x${typeId.toString(16)}`);
252
- stream.abort(new Error("unexpected stream type"));
334
+ throw new ProtocolViolation(`unknown bidi stream type: 0x${typeId.toString(16)}`);
335
+ }
336
+ }
337
+ /**
338
+ * Finish decoding a request, refusing it instead when its AUTHORIZATION TOKENs repeat.
339
+ * Section 8.9 rejects that message rather than the session, unlike any other decode error.
340
+ *
341
+ * @returns undefined once refused.
342
+ */
343
+ async #request(stream, kind, decoded) {
344
+ let msg;
345
+ try {
346
+ msg = await decoded;
347
+ }
348
+ catch (err) {
349
+ if (!(err instanceof MalformedAuthToken) || err.requestId === undefined)
350
+ throw malformed(err, kind);
351
+ this.#spend(err.requestId);
352
+ await this.#refuseToken(stream, kind);
353
+ return undefined;
354
+ }
355
+ this.#spend(msg.requestId);
356
+ return msg;
357
+ }
358
+ /** Spend a request's ID, closing the session if it was already used. */
359
+ #spend(requestId) {
360
+ this.#session.checkRequestId(requestId);
361
+ }
362
+ /** Refuse a request we never serve NOT_SUPPORTED, ending its stream. */
363
+ async #refuseUnsupported(stream, kind, reasonPhrase) {
364
+ await refuse(stream, this.#session.version, kind, { condition: "not_supported", reasonPhrase });
365
+ }
366
+ /** Refuse a request MALFORMED_AUTH_TOKEN, ending its stream. Mirrors Rust's `token::reject`. */
367
+ async #refuseToken(stream, kind) {
368
+ await refuse(stream, this.#session.version, kind, {
369
+ condition: "malformed_auth_token",
370
+ reasonPhrase: "repeated AUTHORIZATION TOKEN",
371
+ });
372
+ }
373
+ // A malformed OBJECT_DATAGRAM is the peer breaking the protocol, like an invalid stream type.
374
+ async #runDatagrams() {
375
+ try {
376
+ await this.#subscriber.runDatagrams();
377
+ }
378
+ catch (err) {
379
+ if (!(err instanceof ProtocolViolation))
380
+ throw err;
381
+ console.warn("malformed datagram", err);
382
+ this.#violated(err);
253
383
  }
254
384
  }
255
385
  /**
@@ -273,7 +403,8 @@ export class Connection {
273
403
  stream.stop(new StreamError(StreamCode.Cancel, { message: "cancel" }));
274
404
  })
275
405
  .catch((err) => {
276
- console.error("error processing object stream", err);
406
+ // A peer resetting a stream it no longer wants to send is routine, not an error;
407
+ // only a violation is, and that one closes the session with its code.
277
408
  stream.stop(err);
278
409
  // An unknown or invalid stream type MUST close the session, not just the stream.
279
410
  if (err instanceof ProtocolViolation)
@@ -292,55 +423,86 @@ export class Connection {
292
423
  }
293
424
  // The receiver MUST discard padding. We read it to the end rather than cancel,
294
425
  // so a peer probing for bandwidth gets the throughput it is measuring.
295
- if (type === PADDING && version >= Version.DRAFT_18) {
426
+ if (type === PADDING) {
296
427
  await stream.discard();
297
428
  return;
298
429
  }
299
- // We never FETCH, so a fetch response answers nothing of ours.
300
- if (type === BigInt(FetchHeader.type))
301
- throw new Error("unexpected fetch stream");
430
+ // The head of a join, answering our draft-18 joining FETCH or draft-22 fill.
431
+ if (type === BigInt(FetchHeader.type)) {
432
+ await this.#subscriber.handleFetch(stream);
433
+ return;
434
+ }
302
435
  // Anything else is unknown, and a second SETUP is a violation too.
303
436
  throw new ProtocolViolation(`unknown uni stream type: 0x${type.toString(16)}`);
304
437
  }
305
438
  /**
306
- * v17+ only: reads GoAway from the setup/control stream.
439
+ * Reads GOAWAY from the SETUP stream.
307
440
  *
308
441
  * The session keeps serving after a GOAWAY so its groups in flight can finish while the
309
442
  * caller migrates; only the stream ending, or a second GOAWAY, closes it here.
310
443
  */
311
444
  async #runGoAway(controlStream, version) {
312
445
  try {
313
- for (;;) {
314
- const done = await controlStream.reader.done();
315
- if (done)
316
- return;
317
- const typeId = await controlStream.reader.u53();
318
- if (typeId !== GoAway.id) {
319
- console.warn(`unexpected message on setup stream: 0x${typeId.toString(16)}`);
320
- return;
446
+ const read = async () => {
447
+ for (;;) {
448
+ const done = await controlStream.reader.done();
449
+ if (done)
450
+ throw new ProtocolViolation("control stream closed");
451
+ const msg = await this.#readGoAway(controlStream, version).catch((err) => {
452
+ throw malformed(err, "setup stream message");
453
+ });
454
+ if (this.#goaway.peek() !== undefined)
455
+ throw new ProtocolViolation("duplicate GOAWAY");
456
+ // A client may leave, but only the server may name where to go.
457
+ if (!this.#client && msg.newSessionUri !== "") {
458
+ throw new ProtocolViolation("client GOAWAY must not name a redirect");
459
+ }
460
+ // Draft-18's Request ID names our IDs: even when we are the client, odd for a server.
461
+ // It is required here, on the control stream.
462
+ if (version === Version.DRAFT_18 && msg.requestId === undefined) {
463
+ throw new ProtocolViolation("draft-18 GOAWAY on the control stream lacks a Request ID");
464
+ }
465
+ if (msg.requestId !== undefined && msg.requestId % 2n !== (this.#client ? 0n : 1n)) {
466
+ throw new ProtocolViolation("GOAWAY Request ID has the wrong parity", {
467
+ code: IetfSessionCode.InvalidRequestId,
468
+ });
469
+ }
470
+ // Reject bytes already behind GOAWAY before a caller can close on the drain.
471
+ if (controlStream.reader.tryDecode((c) => c.u8()) !== undefined)
472
+ throw new ProtocolViolation("message after control stream GOAWAY");
473
+ this.#goaway.set(msg.drain());
321
474
  }
322
- const msg = await GoAway.decode(controlStream.reader, version);
323
- if (this.#goaway.peek() !== undefined)
324
- throw new ProtocolViolation("duplicate GOAWAY");
325
- // A client may leave, but only the server may name where to go.
326
- if (!this.#client && msg.newSessionUri !== "") {
327
- throw new ProtocolViolation("client GOAWAY must not name a redirect");
328
- }
329
- this.#goaway.set(msg.drain());
330
- }
475
+ };
476
+ const stopped = controlStream.writer.closed.then(() => {
477
+ throw new ProtocolViolation("control stream stopped");
478
+ });
479
+ await race([read(), stopped]);
331
480
  }
332
481
  catch (err) {
333
- if (!this.#closed) {
334
- console.error("error reading setup stream", err);
335
- }
482
+ if (this.#phase.kind !== "closed" && !sessionClosed(err))
483
+ this.#violated(err instanceof ProtocolViolation
484
+ ? err
485
+ : new ProtocolViolation("control stream failed", { cause: err }));
336
486
  }
337
487
  finally {
338
488
  this.#close();
339
489
  }
340
490
  }
341
- /** Resolves when the session closes, decoding the peer's close code; see {@link Established.closed}. */
491
+ // The setup stream carries nothing but GOAWAY after SETUP.
492
+ async #readGoAway(controlStream, version) {
493
+ const typeId = await controlStream.reader.u53();
494
+ if (typeId !== GoAway.id) {
495
+ throw new ProtocolViolation(`unexpected message on setup stream: 0x${typeId.toString(16)}`);
496
+ }
497
+ return GoAway.decode(controlStream.reader, version);
498
+ }
499
+ /** Settles with the peer's GOAWAY; see {@link Session.draining}. */
500
+ get draining() {
501
+ return this.#goaway;
502
+ }
503
+ /** Settles when the session closes, decoding the peer's close code; see {@link Session.closed}. */
342
504
  get closed() {
343
- return this.#quic.closed.then(fromClose, (err) => error(err));
505
+ return this.#closed;
344
506
  }
345
507
  }
346
508
  //# sourceMappingURL=connection.js.map