@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.
- package/README.md +7 -1
- package/announce.d.ts +1 -1
- package/announce.d.ts.map +1 -1
- package/announce.js +1 -2
- package/announce.js.map +1 -1
- package/announced.d.ts +51 -47
- package/announced.d.ts.map +1 -1
- package/announced.js +183 -32
- package/announced.js.map +1 -1
- package/announced.test-util.d.ts +2 -0
- package/announced.test-util.d.ts.map +1 -0
- package/announced.test-util.js +27 -0
- package/announced.test-util.js.map +1 -0
- package/auth.d.ts +64 -0
- package/auth.d.ts.map +1 -0
- package/auth.js +20 -0
- package/auth.js.map +1 -0
- package/auth_gate.d.ts +2 -0
- package/auth_gate.d.ts.map +1 -0
- package/auth_gate.js +24 -0
- package/auth_gate.js.map +1 -0
- package/auth_session.d.ts +49 -0
- package/auth_session.d.ts.map +1 -0
- package/auth_session.js +1097 -0
- package/auth_session.js.map +1 -0
- package/bandwidth.d.ts +129 -25
- package/bandwidth.d.ts.map +1 -1
- package/bandwidth.js +410 -139
- package/bandwidth.js.map +1 -1
- package/bandwidth_api.d.ts +1 -1
- package/bandwidth_api.d.ts.map +1 -1
- package/bandwidth_api.js +1 -2
- package/bandwidth_api.js.map +1 -1
- package/broadcast.d.ts +64 -38
- package/broadcast.d.ts.map +1 -1
- package/broadcast.js +556 -173
- package/broadcast.js.map +1 -1
- package/cache.d.ts +103 -0
- package/cache.d.ts.map +1 -0
- package/cache.js +254 -0
- package/cache.js.map +1 -0
- package/claim.test-util.d.ts +5 -0
- package/claim.test-util.d.ts.map +1 -0
- package/claim.test-util.js +13 -0
- package/claim.test-util.js.map +1 -0
- package/connection/accept.d.ts +21 -13
- package/connection/accept.d.ts.map +1 -1
- package/connection/accept.js +97 -130
- package/connection/accept.js.map +1 -1
- package/connection/browser.d.ts.map +1 -1
- package/connection/browser.js +28 -20
- package/connection/browser.js.map +1 -1
- package/connection/connect.d.ts +120 -24
- package/connection/connect.d.ts.map +1 -1
- package/connection/connect.js +535 -217
- package/connection/connect.js.map +1 -1
- package/connection/dials.d.ts +45 -0
- package/connection/dials.d.ts.map +1 -0
- package/connection/dials.js +109 -0
- package/connection/dials.js.map +1 -0
- package/connection/endpoint.d.ts +60 -0
- package/connection/endpoint.d.ts.map +1 -0
- package/connection/endpoint.js +114 -0
- package/connection/endpoint.js.map +1 -0
- package/connection/forward.d.ts +7 -1
- package/connection/forward.d.ts.map +1 -1
- package/connection/forward.js +265 -81
- package/connection/forward.js.map +1 -1
- package/connection/goaway.d.ts +16 -9
- package/connection/goaway.d.ts.map +1 -1
- package/connection/goaway.js +22 -95
- package/connection/goaway.js.map +1 -1
- package/connection/handshake.d.ts +34 -8
- package/connection/handshake.d.ts.map +1 -1
- package/connection/handshake.js +97 -21
- package/connection/handshake.js.map +1 -1
- package/connection/index.d.ts +4 -7
- package/connection/index.d.ts.map +1 -1
- package/connection/index.js +1 -3
- package/connection/index.js.map +1 -1
- package/connection/liveness.d.ts +14 -0
- package/connection/liveness.d.ts.map +1 -0
- package/connection/liveness.js +30 -0
- package/connection/liveness.js.map +1 -0
- package/connection/pool.d.ts +142 -63
- package/connection/pool.d.ts.map +1 -1
- package/connection/pool.js +281 -118
- package/connection/pool.js.map +1 -1
- package/connection/reload.d.ts +60 -12
- package/connection/reload.d.ts.map +1 -1
- package/connection/reload.js +859 -234
- package/connection/reload.js.map +1 -1
- package/connection/session.d.ts +91 -0
- package/connection/session.d.ts.map +1 -0
- package/connection/session.js +2 -0
- package/connection/session.js.map +1 -0
- package/connection/stats.d.ts +20 -11
- package/connection/stats.d.ts.map +1 -1
- package/connection/stats.js +64 -9
- package/connection/stats.js.map +1 -1
- package/connection/ticker.d.ts +4 -0
- package/connection/ticker.d.ts.map +1 -0
- package/connection/ticker.js +66 -0
- package/connection/ticker.js.map +1 -0
- package/connection/tokens.d.ts +2 -0
- package/connection/tokens.d.ts.map +1 -0
- package/connection/tokens.js +404 -0
- package/connection/tokens.js.map +1 -0
- package/connection/transport.d.ts.map +1 -1
- package/connection/transport.js +4 -5
- package/connection/transport.js.map +1 -1
- package/connection/withdrawal.d.ts +2 -0
- package/connection/withdrawal.d.ts.map +1 -0
- package/connection/withdrawal.js +23 -0
- package/connection/withdrawal.js.map +1 -0
- package/consume.js +213 -47
- package/consume.js.map +1 -1
- package/cover.d.ts +59 -0
- package/cover.d.ts.map +1 -0
- package/cover.js +375 -0
- package/cover.js.map +1 -0
- package/datagram.d.ts +70 -11
- package/datagram.d.ts.map +1 -1
- package/datagram.js +317 -2
- package/datagram.js.map +1 -1
- package/datagram_stream.d.ts +18 -0
- package/datagram_stream.d.ts.map +1 -0
- package/datagram_stream.js +67 -0
- package/datagram_stream.js.map +1 -0
- package/defined.test-util.d.ts +2 -0
- package/defined.test-util.d.ts.map +1 -0
- package/defined.test-util.js +7 -0
- package/defined.test-util.js.map +1 -0
- package/delivered.d.ts +75 -0
- package/delivered.d.ts.map +1 -0
- package/delivered.js +228 -0
- package/delivered.js.map +1 -0
- package/demand.d.ts +173 -0
- package/demand.d.ts.map +1 -0
- package/demand.js +582 -0
- package/demand.js.map +1 -0
- package/drops.d.ts +93 -0
- package/drops.d.ts.map +1 -0
- package/drops.js +283 -0
- package/drops.js.map +1 -0
- package/error.d.ts +120 -21
- package/error.d.ts.map +1 -1
- package/error.js +230 -38
- package/error.js.map +1 -1
- package/errors.d.ts +2 -2
- package/errors.d.ts.map +1 -1
- package/errors.js +2 -3
- package/errors.js.map +1 -1
- package/fill.d.ts +174 -0
- package/fill.d.ts.map +1 -0
- package/fill.js +760 -0
- package/fill.js.map +1 -0
- package/flate/decoder.d.ts +2 -0
- package/flate/decoder.d.ts.map +1 -0
- package/flate/decoder.js +63 -0
- package/flate/decoder.js.map +1 -0
- package/flate/encoder.d.ts +2 -0
- package/flate/encoder.d.ts.map +1 -0
- package/flate/encoder.js +64 -0
- package/flate/encoder.js.map +1 -0
- package/flate/group.d.ts +34 -0
- package/flate/group.d.ts.map +1 -0
- package/flate/group.js +140 -0
- package/flate/group.js.map +1 -0
- package/frame.d.ts +80 -0
- package/frame.d.ts.map +1 -0
- package/frame.js +296 -0
- package/frame.js.map +1 -0
- package/frame.test-util.d.ts +5 -0
- package/frame.test-util.d.ts.map +1 -0
- package/frame.test-util.js +9 -0
- package/frame.test-util.js.map +1 -0
- package/group.d.ts +108 -45
- package/group.d.ts.map +1 -1
- package/group.js +1616 -308
- package/group.js.map +1 -1
- package/group_api.d.ts +7 -0
- package/group_api.d.ts.map +1 -0
- package/group_api.js +7 -0
- package/group_api.js.map +1 -0
- package/hop.d.ts +62 -76
- package/hop.d.ts.map +1 -1
- package/hop.js +92 -65
- package/hop.js.map +1 -1
- package/identity.d.ts +39 -0
- package/identity.d.ts.map +1 -0
- package/identity.js +47 -0
- package/identity.js.map +1 -0
- package/ietf/active_count.d.ts +2 -0
- package/ietf/active_count.d.ts.map +1 -0
- package/ietf/active_count.js +30 -0
- package/ietf/active_count.js.map +1 -0
- package/ietf/aliases.js +69 -36
- package/ietf/aliases.js.map +1 -1
- package/ietf/cluster.d.ts +3 -3
- package/ietf/cluster.js +14 -55
- package/ietf/cluster.js.map +1 -1
- package/ietf/connection.d.ts +1 -31
- package/ietf/connection.d.ts.map +1 -1
- package/ietf/connection.js +305 -144
- package/ietf/connection.js.map +1 -1
- package/ietf/datagram.d.ts +60 -0
- package/ietf/datagram.d.ts.map +1 -0
- package/ietf/datagram.js +152 -0
- package/ietf/datagram.js.map +1 -0
- package/ietf/error.d.ts +3 -3
- package/ietf/error.js +82 -101
- package/ietf/error.js.map +1 -1
- package/ietf/fetch.d.ts +93 -37
- package/ietf/fetch.d.ts.map +1 -1
- package/ietf/fetch.js +172 -94
- package/ietf/fetch.js.map +1 -1
- package/ietf/filter.d.ts +21 -31
- package/ietf/filter.d.ts.map +1 -1
- package/ietf/filter.js +140 -172
- package/ietf/filter.js.map +1 -1
- package/ietf/goaway.d.ts +12 -10
- package/ietf/goaway.d.ts.map +1 -1
- package/ietf/goaway.js +22 -36
- package/ietf/goaway.js.map +1 -1
- package/ietf/hidden.js +1 -2
- package/ietf/hidden.js.map +1 -1
- package/ietf/index.d.ts +8 -20
- package/ietf/index.d.ts.map +1 -1
- package/ietf/index.js +4 -15
- package/ietf/index.js.map +1 -1
- package/ietf/join.d.ts +7 -0
- package/ietf/join.d.ts.map +1 -0
- package/ietf/join.js +234 -0
- package/ietf/join.js.map +1 -0
- package/ietf/message.d.ts +18 -2
- package/ietf/message.d.ts.map +1 -1
- package/ietf/message.js +60 -41
- package/ietf/message.js.map +1 -1
- package/ietf/message.test-util.d.ts +6 -0
- package/ietf/message.test-util.d.ts.map +1 -0
- package/ietf/message.test-util.js +13 -0
- package/ietf/message.test-util.js.map +1 -0
- package/ietf/namespace.d.ts +19 -5
- package/ietf/namespace.d.ts.map +1 -1
- package/ietf/namespace.js +78 -27
- package/ietf/namespace.js.map +1 -1
- package/ietf/object.d.ts +195 -33
- package/ietf/object.d.ts.map +1 -1
- package/ietf/object.js +405 -179
- package/ietf/object.js.map +1 -1
- package/ietf/parameters.d.ts +25 -45
- package/ietf/parameters.d.ts.map +1 -1
- package/ietf/parameters.js +260 -473
- package/ietf/parameters.js.map +1 -1
- package/ietf/priority.d.ts +17 -2
- package/ietf/priority.d.ts.map +1 -1
- package/ietf/priority.js +19 -5
- package/ietf/priority.js.map +1 -1
- package/ietf/properties.d.ts +6 -5
- package/ietf/properties.d.ts.map +1 -1
- package/ietf/properties.js +78 -49
- package/ietf/properties.js.map +1 -1
- package/ietf/publish.d.ts +25 -33
- package/ietf/publish.d.ts.map +1 -1
- package/ietf/publish.js +45 -140
- package/ietf/publish.js.map +1 -1
- package/ietf/publish_namespace.d.ts +49 -72
- package/ietf/publish_namespace.d.ts.map +1 -1
- package/ietf/publish_namespace.js +66 -185
- package/ietf/publish_namespace.js.map +1 -1
- package/ietf/publisher.js +1800 -601
- package/ietf/publisher.js.map +1 -1
- package/ietf/range.d.ts +2 -0
- package/ietf/range.d.ts.map +1 -0
- package/ietf/range.js +222 -0
- package/ietf/range.js.map +1 -0
- package/ietf/request.d.ts +6 -30
- package/ietf/request.d.ts.map +1 -1
- package/ietf/request.js +41 -79
- package/ietf/request.js.map +1 -1
- package/ietf/request_stream.d.ts +1 -6
- package/ietf/request_stream.d.ts.map +1 -1
- package/ietf/request_stream.js +306 -17
- package/ietf/request_stream.js.map +1 -1
- package/ietf/session.d.ts +41 -0
- package/ietf/session.d.ts.map +1 -0
- package/ietf/session.js +65 -0
- package/ietf/session.js.map +1 -0
- package/ietf/setup.d.ts +5 -30
- package/ietf/setup.d.ts.map +1 -1
- package/ietf/setup.js +6 -118
- package/ietf/setup.js.map +1 -1
- package/ietf/setup_options.d.ts +31 -0
- package/ietf/setup_options.d.ts.map +1 -0
- package/ietf/setup_options.js +138 -0
- package/ietf/setup_options.js.map +1 -0
- package/ietf/solicit.js +4 -15
- package/ietf/solicit.js.map +1 -1
- package/ietf/subscribe.d.ts +52 -45
- package/ietf/subscribe.d.ts.map +1 -1
- package/ietf/subscribe.js +118 -240
- package/ietf/subscribe.js.map +1 -1
- package/ietf/subscribe_namespace.d.ts +16 -79
- package/ietf/subscribe_namespace.d.ts.map +1 -1
- package/ietf/subscribe_namespace.js +30 -202
- package/ietf/subscribe_namespace.js.map +1 -1
- package/ietf/subscriber.js +1839 -537
- package/ietf/subscriber.js.map +1 -1
- package/ietf/token.js +105 -28
- package/ietf/token.js.map +1 -1
- package/ietf/track.d.ts +27 -24
- package/ietf/track.d.ts.map +1 -1
- package/ietf/track.js +48 -62
- package/ietf/track.js.map +1 -1
- package/ietf/version.d.ts +13 -42
- package/ietf/version.d.ts.map +1 -1
- package/ietf/version.js +22 -49
- package/ietf/version.js.map +1 -1
- package/implementation.d.ts +2 -0
- package/implementation.d.ts.map +1 -0
- package/implementation.js +5 -0
- package/implementation.js.map +1 -0
- package/index.d.ts +34 -19
- package/index.d.ts.map +1 -1
- package/index.js +19 -7
- package/index.js.map +1 -1
- package/internal.d.ts +1515 -67
- package/internal.d.ts.map +1 -1
- package/internal.js +557 -80
- package/internal.js.map +1 -1
- package/ledger.d.ts +23 -0
- package/ledger.d.ts.map +1 -0
- package/ledger.js +247 -0
- package/ledger.js.map +1 -0
- package/listing.d.ts +132 -0
- package/listing.d.ts.map +1 -0
- package/listing.js +486 -0
- package/listing.js.map +1 -0
- package/lite/announce.d.ts +127 -66
- package/lite/announce.d.ts.map +1 -1
- package/lite/announce.js +384 -159
- package/lite/announce.js.map +1 -1
- package/lite/announce_stream.d.ts +2 -0
- package/lite/announce_stream.d.ts.map +1 -0
- package/lite/announce_stream.js +92 -0
- package/lite/announce_stream.js.map +1 -0
- package/lite/answer.d.ts +22 -0
- package/lite/answer.d.ts.map +1 -0
- package/lite/answer.js +301 -0
- package/lite/answer.js.map +1 -0
- package/lite/auth.d.ts +45 -0
- package/lite/auth.d.ts.map +1 -0
- package/lite/auth.js +204 -0
- package/lite/auth.js.map +1 -0
- package/lite/compat.d.ts +31 -0
- package/lite/compat.d.ts.map +1 -0
- package/lite/compat.js +86 -0
- package/lite/compat.js.map +1 -0
- package/lite/connection.d.ts +1 -45
- package/lite/connection.d.ts.map +1 -1
- package/lite/connection.js +360 -78
- package/lite/connection.js.map +1 -1
- package/lite/datagram-end.d.ts +26 -0
- package/lite/datagram-end.d.ts.map +1 -0
- package/lite/datagram-end.js +30 -0
- package/lite/datagram-end.js.map +1 -0
- package/lite/datagram.d.ts +73 -8
- package/lite/datagram.d.ts.map +1 -1
- package/lite/datagram.js +144 -10
- package/lite/datagram.js.map +1 -1
- package/lite/duration.d.ts +6 -0
- package/lite/duration.d.ts.map +1 -0
- package/lite/duration.js +14 -0
- package/lite/duration.js.map +1 -0
- package/lite/error.d.ts +9 -0
- package/lite/error.d.ts.map +1 -0
- package/lite/error.js +24 -0
- package/lite/error.js.map +1 -0
- package/lite/fills.d.ts +162 -0
- package/lite/fills.d.ts.map +1 -0
- package/lite/fills.js +486 -0
- package/lite/fills.js.map +1 -0
- package/lite/fit.d.ts +49 -0
- package/lite/fit.d.ts.map +1 -0
- package/lite/fit.js +305 -0
- package/lite/fit.js.map +1 -0
- package/lite/goaway.d.ts +2 -2
- package/lite/goaway.d.ts.map +1 -1
- package/lite/goaway.js +5 -14
- package/lite/goaway.js.map +1 -1
- package/lite/group.d.ts +67 -16
- package/lite/group.d.ts.map +1 -1
- package/lite/group.js +108 -31
- package/lite/group.js.map +1 -1
- package/lite/identity.d.ts +25 -0
- package/lite/identity.d.ts.map +1 -0
- package/lite/identity.js +79 -0
- package/lite/identity.js.map +1 -0
- package/lite/index.d.ts +14 -13
- package/lite/index.d.ts.map +1 -1
- package/lite/index.js +2 -2
- package/lite/index.js.map +1 -1
- package/lite/message.d.ts +10 -2
- package/lite/message.d.ts.map +1 -1
- package/lite/message.js +28 -45
- package/lite/message.js.map +1 -1
- package/lite/priority.d.ts +9 -2
- package/lite/priority.d.ts.map +1 -1
- package/lite/priority.js +11 -106
- package/lite/priority.js.map +1 -1
- package/lite/probe.d.ts +2 -2
- package/lite/probe.d.ts.map +1 -1
- package/lite/probe.js +9 -1
- package/lite/probe.js.map +1 -1
- package/lite/publisher.d.ts +10 -1
- package/lite/publisher.d.ts.map +1 -1
- package/lite/publisher.js +2548 -438
- package/lite/publisher.js.map +1 -1
- package/lite/routed.d.ts +59 -0
- package/lite/routed.d.ts.map +1 -0
- package/lite/routed.js +564 -0
- package/lite/routed.js.map +1 -0
- package/lite/session.d.ts +2 -28
- package/lite/session.d.ts.map +1 -1
- package/lite/session.js +0 -100
- package/lite/session.js.map +1 -1
- package/lite/setup.d.ts +32 -5
- package/lite/setup.d.ts.map +1 -1
- package/lite/setup.js +95 -22
- package/lite/setup.js.map +1 -1
- package/lite/stream.d.ts +5 -11
- package/lite/stream.d.ts.map +1 -1
- package/lite/stream.js +5 -2
- package/lite/stream.js.map +1 -1
- package/lite/subscribe.d.ts +478 -78
- package/lite/subscribe.d.ts.map +1 -1
- package/lite/subscribe.js +1373 -143
- package/lite/subscribe.js.map +1 -1
- package/lite/subscriber.d.ts +7 -44
- package/lite/subscriber.d.ts.map +1 -1
- package/lite/subscriber.js +3290 -516
- package/lite/subscriber.js.map +1 -1
- package/lite/track.d.ts +27 -12
- package/lite/track.d.ts.map +1 -1
- package/lite/track.js +116 -38
- package/lite/track.js.map +1 -1
- package/lite/tracks.d.ts +55 -0
- package/lite/tracks.d.ts.map +1 -0
- package/lite/tracks.js +114 -0
- package/lite/tracks.js.map +1 -0
- package/lite/version.d.ts +132 -24
- package/lite/version.d.ts.map +1 -1
- package/lite/version.js +378 -34
- package/lite/version.js.map +1 -1
- package/meta.d.ts +77 -0
- package/meta.d.ts.map +1 -0
- package/meta.js +130 -0
- package/meta.js.map +1 -0
- package/meta_api.d.ts +7 -0
- package/meta_api.d.ts.map +1 -0
- package/meta_api.js +7 -0
- package/meta_api.js.map +1 -0
- package/mint.d.ts +28 -0
- package/mint.d.ts.map +1 -0
- package/mint.js +66 -0
- package/mint.js.map +1 -0
- package/open.d.ts +63 -0
- package/open.d.ts.map +1 -0
- package/open.js +250 -0
- package/open.js.map +1 -0
- package/origin.d.ts +394 -142
- package/origin.d.ts.map +1 -1
- package/origin.js +2533 -687
- package/origin.js.map +1 -1
- package/package.json +8 -13
- package/path.d.ts +51 -51
- package/path.d.ts.map +1 -1
- package/path.js +210 -58
- package/path.js.map +1 -1
- package/payload.d.ts +33 -0
- package/payload.d.ts.map +1 -0
- package/payload.js +65 -0
- package/payload.js.map +1 -0
- package/prefix.d.ts +152 -0
- package/prefix.d.ts.map +1 -0
- package/prefix.js +349 -0
- package/prefix.js.map +1 -0
- package/priority.d.ts +8 -0
- package/priority.d.ts.map +1 -0
- package/priority.js +185 -0
- package/priority.js.map +1 -0
- package/queue.d.ts +2 -0
- package/queue.d.ts.map +1 -0
- package/queue.js +46 -0
- package/queue.js.map +1 -0
- package/ranges.d.ts +36 -0
- package/ranges.d.ts.map +1 -0
- package/ranges.js +312 -0
- package/ranges.js.map +1 -0
- package/rescale.d.ts +24 -0
- package/rescale.d.ts.map +1 -0
- package/rescale.js +39 -0
- package/rescale.js.map +1 -0
- package/resume.d.ts +55 -0
- package/resume.d.ts.map +1 -0
- package/resume.js +4173 -0
- package/resume.js.map +1 -0
- package/resume.test-util.d.ts +2 -0
- package/resume.test-util.d.ts.map +1 -0
- package/resume.test-util.js +25 -0
- package/resume.test-util.js.map +1 -0
- package/skips.d.ts +48 -0
- package/skips.d.ts.map +1 -0
- package/skips.js +182 -0
- package/skips.js.map +1 -0
- package/stream.d.ts +78 -40
- package/stream.d.ts.map +1 -1
- package/stream.js +236 -93
- package/stream.js.map +1 -1
- package/subscription.test-util.d.ts +2 -0
- package/subscription.test-util.d.ts.map +1 -0
- package/subscription.test-util.js +49 -0
- package/subscription.test-util.js.map +1 -0
- package/tail.d.ts +23 -14
- package/tail.d.ts.map +1 -1
- package/tail.js +224 -98
- package/tail.js.map +1 -1
- package/time.d.ts +41 -102
- package/time.d.ts.map +1 -1
- package/time.js +129 -92
- package/time.js.map +1 -1
- package/timed.d.ts +21 -0
- package/timed.d.ts.map +1 -0
- package/timed.js +2 -0
- package/timed.js.map +1 -0
- package/track.d.ts +578 -246
- package/track.d.ts.map +1 -1
- package/track.js +7306 -772
- package/track.js.map +1 -1
- package/track_api.d.ts +7 -0
- package/track_api.d.ts.map +1 -0
- package/track_api.js +7 -0
- package/track_api.js.map +1 -0
- package/util/abort.d.ts +1 -0
- package/util/abort.d.ts.map +1 -1
- package/util/abort.js +23 -2
- package/util/abort.js.map +1 -1
- package/util/announce.d.ts +4 -0
- package/util/announce.d.ts.map +1 -0
- package/util/announce.js +11 -0
- package/util/announce.js.map +1 -0
- package/util/bigint.d.ts +3 -0
- package/util/bigint.d.ts.map +1 -0
- package/util/bigint.js +8 -0
- package/util/bigint.js.map +1 -0
- package/util/change.d.ts +12 -0
- package/util/change.d.ts.map +1 -0
- package/util/change.js +18 -0
- package/util/change.js.map +1 -0
- package/util/deadline.d.ts +2 -0
- package/util/deadline.d.ts.map +1 -0
- package/util/deadline.js +108 -0
- package/util/deadline.js.map +1 -0
- package/util/decode_error.d.ts +3 -0
- package/util/decode_error.d.ts.map +1 -0
- package/util/decode_error.js +11 -0
- package/util/decode_error.js.map +1 -0
- package/util/demand.d.ts +8 -0
- package/util/demand.d.ts.map +1 -0
- package/util/demand.js +24 -0
- package/util/demand.js.map +1 -0
- package/util/given_up.d.ts +2 -0
- package/util/given_up.d.ts.map +1 -0
- package/util/given_up.js +101 -0
- package/util/given_up.js.map +1 -0
- package/util/hex.d.ts +6 -0
- package/util/hex.d.ts.map +1 -1
- package/util/hex.js +19 -5
- package/util/hex.js.map +1 -1
- package/util/key.d.ts +15 -0
- package/util/key.d.ts.map +1 -0
- package/util/key.js +38 -0
- package/util/key.js.map +1 -0
- package/util/limits.d.ts +2 -0
- package/util/limits.d.ts.map +1 -0
- package/util/limits.js +76 -0
- package/util/limits.js.map +1 -0
- package/util/observed.d.ts +23 -0
- package/util/observed.d.ts.map +1 -0
- package/util/observed.js +122 -0
- package/util/observed.js.map +1 -0
- package/util/sorted.d.ts +2 -0
- package/util/sorted.d.ts.map +1 -0
- package/util/sorted.js +149 -0
- package/util/sorted.js.map +1 -0
- package/util/timeout.d.ts +2 -1
- package/util/timeout.d.ts.map +1 -1
- package/util/timeout.js +13 -10
- package/util/timeout.js.map +1 -1
- package/util/timer.d.ts +2 -0
- package/util/timer.d.ts.map +1 -0
- package/util/timer.js +19 -0
- package/util/timer.js.map +1 -0
- package/util/u64.js +0 -1
- package/util/utf8.d.ts +2 -0
- package/util/utf8.d.ts.map +1 -1
- package/util/utf8.js +7 -2
- package/util/utf8.js.map +1 -1
- package/util/varint.d.ts.map +1 -1
- package/util/varint.js +8 -2
- package/util/varint.js.map +1 -1
- package/util/watch.d.ts +8 -0
- package/util/watch.d.ts.map +1 -0
- package/util/watch.js +38 -0
- package/util/watch.js.map +1 -0
- package/util/yield.d.ts +2 -0
- package/util/yield.d.ts.map +1 -0
- package/util/yield.js +31 -0
- package/util/yield.js.map +1 -0
- package/varint.d.ts +0 -29
- package/varint.d.ts.map +1 -1
- package/varint.js +7 -29
- package/varint.js.map +1 -1
- package/varint_api.d.ts +7 -0
- package/varint_api.d.ts.map +1 -0
- package/varint_api.js +7 -0
- package/varint_api.js.map +1 -0
- package/version.d.ts +2 -0
- package/version.d.ts.map +1 -0
- package/version.js +4 -0
- package/version.js.map +1 -0
- package/window.d.ts +570 -0
- package/window.d.ts.map +1 -0
- package/window.js +1677 -0
- package/window.js.map +1 -0
- package/wire.d.ts +150 -35
- package/wire.d.ts.map +1 -1
- package/wire.js +27 -1
- package/wire.js.map +1 -1
- package/connection/established.d.ts +0 -53
- package/connection/established.d.ts.map +0 -1
- package/connection/established.js +0 -3
- package/connection/established.js.map +0 -1
- package/ietf/adapter.d.ts +0 -75
- package/ietf/adapter.d.ts.map +0 -1
- package/ietf/adapter.js +0 -700
- package/ietf/adapter.js.map +0 -1
- package/lite/datagram_stream.d.ts +0 -8
- package/lite/datagram_stream.d.ts.map +0 -1
- package/lite/datagram_stream.js +0 -44
- package/lite/datagram_stream.js.map +0 -1
- package/lite/fetch.d.ts +0 -28
- package/lite/fetch.d.ts.map +0 -1
- package/lite/fetch.js +0 -79
- package/lite/fetch.js.map +0 -1
- package/util/log.d.ts +0 -5
- package/util/log.d.ts.map +0 -1
- package/util/log.js +0 -17
- package/util/log.js.map +0 -1
- package/zod.d.ts +0 -13
- package/zod.d.ts.map +0 -1
- package/zod.js +0 -19
- package/zod.js.map +0 -1
package/auth_session.js
ADDED
|
@@ -0,0 +1,1097 @@
|
|
|
1
|
+
import { Duration, now, sleep, wall, yieldNow } from "@moq/clock";
|
|
2
|
+
import { Once, race, Signal } from "@moq/signals";
|
|
3
|
+
import { closeReason, error, ProtocolViolation, SessionCode, SessionError, StreamCode, StreamError } from "./error.js";
|
|
4
|
+
import * as Path from "./path.js";
|
|
5
|
+
/** Write a grant's prefixes as a count and each one's text, the encoding both wires' AUTH_OK share. @internal */
|
|
6
|
+
export async function encodePrefixes(w, prefixes) {
|
|
7
|
+
await w.u53(prefixes.size);
|
|
8
|
+
for (const prefix of prefixes)
|
|
9
|
+
await w.string(prefix.text);
|
|
10
|
+
}
|
|
11
|
+
/** Read a grant's prefixes, refusing any that is a wildcard or not a valid path. @internal */
|
|
12
|
+
export async function decodePrefixes(r) {
|
|
13
|
+
const count = await r.u53();
|
|
14
|
+
const prefixes = [];
|
|
15
|
+
for (let i = 0; i < count; i++)
|
|
16
|
+
prefixes.push(Path.Prefix.parse(await r.string()));
|
|
17
|
+
// Sort and sweep once, so a peer's count costs n log n whatever its shape.
|
|
18
|
+
return new Path.Prefixes(prefixes);
|
|
19
|
+
}
|
|
20
|
+
/** Whether two grants allow the same paths and lapse together. */
|
|
21
|
+
function grantsEqual(a, b) {
|
|
22
|
+
if (a === undefined || b === undefined)
|
|
23
|
+
return a === b;
|
|
24
|
+
const expires = a.expires === undefined || b.expires === undefined ? a.expires === b.expires : a.expires.eq(b.expires);
|
|
25
|
+
return a.publish.equals(b.publish) && a.subscribe.equals(b.subscribe) && expires;
|
|
26
|
+
}
|
|
27
|
+
/** The session or peer carries no AUTH exchange, or takes no tokens in band. */
|
|
28
|
+
export class Unsupported extends Error {
|
|
29
|
+
/** The moq-lite session code for this condition. */
|
|
30
|
+
// fallow-ignore-next-line unused-class-member
|
|
31
|
+
code = SessionCode.Unsupported;
|
|
32
|
+
constructor(message = "auth unsupported") {
|
|
33
|
+
super(message);
|
|
34
|
+
this.name = "Unsupported";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** A handle already backs a session that is open and not draining, or its requests were already taken. */
|
|
38
|
+
export class Duplicate extends Error {
|
|
39
|
+
constructor(message = "auth handle already backs an active session") {
|
|
40
|
+
super(message);
|
|
41
|
+
this.name = "Duplicate";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* How long a token refused for a reason that may pass waits before its session presents it
|
|
46
|
+
* again, doubling on each refusal up to RETRY_MAX. A moq-transport refusal that may pass asks
|
|
47
|
+
* its peer to wait as long.
|
|
48
|
+
*
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
export const RETRY_INITIAL = Duration.millis(1000);
|
|
52
|
+
const RETRY_MAX = Duration.millis(30_000);
|
|
53
|
+
// Whether a token's stream ending with `result` is the peer's verdict on it: a final refusal,
|
|
54
|
+
// Unsupported, or a clean close after a grant. Anything else left the token undecided.
|
|
55
|
+
function isVerdict(refused, granted, result) {
|
|
56
|
+
return refused === "final" || result instanceof Unsupported || (result === null && granted);
|
|
57
|
+
}
|
|
58
|
+
/** The paths any of `grants` allows. Reduced once over all of them, not pairwise. */
|
|
59
|
+
function union(grants) {
|
|
60
|
+
const publish = [];
|
|
61
|
+
const subscribe = [];
|
|
62
|
+
let expires;
|
|
63
|
+
for (const grant of grants) {
|
|
64
|
+
for (const prefix of grant.publish)
|
|
65
|
+
publish.push(prefix);
|
|
66
|
+
for (const prefix of grant.subscribe)
|
|
67
|
+
subscribe.push(prefix);
|
|
68
|
+
// The earliest expiry is when the union next shrinks.
|
|
69
|
+
if (grant.expires !== undefined && (expires === undefined || grant.expires.lt(expires)))
|
|
70
|
+
expires = grant.expires;
|
|
71
|
+
}
|
|
72
|
+
return { publish: new Path.Prefixes(publish), subscribe: new Path.Prefixes(subscribe), expires };
|
|
73
|
+
}
|
|
74
|
+
// The transport closed under the stream, which ends the whole session rather than one token.
|
|
75
|
+
function transportClosed(err) {
|
|
76
|
+
return typeof err === "object" && err !== null && "source" in err && err.source === "session";
|
|
77
|
+
}
|
|
78
|
+
function cancel() {
|
|
79
|
+
return new StreamError(StreamCode.Cancel, { message: "cancel" });
|
|
80
|
+
}
|
|
81
|
+
/** One token as one session presents it. */
|
|
82
|
+
class Presented {
|
|
83
|
+
token;
|
|
84
|
+
/** The session's own credential, presented at setup on this session alone. */
|
|
85
|
+
setup;
|
|
86
|
+
/** The handle's token this presents, or undefined for the session's own credential. */
|
|
87
|
+
owner;
|
|
88
|
+
/** The latest grant: undefined before the first, during a retry, and once it ends here. */
|
|
89
|
+
grant;
|
|
90
|
+
stream;
|
|
91
|
+
/** Wakes a retry backoff early once the presentation is no longer wanted. */
|
|
92
|
+
retry;
|
|
93
|
+
withdrawn = false;
|
|
94
|
+
isAnswered = false;
|
|
95
|
+
ended = false;
|
|
96
|
+
constructor(token, setup, owner) {
|
|
97
|
+
this.token = token;
|
|
98
|
+
this.setup = setup;
|
|
99
|
+
this.owner = owner;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/** A token the application added to a {@link Handle}, presented on every session of it. */
|
|
103
|
+
class Token {
|
|
104
|
+
grant = new Signal(undefined);
|
|
105
|
+
answered;
|
|
106
|
+
bytes;
|
|
107
|
+
isAnswered = false;
|
|
108
|
+
ended = false;
|
|
109
|
+
inband = false;
|
|
110
|
+
#state;
|
|
111
|
+
#closed = new Once();
|
|
112
|
+
#answer;
|
|
113
|
+
#refuse;
|
|
114
|
+
constructor(bytes, state) {
|
|
115
|
+
this.bytes = bytes;
|
|
116
|
+
this.#state = state;
|
|
117
|
+
this.answered = new Promise((resolve, reject) => {
|
|
118
|
+
this.#answer = resolve;
|
|
119
|
+
this.#refuse = reject;
|
|
120
|
+
});
|
|
121
|
+
// A caller that never awaits the answer must not see an unhandled rejection.
|
|
122
|
+
this.answered.catch(() => void 0);
|
|
123
|
+
}
|
|
124
|
+
answer() {
|
|
125
|
+
if (this.isAnswered)
|
|
126
|
+
return;
|
|
127
|
+
this.isAnswered = true;
|
|
128
|
+
this.#answer();
|
|
129
|
+
}
|
|
130
|
+
end(err) {
|
|
131
|
+
if (this.ended)
|
|
132
|
+
return;
|
|
133
|
+
this.ended = true;
|
|
134
|
+
this.grant.set(undefined);
|
|
135
|
+
if (!this.isAnswered) {
|
|
136
|
+
this.isAnswered = true;
|
|
137
|
+
this.#refuse(err ?? new Error("withdrawn"));
|
|
138
|
+
}
|
|
139
|
+
this.#closed.set(err);
|
|
140
|
+
}
|
|
141
|
+
get closed() {
|
|
142
|
+
return this.#closed;
|
|
143
|
+
}
|
|
144
|
+
get held() {
|
|
145
|
+
return this.#state.sessions.some((session) => session.grantOf(this) !== undefined);
|
|
146
|
+
}
|
|
147
|
+
close() {
|
|
148
|
+
this.#state.withdraw(this);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/** The state behind one {@link Handle}: the tokens it presents, and every session it backs. */
|
|
152
|
+
class HandleState {
|
|
153
|
+
/** The live session's union. */
|
|
154
|
+
grant = new Signal(undefined);
|
|
155
|
+
/** Created by a session for itself, so it ends with that session. */
|
|
156
|
+
own = false;
|
|
157
|
+
/** Set once the handle ends. */
|
|
158
|
+
closed;
|
|
159
|
+
/** The handle's end, for a watcher that outlives its sessions. */
|
|
160
|
+
end = new Signal(undefined);
|
|
161
|
+
/** Every token the application added that has not ended. */
|
|
162
|
+
tokens = new Set();
|
|
163
|
+
/** Every open session built on this handle, oldest first. */
|
|
164
|
+
sessions = [];
|
|
165
|
+
acceptor = "undecided";
|
|
166
|
+
/** The session the handle backs now: the newest one still open. */
|
|
167
|
+
get live() {
|
|
168
|
+
return this.sessions.at(-1);
|
|
169
|
+
}
|
|
170
|
+
/** Fail unless a new session can be built on the handle. */
|
|
171
|
+
vacant() {
|
|
172
|
+
if (this.closed)
|
|
173
|
+
throw this.closed;
|
|
174
|
+
if (this.sessions.some((session) => session.active))
|
|
175
|
+
throw new Duplicate();
|
|
176
|
+
}
|
|
177
|
+
attach(session) {
|
|
178
|
+
this.vacant();
|
|
179
|
+
this.sessions.push(session);
|
|
180
|
+
// The successor is live now, so its predecessor's grants no longer apply.
|
|
181
|
+
this.refresh();
|
|
182
|
+
}
|
|
183
|
+
/** A session closed: it presents nothing anymore. A handle of its own ends with it. */
|
|
184
|
+
detach(session, err) {
|
|
185
|
+
const index = this.sessions.indexOf(session);
|
|
186
|
+
if (index >= 0)
|
|
187
|
+
this.sessions.splice(index, 1);
|
|
188
|
+
if (this.own)
|
|
189
|
+
this.abort(err);
|
|
190
|
+
this.refresh();
|
|
191
|
+
}
|
|
192
|
+
/** Point the handle's grant, and each token's, at the live session. */
|
|
193
|
+
refresh() {
|
|
194
|
+
const live = this.live;
|
|
195
|
+
const union = live?.grant.peek();
|
|
196
|
+
if (!grantsEqual(union, this.grant.peek()))
|
|
197
|
+
this.grant.set(union);
|
|
198
|
+
for (const token of this.tokens) {
|
|
199
|
+
const grant = live?.grantOf(token);
|
|
200
|
+
if (!grantsEqual(grant, token.grant.peek()))
|
|
201
|
+
token.grant.set(grant);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
add(bytes) {
|
|
205
|
+
if (this.closed)
|
|
206
|
+
throw this.closed;
|
|
207
|
+
// A draining session takes no new tokens, and a handle of its own has no successor.
|
|
208
|
+
if (this.own && !this.sessions.some((session) => session.active)) {
|
|
209
|
+
throw new StreamError(StreamCode.GoingAway);
|
|
210
|
+
}
|
|
211
|
+
const token = new Token(bytes, this);
|
|
212
|
+
this.tokens.add(token);
|
|
213
|
+
for (const session of [...this.sessions])
|
|
214
|
+
session.offer(token);
|
|
215
|
+
return token;
|
|
216
|
+
}
|
|
217
|
+
/** The application dropped the token: every session stops presenting it. */
|
|
218
|
+
withdraw(token) {
|
|
219
|
+
if (!this.tokens.delete(token))
|
|
220
|
+
return;
|
|
221
|
+
for (const session of this.sessions)
|
|
222
|
+
session.withdraw(token);
|
|
223
|
+
token.end(null);
|
|
224
|
+
}
|
|
225
|
+
/** The peer's verdict, or the handle's end: the token ends on every session. */
|
|
226
|
+
verdict(token, err) {
|
|
227
|
+
if (!this.tokens.delete(token))
|
|
228
|
+
return;
|
|
229
|
+
token.end(err);
|
|
230
|
+
for (const session of this.sessions)
|
|
231
|
+
session.withdraw(token);
|
|
232
|
+
}
|
|
233
|
+
/** Decide who answers the peer's tokens, once: the application if it took them. */
|
|
234
|
+
decide() {
|
|
235
|
+
if (this.acceptor === "undecided")
|
|
236
|
+
this.acceptor = "default";
|
|
237
|
+
return this.acceptor instanceof RequestQueue ? this.acceptor : undefined;
|
|
238
|
+
}
|
|
239
|
+
abort(err) {
|
|
240
|
+
if (this.closed)
|
|
241
|
+
return;
|
|
242
|
+
this.closed = err;
|
|
243
|
+
this.end.set(err);
|
|
244
|
+
for (const token of [...this.tokens])
|
|
245
|
+
this.verdict(token, err);
|
|
246
|
+
if (this.acceptor instanceof RequestQueue)
|
|
247
|
+
this.acceptor.close();
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
const states = new WeakMap();
|
|
251
|
+
function stateOf(handle) {
|
|
252
|
+
const state = states.get(handle);
|
|
253
|
+
if (!state)
|
|
254
|
+
throw new TypeError("not an auth handle");
|
|
255
|
+
return state;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Fail unless a session can be built on `handle`: it ended, or it backs an active session.
|
|
259
|
+
*
|
|
260
|
+
* @internal
|
|
261
|
+
*/
|
|
262
|
+
export function vacant(handle) {
|
|
263
|
+
stateOf(handle).vacant();
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Why `handle` ended, or undefined while it can still back a session.
|
|
267
|
+
*
|
|
268
|
+
* @internal
|
|
269
|
+
*/
|
|
270
|
+
export function ended(handle) {
|
|
271
|
+
return stateOf(handle).closed;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* When `handle` ends, with why, for a watcher that outlives its sessions.
|
|
275
|
+
*
|
|
276
|
+
* @internal
|
|
277
|
+
*/
|
|
278
|
+
export function ending(handle) {
|
|
279
|
+
return stateOf(handle).end;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* The tokens this side presents and the grant they earn, across every session built on it.
|
|
283
|
+
*
|
|
284
|
+
* A session made without one creates its own, returned by `Session.auth`, which ends with
|
|
285
|
+
* that session. Pass one to `connect` as `auth` instead and it outlives its sessions: each
|
|
286
|
+
* presents every token the handle holds, so a {@link Credential} it returned keeps riding a route's
|
|
287
|
+
* announcements across a reconnect. It backs one active session at a time, plus the ones
|
|
288
|
+
* draining after a GOAWAY or a `close()`. Mirrors the Rust `moq_net::auth::Handle`.
|
|
289
|
+
*/
|
|
290
|
+
export class Handle {
|
|
291
|
+
/** A handle backing no session yet, for `connect`'s `auth` option. */
|
|
292
|
+
constructor() {
|
|
293
|
+
states.set(this, new HandleState());
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* The union of every grant this side holds on the live session: undefined until its peer
|
|
297
|
+
* first answers a token, while no session is live, and forever on a version without AUTH.
|
|
298
|
+
*/
|
|
299
|
+
get grant() {
|
|
300
|
+
return stateOf(this).grant;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Present another token on every session of this handle, returning it at once; its
|
|
304
|
+
* {@link Credential.answered} settles on the peer's first verdict, and closing it withdraws
|
|
305
|
+
* it, answered or not.
|
|
306
|
+
*
|
|
307
|
+
* With no session live it waits for the next one. A refusal that may pass, such as an
|
|
308
|
+
* unreachable auth server, is presented again after a backoff on moq-lite, and so is a token
|
|
309
|
+
* whose stream the peer drops without a verdict. Throws once the handle ended, or while its
|
|
310
|
+
* own session drains with no successor.
|
|
311
|
+
*/
|
|
312
|
+
add(token) {
|
|
313
|
+
return this.present(token);
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Present another token like {@link add}, returning what the token rotation reads.
|
|
317
|
+
*
|
|
318
|
+
* @internal
|
|
319
|
+
*/
|
|
320
|
+
present(token) {
|
|
321
|
+
// A copy, so the caller reusing its buffer never changes what a request carries.
|
|
322
|
+
const bytes = typeof token === "string" ? new TextEncoder().encode(token) : token.slice();
|
|
323
|
+
return stateOf(this).add(bytes);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Answer every token the peer presents, instead of the default: granting what this side
|
|
327
|
+
* publishes and consumes for the connection's own credential and refusing any other.
|
|
328
|
+
*
|
|
329
|
+
* Call it as soon as connect or accept resolves, in the same task: whoever answers is
|
|
330
|
+
* decided once, right after. Throws {@link Duplicate} once that has happened.
|
|
331
|
+
*
|
|
332
|
+
* The peer's stream credit bounds how many tokens wait unanswered, since each holds its
|
|
333
|
+
* stream open until answered or withdrawn. A withdrawn token leaves the queue.
|
|
334
|
+
*
|
|
335
|
+
* @internal See {@link Request}.
|
|
336
|
+
*/
|
|
337
|
+
requests() {
|
|
338
|
+
const state = stateOf(this);
|
|
339
|
+
if (state.acceptor !== "undecided")
|
|
340
|
+
throw new Duplicate("auth requests already taken or answered by default");
|
|
341
|
+
const queue = new RequestQueue();
|
|
342
|
+
// A session of its own that carries no AUTH never receives a token.
|
|
343
|
+
if (state.closed || (state.own && !state.live?.negotiated))
|
|
344
|
+
queue.close();
|
|
345
|
+
state.acceptor = queue;
|
|
346
|
+
return queue;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* End the handle with `err`: every token ends, its sessions stop presenting them, and the
|
|
350
|
+
* peer's queued tokens are refused. A handle a session created for itself ends with that
|
|
351
|
+
* session.
|
|
352
|
+
*/
|
|
353
|
+
abort(err = new Error("auth handle closed")) {
|
|
354
|
+
stateOf(this).abort(err);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
/** A handle of a session's own, which ends with it. */
|
|
358
|
+
function ownHandle() {
|
|
359
|
+
const handle = new Handle();
|
|
360
|
+
stateOf(handle).own = true;
|
|
361
|
+
return handle;
|
|
362
|
+
}
|
|
363
|
+
/** The peer's token, answered by the application. */
|
|
364
|
+
class PeerRequest {
|
|
365
|
+
token;
|
|
366
|
+
#issued;
|
|
367
|
+
#answered = false;
|
|
368
|
+
constructor(token, issued) {
|
|
369
|
+
this.token = token;
|
|
370
|
+
this.#issued = issued;
|
|
371
|
+
}
|
|
372
|
+
get closed() {
|
|
373
|
+
return this.#issued.closed;
|
|
374
|
+
}
|
|
375
|
+
get ended() {
|
|
376
|
+
return this.#issued.ended;
|
|
377
|
+
}
|
|
378
|
+
accept(grant) {
|
|
379
|
+
if (this.#answered)
|
|
380
|
+
throw new Error("already answered");
|
|
381
|
+
this.#answered = true;
|
|
382
|
+
this.#issued.update(grant);
|
|
383
|
+
return this.#issued;
|
|
384
|
+
}
|
|
385
|
+
reject(code, reason) {
|
|
386
|
+
if (this.#answered)
|
|
387
|
+
throw new Error("already answered");
|
|
388
|
+
this.#answered = true;
|
|
389
|
+
this.#issued.revoke(code, reason);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
/** Our side of one of the peer's tokens: the grant we issued and its stream. */
|
|
393
|
+
class IssuedGrant {
|
|
394
|
+
#closed = new Once();
|
|
395
|
+
#stream;
|
|
396
|
+
#wire;
|
|
397
|
+
#writes = Promise.resolve();
|
|
398
|
+
/**
|
|
399
|
+
* Open, holding the latest grant until its write starts, so a newer one replaces it rather
|
|
400
|
+
* than queueing; or done: closed, revoked, or a reply that could not be sent.
|
|
401
|
+
*/
|
|
402
|
+
#state = { kind: "open" };
|
|
403
|
+
constructor(stream, wire) {
|
|
404
|
+
this.#stream = stream;
|
|
405
|
+
this.#wire = wire;
|
|
406
|
+
// The presenter withdraws by closing or cancelling its side.
|
|
407
|
+
void wire.withdrawn(stream).then(() => this.#closed.set(null), (err) => this.#closed.set(err instanceof StreamError && err.code === StreamCode.Cancel ? null : error(err)));
|
|
408
|
+
}
|
|
409
|
+
get closed() {
|
|
410
|
+
return this.#closed;
|
|
411
|
+
}
|
|
412
|
+
get ended() {
|
|
413
|
+
return this.#closed.peek() !== undefined;
|
|
414
|
+
}
|
|
415
|
+
#write(write) {
|
|
416
|
+
this.#writes = this.#writes.then(write).catch((err) => {
|
|
417
|
+
// The peer already closed the stream: nothing left to tell it.
|
|
418
|
+
if (err instanceof StreamError)
|
|
419
|
+
return;
|
|
420
|
+
// A grant the wire cannot carry is withheld, never widened, and so is any other
|
|
421
|
+
// reply that fails to encode. An update since then is dropped with it.
|
|
422
|
+
if (!(err instanceof Unsupported))
|
|
423
|
+
console.warn("auth reply not sent", err);
|
|
424
|
+
this.#state = { kind: "done" };
|
|
425
|
+
return this.#wire.unsupported(this.#stream, error(err).message).catch(() => void 0);
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
update(grant) {
|
|
429
|
+
const state = this.#state;
|
|
430
|
+
if (state.kind === "done")
|
|
431
|
+
return;
|
|
432
|
+
// A grant still waiting to be written is replaced, so a peer withholding stream credit
|
|
433
|
+
// holds at most one.
|
|
434
|
+
const queued = state.queued !== undefined;
|
|
435
|
+
state.queued = grant;
|
|
436
|
+
if (queued)
|
|
437
|
+
return;
|
|
438
|
+
this.#write(async () => {
|
|
439
|
+
// A close since then sends the grant itself.
|
|
440
|
+
const state = this.#state;
|
|
441
|
+
if (state.kind === "done" || state.queued === undefined)
|
|
442
|
+
return;
|
|
443
|
+
const grant = state.queued;
|
|
444
|
+
state.queued = undefined;
|
|
445
|
+
await this.#send(grant);
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
async #send(grant) {
|
|
449
|
+
const expires = grant.expires?.since(wall()).asMillis();
|
|
450
|
+
await this.#wire.grant(this.#stream, { publish: grant.publish, subscribe: grant.subscribe, expires });
|
|
451
|
+
}
|
|
452
|
+
revoke(code, reason) {
|
|
453
|
+
if (this.#state.kind === "done")
|
|
454
|
+
return;
|
|
455
|
+
// The peer never saw a grant still queued, so the refusal replaces it.
|
|
456
|
+
this.#state = { kind: "done" };
|
|
457
|
+
this.#write(() => this.#wire.refuse(this.#stream, code, reason));
|
|
458
|
+
this.#writes = this.#writes.then(() => this.#stream.writer.close());
|
|
459
|
+
}
|
|
460
|
+
close() {
|
|
461
|
+
const state = this.#state;
|
|
462
|
+
if (state.kind === "done")
|
|
463
|
+
return;
|
|
464
|
+
this.#state = { kind: "done" };
|
|
465
|
+
// The grant still queued is the last thing the peer hears before the end.
|
|
466
|
+
const last = state.queued;
|
|
467
|
+
if (last !== undefined)
|
|
468
|
+
this.#write(() => this.#send(last));
|
|
469
|
+
this.#writes = this.#writes.then(() => this.#stream.writer.close());
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
/** The peer's tokens, queued for the application. */
|
|
473
|
+
class RequestQueue {
|
|
474
|
+
#queue = [];
|
|
475
|
+
// How many requests survived the last prune: pruning again only once the queue doubles
|
|
476
|
+
// keeps a push amortized O(1).
|
|
477
|
+
#survivors = 0;
|
|
478
|
+
#waiters = [];
|
|
479
|
+
#closed = false;
|
|
480
|
+
/** Queue the token for the application, or refuse it when closed. */
|
|
481
|
+
push(request) {
|
|
482
|
+
if (this.#closed) {
|
|
483
|
+
request.reject(SessionCode.Unauthorized, "not accepting tokens");
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
// A withdrawn token gave its stream back, so it must not stay queued while the
|
|
487
|
+
// application is busy: that would let a peer that keeps withdrawing grow the queue.
|
|
488
|
+
if (this.#queue.length >= 2 * Math.max(this.#survivors, 1)) {
|
|
489
|
+
this.#queue = this.#queue.filter((queued) => !queued.ended);
|
|
490
|
+
this.#survivors = this.#queue.length;
|
|
491
|
+
}
|
|
492
|
+
const waiter = this.#waiters.shift();
|
|
493
|
+
if (waiter)
|
|
494
|
+
waiter(request);
|
|
495
|
+
else
|
|
496
|
+
this.#queue.push(request);
|
|
497
|
+
}
|
|
498
|
+
next() {
|
|
499
|
+
let next = this.#queue.shift();
|
|
500
|
+
while (next?.ended)
|
|
501
|
+
next = this.#queue.shift();
|
|
502
|
+
if (next || this.#closed)
|
|
503
|
+
return Promise.resolve(next);
|
|
504
|
+
return new Promise((resolve) => this.#waiters.push(resolve));
|
|
505
|
+
}
|
|
506
|
+
close() {
|
|
507
|
+
this.#closed = true;
|
|
508
|
+
for (const request of this.#queue.splice(0)) {
|
|
509
|
+
request.reject(SessionCode.Unauthorized, "not accepting tokens");
|
|
510
|
+
}
|
|
511
|
+
for (const waiter of this.#waiters.splice(0))
|
|
512
|
+
waiter(undefined);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* One session's side of a {@link Handle}: presents the handle's tokens and its own
|
|
517
|
+
* credential, one stream each, and answers the peer's. The wire decides only the encoding;
|
|
518
|
+
* see {@link AuthWire}.
|
|
519
|
+
*
|
|
520
|
+
* @internal
|
|
521
|
+
*/
|
|
522
|
+
export class AuthSession {
|
|
523
|
+
/** The peer sent a malformed AUTH message; the owning connection closes the session. */
|
|
524
|
+
violated = new Once();
|
|
525
|
+
/** The handle this session is built on. */
|
|
526
|
+
handle;
|
|
527
|
+
#state;
|
|
528
|
+
#wire;
|
|
529
|
+
#requests;
|
|
530
|
+
#peerGrant;
|
|
531
|
+
#draining;
|
|
532
|
+
#ended = new Signal(0);
|
|
533
|
+
#union = new Signal(undefined);
|
|
534
|
+
// The union until the session ends, which is not a revocation: what the session covered
|
|
535
|
+
// ends with the session's own error, not as unauthorized.
|
|
536
|
+
#scope = new Signal(undefined);
|
|
537
|
+
// The peer replied to some token, so the union is known even when empty.
|
|
538
|
+
#replied = false;
|
|
539
|
+
#presented = new Set();
|
|
540
|
+
// The handle's tokens as this session presents them, so a request carries only those.
|
|
541
|
+
#byToken = new Map();
|
|
542
|
+
// How many presented tokens await a reply: at setup, and with bytes. Recounted from
|
|
543
|
+
// #presented by #recount after every change to it or to an `isAnswered`.
|
|
544
|
+
#setupPending = new Signal(0);
|
|
545
|
+
#pending = new Signal(0);
|
|
546
|
+
// The peer's verdict on the connection credential this session presented: null once accepted,
|
|
547
|
+
// the refusal, or undefined while it has none.
|
|
548
|
+
#credential = new Signal(undefined);
|
|
549
|
+
// Whether the peer said it accepts the connection credential, which a silent version never does.
|
|
550
|
+
#accepted = new Signal(false);
|
|
551
|
+
#silent;
|
|
552
|
+
#closed = false;
|
|
553
|
+
// Whoever answers the peer's tokens is decided once, after the task that established
|
|
554
|
+
// the session: an app that calls requests() as soon as connect/accept resolves always
|
|
555
|
+
// wins, however quickly the peer's first token arrives.
|
|
556
|
+
#decided = yieldNow();
|
|
557
|
+
/** Throws {@link Duplicate} while `handle` backs another active session, or the handle's end. */
|
|
558
|
+
constructor({ wire, requests, peerGrant, handle, draining, awaiting, silent }) {
|
|
559
|
+
this.handle = handle ?? ownHandle();
|
|
560
|
+
this.#state = stateOf(this.handle);
|
|
561
|
+
this.#wire = wire;
|
|
562
|
+
this.#requests = requests ?? false;
|
|
563
|
+
this.#peerGrant = peerGrant;
|
|
564
|
+
this.#draining = draining ?? (() => false);
|
|
565
|
+
this.#silent = silent ?? false;
|
|
566
|
+
this.#state.attach(this);
|
|
567
|
+
// A session without AUTH has the peer's acceptance with its handshake, unless it awaits its SETUP.
|
|
568
|
+
if (!wire && !awaiting) {
|
|
569
|
+
this.#credential.set(null);
|
|
570
|
+
if (!silent)
|
|
571
|
+
this.#accepted.set(true);
|
|
572
|
+
}
|
|
573
|
+
// Present the connection's own credential right away, so both sides learn their
|
|
574
|
+
// grant without waiting on the app.
|
|
575
|
+
if (wire)
|
|
576
|
+
this.#present(wire, new Presented(new Uint8Array(), true));
|
|
577
|
+
for (const token of [...this.#state.tokens])
|
|
578
|
+
this.offer(token);
|
|
579
|
+
}
|
|
580
|
+
/** Whether the session still takes new work: open, neither closing nor past a GOAWAY. */
|
|
581
|
+
get active() {
|
|
582
|
+
return !this.#closed && !this.#draining();
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* The peer's verdict on the connection credential this session presented: `null` once it
|
|
586
|
+
* accepted it, its refusal, or undefined while it has none, which the session ending leaves
|
|
587
|
+
* to the session's own close.
|
|
588
|
+
*/
|
|
589
|
+
get credential() {
|
|
590
|
+
return this.#credential;
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* Whether the peer said it accepts the connection credential: with its handshake, its SETUP,
|
|
594
|
+
* or the AUTH_OK to the connection's own credential (moq-lite-07). Never on a silent version.
|
|
595
|
+
* The session ending leaves it as it was.
|
|
596
|
+
*/
|
|
597
|
+
get accepted() {
|
|
598
|
+
return this.#accepted;
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Whether the version never answers the connection credential (a moq-lite-03/04 client), so
|
|
602
|
+
* only uptime suggests the peer took it.
|
|
603
|
+
*/
|
|
604
|
+
get silent() {
|
|
605
|
+
return this.#silent;
|
|
606
|
+
}
|
|
607
|
+
/** The peer's SETUP arrived, so it accepted the connection credential a session without AUTH presented. */
|
|
608
|
+
accept() {
|
|
609
|
+
if (this.#wire)
|
|
610
|
+
return;
|
|
611
|
+
this.#credential.set(null);
|
|
612
|
+
this.#accepted.set(true);
|
|
613
|
+
}
|
|
614
|
+
/** The union of this session's grants, undefined until its peer first answers. */
|
|
615
|
+
get grant() {
|
|
616
|
+
return this.#union;
|
|
617
|
+
}
|
|
618
|
+
/** The grant this session enforces: {@link grant}, kept as it was once the session ends. */
|
|
619
|
+
get scope() {
|
|
620
|
+
return this.#scope;
|
|
621
|
+
}
|
|
622
|
+
/** Whether this session exchanges tokens at all. */
|
|
623
|
+
get negotiated() {
|
|
624
|
+
return this.#wire !== undefined;
|
|
625
|
+
}
|
|
626
|
+
/** The handle's `token` grant on this session. */
|
|
627
|
+
grantOf(token) {
|
|
628
|
+
return this.#byToken.get(token)?.grant;
|
|
629
|
+
}
|
|
630
|
+
/** Whether this session still presents the handle's `token`. */
|
|
631
|
+
presents(token) {
|
|
632
|
+
const presented = this.#byToken.get(token);
|
|
633
|
+
return presented !== undefined && !presented.ended && !presented.withdrawn;
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* Present one of the handle's tokens on this session. A draining session takes no new
|
|
637
|
+
* tokens, so its verdict never ends one its successor carries.
|
|
638
|
+
*/
|
|
639
|
+
offer(token) {
|
|
640
|
+
if (!this.active || this.#byToken.has(token))
|
|
641
|
+
return;
|
|
642
|
+
if (!this.#wire && !this.#requests) {
|
|
643
|
+
this.#state.verdict(token, new Unsupported());
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
const presented = new Presented(token.bytes, false, token);
|
|
647
|
+
this.#byToken.set(token, presented);
|
|
648
|
+
if (this.#wire) {
|
|
649
|
+
this.#present(this.#wire, presented);
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
// Only a request carries it, and the peer judges it there: no grant to wait for.
|
|
653
|
+
presented.isAnswered = true;
|
|
654
|
+
this.#presented.add(presented);
|
|
655
|
+
token.answer();
|
|
656
|
+
}
|
|
657
|
+
/** Stop presenting one of the handle's tokens: withdrawn, or ended for good elsewhere. */
|
|
658
|
+
withdraw(token) {
|
|
659
|
+
const presented = this.#byToken.get(token);
|
|
660
|
+
if (!presented || presented.withdrawn)
|
|
661
|
+
return;
|
|
662
|
+
presented.withdrawn = true;
|
|
663
|
+
presented.grant = undefined;
|
|
664
|
+
// The stream's loop notices and ends the presentation; one still opening checks on
|
|
665
|
+
// arrival, and one waiting to retry wakes. One without a stream to come (carried only by
|
|
666
|
+
// requests) ends here.
|
|
667
|
+
if (presented.stream)
|
|
668
|
+
presented.stream.abort(cancel());
|
|
669
|
+
else if (presented.retry)
|
|
670
|
+
presented.retry.abort();
|
|
671
|
+
else if (!this.#wire) {
|
|
672
|
+
presented.ended = true;
|
|
673
|
+
this.#presented.delete(presented);
|
|
674
|
+
this.#byToken.delete(token);
|
|
675
|
+
this.#ended.update((n) => n + 1);
|
|
676
|
+
}
|
|
677
|
+
this.#recompute();
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* The bytes a request carries for `token`: undefined for none, for one another handle
|
|
681
|
+
* issued, or for one that ended here.
|
|
682
|
+
*/
|
|
683
|
+
carried(token) {
|
|
684
|
+
if (!this.#requests || !(token instanceof Token))
|
|
685
|
+
return undefined;
|
|
686
|
+
const presented = this.#byToken.get(token);
|
|
687
|
+
if (!presented || presented.ended || presented.withdrawn)
|
|
688
|
+
return undefined;
|
|
689
|
+
return presented.token;
|
|
690
|
+
}
|
|
691
|
+
/** Bumps whenever one of this session's tokens ends, so a request carrying it drops it. */
|
|
692
|
+
get ended() {
|
|
693
|
+
return this.#ended;
|
|
694
|
+
}
|
|
695
|
+
/** Resolves once every token the session presented at setup has its first reply. */
|
|
696
|
+
async setupAnswered() {
|
|
697
|
+
while (this.#setupPending.peek() > 0)
|
|
698
|
+
await this.#setupPending.changed();
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Wait for presented tokens that might admit this path, without delaying a covered path.
|
|
702
|
+
* Resolves false once `until`, the request's own lifetime, settles first, so an abandoned
|
|
703
|
+
* request never waits on a token that may never be answered. `until` is called only once
|
|
704
|
+
* the request has to wait.
|
|
705
|
+
*/
|
|
706
|
+
async ready(path, direction, { signal, until } = {}) {
|
|
707
|
+
let started;
|
|
708
|
+
let ended = false;
|
|
709
|
+
let wake;
|
|
710
|
+
const end = () => {
|
|
711
|
+
ended = true;
|
|
712
|
+
wake?.();
|
|
713
|
+
};
|
|
714
|
+
try {
|
|
715
|
+
while (this.#pending.peek() > 0 && !this.#union.peek()?.[direction].matches(path)) {
|
|
716
|
+
if (ended)
|
|
717
|
+
return false;
|
|
718
|
+
if (started === undefined) {
|
|
719
|
+
started = now();
|
|
720
|
+
until?.().then(end, end);
|
|
721
|
+
}
|
|
722
|
+
signal?.throwIfAborted();
|
|
723
|
+
await new Promise((resolve, reject) => {
|
|
724
|
+
const cleanup = () => {
|
|
725
|
+
pending();
|
|
726
|
+
grant();
|
|
727
|
+
wake = undefined;
|
|
728
|
+
signal?.removeEventListener("abort", abort);
|
|
729
|
+
};
|
|
730
|
+
const done = () => {
|
|
731
|
+
cleanup();
|
|
732
|
+
resolve();
|
|
733
|
+
};
|
|
734
|
+
const abort = () => {
|
|
735
|
+
cleanup();
|
|
736
|
+
reject(signal?.reason);
|
|
737
|
+
};
|
|
738
|
+
const pending = this.#pending.changed(done);
|
|
739
|
+
const grant = this.#union.changed(done);
|
|
740
|
+
wake = done;
|
|
741
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
return true;
|
|
745
|
+
}
|
|
746
|
+
finally {
|
|
747
|
+
if (started !== undefined) {
|
|
748
|
+
console.debug(`request waited for authorization: path=${path} waited=${now().since(started)}`);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
/** Answer one of the peer's token streams, for the life of its token. */
|
|
753
|
+
async serve(stream) {
|
|
754
|
+
const wire = this.#wire;
|
|
755
|
+
if (!wire)
|
|
756
|
+
throw new Error("auth not negotiated");
|
|
757
|
+
let token;
|
|
758
|
+
try {
|
|
759
|
+
token = await wire.accept(stream);
|
|
760
|
+
}
|
|
761
|
+
catch (err) {
|
|
762
|
+
if (err instanceof StreamError ||
|
|
763
|
+
err instanceof SessionError ||
|
|
764
|
+
err instanceof Unsupported ||
|
|
765
|
+
transportClosed(err))
|
|
766
|
+
throw err;
|
|
767
|
+
throw new ProtocolViolation("malformed AUTH", { cause: err });
|
|
768
|
+
}
|
|
769
|
+
await this.#decided;
|
|
770
|
+
const acceptor = this.#state.decide();
|
|
771
|
+
const issued = new IssuedGrant(stream, wire);
|
|
772
|
+
if (acceptor) {
|
|
773
|
+
const request = new PeerRequest(token, issued);
|
|
774
|
+
acceptor.push(request);
|
|
775
|
+
}
|
|
776
|
+
else if (token.byteLength > 0) {
|
|
777
|
+
// Only the connection's own credential has a default answer; a token needs
|
|
778
|
+
// someone to verify it.
|
|
779
|
+
await wire.unsupported(stream, "no acceptor for tokens");
|
|
780
|
+
return;
|
|
781
|
+
}
|
|
782
|
+
else {
|
|
783
|
+
issued.update(this.#peerGrant);
|
|
784
|
+
}
|
|
785
|
+
const ended = await issued.closed;
|
|
786
|
+
issued.close();
|
|
787
|
+
if (ended instanceof ProtocolViolation)
|
|
788
|
+
throw ended;
|
|
789
|
+
}
|
|
790
|
+
/**
|
|
791
|
+
* End the session: fail every pending token here, leaving the handle's tokens for the next
|
|
792
|
+
* session. A handle of the session's own ends with it, closing the requests.
|
|
793
|
+
*/
|
|
794
|
+
close(err = new Error("session closed")) {
|
|
795
|
+
if (this.#closed)
|
|
796
|
+
return;
|
|
797
|
+
this.#closed = true;
|
|
798
|
+
for (const presented of this.#presented) {
|
|
799
|
+
presented.ended = true;
|
|
800
|
+
presented.isAnswered = true;
|
|
801
|
+
presented.grant = undefined;
|
|
802
|
+
presented.retry?.abort();
|
|
803
|
+
}
|
|
804
|
+
this.#presented.clear();
|
|
805
|
+
this.#byToken.clear();
|
|
806
|
+
this.#recompute();
|
|
807
|
+
this.#state.detach(this, err);
|
|
808
|
+
}
|
|
809
|
+
#present(wire, presented) {
|
|
810
|
+
this.#presented.add(presented);
|
|
811
|
+
this.#recount();
|
|
812
|
+
void this.#run(wire, presented);
|
|
813
|
+
}
|
|
814
|
+
async #run(wire, presented) {
|
|
815
|
+
let result = null;
|
|
816
|
+
let closed = false;
|
|
817
|
+
// The peer refused the last attempt with a reply, rather than losing its stream.
|
|
818
|
+
let refused;
|
|
819
|
+
// The peer granted the token, so a clean close ends the grant. A retry clears it.
|
|
820
|
+
let granted = false;
|
|
821
|
+
// The peer replied to an earlier attempt, so it knows AUTH.
|
|
822
|
+
let replied = false;
|
|
823
|
+
let delay;
|
|
824
|
+
for (;;) {
|
|
825
|
+
refused = undefined;
|
|
826
|
+
// Whether the peer answered this token, so a close is not the peer predating AUTH:
|
|
827
|
+
// a grant on this stream, or a reply to an earlier one that this retry follows.
|
|
828
|
+
let answered = replied;
|
|
829
|
+
try {
|
|
830
|
+
const stream = await wire.present(presented.token);
|
|
831
|
+
presented.stream = stream;
|
|
832
|
+
if (presented.withdrawn || presented.ended)
|
|
833
|
+
throw cancel();
|
|
834
|
+
for (;;) {
|
|
835
|
+
let reply;
|
|
836
|
+
try {
|
|
837
|
+
reply = await wire.read(stream);
|
|
838
|
+
}
|
|
839
|
+
catch (err) {
|
|
840
|
+
if (err instanceof StreamError ||
|
|
841
|
+
err instanceof SessionError ||
|
|
842
|
+
err instanceof Unsupported ||
|
|
843
|
+
transportClosed(err))
|
|
844
|
+
throw err;
|
|
845
|
+
throw new ProtocolViolation("malformed AUTH reply", { cause: err });
|
|
846
|
+
}
|
|
847
|
+
if (!reply) {
|
|
848
|
+
// The peer ended the grant without revoking it, or closed without ever
|
|
849
|
+
// answering. Close our side too, which is what settles its Issued.closed.
|
|
850
|
+
result = answered ? null : new Unsupported();
|
|
851
|
+
stream.close();
|
|
852
|
+
break;
|
|
853
|
+
}
|
|
854
|
+
if ("grant" in reply) {
|
|
855
|
+
const expires = reply.grant.expires === undefined
|
|
856
|
+
? undefined
|
|
857
|
+
: wall().add(Duration.millis(reply.grant.expires));
|
|
858
|
+
presented.grant = { publish: reply.grant.publish, subscribe: reply.grant.subscribe, expires };
|
|
859
|
+
answered = granted = replied = true;
|
|
860
|
+
delay = undefined;
|
|
861
|
+
this.#replied = true;
|
|
862
|
+
if (presented.setup) {
|
|
863
|
+
this.#credential.set(null);
|
|
864
|
+
this.#accepted.set(true);
|
|
865
|
+
}
|
|
866
|
+
this.#answered(presented);
|
|
867
|
+
this.#recompute();
|
|
868
|
+
continue;
|
|
869
|
+
}
|
|
870
|
+
console.warn("auth token refused", reply.refused);
|
|
871
|
+
// A refused setup token leaves an empty union, not an unknown (unrestricted)
|
|
872
|
+
// one. A grant the acceptor could not tell is unknown, not empty.
|
|
873
|
+
if (!(reply.refused instanceof Unsupported))
|
|
874
|
+
this.#replied = true;
|
|
875
|
+
result = reply.refused;
|
|
876
|
+
replied = true;
|
|
877
|
+
refused = reply.undecided ? "undecided" : "final";
|
|
878
|
+
stream.close();
|
|
879
|
+
break;
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
catch (err) {
|
|
883
|
+
// End both halves: a peer that reset only its own leaves ours open, and a retry that
|
|
884
|
+
// abandoned it would hold the stream's credit until the session ends.
|
|
885
|
+
presented.stream?.abort(cancel());
|
|
886
|
+
closed = transportClosed(err);
|
|
887
|
+
if (presented.withdrawn || presented.ended) {
|
|
888
|
+
result = null;
|
|
889
|
+
}
|
|
890
|
+
else if (!answered && err instanceof StreamError) {
|
|
891
|
+
// A peer that predates AUTH resets a stream type it does not know.
|
|
892
|
+
result = new Unsupported();
|
|
893
|
+
}
|
|
894
|
+
else {
|
|
895
|
+
result = error(err);
|
|
896
|
+
if (result instanceof ProtocolViolation && !this.#closed && this.violated.peek() === undefined) {
|
|
897
|
+
this.violated.set(result);
|
|
898
|
+
}
|
|
899
|
+
if (!this.#closed)
|
|
900
|
+
console.warn("auth token ended", result);
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
presented.stream = undefined;
|
|
904
|
+
// Present the token again after a backoff while it is still wanted on an active
|
|
905
|
+
// session: after a refusal that may pass, such as an unreachable auth server (only
|
|
906
|
+
// moq-lite's AUTH_ERROR carries such a code), or, on a shared handle, after its stream
|
|
907
|
+
// was lost without a verdict, so the session never runs on without it. A handle of the
|
|
908
|
+
// session's own ends a lost token instead, which tells the application.
|
|
909
|
+
if (isVerdict(refused, granted, result) ||
|
|
910
|
+
closed ||
|
|
911
|
+
!this.active ||
|
|
912
|
+
presented.withdrawn ||
|
|
913
|
+
presented.ended ||
|
|
914
|
+
result instanceof ProtocolViolation ||
|
|
915
|
+
(refused === undefined && this.#state.own))
|
|
916
|
+
break;
|
|
917
|
+
presented.grant = undefined;
|
|
918
|
+
granted = false;
|
|
919
|
+
// Unanswered again, as on its first presentation: a request or publication the token
|
|
920
|
+
// might cover waits for the retry's verdict rather than being judged without it.
|
|
921
|
+
presented.isAnswered = false;
|
|
922
|
+
this.#recompute();
|
|
923
|
+
delay = delay === undefined ? RETRY_INITIAL : delay.mul(2).min(RETRY_MAX);
|
|
924
|
+
presented.retry = new AbortController();
|
|
925
|
+
await sleep(delay, { signal: presented.retry.signal }).catch(() => void 0);
|
|
926
|
+
presented.retry = undefined;
|
|
927
|
+
if (this.#closed || presented.withdrawn || presented.ended) {
|
|
928
|
+
refused = undefined;
|
|
929
|
+
result = null;
|
|
930
|
+
break;
|
|
931
|
+
}
|
|
932
|
+
// After a GOAWAY the peer must not see new streams: the successor presents it.
|
|
933
|
+
if (this.#draining()) {
|
|
934
|
+
refused = undefined;
|
|
935
|
+
result = new StreamError(StreamCode.GoingAway);
|
|
936
|
+
break;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
// Already ended by the session's close.
|
|
940
|
+
if (presented.ended)
|
|
941
|
+
return;
|
|
942
|
+
// The peer's verdict on the credential: Unsupported is the moq-transport SETUP that
|
|
943
|
+
// carried it accepting it before the peer declined AUTH. Anything else leaves it to the close.
|
|
944
|
+
if (presented.setup && !presented.withdrawn && isVerdict(refused, granted, result)) {
|
|
945
|
+
this.#credential.set(result instanceof Unsupported ? null : (result ?? new Error("the peer ended the credential")));
|
|
946
|
+
}
|
|
947
|
+
presented.ended = true;
|
|
948
|
+
presented.grant = undefined;
|
|
949
|
+
// A token that ends unanswered counts as answered for enforcement: its refusal is
|
|
950
|
+
// the reply.
|
|
951
|
+
presented.isAnswered = true;
|
|
952
|
+
this.#presented.delete(presented);
|
|
953
|
+
const owner = presented.owner;
|
|
954
|
+
if (owner && this.#byToken.get(owner) === presented)
|
|
955
|
+
this.#byToken.delete(owner);
|
|
956
|
+
this.#ended.update((n) => n + 1);
|
|
957
|
+
// Only the peer's verdict ends one of the handle's tokens on every session: a refusal,
|
|
958
|
+
// Unsupported, or a clean close after a grant. Anything else leaves it for the next
|
|
959
|
+
// session, since an active one presents it again instead.
|
|
960
|
+
// A draining session's verdict is stale while an active session still presents the
|
|
961
|
+
// token: that session's own answer decides, even mid-retry with no grant right now.
|
|
962
|
+
const superseded = !this.active &&
|
|
963
|
+
owner !== undefined &&
|
|
964
|
+
this.#state.sessions.some((session) => session !== this && session.active && session.presents(owner));
|
|
965
|
+
// A handle of the session's own has no next session to present it, so any end is final.
|
|
966
|
+
const settled = !this.#closed &&
|
|
967
|
+
!presented.withdrawn &&
|
|
968
|
+
!superseded &&
|
|
969
|
+
(this.#state.own || isVerdict(refused, granted, result));
|
|
970
|
+
if (owner && settled)
|
|
971
|
+
this.#state.verdict(owner, result);
|
|
972
|
+
// Closed before the union shrinks, so the scope never reads it as a revocation.
|
|
973
|
+
if (closed)
|
|
974
|
+
this.close();
|
|
975
|
+
this.#recompute();
|
|
976
|
+
}
|
|
977
|
+
/** The peer granted `presented`: it counts as answered, and so does the handle's token. */
|
|
978
|
+
#answered(presented) {
|
|
979
|
+
presented.isAnswered = true;
|
|
980
|
+
if (presented.owner)
|
|
981
|
+
presented.owner.inband = true;
|
|
982
|
+
presented.owner?.answer();
|
|
983
|
+
}
|
|
984
|
+
/** Count the presented tokens still awaiting a reply, for enforcement and the setup wait. */
|
|
985
|
+
#recount() {
|
|
986
|
+
let setup = 0;
|
|
987
|
+
let pending = 0;
|
|
988
|
+
for (const presented of this.#presented) {
|
|
989
|
+
if (presented.isAnswered)
|
|
990
|
+
continue;
|
|
991
|
+
if (presented.setup)
|
|
992
|
+
setup += 1;
|
|
993
|
+
if (presented.token.byteLength > 0)
|
|
994
|
+
pending += 1;
|
|
995
|
+
}
|
|
996
|
+
this.#setupPending.set(setup);
|
|
997
|
+
this.#pending.set(pending);
|
|
998
|
+
}
|
|
999
|
+
#recompute() {
|
|
1000
|
+
this.#recount();
|
|
1001
|
+
const granted = [];
|
|
1002
|
+
for (const presented of this.#presented) {
|
|
1003
|
+
if (presented.grant)
|
|
1004
|
+
granted.push(presented.grant);
|
|
1005
|
+
}
|
|
1006
|
+
// Undefined until the first reply; an empty union afterwards grants nothing.
|
|
1007
|
+
if (granted.length > 0 || this.#replied) {
|
|
1008
|
+
const next = union(granted);
|
|
1009
|
+
if (!grantsEqual(next, this.#union.peek()))
|
|
1010
|
+
this.#union.set(next);
|
|
1011
|
+
if (!this.#closed && !grantsEqual(next, this.#scope.peek()))
|
|
1012
|
+
this.#scope.set(next);
|
|
1013
|
+
}
|
|
1014
|
+
this.#state.refresh();
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
/**
|
|
1018
|
+
* Close the session when our origin publishes a broadcast our grant does not cover,
|
|
1019
|
+
* instead of leaving it to wait for a subscription that never comes.
|
|
1020
|
+
*
|
|
1021
|
+
* Starts once the tokens the session presented at setup are answered, then checks each
|
|
1022
|
+
* broadcast when it first appears. A grant that later shrinks withdraws what it no longer
|
|
1023
|
+
* covers without closing anything: the grant is read before the table, so a revocation is
|
|
1024
|
+
* never mistaken for a new unauthorized publication. Only the dialing side enforces: a
|
|
1025
|
+
* server's publish origin is everything the peer may read, not what it intends to push.
|
|
1026
|
+
*
|
|
1027
|
+
* @internal
|
|
1028
|
+
*/
|
|
1029
|
+
export async function enforceGrant({ quic, advertised, grant, setupAnswered, auth, }) {
|
|
1030
|
+
const closed = quic.closed.then(() => "closed", () => "closed");
|
|
1031
|
+
if ((await Promise.race([setupAnswered.then(() => "ready"), closed])) === "closed")
|
|
1032
|
+
return;
|
|
1033
|
+
// Ends an authorization wait with the session, without adding a reaction on `closed` per wait.
|
|
1034
|
+
const ended = new AbortController();
|
|
1035
|
+
void closed.then(() => ended.abort());
|
|
1036
|
+
// Every broadcast admitted so far that is still published.
|
|
1037
|
+
const live = new Set();
|
|
1038
|
+
for (;;) {
|
|
1039
|
+
let dispose = () => { };
|
|
1040
|
+
const woke = new Promise((resolve) => {
|
|
1041
|
+
const table = advertised.changed(() => resolve("changed"));
|
|
1042
|
+
const granted = grant.changed(() => resolve("changed"));
|
|
1043
|
+
dispose = () => {
|
|
1044
|
+
table();
|
|
1045
|
+
granted();
|
|
1046
|
+
};
|
|
1047
|
+
});
|
|
1048
|
+
const current = grant.peek();
|
|
1049
|
+
const table = advertised.peek();
|
|
1050
|
+
if (!table) {
|
|
1051
|
+
dispose();
|
|
1052
|
+
return;
|
|
1053
|
+
}
|
|
1054
|
+
if (current) {
|
|
1055
|
+
for (const path of live) {
|
|
1056
|
+
if (!table.has(path))
|
|
1057
|
+
live.delete(path);
|
|
1058
|
+
}
|
|
1059
|
+
for (const path of table.keys()) {
|
|
1060
|
+
if (live.has(path))
|
|
1061
|
+
continue;
|
|
1062
|
+
if (!current.publish.matches(path)) {
|
|
1063
|
+
try {
|
|
1064
|
+
await auth?.ready(path, "publish", { signal: ended.signal });
|
|
1065
|
+
}
|
|
1066
|
+
catch (err) {
|
|
1067
|
+
dispose();
|
|
1068
|
+
if (ended.signal.aborted)
|
|
1069
|
+
return;
|
|
1070
|
+
throw err;
|
|
1071
|
+
}
|
|
1072
|
+
// A broadcast withdrawn during the wait is no longer ours to judge.
|
|
1073
|
+
if (!advertised.peek()?.has(path))
|
|
1074
|
+
continue;
|
|
1075
|
+
if (grant.peek()?.publish.matches(path)) {
|
|
1076
|
+
live.add(path);
|
|
1077
|
+
continue;
|
|
1078
|
+
}
|
|
1079
|
+
console.error(`publishing outside our grant; closing the session: broadcast=${path}`);
|
|
1080
|
+
quic.close({
|
|
1081
|
+
closeCode: SessionCode.Unauthorized,
|
|
1082
|
+
reason: closeReason(`unauthorized: ${path}`),
|
|
1083
|
+
});
|
|
1084
|
+
dispose();
|
|
1085
|
+
return;
|
|
1086
|
+
}
|
|
1087
|
+
live.add(path);
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
// `race` drops its reaction on `closed` with the rest, which lives for the session.
|
|
1091
|
+
const why = await race([woke, closed]);
|
|
1092
|
+
dispose();
|
|
1093
|
+
if (why === "closed")
|
|
1094
|
+
return;
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
//# sourceMappingURL=auth_session.js.map
|