@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/lite/subscribe.js
CHANGED
|
@@ -1,20 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
import { Duration as ClockDuration } from "@moq/clock";
|
|
2
|
+
import { ProtocolViolation } from "../error.js";
|
|
3
|
+
import { NO_MAX_DELAY } from "../internal.js";
|
|
2
4
|
import * as Path from "../path.js";
|
|
5
|
+
import { UNBOUNDED } from "../util/key.js";
|
|
6
|
+
import { lengthLeadingOnes, parts, split } from "../util/varint.js";
|
|
7
|
+
import { withPolicy as atPolicy, EMPTY, isEmpty, liveMillis, rangeBudget, policyOf as rangePolicy, rangeTime, } from "../window.js";
|
|
8
|
+
import * as Duration from "./duration.js";
|
|
9
|
+
import { decodeNode, decodePin, encodeNode, encodePin } from "./identity.js";
|
|
3
10
|
import * as Message from "./message.js";
|
|
4
|
-
import {
|
|
11
|
+
import { fromWire, toWire } from "./priority.js";
|
|
12
|
+
import { hasFrameBounds, hasGroupOrder, hasGroupSpan, hasMeta, hasOrder, hasRanges, hasRefresh, hasSkip, resolvesStart, Version, } from "./version.js";
|
|
5
13
|
/**
|
|
6
14
|
* Encode the `Group Start` field shared by SUBSCRIBE and SUBSCRIBE_UPDATE.
|
|
7
15
|
*
|
|
8
16
|
* Lite-06 writes the raw floor (`undefined` and 0 are both group 0). A pre-06 wire
|
|
9
|
-
* encodes the
|
|
17
|
+
* encodes the key + 1: omitting the floor is 0 (the latest group, where the
|
|
10
18
|
* publisher starts) and an explicit 0 is 1, replay from the beginning.
|
|
11
19
|
*/
|
|
12
20
|
async function encodeStartGroup(w, version, startGroup) {
|
|
13
21
|
if (resolvesStart(version)) {
|
|
14
|
-
await w.
|
|
22
|
+
await w.u62(startGroup ?? 0n);
|
|
15
23
|
return;
|
|
16
24
|
}
|
|
17
|
-
await w.
|
|
25
|
+
await w.u62(startGroup === undefined ? 0n : startGroup + 1n);
|
|
18
26
|
}
|
|
19
27
|
/**
|
|
20
28
|
* Decode the `Group Start` field shared by SUBSCRIBE and SUBSCRIBE_UPDATE.
|
|
@@ -23,10 +31,10 @@ async function encodeStartGroup(w, version, startGroup) {
|
|
|
23
31
|
* {@link canonicalStartGroup} once the frame bounds are known.
|
|
24
32
|
*/
|
|
25
33
|
async function decodeStartGroup(r, version) {
|
|
26
|
-
const value = await r.
|
|
34
|
+
const value = await r.u62();
|
|
27
35
|
if (resolvesStart(version))
|
|
28
36
|
return value;
|
|
29
|
-
return value >
|
|
37
|
+
return value > 0n ? value - 1n : undefined;
|
|
30
38
|
}
|
|
31
39
|
/**
|
|
32
40
|
* Canonicalize a decoded floor: a lite-06 `Group Start` of 0 with no frame offset is the
|
|
@@ -35,7 +43,7 @@ async function decodeStartGroup(r, version) {
|
|
|
35
43
|
* partway through group 0: a catalog never leaves it).
|
|
36
44
|
*/
|
|
37
45
|
function canonicalStartGroup(version, startGroup, startFrame) {
|
|
38
|
-
if (resolvesStart(version) && startGroup ===
|
|
46
|
+
if (resolvesStart(version) && startGroup === 0n && startFrame === 0)
|
|
39
47
|
return undefined;
|
|
40
48
|
return startGroup;
|
|
41
49
|
}
|
|
@@ -74,6 +82,876 @@ async function decodeFrameBounds(r, version, startGroup, endGroup) {
|
|
|
74
82
|
}
|
|
75
83
|
return { startFrame, endFrame: endFrame > 0 ? endFrame - 1 : undefined };
|
|
76
84
|
}
|
|
85
|
+
/** The policy `range` carries. */
|
|
86
|
+
export function policyOf(range) {
|
|
87
|
+
return { priority: range.priority ?? 0, order: range.order ?? "descending" };
|
|
88
|
+
}
|
|
89
|
+
/** `range` under `policy`, which it omits where it is the default. */
|
|
90
|
+
export function withPolicy(range, policy) {
|
|
91
|
+
const { priority: _, order: __, ...rest } = range;
|
|
92
|
+
const out = rest;
|
|
93
|
+
if (policy.priority)
|
|
94
|
+
out.priority = policy.priority;
|
|
95
|
+
if (policy.order === "ascending")
|
|
96
|
+
out.order = "ascending";
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* What a subscription of `ranges` asks as a whole, for a wire or a sender without a policy per
|
|
101
|
+
* range: the highest priority, newest first if any range at that priority is. Mirrors the Rust
|
|
102
|
+
* `Policy::of`.
|
|
103
|
+
*/
|
|
104
|
+
export function subscriptionPolicy(ranges) {
|
|
105
|
+
let top;
|
|
106
|
+
for (const range of ranges) {
|
|
107
|
+
const policy = policyOf(range);
|
|
108
|
+
if (top === undefined ||
|
|
109
|
+
policy.priority > top.priority ||
|
|
110
|
+
(policy.priority === top.priority && policy.order === "descending"))
|
|
111
|
+
top = policy;
|
|
112
|
+
}
|
|
113
|
+
return top ?? { priority: 0, order: "descending" };
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The policy a group goes out at, `covers` being the Range IDs covering it, each at its current
|
|
117
|
+
* budget, and `aged` the widest budget it is known to have aged past: the highest priority
|
|
118
|
+
* among the ranges still wanting it, at that priority's order, descending breaking a tie. The
|
|
119
|
+
* subscription's whole when no range with a policy wants it. `lasts` is the budget whose aging may
|
|
120
|
+
* lower that policy, undefined once none can: a range ranked below it wanting the group longer.
|
|
121
|
+
* Mirrors the Rust `Steer::serving`.
|
|
122
|
+
*/
|
|
123
|
+
export function groupPolicy(steer, covers, aged) {
|
|
124
|
+
const wanting = [];
|
|
125
|
+
for (const id of covers) {
|
|
126
|
+
const steering = steer.steering(id);
|
|
127
|
+
if (steering && (aged === undefined || steering.budget > aged))
|
|
128
|
+
wanting.push([steering.policy, steering.budget]);
|
|
129
|
+
}
|
|
130
|
+
let top;
|
|
131
|
+
for (const [policy] of wanting) {
|
|
132
|
+
if (top === undefined ||
|
|
133
|
+
policy.priority > top.priority ||
|
|
134
|
+
(policy.priority === top.priority && policy.order === "descending"))
|
|
135
|
+
top = policy;
|
|
136
|
+
}
|
|
137
|
+
if (!top)
|
|
138
|
+
return { policy: steer.whole };
|
|
139
|
+
const best = top;
|
|
140
|
+
const same = (policy) => policy.priority === best.priority && policy.order === best.order;
|
|
141
|
+
let lasts = 0;
|
|
142
|
+
for (const [policy, budget] of wanting)
|
|
143
|
+
if (same(policy))
|
|
144
|
+
lasts = Math.max(lasts, budget);
|
|
145
|
+
const outlasted = wanting.some(([policy, budget]) => !same(policy) && budget > lasts);
|
|
146
|
+
return outlasted ? { policy: best, lasts } : { policy: best };
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The wire form of model `ranges`: the same times, a time being a group start, and live joins by lag
|
|
150
|
+
* and max, or, `placed` already at a group by index, as `joined` there (see {@link WireJoined}).
|
|
151
|
+
*/
|
|
152
|
+
export function toWireRanges(ranges, placed) {
|
|
153
|
+
return ranges.map((range, index) => {
|
|
154
|
+
const out = withPolicy({}, rangePolicy(range));
|
|
155
|
+
const time = rangeTime(range);
|
|
156
|
+
const min = liveMillis(range);
|
|
157
|
+
const group = placed?.get(index);
|
|
158
|
+
if (time !== undefined)
|
|
159
|
+
out.start = group === undefined ? { time } : { absolute: group, frame: 0 };
|
|
160
|
+
else if (min !== undefined) {
|
|
161
|
+
const budget = rangeBudget(range);
|
|
162
|
+
const max = budget < NO_MAX_DELAY ? budget : null;
|
|
163
|
+
out.start = group === undefined ? { live: { min, max } } : { joined: { absolute: group, frame: 0, max } };
|
|
164
|
+
}
|
|
165
|
+
if (range.end !== undefined)
|
|
166
|
+
out.end = { time: range.end };
|
|
167
|
+
return out;
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The lite-07 Anchor Type and values of a range's start or `end`: None (0), Time (1), Position (2),
|
|
172
|
+
* Live (3), or Joined (4). Both time ends are inclusive, so an absolute end, exclusive, goes out as
|
|
173
|
+
* the time just before it; one at group 0 holds nothing a time can say. An end or start partway
|
|
174
|
+
* through a group is a Position: its start, then the frame. A live join goes out as its lag then
|
|
175
|
+
* its max in milliseconds plus one, 0 for no limit, and only as a start; one already placed as its
|
|
176
|
+
* group's start, the frame, which may be 0, then its max as a live join carries it.
|
|
177
|
+
*/
|
|
178
|
+
function wireAnchor(anchor, end) {
|
|
179
|
+
if (anchor?.joined !== undefined) {
|
|
180
|
+
if (end)
|
|
181
|
+
throw new Error("a range ends only at a group");
|
|
182
|
+
const { absolute, frame, max } = anchor.joined;
|
|
183
|
+
if (max !== null && (!Number.isSafeInteger(max) || max < 0))
|
|
184
|
+
throw new RangeError("duration exceeds safe milliseconds");
|
|
185
|
+
return [4, absolute, BigInt(frame), max === null ? 0n : BigInt(max) + 1n];
|
|
186
|
+
}
|
|
187
|
+
if (anchor?.live !== undefined) {
|
|
188
|
+
if (end)
|
|
189
|
+
throw new Error("a range ends only at a group");
|
|
190
|
+
const { min, max } = anchor.live;
|
|
191
|
+
for (const limit of [min, max]) {
|
|
192
|
+
if (limit !== null && (!Number.isSafeInteger(limit) || limit < 0))
|
|
193
|
+
throw new RangeError("duration exceeds safe milliseconds");
|
|
194
|
+
}
|
|
195
|
+
// Each plus one, so zero says no limit.
|
|
196
|
+
return [3, min === null ? 0n : BigInt(min) + 1n, max === null ? 0n : BigInt(max) + 1n];
|
|
197
|
+
}
|
|
198
|
+
if (anchor?.absolute !== undefined) {
|
|
199
|
+
return [2, anchor.absolute, BigInt(anchor.frame ?? 0)];
|
|
200
|
+
}
|
|
201
|
+
if (anchor?.time !== undefined)
|
|
202
|
+
return [1, anchor.time];
|
|
203
|
+
return [0];
|
|
204
|
+
}
|
|
205
|
+
/** Encode one lite-07 range: its policy, then its start, then its end; see {@link wireAnchor}. */
|
|
206
|
+
async function encodeRange(w, range) {
|
|
207
|
+
await encodePolicy(w, policyOf(range));
|
|
208
|
+
for (const [anchor, end] of [
|
|
209
|
+
[range.start, false],
|
|
210
|
+
[range.end, true],
|
|
211
|
+
]) {
|
|
212
|
+
const [kind, ...values] = wireAnchor(anchor, end);
|
|
213
|
+
await w.u53(kind);
|
|
214
|
+
for (const value of values)
|
|
215
|
+
await w.u62(value);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Encode the span after the max delay. Before lite-07 that is `Group Start`, `Group End`,
|
|
220
|
+
* and the frame bounds; lite-07 carries a list of ranges, which is `ranges` when given and
|
|
221
|
+
* otherwise this span as its only one.
|
|
222
|
+
*/
|
|
223
|
+
async function encodeSpan(w, version, span, ranges, policy) {
|
|
224
|
+
if (ranges !== undefined && hasRanges(version)) {
|
|
225
|
+
if (ranges.length === 0)
|
|
226
|
+
throw new Error(EMPTY_RANGE);
|
|
227
|
+
await w.u53(ranges.length);
|
|
228
|
+
for (const range of ranges)
|
|
229
|
+
await encodeRange(w, range);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (!hasRanges(version)) {
|
|
233
|
+
await encodeStartGroup(w, version, span.startGroup);
|
|
234
|
+
await w.u62(span.endGroup !== undefined ? span.endGroup + 1n : 0n);
|
|
235
|
+
await encodeFrameBounds(w, version, span);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
// A lite-07 range starts partway through a group as a Position, but ends only at a group's
|
|
239
|
+
// start, so it asks no slice of a group.
|
|
240
|
+
if (span.endFrame !== undefined || (span.startFrame !== 0 && span.startGroup === undefined))
|
|
241
|
+
throw new Error("frame bounds not supported for this version");
|
|
242
|
+
await w.u53(1);
|
|
243
|
+
const range = {};
|
|
244
|
+
if (span.startGroup !== undefined)
|
|
245
|
+
range.start = span.startFrame
|
|
246
|
+
? { absolute: span.startGroup, frame: span.startFrame }
|
|
247
|
+
: { time: span.startGroup };
|
|
248
|
+
if (span.endGroup !== undefined)
|
|
249
|
+
range.end = { time: span.endGroup };
|
|
250
|
+
await encodeRange(w, withPolicy(range, policy ?? {}));
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* The model ranges a decoded SUBSCRIBE or SUBSCRIBE_UPDATE asks for: its lite-07 list, or the one
|
|
254
|
+
* span an older wire carries, whole groups either way. Mirrors the Rust `Bounds::new`.
|
|
255
|
+
*
|
|
256
|
+
* A group ID is a group's start, so an absolute anchor and a time anchor both name one: a time
|
|
257
|
+
* start resolves to the group containing it. An older wire means its start as the first group
|
|
258
|
+
* starting at or after it, which the publisher's floor keeps (see `cursorFloor`), and its span with
|
|
259
|
+
* no start takes `legacy` (see {@link legacyStart}).
|
|
260
|
+
*/
|
|
261
|
+
export function requestedRanges(msg, legacy) {
|
|
262
|
+
if (msg.ranges)
|
|
263
|
+
return msg.ranges.map(requestedRange);
|
|
264
|
+
// A wire before lite-07 carries one priority and order, which every range takes.
|
|
265
|
+
const policy = { priority: msg.priority ?? 0, order: msg.order ?? "descending" };
|
|
266
|
+
const range = {};
|
|
267
|
+
const max = legacyMax(legacy);
|
|
268
|
+
// One max age bounds a named start too: a live join placed there (see {@link requestedPlaced}).
|
|
269
|
+
if (msg.startGroup !== undefined && max !== undefined)
|
|
270
|
+
range.start = { live: { min: ClockDuration.ZERO, max } };
|
|
271
|
+
else if (msg.startGroup !== undefined)
|
|
272
|
+
range.start = msg.startGroup;
|
|
273
|
+
else if (legacy !== undefined)
|
|
274
|
+
range.start = legacy;
|
|
275
|
+
if (msg.endGroup !== undefined)
|
|
276
|
+
range.end = msg.endGroup;
|
|
277
|
+
return [atPolicy(range, policy)];
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* The start a span with none takes on a `version` before lite-07, where one `Subscriber Max Age`
|
|
281
|
+
* (`maxDelay` milliseconds, `null` for none) bounds the whole subscription; undefined on lite-07,
|
|
282
|
+
* which carries one on each live start instead, and for the oldest group.
|
|
283
|
+
*
|
|
284
|
+
* An absent start takes every group still within that max age, or every group with none, as
|
|
285
|
+
* lite-01/02 never carry one. Lite-06 resolves it there. Before lite-06 an absent start is the
|
|
286
|
+
* latest group, which the publisher places as the floor once the source's feed says where it
|
|
287
|
+
* starts (see `cursorFloor`). A named start with a max age is a live join placed there; without
|
|
288
|
+
* one, a history floor bounded by the publisher's max age. Mirrors the Rust `Bounds::legacy`.
|
|
289
|
+
*/
|
|
290
|
+
export function legacyStart(version, maxDelay) {
|
|
291
|
+
if (hasRanges(version) || maxDelay === null)
|
|
292
|
+
return undefined;
|
|
293
|
+
// A join with no lag limit takes every group still within its max. Mirrors the Rust `Start::within`.
|
|
294
|
+
return { live: { min: null, max: ClockDuration.millis(maxDelay) } };
|
|
295
|
+
}
|
|
296
|
+
/** The max age a pre-07 `legacy` start carries, undefined when it carries none. */
|
|
297
|
+
function legacyMax(legacy) {
|
|
298
|
+
if (legacy === undefined || typeof legacy === "bigint" || legacy.live.max === null)
|
|
299
|
+
return undefined;
|
|
300
|
+
return legacy.live.max ?? ClockDuration.ZERO;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* The group each live join already placed among the ranges `msg` asks for starts at, by its index:
|
|
304
|
+
* a lite-07 {@link WireJoined}, or an older wire's named start under a max age (see
|
|
305
|
+
* {@link requestedRanges}). See `Subscription.placed`.
|
|
306
|
+
*/
|
|
307
|
+
export function requestedPlaced(msg, legacy) {
|
|
308
|
+
const placed = new Map();
|
|
309
|
+
if (!msg.ranges) {
|
|
310
|
+
if (msg.startGroup !== undefined && legacyMax(legacy) !== undefined)
|
|
311
|
+
placed.set(0, msg.startGroup);
|
|
312
|
+
return placed;
|
|
313
|
+
}
|
|
314
|
+
for (const [index, range] of msg.ranges.entries()) {
|
|
315
|
+
const at = range.start?.joined?.absolute ?? range.start?.absolute;
|
|
316
|
+
if (at !== undefined)
|
|
317
|
+
placed.set(index, at);
|
|
318
|
+
}
|
|
319
|
+
return placed;
|
|
320
|
+
}
|
|
321
|
+
/** The model range one lite-07 range asks for; see {@link requestedRanges}. */
|
|
322
|
+
export function requestedRange(range) {
|
|
323
|
+
const policy = policyOf(range);
|
|
324
|
+
// Empty, as group bounds say it: keep its place, covering no group.
|
|
325
|
+
const start = range.start?.absolute;
|
|
326
|
+
const end = range.end && endGroup(range.end);
|
|
327
|
+
if (frameEmpty(range))
|
|
328
|
+
return atPolicy({ ...EMPTY }, policy);
|
|
329
|
+
if (end === 0n)
|
|
330
|
+
return atPolicy({ ...EMPTY }, policy);
|
|
331
|
+
const out = {};
|
|
332
|
+
const live = range.start?.live;
|
|
333
|
+
const joined = range.start?.joined;
|
|
334
|
+
const maxOf = (max) => (max === null || max >= NO_MAX_DELAY ? null : ClockDuration.millis(max));
|
|
335
|
+
if (live !== undefined)
|
|
336
|
+
out.start = { live: { min: live.min === null ? null : ClockDuration.millis(live.min), max: maxOf(live.max) } };
|
|
337
|
+
// Placed already, so its lag places nothing: it starts where it was placed (see
|
|
338
|
+
// {@link requestedPlaced}) and expires as a live join under its max.
|
|
339
|
+
else if (joined !== undefined)
|
|
340
|
+
out.start = { live: { min: ClockDuration.ZERO, max: maxOf(joined.max) } };
|
|
341
|
+
else if (range.start)
|
|
342
|
+
out.start = start ?? range.start.time;
|
|
343
|
+
// An absolute end is exclusive; every model end includes its group.
|
|
344
|
+
if (range.end)
|
|
345
|
+
out.end = end === undefined ? range.end.time : end - 1n;
|
|
346
|
+
return atPolicy(out, policy);
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Decode one lite-07 range end, `undefined` for none: a time, inclusive as an end, a position
|
|
350
|
+
* partway through a group, never at frame 0, which a time says, a live join's lag then max in
|
|
351
|
+
* milliseconds, a start only, or one already placed, its group's start, a frame that may be 0, then
|
|
352
|
+
* its max, a start only too. Any other Anchor Type is a protocol violation.
|
|
353
|
+
*/
|
|
354
|
+
async function decodeAnchor(r, end) {
|
|
355
|
+
const kind = await r.u53();
|
|
356
|
+
switch (kind) {
|
|
357
|
+
case 0:
|
|
358
|
+
return undefined;
|
|
359
|
+
case 1:
|
|
360
|
+
return { time: await r.u62() };
|
|
361
|
+
case 2: {
|
|
362
|
+
const absolute = await r.u62();
|
|
363
|
+
const frame = await r.u53();
|
|
364
|
+
return { absolute, frame };
|
|
365
|
+
}
|
|
366
|
+
case 3:
|
|
367
|
+
if (end)
|
|
368
|
+
throw new ProtocolViolation("a range ends at a live join");
|
|
369
|
+
return {
|
|
370
|
+
live: {
|
|
371
|
+
min: (await Duration.decodeOptional(r)) ?? null,
|
|
372
|
+
max: (await Duration.decodeOptional(r)) ?? null,
|
|
373
|
+
},
|
|
374
|
+
};
|
|
375
|
+
case 4: {
|
|
376
|
+
if (end)
|
|
377
|
+
throw new ProtocolViolation("a range ends at a live join");
|
|
378
|
+
const absolute = await r.u62();
|
|
379
|
+
const frame = await r.u53();
|
|
380
|
+
return { joined: { absolute, frame, max: (await Duration.decodeOptional(r)) ?? null } };
|
|
381
|
+
}
|
|
382
|
+
default:
|
|
383
|
+
throw new ProtocolViolation(`unknown range anchor: ${kind}`);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
/** Decode one lite-07 range: its policy, then its start, then its end. */
|
|
387
|
+
async function decodeRange(r) {
|
|
388
|
+
const policy = await decodePolicy(r);
|
|
389
|
+
const start = await decodeAnchor(r, false);
|
|
390
|
+
const end = await decodeAnchor(r, true);
|
|
391
|
+
const range = {};
|
|
392
|
+
if (start)
|
|
393
|
+
range.start = start;
|
|
394
|
+
if (end)
|
|
395
|
+
range.end = end;
|
|
396
|
+
return withPolicy(range, policy);
|
|
397
|
+
}
|
|
398
|
+
/** Encode a lite-07 range's or retune's `Priority` then `Group Order`. */
|
|
399
|
+
async function encodePolicy(w, policy) {
|
|
400
|
+
await w.u8(toWire(policy.priority));
|
|
401
|
+
await encodeOrder(w, Version.DRAFT_07, policy.order);
|
|
402
|
+
}
|
|
403
|
+
/** Decode the inverse of {@link encodePolicy}. */
|
|
404
|
+
async function decodePolicy(r) {
|
|
405
|
+
const priority = fromWire(await r.u8());
|
|
406
|
+
const order = await decodeOrder(r, Version.DRAFT_07);
|
|
407
|
+
return { priority, order };
|
|
408
|
+
}
|
|
409
|
+
/** Decode a lite-07 `Range Count` and its ranges, which may be none. */
|
|
410
|
+
async function decodeRanges(r) {
|
|
411
|
+
// Not preallocated: each range costs at least two bytes of the bounded message.
|
|
412
|
+
const ranges = [];
|
|
413
|
+
for (let count = await r.u53(); count > 0; count--)
|
|
414
|
+
ranges.push(await decodeRange(r));
|
|
415
|
+
return ranges;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Lite-07 `ranges` and the one span covering every one of them, which the subscriber narrows
|
|
419
|
+
* again. A range covers whole groups but for a Position start (see {@link positionFrames}),
|
|
420
|
+
* whose frame the span keeps when the span starts there. The publisher reads every Position
|
|
421
|
+
* from the ranges themselves.
|
|
422
|
+
*/
|
|
423
|
+
export function spanOf(version, ranges) {
|
|
424
|
+
let start;
|
|
425
|
+
let end;
|
|
426
|
+
let floor = true;
|
|
427
|
+
let live = false;
|
|
428
|
+
for (const range of ranges) {
|
|
429
|
+
const [from, to] = rangeBounds(range);
|
|
430
|
+
if (from === undefined)
|
|
431
|
+
floor = false;
|
|
432
|
+
else if (start === undefined || from < start)
|
|
433
|
+
start = from;
|
|
434
|
+
if (to === undefined)
|
|
435
|
+
live = true;
|
|
436
|
+
else if (end === undefined || end < to)
|
|
437
|
+
end = to;
|
|
438
|
+
}
|
|
439
|
+
start = floor ? start : undefined;
|
|
440
|
+
const startFrame = start === undefined ? 0 : (positionFrames(ranges).get(start) ?? 0);
|
|
441
|
+
return { ranges: [...ranges], ...spanBetween(version, start, live ? undefined : end, startFrame) };
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* The group a lite-07 range starts at and the exclusive group it ends before, either undefined
|
|
445
|
+
* when it has none: a time is the start of the group it names, inclusive as an end.
|
|
446
|
+
*/
|
|
447
|
+
export function rangeBounds(range) {
|
|
448
|
+
const from = range.start?.absolute ?? range.start?.time ?? range.start?.joined?.absolute;
|
|
449
|
+
const end = range.end;
|
|
450
|
+
const to = end && (endGroup(end) ?? (end.time === undefined ? undefined : end.time + 1n));
|
|
451
|
+
return [from, to];
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* The exclusive group an absolute end stops before, `undefined` for a time: past its group when
|
|
455
|
+
* it stops partway through it.
|
|
456
|
+
*/
|
|
457
|
+
function endGroup(end) {
|
|
458
|
+
if (end.absolute === undefined)
|
|
459
|
+
return undefined;
|
|
460
|
+
return end.frame ? end.absolute + 1n : end.absolute;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* How one lite-07 range, as its subscriber asked it, counts toward a fetch: `undefined` when it
|
|
464
|
+
* covers no group, else whether it names its groups, from a Position up to an end. See
|
|
465
|
+
* {@link ExactRanges}.
|
|
466
|
+
*/
|
|
467
|
+
function exactRange(range) {
|
|
468
|
+
if (isEmpty(requestedRange(range)))
|
|
469
|
+
return undefined;
|
|
470
|
+
return range.start?.absolute !== undefined && range.end !== undefined;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* How a lite-07 subscription's live ranges, as its subscriber asked them, count toward a fetch,
|
|
474
|
+
* by Range ID, tallied as they come and go so an edit costs only the ranges it names. Mirrors
|
|
475
|
+
* the Rust `Prefs::fetches`.
|
|
476
|
+
*/
|
|
477
|
+
export class ExactRanges {
|
|
478
|
+
#ranges = new Map();
|
|
479
|
+
// How many ranges read a group they don't name, and how many name a group to read.
|
|
480
|
+
#inexact = 0;
|
|
481
|
+
#named = 0;
|
|
482
|
+
/** The ranges a SUBSCRIBE asked, keyed by their positions, which are their Range IDs. */
|
|
483
|
+
constructor(ranges) {
|
|
484
|
+
for (const [id, range] of ranges.entries())
|
|
485
|
+
this.set(BigInt(id), range);
|
|
486
|
+
}
|
|
487
|
+
/** Hold `range` under `id`, replacing any range held there. */
|
|
488
|
+
set(id, range) {
|
|
489
|
+
this.delete(id);
|
|
490
|
+
const exact = exactRange(range);
|
|
491
|
+
this.#ranges.set(id, exact);
|
|
492
|
+
this.#count(exact, 1);
|
|
493
|
+
}
|
|
494
|
+
/** Drop the range held under `id`, if any. */
|
|
495
|
+
delete(id) {
|
|
496
|
+
if (!this.#ranges.has(id))
|
|
497
|
+
return;
|
|
498
|
+
this.#count(this.#ranges.get(id), -1);
|
|
499
|
+
this.#ranges.delete(id);
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Whether the ranges read only named groups, a fetch: none of them other ranges, and at least
|
|
503
|
+
* one not empty. Mirrors the Rust `Subscription::exact_bounded`.
|
|
504
|
+
*/
|
|
505
|
+
fetches() {
|
|
506
|
+
return this.#inexact === 0 && this.#named > 0;
|
|
507
|
+
}
|
|
508
|
+
#count(exact, by) {
|
|
509
|
+
if (exact === false)
|
|
510
|
+
this.#inexact += by;
|
|
511
|
+
if (exact === true)
|
|
512
|
+
this.#named += by;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
/** Whether a range ends at or before its start, frames included: empty, covering no group. */
|
|
516
|
+
function frameEmpty(range) {
|
|
517
|
+
return range.end !== undefined && endsBefore(range.end, range.start);
|
|
518
|
+
}
|
|
519
|
+
/** Whether absolute `end`, exclusive, stops at or before `start`, frames included. */
|
|
520
|
+
function endsBefore(end, start) {
|
|
521
|
+
if (end.absolute === undefined)
|
|
522
|
+
return false;
|
|
523
|
+
const from = start?.absolute !== undefined ? start : start?.joined;
|
|
524
|
+
if (from === undefined)
|
|
525
|
+
return false;
|
|
526
|
+
if (end.absolute !== from.absolute)
|
|
527
|
+
return end.absolute < from.absolute;
|
|
528
|
+
return (end.frame ?? 0) <= (from.frame ?? 0);
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* The span from group `start`, at frame `startFrame` of it, up to the exclusive group `end`, either
|
|
532
|
+
* group undefined for none.
|
|
533
|
+
*/
|
|
534
|
+
export function spanBetween(version, start, end, startFrame = 0) {
|
|
535
|
+
// An exclusive end at the very first group names nothing.
|
|
536
|
+
if (end === 0n)
|
|
537
|
+
throw new ProtocolViolation(EMPTY_RANGE);
|
|
538
|
+
return {
|
|
539
|
+
startGroup: canonicalStartGroup(version, start, startFrame),
|
|
540
|
+
startFrame,
|
|
541
|
+
endGroup: end === undefined ? undefined : end - 1n,
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* The first frame each lite-07 Position start asks its group from, by group, for each group no
|
|
546
|
+
* other range may cover: a group is delivered once, so one another range covers goes whole.
|
|
547
|
+
* A peer may send thousands of ranges, so this sorts their bounds once rather than scanning
|
|
548
|
+
* them per Position.
|
|
549
|
+
*/
|
|
550
|
+
export function positionFrames(ranges) {
|
|
551
|
+
const positions = [];
|
|
552
|
+
for (const range of ranges) {
|
|
553
|
+
if (frameEmpty(range))
|
|
554
|
+
continue;
|
|
555
|
+
// A Position start, or a placed join's, partway through its group.
|
|
556
|
+
const start = range.start?.joined ?? range.start;
|
|
557
|
+
// One ending at or before the group it starts partway through covers nothing.
|
|
558
|
+
const [, to] = rangeBounds(range);
|
|
559
|
+
if (start?.absolute !== undefined && start.frame && (to === undefined || to > start.absolute))
|
|
560
|
+
positions.push([start.absolute, start.frame]);
|
|
561
|
+
}
|
|
562
|
+
return onlyCovered(positions, ranges);
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* The frame each lite-07 Position end stops its group before, by group, for each group no other
|
|
566
|
+
* range may cover, as {@link positionFrames} keeps starts. Mirrors the Rust `stops`.
|
|
567
|
+
*/
|
|
568
|
+
export function positionStops(ranges) {
|
|
569
|
+
const positions = [];
|
|
570
|
+
for (const range of ranges) {
|
|
571
|
+
if (frameEmpty(range))
|
|
572
|
+
continue;
|
|
573
|
+
const end = range.end;
|
|
574
|
+
// One starting past the group it stops partway through covers nothing.
|
|
575
|
+
const [from, to] = rangeBounds(range);
|
|
576
|
+
if (end?.absolute !== undefined && end.frame && (from === undefined || to === undefined || from < to))
|
|
577
|
+
positions.push([end.absolute, end.frame]);
|
|
578
|
+
}
|
|
579
|
+
return onlyCovered(positions, ranges);
|
|
580
|
+
}
|
|
581
|
+
/** The `positions` whose group no range in `ranges` but their own may cover, by group. */
|
|
582
|
+
function onlyCovered(positions, ranges) {
|
|
583
|
+
const frames = new Map();
|
|
584
|
+
if (positions.length === 0)
|
|
585
|
+
return frames;
|
|
586
|
+
// A range may cover a group unless it starts past it or ends at or before it. One that
|
|
587
|
+
// starts at or past its end covers none, so with it left out, no range does both and the
|
|
588
|
+
// ranges covering a group are the rest less those two counts.
|
|
589
|
+
const starts = [];
|
|
590
|
+
const ends = [];
|
|
591
|
+
let count = 0;
|
|
592
|
+
for (const range of ranges) {
|
|
593
|
+
if (frameEmpty(range))
|
|
594
|
+
continue;
|
|
595
|
+
// No start, or no end, may cover it.
|
|
596
|
+
const [from, to] = rangeBounds(range);
|
|
597
|
+
if (from !== undefined && to !== undefined && from >= to)
|
|
598
|
+
continue;
|
|
599
|
+
count++;
|
|
600
|
+
if (from !== undefined)
|
|
601
|
+
starts.push(from);
|
|
602
|
+
if (to !== undefined)
|
|
603
|
+
ends.push(to);
|
|
604
|
+
}
|
|
605
|
+
const order = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
606
|
+
starts.sort(order);
|
|
607
|
+
ends.sort(order);
|
|
608
|
+
for (const [group, frame] of positions) {
|
|
609
|
+
const past = starts.length - countAtOrBelow(starts, group);
|
|
610
|
+
const before = countAtOrBelow(ends, group);
|
|
611
|
+
if (count - past - before === 1)
|
|
612
|
+
frames.set(group, frame);
|
|
613
|
+
}
|
|
614
|
+
return frames;
|
|
615
|
+
}
|
|
616
|
+
/** How many of the `sorted` values are at or below `value`. */
|
|
617
|
+
function countAtOrBelow(sorted, value) {
|
|
618
|
+
let low = 0;
|
|
619
|
+
let high = sorted.length;
|
|
620
|
+
while (low < high) {
|
|
621
|
+
const mid = (low + high) >> 1;
|
|
622
|
+
if (sorted[mid] <= value)
|
|
623
|
+
low = mid + 1;
|
|
624
|
+
else
|
|
625
|
+
high = mid;
|
|
626
|
+
}
|
|
627
|
+
return low;
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* The inverse of {@link encodeSpan}. A lite-07 list decodes as its ranges and as the one span
|
|
631
|
+
* covering every range in it, which the subscriber narrows again.
|
|
632
|
+
*/
|
|
633
|
+
async function decodeSpan(r, version) {
|
|
634
|
+
if (!hasRanges(version)) {
|
|
635
|
+
const startGroup = await decodeStartGroup(r, version);
|
|
636
|
+
const endGroup = (await r.u62()) || undefined;
|
|
637
|
+
const end = endGroup !== undefined ? endGroup - 1n : undefined;
|
|
638
|
+
const frames = await decodeFrameBounds(r, version, startGroup, end);
|
|
639
|
+
return { startGroup: canonicalStartGroup(version, startGroup, frames.startFrame), endGroup: end, ...frames };
|
|
640
|
+
}
|
|
641
|
+
const ranges = await decodeRanges(r);
|
|
642
|
+
if (ranges.length === 0)
|
|
643
|
+
throw new ProtocolViolation("a subscription asks for no range");
|
|
644
|
+
return spanOf(version, ranges);
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* The ranges `msg` carries on lite-07: its list, or else the one span it encodes as its only
|
|
648
|
+
* range, in whole groups.
|
|
649
|
+
*/
|
|
650
|
+
export function rangesOf(msg) {
|
|
651
|
+
if (msg.ranges)
|
|
652
|
+
return msg.ranges;
|
|
653
|
+
const range = {};
|
|
654
|
+
if (msg.startGroup !== undefined)
|
|
655
|
+
range.start = { absolute: msg.startGroup };
|
|
656
|
+
if (msg.endGroup !== undefined)
|
|
657
|
+
range.end = { absolute: msg.endGroup + 1n };
|
|
658
|
+
return [range];
|
|
659
|
+
}
|
|
660
|
+
/** The bytes `value` takes as a lite-07 varint, which counts leading ones. */
|
|
661
|
+
export function varintSize(value) {
|
|
662
|
+
const lo = split(value);
|
|
663
|
+
return lengthLeadingOnes(parts.hi, lo);
|
|
664
|
+
}
|
|
665
|
+
/** The bytes a lite-07 range takes on the wire, whose varints count leading ones. */
|
|
666
|
+
export function rangeSize(range) {
|
|
667
|
+
const anchor = (anchor, end) => {
|
|
668
|
+
let total = 0;
|
|
669
|
+
for (const value of wireAnchor(anchor, end))
|
|
670
|
+
total += varintSize(value);
|
|
671
|
+
return total;
|
|
672
|
+
};
|
|
673
|
+
// Its priority and order, a byte each.
|
|
674
|
+
return 2 + anchor(range.start, false) + anchor(range.end, true);
|
|
675
|
+
}
|
|
676
|
+
/** A range's anchors and policy as a key, so equal ranges compare equal. */
|
|
677
|
+
function rangeKey(range) {
|
|
678
|
+
const { priority, order } = policyOf(range);
|
|
679
|
+
return `${anchorsKey(range)}@${priority}${order[0]}`;
|
|
680
|
+
}
|
|
681
|
+
/** A range's anchors alone as a key. */
|
|
682
|
+
function anchorsKey(range) {
|
|
683
|
+
const anchor = (anchor) => {
|
|
684
|
+
if (anchor?.absolute !== undefined)
|
|
685
|
+
return `a${anchor.absolute}.${anchor.frame ?? 0}`;
|
|
686
|
+
if (anchor?.time !== undefined)
|
|
687
|
+
return `t${anchor.time}`;
|
|
688
|
+
if (anchor?.live !== undefined)
|
|
689
|
+
return `l${anchor.live.min}/${anchor.live.max ?? "-"}`;
|
|
690
|
+
if (anchor?.joined !== undefined)
|
|
691
|
+
return `j${anchor.joined.absolute}.${anchor.joined.frame}/${anchor.joined.max ?? "-"}`;
|
|
692
|
+
return "-";
|
|
693
|
+
};
|
|
694
|
+
return `${anchor(range.start)}:${anchor(range.end)}`;
|
|
695
|
+
}
|
|
696
|
+
/**
|
|
697
|
+
* A subscription's live ranges by Range ID, which both ends of a Subscribe Stream keep: the
|
|
698
|
+
* subscriber to write each update as an edit, the publisher to resolve one. Mirrors the Rust
|
|
699
|
+
* `LiveRanges`.
|
|
700
|
+
*
|
|
701
|
+
* The SUBSCRIBE's ranges take Range IDs from 0 in order, and each range an update adds takes the
|
|
702
|
+
* next. Before lite-07 an update replaces the list, numbered afresh.
|
|
703
|
+
*/
|
|
704
|
+
export class LiveRanges {
|
|
705
|
+
#version;
|
|
706
|
+
#next = 0n;
|
|
707
|
+
// In Range ID order, since each id is the next.
|
|
708
|
+
#live = new Map();
|
|
709
|
+
// The bytes the live ranges take on the wire, held to what one SUBSCRIBE carries.
|
|
710
|
+
#size = 0;
|
|
711
|
+
/** The ranges a SUBSCRIBE carried. */
|
|
712
|
+
constructor(version, ranges) {
|
|
713
|
+
this.#version = version;
|
|
714
|
+
this.#add(ranges);
|
|
715
|
+
}
|
|
716
|
+
#add(ranges) {
|
|
717
|
+
for (const range of ranges) {
|
|
718
|
+
// Only lite-07 numbers ranges on the wire, and only it is held to one SUBSCRIBE.
|
|
719
|
+
if (hasRanges(this.#version))
|
|
720
|
+
this.#size += rangeSize(range);
|
|
721
|
+
this.#live.set(this.#next++, range);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
#remove(id) {
|
|
725
|
+
const range = this.#live.get(id);
|
|
726
|
+
if (!range)
|
|
727
|
+
return undefined;
|
|
728
|
+
if (hasRanges(this.#version))
|
|
729
|
+
this.#size -= rangeSize(range);
|
|
730
|
+
this.#live.delete(id);
|
|
731
|
+
return range;
|
|
732
|
+
}
|
|
733
|
+
// Replace the live range with Range ID `id` by `range` in place, keeping Range ID order.
|
|
734
|
+
#replace(id, range) {
|
|
735
|
+
const old = this.#live.get(id);
|
|
736
|
+
if (old && hasRanges(this.#version))
|
|
737
|
+
this.#size += rangeSize(range) - rangeSize(old);
|
|
738
|
+
this.#live.set(id, range);
|
|
739
|
+
}
|
|
740
|
+
/** The Range ID the next range added takes. */
|
|
741
|
+
next() {
|
|
742
|
+
return this.#next;
|
|
743
|
+
}
|
|
744
|
+
/** The live range with Range ID `id`. */
|
|
745
|
+
get(id) {
|
|
746
|
+
return this.#live.get(id);
|
|
747
|
+
}
|
|
748
|
+
/** Whether `id` was ever assigned. */
|
|
749
|
+
assigned(id) {
|
|
750
|
+
return id < this.#next;
|
|
751
|
+
}
|
|
752
|
+
/** Every live Range ID, in order. */
|
|
753
|
+
ids() {
|
|
754
|
+
return [...this.#live.keys()];
|
|
755
|
+
}
|
|
756
|
+
/** Every live range, in Range ID order. */
|
|
757
|
+
ranges() {
|
|
758
|
+
return [...this.#live.values()];
|
|
759
|
+
}
|
|
760
|
+
/** Every live range with its Range ID, in order. */
|
|
761
|
+
entries() {
|
|
762
|
+
return [...this.#live];
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Apply a received lite-07 `update`'s edit, returning it by Range ID: the ranges retired, then
|
|
766
|
+
* each added with the Range ID it took, then each live join retuned to its new max in place,
|
|
767
|
+
* costing the ranges it names. Throws {@link ProtocolViolation} for an edit it cannot apply.
|
|
768
|
+
* Before lite-07 an update restates its ranges, so nothing is numbered and the edit is empty.
|
|
769
|
+
* Mirrors the Rust `LiveRanges::apply`.
|
|
770
|
+
*/
|
|
771
|
+
apply(update) {
|
|
772
|
+
if (!hasRanges(this.#version))
|
|
773
|
+
return { retired: [], added: [], retuned: [] };
|
|
774
|
+
const retired = update.remove ?? [];
|
|
775
|
+
for (const id of retired) {
|
|
776
|
+
// An id never assigned, or already retired (including earlier in this list).
|
|
777
|
+
if (!this.#remove(id))
|
|
778
|
+
throw new ProtocolViolation(`unknown range id: ${id}`);
|
|
779
|
+
}
|
|
780
|
+
// Retuned before the adds, so a retune names a range live before this edit.
|
|
781
|
+
const retuned = [];
|
|
782
|
+
for (const [id, retune] of update.retune ?? []) {
|
|
783
|
+
// Each range once: one retuned twice in an edit says nothing a single one doesn't.
|
|
784
|
+
if (retuned.some(([tuned]) => tuned === id))
|
|
785
|
+
throw new ProtocolViolation(`range id retuned twice: ${id}`);
|
|
786
|
+
const range = this.#live.get(id);
|
|
787
|
+
if (range === undefined)
|
|
788
|
+
throw new ProtocolViolation(`no live range to retune: ${id}`);
|
|
789
|
+
const live = range.start?.live;
|
|
790
|
+
const joined = range.start?.joined;
|
|
791
|
+
// Only a live join has a max age to change.
|
|
792
|
+
if (live === undefined && joined === undefined && retune.max !== null)
|
|
793
|
+
throw new ProtocolViolation(`no live join to retune: ${id}`);
|
|
794
|
+
// One already placed stays where it was placed.
|
|
795
|
+
let tuned = range;
|
|
796
|
+
if (joined)
|
|
797
|
+
tuned = { ...range, start: { joined: { ...joined, max: retune.max } } };
|
|
798
|
+
else if (live)
|
|
799
|
+
tuned = { ...range, start: { live: { min: live.min, max: retune.max } } };
|
|
800
|
+
tuned = withPolicy(tuned, retune);
|
|
801
|
+
this.#replace(id, tuned);
|
|
802
|
+
retuned.push([id, tuned]);
|
|
803
|
+
}
|
|
804
|
+
const first = this.#next;
|
|
805
|
+
const add = update.ranges ?? [];
|
|
806
|
+
this.#add(add);
|
|
807
|
+
// Asking for nothing is refused like a SUBSCRIBE that does, and a set no SUBSCRIBE
|
|
808
|
+
// could carry like one too large to send.
|
|
809
|
+
if (this.#live.size === 0)
|
|
810
|
+
throw new ProtocolViolation("a subscription asks for no range");
|
|
811
|
+
if (this.#size > Message.MAX_MESSAGE_SIZE)
|
|
812
|
+
throw new ProtocolViolation("too many ranges");
|
|
813
|
+
return {
|
|
814
|
+
retired: [...retired],
|
|
815
|
+
added: add.map((range, index) => [first + BigInt(index), range]),
|
|
816
|
+
retuned,
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* The edit that turns the live ranges into `ranges`, which become the live ones: the Range IDs
|
|
821
|
+
* to retire and the ranges to add. A range already live keeps its Range ID, so an update that
|
|
822
|
+
* changes one range sends only that one, and the publisher keeps where the rest resolved.
|
|
823
|
+
* Before lite-07 replaced ranges take fresh Range IDs.
|
|
824
|
+
*
|
|
825
|
+
* `ranges` are the demand's, then `kinds.probes` probes, then `kinds.fills` asking for fills,
|
|
826
|
+
* and `kinds.kindOf` names what each live one asks for: a probe or a fill asking for what a
|
|
827
|
+
* demand range does still takes a range of its own, so each Range ID stays one kind's.
|
|
828
|
+
* `fillIds` and `probeIds` are the Range IDs the added ones of each took. The live ranges in
|
|
829
|
+
* `renew` are retired and added again even when wanted, so the publisher resolves them afresh.
|
|
830
|
+
* A range wanted again under another policy, or a live join under another max, as the same
|
|
831
|
+
* kind, is retuned in place, keeping its Range ID and so where it was placed. Mirrors the Rust
|
|
832
|
+
* `SubStream::edit`.
|
|
833
|
+
*/
|
|
834
|
+
edit(ranges, kinds = {}, renew = new Set()) {
|
|
835
|
+
if (ranges.length === 0)
|
|
836
|
+
throw new Error(EMPTY_RANGE);
|
|
837
|
+
if (!hasRanges(this.#version)) {
|
|
838
|
+
const same = ranges.length === this.#live.size &&
|
|
839
|
+
this.ranges().every((range, index) => rangeKey(range) === rangeKey(ranges[index]));
|
|
840
|
+
if (!same) {
|
|
841
|
+
this.#live.clear();
|
|
842
|
+
this.#add(ranges);
|
|
843
|
+
}
|
|
844
|
+
return { remove: [], add: [...ranges], retune: [], fillIds: [], probeIds: [] };
|
|
845
|
+
}
|
|
846
|
+
const probes = kinds.probes ?? 0;
|
|
847
|
+
const demand = ranges.length - (kinds.fills ?? 0) - probes;
|
|
848
|
+
const kindOf = kinds.kindOf ?? (() => "demand");
|
|
849
|
+
const kindAt = (index) => index < demand ? "demand" : index < demand + probes ? "probe" : "fill";
|
|
850
|
+
const key = (range, kind) => `${kind[0]}${rangeKey(range)}`;
|
|
851
|
+
// Each live range keeps at most one wanted copy, so duplicates edit like any other.
|
|
852
|
+
const wanted = new Map();
|
|
853
|
+
ranges.forEach((range, index) => {
|
|
854
|
+
const k = key(range, kindAt(index));
|
|
855
|
+
wanted.set(k, (wanted.get(k) ?? 0) + 1);
|
|
856
|
+
});
|
|
857
|
+
const remove = [];
|
|
858
|
+
// The bytes the live ranges take once the edit applies.
|
|
859
|
+
let size = this.#size;
|
|
860
|
+
for (const [id, range] of this.#live) {
|
|
861
|
+
const k = key(range, kindOf(id));
|
|
862
|
+
const count = wanted.get(k) ?? 0;
|
|
863
|
+
if (count > 0 && !renew.has(id)) {
|
|
864
|
+
wanted.set(k, count - 1);
|
|
865
|
+
}
|
|
866
|
+
else {
|
|
867
|
+
remove.push(id);
|
|
868
|
+
size -= rangeSize(range);
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
// In the order asked for, each with its kind, so the publisher numbers them the way this
|
|
872
|
+
// side does.
|
|
873
|
+
const adding = [];
|
|
874
|
+
ranges.forEach((range, index) => {
|
|
875
|
+
const kind = kindAt(index);
|
|
876
|
+
const k = key(range, kind);
|
|
877
|
+
const count = wanted.get(k) ?? 0;
|
|
878
|
+
if (count === 0)
|
|
879
|
+
return;
|
|
880
|
+
wanted.set(k, count - 1);
|
|
881
|
+
adding.push([range, kind]);
|
|
882
|
+
});
|
|
883
|
+
// A range wanted again under another policy, or a live join under another max, its placement
|
|
884
|
+
// kept: one being renewed is placed afresh. Added ranges are indexed by kind, start, and end,
|
|
885
|
+
// where a live join's start is its lag, one placed its placement, and any other as is, so
|
|
886
|
+
// each retire finds its match without scanning them all.
|
|
887
|
+
const startKey = (anchor) => anchor?.live !== undefined
|
|
888
|
+
? `l${anchor.live.min}`
|
|
889
|
+
: anchor?.joined !== undefined
|
|
890
|
+
? `j${anchor.joined.absolute}.${anchor.joined.frame}`
|
|
891
|
+
: `o${anchorsKey({ start: anchor })}`;
|
|
892
|
+
const retuneKey = (range, kind) => `${kind[0]}${startKey(range.start)}${anchorsKey({ end: range.end })}`;
|
|
893
|
+
const byKey = new Map();
|
|
894
|
+
adding.forEach(([range, kind], index) => {
|
|
895
|
+
const k = retuneKey(range, kind);
|
|
896
|
+
const queue = byKey.get(k);
|
|
897
|
+
if (queue)
|
|
898
|
+
queue.push(index);
|
|
899
|
+
else
|
|
900
|
+
byKey.set(k, [index]);
|
|
901
|
+
});
|
|
902
|
+
const taken = new Set();
|
|
903
|
+
const retuned = [];
|
|
904
|
+
const kept = remove.filter((id) => {
|
|
905
|
+
if (renew.has(id))
|
|
906
|
+
return true;
|
|
907
|
+
const range = this.#live.get(id);
|
|
908
|
+
if (!range)
|
|
909
|
+
return true;
|
|
910
|
+
const queue = byKey.get(retuneKey(range, kindOf(id)));
|
|
911
|
+
const index = queue?.shift();
|
|
912
|
+
if (index === undefined)
|
|
913
|
+
return true;
|
|
914
|
+
retuned.push([id, adding[index][0]]);
|
|
915
|
+
taken.add(index);
|
|
916
|
+
return false;
|
|
917
|
+
});
|
|
918
|
+
if (taken.size > 0) {
|
|
919
|
+
const rest = adding.filter((_, index) => !taken.has(index));
|
|
920
|
+
adding.length = 0;
|
|
921
|
+
adding.push(...rest);
|
|
922
|
+
}
|
|
923
|
+
const add = [];
|
|
924
|
+
const fillIds = [];
|
|
925
|
+
const probeIds = [];
|
|
926
|
+
const first = this.#next;
|
|
927
|
+
for (const [range, kind] of adding) {
|
|
928
|
+
add.push(range);
|
|
929
|
+
const id = first + BigInt(add.length - 1);
|
|
930
|
+
if (kind === "fill")
|
|
931
|
+
fillIds.push(id);
|
|
932
|
+
else if (kind === "probe")
|
|
933
|
+
probeIds.push(id);
|
|
934
|
+
}
|
|
935
|
+
// Checked before anything changes, so a refused edit leaves the ranges as last sent.
|
|
936
|
+
for (const range of add)
|
|
937
|
+
size += rangeSize(range);
|
|
938
|
+
// A retuned join was counted out among the removed, so it counts back in as it now reads.
|
|
939
|
+
for (const [, range] of retuned)
|
|
940
|
+
size += rangeSize(range);
|
|
941
|
+
if (size > Message.MAX_MESSAGE_SIZE)
|
|
942
|
+
throw new Error("too many ranges for one SUBSCRIBE");
|
|
943
|
+
for (const id of kept)
|
|
944
|
+
this.#remove(id);
|
|
945
|
+
for (const [id, range] of retuned)
|
|
946
|
+
this.#replace(id, range);
|
|
947
|
+
this.#add(add);
|
|
948
|
+
const retune = retuned.map(([id, range]) => [
|
|
949
|
+
id,
|
|
950
|
+
{ ...policyOf(range), max: range.start?.live?.max ?? range.start?.joined?.max ?? null },
|
|
951
|
+
]);
|
|
952
|
+
return { remove: kept, add, retune, fillIds, probeIds };
|
|
953
|
+
}
|
|
954
|
+
}
|
|
77
955
|
/** Step over the retired `Ordered` byte on a version whose layout still has it. */
|
|
78
956
|
async function skipGroupOrder(r, version) {
|
|
79
957
|
if (hasGroupOrder(version))
|
|
@@ -85,71 +963,179 @@ async function padGroupOrder(w, version) {
|
|
|
85
963
|
await w.bool(false);
|
|
86
964
|
}
|
|
87
965
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
|
|
91
|
-
|
|
966
|
+
* Decode the byte after the subscriber priority shared by SUBSCRIBE and SUBSCRIBE_UPDATE:
|
|
967
|
+
* lite-07's `Group Order`, or the retired `Ordered` byte an older layout still carries.
|
|
968
|
+
*/
|
|
969
|
+
async function decodeOrder(r, version) {
|
|
970
|
+
if (!hasOrder(version)) {
|
|
971
|
+
await skipGroupOrder(r, version);
|
|
972
|
+
return "descending";
|
|
973
|
+
}
|
|
974
|
+
const order = await r.u8();
|
|
975
|
+
switch (order) {
|
|
976
|
+
case 0:
|
|
977
|
+
return "descending";
|
|
978
|
+
case 1:
|
|
979
|
+
return "ascending";
|
|
980
|
+
default:
|
|
981
|
+
throw new ProtocolViolation(`unknown group order: ${order}`);
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
/**
|
|
985
|
+
* The inverse of {@link decodeOrder}. A wire without `Group Order` serves newest first, so an
|
|
986
|
+
* ascending subscription over it falls back to descending.
|
|
987
|
+
*/
|
|
988
|
+
async function encodeOrder(w, version, order) {
|
|
989
|
+
if (!hasOrder(version)) {
|
|
990
|
+
await padGroupOrder(w, version);
|
|
991
|
+
return;
|
|
992
|
+
}
|
|
993
|
+
await w.u8(order === "ascending" ? 1 : 0);
|
|
994
|
+
}
|
|
995
|
+
/**
|
|
996
|
+
* Decode SUBSCRIBE's trailing `Meta` byte, lite-07's only: 1 for headers alone, 0 for the payload,
|
|
997
|
+
* anything else malformed. An earlier wire always asks for the payload.
|
|
92
998
|
*/
|
|
93
|
-
|
|
94
|
-
|
|
999
|
+
async function decodeMeta(r, version) {
|
|
1000
|
+
if (!hasMeta(version))
|
|
1001
|
+
return false;
|
|
1002
|
+
const meta = await r.u8();
|
|
1003
|
+
switch (meta) {
|
|
1004
|
+
case 0:
|
|
1005
|
+
return false;
|
|
1006
|
+
case 1:
|
|
1007
|
+
return true;
|
|
1008
|
+
default:
|
|
1009
|
+
throw new ProtocolViolation(`unknown meta: ${meta}`);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
/** The inverse of {@link decodeMeta}, throwing for a metadata subscription on a wire without one. */
|
|
1013
|
+
async function encodeMeta(w, version, meta) {
|
|
1014
|
+
if (hasMeta(version)) {
|
|
1015
|
+
await w.u8(meta ? 1 : 0);
|
|
1016
|
+
}
|
|
1017
|
+
else if (meta) {
|
|
1018
|
+
throw new Error("a metadata subscription needs moq-lite-07");
|
|
1019
|
+
}
|
|
95
1020
|
}
|
|
96
|
-
/** The error for a requested range the wire cannot carry
|
|
1021
|
+
/** The error for a requested range the wire cannot carry: one asking for nothing. */
|
|
97
1022
|
export const EMPTY_RANGE = "empty subscription range cannot be encoded";
|
|
98
1023
|
/**
|
|
99
1024
|
* Inclusive last group a Subscribe message carries, from an exclusive model end.
|
|
100
1025
|
*
|
|
101
1026
|
* Empty (`0`) cannot be encoded: the wire's 0 means unbounded. Callers refuse an empty
|
|
102
|
-
* requested range
|
|
1027
|
+
* requested range before reaching here.
|
|
103
1028
|
*/
|
|
104
1029
|
export function inclusiveGroupEnd(exclusive) {
|
|
105
1030
|
if (exclusive === undefined)
|
|
106
1031
|
return undefined;
|
|
107
|
-
if (exclusive ===
|
|
1032
|
+
if (exclusive === 0n)
|
|
108
1033
|
throw new Error(EMPTY_RANGE);
|
|
109
|
-
return exclusive -
|
|
1034
|
+
return exclusive - 1n;
|
|
110
1035
|
}
|
|
1036
|
+
/** What lite-03 to lite-06 send for no `Subscriber Max Age` limit, which their bare milliseconds can't say. */
|
|
1037
|
+
const MAX_SAFE_DELAY_MS = Number.MAX_SAFE_INTEGER;
|
|
111
1038
|
/**
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
* The wire has no encoding for one: its bounds are inclusive, so flooring the end would
|
|
115
|
-
* either hand back the group the caller excluded (0 means unbounded) or invert the
|
|
116
|
-
* range once the two bounds meet. An absent start is the live edge, so it only empties
|
|
117
|
-
* the range when the end is 0.
|
|
1039
|
+
* Encode the `Subscriber Max Age` before lite-07, bare milliseconds with `null` (no limit) as
|
|
1040
|
+
* {@link MAX_SAFE_DELAY_MS}. Lite-07 carries none: each live start has its own.
|
|
118
1041
|
*/
|
|
119
|
-
|
|
120
|
-
|
|
1042
|
+
async function encodeMaxDelay(w, version, maxDelay) {
|
|
1043
|
+
if (hasRanges(version))
|
|
1044
|
+
return;
|
|
1045
|
+
await w.u53(maxDelay ?? MAX_SAFE_DELAY_MS);
|
|
1046
|
+
}
|
|
1047
|
+
/** Decode the inverse of {@link encodeMaxDelay}: {@link MAX_SAFE_DELAY_MS} or more says no limit. */
|
|
1048
|
+
async function decodeMaxDelay(r, version) {
|
|
1049
|
+
if (hasRanges(version))
|
|
1050
|
+
return null;
|
|
1051
|
+
// Read wide: a peer may send any varint at or past the sentinel, which still means no limit.
|
|
1052
|
+
const millis = await r.u62();
|
|
1053
|
+
return millis < BigInt(MAX_SAFE_DELAY_MS) ? Number(millis) : null;
|
|
121
1054
|
}
|
|
122
1055
|
export class SubscribeUpdate {
|
|
1056
|
+
/** A refresh request for this group or later, judged against the local track's refresh. */
|
|
1057
|
+
wantedGroup;
|
|
123
1058
|
priority;
|
|
124
|
-
/**
|
|
125
|
-
|
|
1059
|
+
/** See {@link Subscribe.order}. */
|
|
1060
|
+
order;
|
|
1061
|
+
/** See {@link Subscribe.maxDelay}. */
|
|
1062
|
+
maxDelay;
|
|
126
1063
|
startGroup;
|
|
127
1064
|
endGroup;
|
|
128
1065
|
/** See {@link Subscribe.startFrame}. */
|
|
129
1066
|
startFrame;
|
|
130
1067
|
/** See {@link Subscribe.endFrame}. */
|
|
131
1068
|
endFrame;
|
|
1069
|
+
/**
|
|
1070
|
+
* See {@link Subscribe.ranges}. On lite-07 the wire carries the ranges to add, after retiring
|
|
1071
|
+
* {@link remove}; {@link LiveRanges.apply} resolves a received update to every live range.
|
|
1072
|
+
*/
|
|
1073
|
+
ranges;
|
|
1074
|
+
/** Lite-07: the Range IDs of the live ranges to retire before adding {@link ranges}. */
|
|
1075
|
+
remove;
|
|
1076
|
+
/**
|
|
1077
|
+
* Lite-07: each live range to give a new policy, and a live join a new max, in place, keeping
|
|
1078
|
+
* where it was placed, by Range ID.
|
|
1079
|
+
*/
|
|
1080
|
+
retune;
|
|
132
1081
|
constructor(props) {
|
|
1082
|
+
if (props.wantedGroup !== undefined && props.wantedGroup < 0n)
|
|
1083
|
+
throw new RangeError("wanted group must be non-negative");
|
|
1084
|
+
this.wantedGroup = props.wantedGroup;
|
|
133
1085
|
this.priority = props.priority;
|
|
134
|
-
this.
|
|
1086
|
+
this.order = props.order ?? "descending";
|
|
1087
|
+
this.maxDelay = props.maxDelay === undefined ? 0 : props.maxDelay;
|
|
135
1088
|
this.startGroup = props.startGroup;
|
|
136
1089
|
this.endGroup = props.endGroup;
|
|
137
1090
|
this.startFrame = props.startFrame ?? 0;
|
|
138
1091
|
this.endFrame = props.endFrame;
|
|
1092
|
+
this.ranges = props.ranges;
|
|
1093
|
+
this.remove = props.remove;
|
|
1094
|
+
this.retune = props.retune;
|
|
139
1095
|
}
|
|
140
1096
|
async #encode(w, version) {
|
|
141
1097
|
switch (version) {
|
|
142
1098
|
case Version.DRAFT_01:
|
|
143
1099
|
case Version.DRAFT_02:
|
|
144
|
-
await w.u8(this.priority);
|
|
1100
|
+
await w.u8(toWire(this.priority));
|
|
145
1101
|
break;
|
|
146
1102
|
default:
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
await
|
|
1103
|
+
// Lite-07 carries a priority and order per range instead.
|
|
1104
|
+
if (!hasRanges(version)) {
|
|
1105
|
+
await w.u8(toWire(this.priority));
|
|
1106
|
+
await encodeOrder(w, version, this.order);
|
|
1107
|
+
}
|
|
1108
|
+
await encodeMaxDelay(w, version, this.maxDelay);
|
|
1109
|
+
if (hasRanges(version)) {
|
|
1110
|
+
// An edit of the live ranges, which may add none: `ranges`, or else the span as
|
|
1111
|
+
// the one range added once `remove` retires the rest.
|
|
1112
|
+
if (this.ranges === undefined && this.remove === undefined)
|
|
1113
|
+
throw new Error("a lite-07 update edits its ranges");
|
|
1114
|
+
const remove = this.remove ?? [];
|
|
1115
|
+
await w.u53(remove.length);
|
|
1116
|
+
for (const id of remove)
|
|
1117
|
+
await w.u62(id);
|
|
1118
|
+
if (this.ranges === undefined) {
|
|
1119
|
+
await encodeSpan(w, version, this, undefined, this);
|
|
1120
|
+
}
|
|
1121
|
+
else {
|
|
1122
|
+
await w.u53(this.ranges.length);
|
|
1123
|
+
for (const range of this.ranges)
|
|
1124
|
+
await encodeRange(w, range);
|
|
1125
|
+
}
|
|
1126
|
+
const retune = this.retune ?? [];
|
|
1127
|
+
await w.u53(retune.length);
|
|
1128
|
+
for (const [id, tuned] of retune) {
|
|
1129
|
+
await w.u62(id);
|
|
1130
|
+
await encodePolicy(w, tuned);
|
|
1131
|
+
await Duration.encodeOptional(w, tuned.max ?? undefined);
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
else {
|
|
1135
|
+
await encodeSpan(w, version, this, this.ranges);
|
|
1136
|
+
}
|
|
1137
|
+
if (hasRefresh(version))
|
|
1138
|
+
await w.u62(this.wantedGroup === undefined ? 0n : this.wantedGroup + 1n);
|
|
153
1139
|
break;
|
|
154
1140
|
}
|
|
155
1141
|
}
|
|
@@ -157,26 +1143,45 @@ export class SubscribeUpdate {
|
|
|
157
1143
|
switch (version) {
|
|
158
1144
|
case Version.DRAFT_01:
|
|
159
1145
|
case Version.DRAFT_02:
|
|
160
|
-
return new SubscribeUpdate({ priority: await r.u8() });
|
|
1146
|
+
return new SubscribeUpdate({ priority: fromWire(await r.u8()), maxDelay: null });
|
|
161
1147
|
default: {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const
|
|
165
|
-
const
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
1148
|
+
// Lite-07 carries a priority and order per range, which the publisher reads off the live
|
|
1149
|
+
// ranges once it applies the edit.
|
|
1150
|
+
const priority = hasRanges(version) ? 0 : fromWire(await r.u8());
|
|
1151
|
+
const order = hasRanges(version) ? "descending" : await decodeOrder(r, version);
|
|
1152
|
+
const maxDelay = await decodeMaxDelay(r, version);
|
|
1153
|
+
let span;
|
|
1154
|
+
if (hasRanges(version)) {
|
|
1155
|
+
// Not preallocated, like the ranges: each id costs a byte of the bounded message.
|
|
1156
|
+
const remove = [];
|
|
1157
|
+
for (let count = await r.u53(); count > 0; count--)
|
|
1158
|
+
remove.push(await r.u62());
|
|
1159
|
+
const ranges = await decodeRanges(r);
|
|
1160
|
+
const retune = [];
|
|
1161
|
+
for (let count = await r.u53(); count > 0; count--) {
|
|
1162
|
+
const id = await r.u62();
|
|
1163
|
+
const policy = await decodePolicy(r);
|
|
1164
|
+
retune.push([id, { ...policy, max: (await Duration.decodeOptional(r)) ?? null }]);
|
|
1165
|
+
}
|
|
1166
|
+
span = { startFrame: 0, remove, ranges, retune };
|
|
1167
|
+
}
|
|
1168
|
+
else {
|
|
1169
|
+
span = await decodeSpan(r, version);
|
|
1170
|
+
}
|
|
1171
|
+
const wanted = hasRefresh(version) ? await r.u62() : 0n;
|
|
169
1172
|
return new SubscribeUpdate({
|
|
1173
|
+
wantedGroup: wanted === 0n ? undefined : wanted - 1n,
|
|
170
1174
|
priority,
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
...frames,
|
|
1175
|
+
order,
|
|
1176
|
+
maxDelay,
|
|
1177
|
+
...span,
|
|
175
1178
|
});
|
|
176
1179
|
}
|
|
177
1180
|
}
|
|
178
1181
|
}
|
|
179
1182
|
async encode(w, version) {
|
|
1183
|
+
if (this.wantedGroup !== undefined && this.wantedGroup < 0n)
|
|
1184
|
+
throw new RangeError("wanted group must be non-negative");
|
|
180
1185
|
return Message.encode(w, (w) => this.#encode(w, version));
|
|
181
1186
|
}
|
|
182
1187
|
static async decode(r, version) {
|
|
@@ -189,10 +1194,22 @@ export class SubscribeUpdate {
|
|
|
189
1194
|
export class Subscribe {
|
|
190
1195
|
id;
|
|
191
1196
|
broadcast;
|
|
1197
|
+
/** The publisher identity the subscriber expects. Lite-07+. */
|
|
1198
|
+
identity;
|
|
192
1199
|
track;
|
|
193
1200
|
priority;
|
|
194
|
-
/**
|
|
195
|
-
|
|
1201
|
+
/**
|
|
1202
|
+
* Which pending group to send first. Lite-07+; earlier wires decode as descending and
|
|
1203
|
+
* cannot ask for anything else.
|
|
1204
|
+
*/
|
|
1205
|
+
order;
|
|
1206
|
+
/**
|
|
1207
|
+
* The `Subscriber Max Age` before lite-07, in milliseconds, `null` for no limit beyond the
|
|
1208
|
+
* publisher's; zero skips once a newer group is available. Lite-01/02 carry none and decode as
|
|
1209
|
+
* `null`. Lite-07 carries a max on each live start instead, so this is ignored there and decodes
|
|
1210
|
+
* as `null`.
|
|
1211
|
+
*/
|
|
1212
|
+
maxDelay;
|
|
196
1213
|
startGroup;
|
|
197
1214
|
endGroup;
|
|
198
1215
|
/**
|
|
@@ -206,60 +1223,88 @@ export class Subscribe {
|
|
|
206
1223
|
* whole group. Lite-06+, and meaningless without an explicit `endGroup`.
|
|
207
1224
|
*/
|
|
208
1225
|
endFrame;
|
|
1226
|
+
/**
|
|
1227
|
+
* Every range. Lite-07 encodes these in place of the span when given, and older versions
|
|
1228
|
+
* the span alone; decoding a lite-07 list fills them alongside the span covering them all.
|
|
1229
|
+
*/
|
|
1230
|
+
ranges;
|
|
1231
|
+
/**
|
|
1232
|
+
* Whether each frame is delivered as its header alone, without its payload, for the
|
|
1233
|
+
* subscription's whole life. Lite-07+: an earlier wire cannot carry it, so encoding one there
|
|
1234
|
+
* throws rather than asking for the payload.
|
|
1235
|
+
*/
|
|
1236
|
+
meta;
|
|
209
1237
|
constructor(props) {
|
|
210
1238
|
this.id = props.id;
|
|
211
1239
|
this.broadcast = props.broadcast;
|
|
1240
|
+
this.identity = props.identity;
|
|
212
1241
|
this.track = props.track;
|
|
213
1242
|
this.priority = props.priority;
|
|
214
|
-
this.
|
|
1243
|
+
this.order = props.order ?? "descending";
|
|
1244
|
+
this.maxDelay = props.maxDelay === undefined ? 0 : props.maxDelay;
|
|
215
1245
|
this.startGroup = props.startGroup;
|
|
216
1246
|
this.endGroup = props.endGroup;
|
|
217
1247
|
this.startFrame = props.startFrame ?? 0;
|
|
218
1248
|
this.endFrame = props.endFrame;
|
|
1249
|
+
this.ranges = props.ranges;
|
|
1250
|
+
this.meta = props.meta ?? false;
|
|
219
1251
|
}
|
|
220
1252
|
async #encode(w, version) {
|
|
221
1253
|
await w.u62(this.id);
|
|
222
1254
|
await w.string(Path.encode(this.broadcast));
|
|
1255
|
+
await encodePin(w, version, this.identity);
|
|
1256
|
+
await encodeNode(w, version);
|
|
223
1257
|
await w.string(this.track);
|
|
224
|
-
await w.u8(this.priority);
|
|
225
1258
|
switch (version) {
|
|
226
1259
|
case Version.DRAFT_01:
|
|
227
1260
|
case Version.DRAFT_02:
|
|
1261
|
+
await w.u8(toWire(this.priority));
|
|
228
1262
|
break;
|
|
229
1263
|
default:
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
1264
|
+
// Lite-07 carries a priority and order per range instead.
|
|
1265
|
+
if (!hasRanges(version)) {
|
|
1266
|
+
await w.u8(toWire(this.priority));
|
|
1267
|
+
await encodeOrder(w, version, this.order);
|
|
1268
|
+
}
|
|
1269
|
+
await encodeMaxDelay(w, version, this.maxDelay);
|
|
1270
|
+
await encodeSpan(w, version, this, this.ranges, this);
|
|
235
1271
|
break;
|
|
236
1272
|
}
|
|
1273
|
+
await encodeMeta(w, version, this.meta);
|
|
237
1274
|
}
|
|
238
1275
|
static async #decode(r, version) {
|
|
239
1276
|
const id = await r.u62();
|
|
240
1277
|
const broadcast = Path.decode(await r.string());
|
|
1278
|
+
const identity = await decodePin(r, version);
|
|
1279
|
+
await decodeNode(r, version);
|
|
241
1280
|
const track = await r.string();
|
|
242
|
-
const priority = await r.u8();
|
|
243
1281
|
switch (version) {
|
|
244
1282
|
case Version.DRAFT_01:
|
|
245
1283
|
case Version.DRAFT_02:
|
|
246
|
-
return new Subscribe({ id, broadcast, track, priority });
|
|
1284
|
+
return new Subscribe({ id, broadcast, track, priority: fromWire(await r.u8()), maxDelay: null });
|
|
247
1285
|
default: {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
1286
|
+
let priority = 0;
|
|
1287
|
+
let order = "descending";
|
|
1288
|
+
if (!hasRanges(version)) {
|
|
1289
|
+
priority = fromWire(await r.u8());
|
|
1290
|
+
order = await decodeOrder(r, version);
|
|
1291
|
+
}
|
|
1292
|
+
const maxDelay = await decodeMaxDelay(r, version);
|
|
1293
|
+
const span = await decodeSpan(r, version);
|
|
1294
|
+
// Each range carries its own priority and order, which the subscription runs at as a whole.
|
|
1295
|
+
if (span.ranges)
|
|
1296
|
+
({ priority, order } = subscriptionPolicy(span.ranges));
|
|
1297
|
+
const meta = await decodeMeta(r, version);
|
|
254
1298
|
return new Subscribe({
|
|
255
1299
|
id,
|
|
256
1300
|
broadcast,
|
|
1301
|
+
identity,
|
|
257
1302
|
track,
|
|
258
1303
|
priority,
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
1304
|
+
order,
|
|
1305
|
+
maxDelay,
|
|
1306
|
+
...span,
|
|
1307
|
+
meta,
|
|
263
1308
|
});
|
|
264
1309
|
}
|
|
265
1310
|
}
|
|
@@ -279,13 +1324,13 @@ export class Subscribe {
|
|
|
279
1324
|
*/
|
|
280
1325
|
export class SubscribeOk {
|
|
281
1326
|
priority;
|
|
282
|
-
/** Accepted subscriber max
|
|
283
|
-
|
|
1327
|
+
/** Accepted subscriber max delay in milliseconds. */
|
|
1328
|
+
maxDelay;
|
|
284
1329
|
startGroup;
|
|
285
1330
|
endGroup;
|
|
286
|
-
constructor({ priority = 0,
|
|
1331
|
+
constructor({ priority = 0, maxDelay = 0, startGroup = undefined, endGroup = undefined, }) {
|
|
287
1332
|
this.priority = priority;
|
|
288
|
-
this.
|
|
1333
|
+
this.maxDelay = maxDelay;
|
|
289
1334
|
this.startGroup = startGroup;
|
|
290
1335
|
this.endGroup = endGroup;
|
|
291
1336
|
}
|
|
@@ -295,22 +1340,22 @@ export class SubscribeOk {
|
|
|
295
1340
|
// noop
|
|
296
1341
|
break;
|
|
297
1342
|
case Version.DRAFT_01:
|
|
298
|
-
await w.u8(this.priority
|
|
1343
|
+
await w.u8(toWire(this.priority));
|
|
299
1344
|
break;
|
|
300
1345
|
// Draft-05+ never sends SUBSCRIBE_OK, but keep the field layout matching
|
|
301
1346
|
// Draft-03/04 so a stray future use stays well-formed.
|
|
302
1347
|
default:
|
|
303
|
-
await w.u8(this.priority);
|
|
1348
|
+
await w.u8(toWire(this.priority));
|
|
304
1349
|
await padGroupOrder(w, version);
|
|
305
|
-
await w.u53(this.
|
|
306
|
-
await w.
|
|
307
|
-
await w.
|
|
1350
|
+
await w.u53(this.maxDelay);
|
|
1351
|
+
await w.u62(this.startGroup !== undefined ? this.startGroup + 1n : 0n);
|
|
1352
|
+
await w.u62(this.endGroup !== undefined ? this.endGroup + 1n : 0n);
|
|
308
1353
|
break;
|
|
309
1354
|
}
|
|
310
1355
|
}
|
|
311
1356
|
static async #decode(version, r) {
|
|
312
1357
|
let priority;
|
|
313
|
-
let
|
|
1358
|
+
let maxDelay;
|
|
314
1359
|
let startGroup;
|
|
315
1360
|
let endGroup;
|
|
316
1361
|
switch (version) {
|
|
@@ -318,21 +1363,21 @@ export class SubscribeOk {
|
|
|
318
1363
|
// noop
|
|
319
1364
|
break;
|
|
320
1365
|
case Version.DRAFT_01:
|
|
321
|
-
priority = await r.u8();
|
|
1366
|
+
priority = fromWire(await r.u8());
|
|
322
1367
|
break;
|
|
323
1368
|
default:
|
|
324
|
-
priority = await r.u8();
|
|
1369
|
+
priority = fromWire(await r.u8());
|
|
325
1370
|
await skipGroupOrder(r, version);
|
|
326
|
-
|
|
327
|
-
startGroup = await r.
|
|
328
|
-
endGroup = await r.
|
|
1371
|
+
maxDelay = await r.u53();
|
|
1372
|
+
startGroup = await r.u62();
|
|
1373
|
+
endGroup = await r.u62();
|
|
329
1374
|
break;
|
|
330
1375
|
}
|
|
331
1376
|
return new SubscribeOk({
|
|
332
1377
|
priority,
|
|
333
|
-
|
|
334
|
-
startGroup: startGroup !== undefined && startGroup >
|
|
335
|
-
endGroup: endGroup !== undefined && endGroup >
|
|
1378
|
+
maxDelay,
|
|
1379
|
+
startGroup: startGroup !== undefined && startGroup > 0n ? startGroup - 1n : undefined,
|
|
1380
|
+
endGroup: endGroup !== undefined && endGroup > 0n ? endGroup - 1n : undefined,
|
|
336
1381
|
});
|
|
337
1382
|
}
|
|
338
1383
|
async encode(w, version) {
|
|
@@ -343,81 +1388,231 @@ export class SubscribeOk {
|
|
|
343
1388
|
}
|
|
344
1389
|
}
|
|
345
1390
|
/**
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
1391
|
+
* Says where one range of a Draft-05+ subscription starts, once the publisher resolves it. Before
|
|
1392
|
+
* lite-07 one answers the subscription's one range; lite-07 answers each range by Range ID, from
|
|
1393
|
+
* the SUBSCRIBE or an update, along with what the publisher knows of the largest position. A start
|
|
1394
|
+
* above the requested one implicitly drops the groups below it.
|
|
349
1395
|
*
|
|
350
|
-
* There is no start frame: a partial group is only served to a subscriber that asked
|
|
351
|
-
*
|
|
352
|
-
*
|
|
1396
|
+
* There is no start frame: a partial group is only served to a subscriber that asked for
|
|
1397
|
+
* one, so a range begins at its requested frame when it starts at its requested group,
|
|
1398
|
+
* and at frame 0 of a later one otherwise.
|
|
353
1399
|
*/
|
|
354
1400
|
export class SubscribeStart {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
1401
|
+
/** The range's Range ID; 0 before lite-07, whose one range has none on the wire. */
|
|
1402
|
+
id;
|
|
1403
|
+
/** The group its delivery starts at, `undefined` for a range with no group there. */
|
|
1404
|
+
start;
|
|
1405
|
+
/** What the publisher knows of the largest position; always `"unknown"` before lite-07. */
|
|
1406
|
+
largest;
|
|
1407
|
+
constructor(props) {
|
|
1408
|
+
this.id = props.id;
|
|
1409
|
+
this.start = props.start;
|
|
1410
|
+
this.largest = props.largest;
|
|
358
1411
|
}
|
|
359
|
-
async encode(w) {
|
|
1412
|
+
async encode(w, version) {
|
|
360
1413
|
return Message.encode(w, async (w) => {
|
|
361
|
-
|
|
1414
|
+
if (!hasRanges(version)) {
|
|
1415
|
+
if (this.id !== 0n || this.start === undefined || this.largest !== "unknown")
|
|
1416
|
+
throw new Error("one start group before draft-07");
|
|
1417
|
+
return w.u62(this.start);
|
|
1418
|
+
}
|
|
1419
|
+
await w.u62(this.id);
|
|
1420
|
+
// Group + 1, so 0 is a range with no group there.
|
|
1421
|
+
await w.u62(this.start === undefined ? 0n : this.start + 1n);
|
|
1422
|
+
if (this.largest === "unknown")
|
|
1423
|
+
return w.u8(0);
|
|
1424
|
+
if (this.largest === "empty")
|
|
1425
|
+
return w.u8(1);
|
|
1426
|
+
await w.u8(2);
|
|
1427
|
+
await w.u62(this.largest.position.group);
|
|
1428
|
+
await w.u53(this.largest.position.frame);
|
|
1429
|
+
await w.u8(this.largest.ended ? 1 : 0);
|
|
362
1430
|
});
|
|
363
1431
|
}
|
|
364
|
-
static async decode(r) {
|
|
365
|
-
return Message.decode(r, async (r) =>
|
|
1432
|
+
static async decode(r, version) {
|
|
1433
|
+
return Message.decode(r, async (r) => {
|
|
1434
|
+
if (!hasRanges(version))
|
|
1435
|
+
return new SubscribeStart({ id: 0n, start: await r.u62(), largest: "unknown" });
|
|
1436
|
+
const id = await r.u62();
|
|
1437
|
+
const wire = await r.u62();
|
|
1438
|
+
const start = wire === 0n ? undefined : wire - 1n;
|
|
1439
|
+
const type = await r.u8();
|
|
1440
|
+
switch (type) {
|
|
1441
|
+
case 0:
|
|
1442
|
+
return new SubscribeStart({ id, start, largest: "unknown" });
|
|
1443
|
+
case 1:
|
|
1444
|
+
return new SubscribeStart({ id, start, largest: "empty" });
|
|
1445
|
+
case 2: {
|
|
1446
|
+
const position = { group: await r.u62(), frame: await r.u53() };
|
|
1447
|
+
const ended = await r.u8();
|
|
1448
|
+
if (ended > 1)
|
|
1449
|
+
throw new ProtocolViolation(`invalid Largest Ended: ${ended}`);
|
|
1450
|
+
return new SubscribeStart({ id, start, largest: { position, ended: ended === 1 } });
|
|
1451
|
+
}
|
|
1452
|
+
default:
|
|
1453
|
+
throw new ProtocolViolation(`invalid Largest Type: ${type}`);
|
|
1454
|
+
}
|
|
1455
|
+
});
|
|
366
1456
|
}
|
|
367
1457
|
}
|
|
368
1458
|
/**
|
|
369
|
-
*
|
|
370
|
-
*
|
|
1459
|
+
* SUBSCRIBE_END: no group at or after `group` (exclusive upper bound) will be produced on a
|
|
1460
|
+
* Draft-05+ subscription. `0` means the track ended before producing any groups.
|
|
371
1461
|
*/
|
|
372
1462
|
export class SubscribeEnd {
|
|
373
|
-
/** The exclusive final group
|
|
1463
|
+
/** The exclusive final group key: the first key that will never be produced. */
|
|
374
1464
|
group;
|
|
375
|
-
|
|
376
|
-
* The number of group streams the publisher opened for this subscription.
|
|
377
|
-
* Draft-07+ only; not on the wire before, where it decodes as 0.
|
|
378
|
-
*/
|
|
379
|
-
streams;
|
|
380
|
-
constructor(group, streams = 0) {
|
|
1465
|
+
constructor(group) {
|
|
381
1466
|
this.group = group;
|
|
382
|
-
|
|
1467
|
+
}
|
|
1468
|
+
async encode(w, _version) {
|
|
1469
|
+
return Message.encode(w, async (w) => {
|
|
1470
|
+
await w.u62(this.group);
|
|
1471
|
+
});
|
|
1472
|
+
}
|
|
1473
|
+
static async decode(r, _version) {
|
|
1474
|
+
return Message.decode(r, async (r) => new SubscribeEnd(await r.u62()));
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
/**
|
|
1478
|
+
* A SUBSCRIBE_DROP range: a non-empty `[Group Start, Group End)` on lite-07, an
|
|
1479
|
+
* inclusive `Group Start` and `Group End` before. Either way it ends by the reserved key
|
|
1480
|
+
* 2^64-1, so it never names that group.
|
|
1481
|
+
*/
|
|
1482
|
+
async function decodeGroups(r, version) {
|
|
1483
|
+
const start = await r.u62();
|
|
1484
|
+
const span = hasGroupSpan(version);
|
|
1485
|
+
const end = span ? await r.u62() : (await r.u62()) + 1n;
|
|
1486
|
+
if (end < start || (span && end === start) || end >= UNBOUNDED)
|
|
1487
|
+
throw new ProtocolViolation(`invalid group range: [${start}, ${end})`);
|
|
1488
|
+
return { start, end };
|
|
1489
|
+
}
|
|
1490
|
+
async function encodeGroups(w, start, end, version) {
|
|
1491
|
+
const span = hasGroupSpan(version);
|
|
1492
|
+
// An empty range at 0 has no inclusive end to spell before lite-07, and lite-07 has no empty one.
|
|
1493
|
+
if (end < start || end >= UNBOUNDED || (span ? end === start : end === 0n))
|
|
1494
|
+
throw new RangeError(`invalid group range: [${start}, ${end})`);
|
|
1495
|
+
await w.u62(start);
|
|
1496
|
+
await w.u62(span ? end : end - 1n);
|
|
1497
|
+
}
|
|
1498
|
+
/**
|
|
1499
|
+
* Names groups this subscription will not deliver, and nothing more: not found here, expired
|
|
1500
|
+
* under the publisher's own max age, or reset where the GROUP header may be lost. On lite-07 it
|
|
1501
|
+
* speaks for this subscription alone, so a reader still owed a group asks for it afresh; before
|
|
1502
|
+
* lite-07 it carries an application code (read and dropped) and reads as stale.
|
|
1503
|
+
*
|
|
1504
|
+
* Draft-03+; publishers send it on Draft-05 and later.
|
|
1505
|
+
*/
|
|
1506
|
+
export class SubscribeDrop {
|
|
1507
|
+
/** The first dropped group key. */
|
|
1508
|
+
start;
|
|
1509
|
+
/** One past the last dropped group key. */
|
|
1510
|
+
end;
|
|
1511
|
+
constructor(props) {
|
|
1512
|
+
this.start = props.start;
|
|
1513
|
+
this.end = props.end;
|
|
383
1514
|
}
|
|
384
1515
|
async encode(w, version) {
|
|
385
1516
|
return Message.encode(w, async (w) => {
|
|
386
|
-
await w.
|
|
387
|
-
if (
|
|
388
|
-
await w.u53(
|
|
1517
|
+
await encodeGroups(w, this.start, this.end, version);
|
|
1518
|
+
if (!hasSkip(version))
|
|
1519
|
+
await w.u53(0);
|
|
389
1520
|
});
|
|
390
1521
|
}
|
|
391
1522
|
static async decode(r, version) {
|
|
392
|
-
return Message.decode(r, async (r) =>
|
|
1523
|
+
return Message.decode(r, async (r) => {
|
|
1524
|
+
const { start, end } = await decodeGroups(r, version);
|
|
1525
|
+
if (!hasSkip(version))
|
|
1526
|
+
await r.u62();
|
|
1527
|
+
return new SubscribeDrop({ start, end });
|
|
1528
|
+
});
|
|
393
1529
|
}
|
|
394
1530
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
1531
|
+
/**
|
|
1532
|
+
* Names group starts the publisher declared never produced: permanent, and it supersedes a copy
|
|
1533
|
+
* that did not finish the group. Lite-07+.
|
|
1534
|
+
*/
|
|
1535
|
+
export class SubscribeSkip {
|
|
1536
|
+
/** The first skipped group key. */
|
|
399
1537
|
start;
|
|
1538
|
+
/** One past the last skipped group key. */
|
|
400
1539
|
end;
|
|
401
|
-
error;
|
|
402
1540
|
constructor(props) {
|
|
403
1541
|
this.start = props.start;
|
|
404
1542
|
this.end = props.end;
|
|
405
|
-
this.error = props.error;
|
|
406
1543
|
}
|
|
407
|
-
async
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
1544
|
+
async encode(w, version) {
|
|
1545
|
+
if (!hasSkip(version))
|
|
1546
|
+
throw new Error("SUBSCRIBE_SKIP needs lite-07");
|
|
1547
|
+
return Message.encode(w, (w) => encodeGroups(w, this.start, this.end, version));
|
|
1548
|
+
}
|
|
1549
|
+
static async decode(r, version) {
|
|
1550
|
+
return Message.decode(r, async (r) => new SubscribeSkip(await decodeGroups(r, version)));
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
/**
|
|
1554
|
+
* Names groups judged stale under a finite `Max Age`, so only a reader no wider settles on them;
|
|
1555
|
+
* a wider one asks for them on a request of its own. Lite-07+.
|
|
1556
|
+
*/
|
|
1557
|
+
export class SubscribeOld {
|
|
1558
|
+
/** The first stale group key. */
|
|
1559
|
+
start;
|
|
1560
|
+
/** One past the last stale group key. */
|
|
1561
|
+
end;
|
|
1562
|
+
/** The `Max Age` in milliseconds the groups were judged stale under. */
|
|
1563
|
+
maxAge;
|
|
1564
|
+
constructor(props) {
|
|
1565
|
+
this.start = props.start;
|
|
1566
|
+
this.end = props.end;
|
|
1567
|
+
this.maxAge = props.maxAge;
|
|
411
1568
|
}
|
|
412
|
-
|
|
413
|
-
|
|
1569
|
+
async encode(w, version) {
|
|
1570
|
+
if (!hasSkip(version))
|
|
1571
|
+
throw new Error("SUBSCRIBE_OLD needs lite-07");
|
|
1572
|
+
// Rounded down, so a reader settles on it only when no wider than the verdict's budget.
|
|
1573
|
+
const maxAge = Math.floor(this.maxAge);
|
|
1574
|
+
if (!Number.isSafeInteger(maxAge) || maxAge < 0)
|
|
1575
|
+
throw new RangeError("max age exceeds safe milliseconds");
|
|
1576
|
+
return Message.encode(w, async (w) => {
|
|
1577
|
+
await encodeGroups(w, this.start, this.end, version);
|
|
1578
|
+
await w.u62(BigInt(maxAge));
|
|
1579
|
+
});
|
|
414
1580
|
}
|
|
415
|
-
async
|
|
416
|
-
return Message.
|
|
1581
|
+
static async decode(r, version) {
|
|
1582
|
+
return Message.decode(r, async (r) => {
|
|
1583
|
+
const { start, end } = await decodeGroups(r, version);
|
|
1584
|
+
const maxAge = await r.u62();
|
|
1585
|
+
if (maxAge > BigInt(Number.MAX_SAFE_INTEGER))
|
|
1586
|
+
throw new RangeError("max age exceeds safe milliseconds");
|
|
1587
|
+
return new SubscribeOld({ start, end, maxAge: Number(maxAge) });
|
|
1588
|
+
});
|
|
417
1589
|
}
|
|
418
|
-
|
|
419
|
-
|
|
1590
|
+
}
|
|
1591
|
+
/**
|
|
1592
|
+
* The response giving up `[start, end)` as `hole`, as `version` carries it. Before lite-07 every
|
|
1593
|
+
* one is a drop. A skip is a skip; a stale verdict names the finite budget it was judged under,
|
|
1594
|
+
* and an `old` with no verdict of its own names `unjudged`, the narrowest finite live-join max
|
|
1595
|
+
* age; with neither, or for anything else, it is a drop. Mirrors the Rust
|
|
1596
|
+
* `SubscribeResponse::given_up`.
|
|
1597
|
+
*/
|
|
1598
|
+
export function givenUp(start, end, hole, unjudged, version) {
|
|
1599
|
+
if (!hasSkip(version))
|
|
1600
|
+
return { drop: new SubscribeDrop({ start, end }) };
|
|
1601
|
+
let maxAge;
|
|
1602
|
+
switch (hole.reason) {
|
|
1603
|
+
case "skip":
|
|
1604
|
+
return { skip: new SubscribeSkip({ start, end }) };
|
|
1605
|
+
case "drop":
|
|
1606
|
+
maxAge = undefined;
|
|
1607
|
+
break;
|
|
1608
|
+
case "old":
|
|
1609
|
+
maxAge = hole.maxAge ?? unjudged;
|
|
1610
|
+
break;
|
|
420
1611
|
}
|
|
1612
|
+
// No finite budget, including one at the no-limit bound, names no Max Age: a drop.
|
|
1613
|
+
if (maxAge === undefined || maxAge >= NO_MAX_DELAY)
|
|
1614
|
+
return { drop: new SubscribeDrop({ start, end }) };
|
|
1615
|
+
return { old: new SubscribeOld({ start, end, maxAge }) };
|
|
421
1616
|
}
|
|
422
1617
|
export async function encodeSubscribeResponse(w, resp, version) {
|
|
423
1618
|
switch (version) {
|
|
@@ -438,25 +1633,33 @@ export async function encodeSubscribeResponse(w, resp, version) {
|
|
|
438
1633
|
}
|
|
439
1634
|
else if ("drop" in resp) {
|
|
440
1635
|
await w.u53(0x1);
|
|
441
|
-
await resp.drop.encode(w);
|
|
1636
|
+
await resp.drop.encode(w, version);
|
|
442
1637
|
}
|
|
443
1638
|
else {
|
|
444
|
-
throw new Error("SUBSCRIBE_START/
|
|
1639
|
+
throw new Error("SUBSCRIBE_START/FINISH not supported for this version");
|
|
445
1640
|
}
|
|
446
1641
|
break;
|
|
447
1642
|
default:
|
|
448
1643
|
// Draft-05+: SUBSCRIBE_OK is gone; START/END/DROP carry the resolved range.
|
|
449
1644
|
if ("start" in resp) {
|
|
450
|
-
await w.u53(0x0);
|
|
451
|
-
await resp.start.encode(w);
|
|
1645
|
+
await w.u53(hasRanges(version) ? 0x4 : 0x0);
|
|
1646
|
+
await resp.start.encode(w, version);
|
|
452
1647
|
}
|
|
453
1648
|
else if ("end" in resp) {
|
|
454
1649
|
await w.u53(0x1);
|
|
455
1650
|
await resp.end.encode(w, version);
|
|
456
1651
|
}
|
|
457
|
-
else if ("drop" in resp
|
|
1652
|
+
else if ("drop" in resp) {
|
|
458
1653
|
await w.u53(0x2);
|
|
459
|
-
await resp.drop.encode(w);
|
|
1654
|
+
await resp.drop.encode(w, version);
|
|
1655
|
+
}
|
|
1656
|
+
else if ("skip" in resp && hasSkip(version)) {
|
|
1657
|
+
await w.u53(0x3);
|
|
1658
|
+
await resp.skip.encode(w, version);
|
|
1659
|
+
}
|
|
1660
|
+
else if ("old" in resp && hasSkip(version)) {
|
|
1661
|
+
await w.u53(0x5);
|
|
1662
|
+
await resp.old.encode(w, version);
|
|
460
1663
|
}
|
|
461
1664
|
else {
|
|
462
1665
|
throw new Error("subscribe response not supported for this version");
|
|
@@ -476,28 +1679,55 @@ export async function decodeSubscribeResponse(r, version) {
|
|
|
476
1679
|
case 0x0:
|
|
477
1680
|
return { ok: await SubscribeOk.decode(r, version) };
|
|
478
1681
|
case 0x1:
|
|
479
|
-
return { drop: await SubscribeDrop.decode(r) };
|
|
1682
|
+
return { drop: await SubscribeDrop.decode(r, version) };
|
|
480
1683
|
default:
|
|
481
|
-
throw new
|
|
1684
|
+
throw new ProtocolViolation(`unknown subscribe response type: ${typ}`);
|
|
482
1685
|
}
|
|
483
1686
|
}
|
|
484
1687
|
default: {
|
|
485
1688
|
const typ = await r.u53();
|
|
486
1689
|
switch (typ) {
|
|
487
1690
|
case 0x0:
|
|
488
|
-
|
|
1691
|
+
if (hasRanges(version))
|
|
1692
|
+
throw new ProtocolViolation(`unknown subscribe response type: ${typ}`);
|
|
1693
|
+
return { start: await SubscribeStart.decode(r, version) };
|
|
489
1694
|
case 0x1:
|
|
490
1695
|
return { end: await SubscribeEnd.decode(r, version) };
|
|
491
1696
|
case 0x2:
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
1697
|
+
return { drop: await SubscribeDrop.decode(r, version) };
|
|
1698
|
+
case 0x3:
|
|
1699
|
+
if (!hasSkip(version))
|
|
1700
|
+
throw new ProtocolViolation(`unknown subscribe response type: ${typ}`);
|
|
1701
|
+
return { skip: await SubscribeSkip.decode(r, version) };
|
|
1702
|
+
case 0x4:
|
|
1703
|
+
if (!hasRanges(version))
|
|
1704
|
+
throw new ProtocolViolation(`unknown subscribe response type: ${typ}`);
|
|
1705
|
+
return { start: await SubscribeStart.decode(r, version) };
|
|
1706
|
+
case 0x5:
|
|
1707
|
+
if (!hasSkip(version))
|
|
1708
|
+
throw new ProtocolViolation(`unknown subscribe response type: ${typ}`);
|
|
1709
|
+
return { old: await SubscribeOld.decode(r, version) };
|
|
495
1710
|
default:
|
|
496
|
-
throw new
|
|
1711
|
+
throw new ProtocolViolation(`unknown subscribe response type: ${typ}`);
|
|
497
1712
|
}
|
|
498
1713
|
}
|
|
499
1714
|
}
|
|
500
1715
|
}
|
|
1716
|
+
/**
|
|
1717
|
+
* Whether the next response `r` holds whole, without reading the stream, is a lite-07
|
|
1718
|
+
* SUBSCRIBE_START, so a subscriber applying a burst of them can take the next before applying.
|
|
1719
|
+
*/
|
|
1720
|
+
export function startBuffered(r, version) {
|
|
1721
|
+
if (!hasRanges(version))
|
|
1722
|
+
return false;
|
|
1723
|
+
const start = r.tryPeek((c) => {
|
|
1724
|
+
if (c.u53() !== 0x4)
|
|
1725
|
+
return false;
|
|
1726
|
+
c.read(c.u53());
|
|
1727
|
+
return true;
|
|
1728
|
+
});
|
|
1729
|
+
return start === true;
|
|
1730
|
+
}
|
|
501
1731
|
/** Like {@link decodeSubscribeResponse} but resolves `undefined` on a clean FIN. */
|
|
502
1732
|
export async function decodeSubscribeResponseMaybe(r, version) {
|
|
503
1733
|
if (await r.done())
|