@moq/net 0.4.8 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/announce.d.ts +1 -1
- package/announce.d.ts.map +1 -1
- package/announce.js +1 -1
- package/announce.js.map +1 -1
- package/announced.d.ts +51 -47
- package/announced.d.ts.map +1 -1
- package/announced.js +183 -31
- 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 -138
- 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 -1
- package/bandwidth_api.js.map +1 -1
- package/broadcast.d.ts +62 -36
- package/broadcast.d.ts.map +1 -1
- package/broadcast.js +556 -172
- 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 +20 -12
- package/connection/accept.d.ts.map +1 -1
- package/connection/accept.js +97 -129
- package/connection/accept.js.map +1 -1
- package/connection/browser.d.ts.map +1 -1
- package/connection/browser.js +28 -19
- package/connection/browser.js.map +1 -1
- package/connection/connect.d.ts +119 -23
- package/connection/connect.d.ts.map +1 -1
- package/connection/connect.js +535 -216
- 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 -80
- 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 -108
- package/connection/goaway.js.map +1 -1
- package/connection/handshake.d.ts +32 -6
- package/connection/handshake.d.ts.map +1 -1
- package/connection/handshake.js +97 -20
- package/connection/handshake.js.map +1 -1
- package/connection/index.d.ts +3 -6
- package/connection/index.d.ts.map +1 -1
- package/connection/index.js +1 -2
- 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 +137 -58
- package/connection/pool.d.ts.map +1 -1
- package/connection/pool.js +281 -117
- 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 -233
- 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 -8
- 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 -4
- 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 -46
- 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 -1
- 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 -37
- package/error.js.map +1 -1
- package/errors.d.ts +2 -2
- package/errors.d.ts.map +1 -1
- package/errors.js +2 -2
- 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 -307
- 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 -64
- 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 -35
- package/ietf/aliases.js.map +1 -1
- package/ietf/cluster.d.ts +3 -3
- package/ietf/cluster.js +14 -62
- 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 -143
- 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 -100
- package/ietf/error.js.map +1 -1
- package/ietf/fetch.d.ts +91 -35
- package/ietf/fetch.d.ts.map +1 -1
- package/ietf/fetch.js +172 -93
- package/ietf/fetch.js.map +1 -1
- package/ietf/filter.d.ts +20 -30
- package/ietf/filter.d.ts.map +1 -1
- package/ietf/filter.js +140 -171
- package/ietf/filter.js.map +1 -1
- package/ietf/goaway.d.ts +11 -9
- package/ietf/goaway.d.ts.map +1 -1
- package/ietf/goaway.js +22 -35
- package/ietf/goaway.js.map +1 -1
- package/ietf/hidden.js +1 -1
- package/ietf/hidden.js.map +1 -1
- package/ietf/index.d.ts +2 -14
- package/ietf/index.d.ts.map +1 -1
- package/ietf/index.js +4 -14
- 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 -40
- 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 +17 -3
- package/ietf/namespace.d.ts.map +1 -1
- package/ietf/namespace.js +78 -26
- package/ietf/namespace.js.map +1 -1
- package/ietf/object.d.ts +194 -32
- package/ietf/object.d.ts.map +1 -1
- package/ietf/object.js +405 -178
- package/ietf/object.js.map +1 -1
- package/ietf/parameters.d.ts +22 -42
- package/ietf/parameters.d.ts.map +1 -1
- package/ietf/parameters.js +260 -472
- 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 -4
- package/ietf/priority.js.map +1 -1
- package/ietf/properties.d.ts +5 -4
- package/ietf/properties.d.ts.map +1 -1
- package/ietf/properties.js +78 -48
- package/ietf/properties.js.map +1 -1
- package/ietf/publish.d.ts +22 -30
- package/ietf/publish.d.ts.map +1 -1
- package/ietf/publish.js +45 -139
- package/ietf/publish.js.map +1 -1
- package/ietf/publish_namespace.d.ts +46 -69
- package/ietf/publish_namespace.d.ts.map +1 -1
- package/ietf/publish_namespace.js +66 -184
- package/ietf/publish_namespace.js.map +1 -1
- package/ietf/publisher.js +1800 -600
- 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 +3 -27
- package/ietf/request.d.ts.map +1 -1
- package/ietf/request.js +41 -78
- 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 -16
- 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 +4 -29
- package/ietf/setup.d.ts.map +1 -1
- package/ietf/setup.js +6 -117
- 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 -14
- package/ietf/solicit.js.map +1 -1
- package/ietf/subscribe.d.ts +48 -41
- package/ietf/subscribe.d.ts.map +1 -1
- package/ietf/subscribe.js +118 -239
- package/ietf/subscribe.js.map +1 -1
- package/ietf/subscribe_namespace.d.ts +13 -76
- package/ietf/subscribe_namespace.d.ts.map +1 -1
- package/ietf/subscribe_namespace.js +30 -201
- package/ietf/subscribe_namespace.js.map +1 -1
- package/ietf/subscriber.js +1839 -536
- package/ietf/subscriber.js.map +1 -1
- package/ietf/token.js +105 -27
- package/ietf/token.js.map +1 -1
- package/ietf/track.d.ts +25 -22
- package/ietf/track.d.ts.map +1 -1
- package/ietf/track.js +48 -61
- 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 -48
- 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 +25 -10
- package/index.d.ts.map +1 -1
- package/index.js +19 -6
- package/index.js.map +1 -1
- package/internal.d.ts +1512 -64
- package/internal.d.ts.map +1 -1
- package/internal.js +557 -79
- 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 +124 -63
- package/lite/announce.d.ts.map +1 -1
- package/lite/announce.js +384 -158
- 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 -77
- 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 -9
- 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 +1 -1
- package/lite/goaway.d.ts.map +1 -1
- package/lite/goaway.js +5 -13
- package/lite/goaway.js.map +1 -1
- package/lite/group.d.ts +64 -13
- package/lite/group.d.ts.map +1 -1
- package/lite/group.js +108 -30
- 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 +2 -1
- package/lite/index.d.ts.map +1 -1
- package/lite/index.js +2 -1
- package/lite/index.js.map +1 -1
- package/lite/message.d.ts +9 -1
- package/lite/message.d.ts.map +1 -1
- package/lite/message.js +28 -44
- 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 -105
- package/lite/priority.js.map +1 -1
- package/lite/probe.d.ts.map +1 -1
- package/lite/probe.js +9 -0
- 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 -437
- 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 +1 -27
- package/lite/session.d.ts.map +1 -1
- package/lite/session.js +0 -99
- package/lite/session.js.map +1 -1
- package/lite/setup.d.ts +29 -2
- package/lite/setup.d.ts.map +1 -1
- package/lite/setup.js +95 -21
- 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 -1
- package/lite/stream.js.map +1 -1
- package/lite/subscribe.d.ts +475 -75
- package/lite/subscribe.d.ts.map +1 -1
- package/lite/subscribe.js +1373 -142
- 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 -515
- package/lite/subscriber.js.map +1 -1
- package/lite/track.d.ts +24 -9
- package/lite/track.d.ts.map +1 -1
- package/lite/track.js +116 -37
- 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 -33
- 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 +392 -140
- package/origin.d.ts.map +1 -1
- package/origin.js +2533 -686
- 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 -57
- 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 +75 -37
- package/stream.d.ts.map +1 -1
- package/stream.js +236 -92
- 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 -97
- package/tail.js.map +1 -1
- package/time.d.ts +41 -102
- package/time.d.ts.map +1 -1
- package/time.js +129 -91
- 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 +577 -245
- package/track.d.ts.map +1 -1
- package/track.js +7306 -771
- 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 -1
- 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 -4
- 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 -9
- 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/utf8.d.ts +2 -0
- package/util/utf8.d.ts.map +1 -1
- package/util/utf8.js +7 -1
- package/util/utf8.js.map +1 -1
- package/util/varint.d.ts.map +1 -1
- package/util/varint.js +8 -1
- 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 -28
- 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 +145 -30
- package/wire.d.ts.map +1 -1
- package/wire.js +27 -0
- 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 -2
- 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 -699
- 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 -43
- 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 -78
- 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 -16
- package/util/log.js.map +0 -1
- package/zod.d.ts +0 -13
- package/zod.d.ts.map +0 -1
- package/zod.js +0 -18
- package/zod.js.map +0 -1
package/connection/reload.js
CHANGED
|
@@ -1,33 +1,97 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { Duration, now, sleep } from "@moq/clock";
|
|
2
|
+
import { Derived, Effect, Once, Signal } from "@moq/signals";
|
|
3
|
+
import { Handle as AuthHandle } from "../auth.js";
|
|
4
|
+
import { ended } from "../auth_session.js";
|
|
5
|
+
import { Allocator, reserved, Viewers } from "../bandwidth.js";
|
|
6
|
+
import { ConnectTimeout, error, reason } from "../error.js";
|
|
5
7
|
import * as Path from "../path.js";
|
|
6
|
-
import
|
|
8
|
+
import { Follow, Observed } from "../util/observed.js";
|
|
9
|
+
import { after } from "../util/timer.js";
|
|
7
10
|
import { wireOf } from "../wire.js";
|
|
8
|
-
import {
|
|
11
|
+
import { webTransportDialed } from "./browser.js";
|
|
12
|
+
import { establish, normalizeVersions, Reached, reachable, } from "./connect.js";
|
|
13
|
+
import { Dials } from "./dials.js";
|
|
14
|
+
import { parse } from "./endpoint.js";
|
|
15
|
+
import { DISCOVERY_REMOVED } from "./forward.js";
|
|
9
16
|
import { DEFAULT_HANDOVER, dialed, handover, pinnedTransport, target } from "./goaway.js";
|
|
17
|
+
import { checkCost, connectTimeout } from "./handshake.js";
|
|
18
|
+
import { estimates } from "./stats.js";
|
|
19
|
+
import { tick } from "./ticker.js";
|
|
20
|
+
import { heldOf, Verdict } from "./tokens.js";
|
|
10
21
|
/**
|
|
11
|
-
* The
|
|
22
|
+
* The wait before a session on the WebSocket fallback first probes WebTransport, before jitter.
|
|
23
|
+
* Each failed probe doubles it, up to {@link PROBE_MAX}, matching moq-tokio.
|
|
24
|
+
*/
|
|
25
|
+
const PROBE_INITIAL = Duration.secs(10);
|
|
26
|
+
/** The longest wait between WebTransport probes, before jitter. */
|
|
27
|
+
const PROBE_MAX = Duration.secs(300);
|
|
28
|
+
/**
|
|
29
|
+
* The backoff applied to whichever {@link Backoff} fields a caller leaves out.
|
|
12
30
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* starts another sequence.
|
|
31
|
+
* Retries are unlimited by default: a loop that gives up stays offline until something
|
|
32
|
+
* redials it, and a page usually has nothing that will, so an outage of any length has to
|
|
33
|
+
* recover on its own. {@link Reload.status} already shows the outage. A caller that can react
|
|
34
|
+
* sets a timeout to surface a persistent failure on {@link Reload.error}; giving up does not
|
|
35
|
+
* dispose the loop, and a new URL or a disable/re-enable starts another sequence.
|
|
18
36
|
*/
|
|
19
|
-
const
|
|
20
|
-
initial:
|
|
37
|
+
const DEFAULT_BACKOFF = {
|
|
38
|
+
initial: Duration.millis(1000),
|
|
21
39
|
multiplier: 2,
|
|
22
|
-
max:
|
|
23
|
-
|
|
40
|
+
max: Duration.millis(5000),
|
|
41
|
+
healthy: Duration.millis(1000),
|
|
42
|
+
timeout: null,
|
|
24
43
|
};
|
|
25
|
-
/**
|
|
26
|
-
|
|
44
|
+
/**
|
|
45
|
+
* {@link Backoff} resolved against its defaults, with the same meaning as moq-tokio's
|
|
46
|
+
* backoff. Throws a RangeError for a value that has none.
|
|
47
|
+
*
|
|
48
|
+
* Field by field rather than by spread: a caller building `{ initial: maybeInitial }` from an
|
|
49
|
+
* optional value passes an explicit undefined, which a spread would take as the answer.
|
|
50
|
+
*/
|
|
51
|
+
function pacing(backoff) {
|
|
52
|
+
const initial = backoff.initial ?? DEFAULT_BACKOFF.initial;
|
|
53
|
+
// `null` means no bound, so only `undefined` takes the default.
|
|
54
|
+
const cap = backoff.max === undefined ? DEFAULT_BACKOFF.max : backoff.max;
|
|
55
|
+
const multiplier = backoff.multiplier ?? DEFAULT_BACKOFF.multiplier;
|
|
56
|
+
if (!Number.isFinite(multiplier))
|
|
57
|
+
throw new RangeError(`invalid backoff.multiplier: ${multiplier}`);
|
|
58
|
+
// Zero would count every session as healthy, resetting the retry window forever under a
|
|
59
|
+
// peer that drops each one on sight.
|
|
60
|
+
const healthy = backoff.healthy ?? DEFAULT_BACKOFF.healthy;
|
|
61
|
+
if (healthy.isZero())
|
|
62
|
+
throw new RangeError("backoff.healthy must be positive");
|
|
63
|
+
const timeout = backoff.timeout === undefined ? DEFAULT_BACKOFF.timeout : backoff.timeout;
|
|
64
|
+
// A multiplier below 1 means no growth, not a delay that shrinks to nothing.
|
|
65
|
+
const growth = Math.max(multiplier, 1);
|
|
66
|
+
return {
|
|
67
|
+
initial: cap === null ? initial : initial.min(cap),
|
|
68
|
+
healthy,
|
|
69
|
+
timeout,
|
|
70
|
+
// How long a session must last to start a new run of redirects. One that outlived the
|
|
71
|
+
// capped delay already redials no faster than the backoff would allow. Uncapped, the
|
|
72
|
+
// healthy bar is the only rate the config names.
|
|
73
|
+
settled: cap ?? healthy,
|
|
74
|
+
/** The delay after one that waited `delay`. */
|
|
75
|
+
next(delay) {
|
|
76
|
+
const next = Math.min(delay.asNanos() * growth, cap?.asNanos() ?? Number.POSITIVE_INFINITY);
|
|
77
|
+
// Saturates, as Rust's Duration does, rather than overflowing the wait.
|
|
78
|
+
return Number.isFinite(next) ? Duration.nanos(next) : delay;
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/** How often the send-rate estimate is sampled from the live transport while a reservation reads it. */
|
|
83
|
+
const BANDWIDTH_POLL = Duration.millis(100);
|
|
27
84
|
/**
|
|
28
85
|
* The reconnect loop behind a Connection handle: connects, waits for the session to end, then
|
|
29
86
|
* redials with exponential backoff.
|
|
30
87
|
*
|
|
88
|
+
* The first attempt for a URL fails fast instead: until a session to it was established (see
|
|
89
|
+
* {@link Backoff}), a failed attempt or a closed session sets {@link Reload.error}
|
|
90
|
+
* rather than retrying, so a setup mistake such as an
|
|
91
|
+
* untrusted certificate or no version in common surfaces at once. A page opened before its
|
|
92
|
+
* relay is reachable therefore stays disconnected until a new URL or a disable/re-enable,
|
|
93
|
+
* {@link Dials} included.
|
|
94
|
+
*
|
|
31
95
|
* @internal
|
|
32
96
|
*/
|
|
33
97
|
export class Reload {
|
|
@@ -35,12 +99,32 @@ export class Reload {
|
|
|
35
99
|
url;
|
|
36
100
|
/** Whether reconnecting is active. */
|
|
37
101
|
enabled;
|
|
38
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* Credentials every dial presents; see {@link ConnectProps.tokens}. Replacing them reaches
|
|
104
|
+
* the next dial and, on a live session with AUTH, presents the new tokens at once,
|
|
105
|
+
* withdrawing the replaced ones once every new one has its answer. With {@link Dials}, the set
|
|
106
|
+
* the latest dial signed, which only that dial presents.
|
|
107
|
+
*/
|
|
108
|
+
tokens;
|
|
109
|
+
// Where each dial asks for its tokens, instead of reading `tokens`.
|
|
110
|
+
#dials;
|
|
111
|
+
/**
|
|
112
|
+
* Why the loop is retrying: how the last attempt or session ended since a session last served,
|
|
113
|
+
* or undefined. The next {@link Dials} dial reads it. Mirrors Rust's `Monitor::failure()`.
|
|
114
|
+
*/
|
|
115
|
+
failure;
|
|
116
|
+
#failure = new Signal(undefined);
|
|
117
|
+
/**
|
|
118
|
+
* Current connection status. A session reads as connected only once its peer accepts the
|
|
119
|
+
* credential (on moq-lite-03/04, which never answer it, once it stays up past the healthy
|
|
120
|
+
* bar), so a refused one never does.
|
|
121
|
+
*/
|
|
39
122
|
status = new Signal("disconnected");
|
|
40
123
|
/**
|
|
41
124
|
* The failure that stopped retrying the current URL, or undefined while the loop is live.
|
|
42
125
|
*
|
|
43
|
-
* Set
|
|
126
|
+
* Set when the first attempt for a URL fails, or when the retry window
|
|
127
|
+
* expires. Cleared when a new URL or a
|
|
44
128
|
* disable/re-enable starts another sequence, not on a page hide/show. Transient drops
|
|
45
129
|
* that are still being retried leave this empty.
|
|
46
130
|
*/
|
|
@@ -51,26 +135,55 @@ export class Reload {
|
|
|
51
135
|
* The current connection's PROBE estimates, spanning reconnects.
|
|
52
136
|
*
|
|
53
137
|
* Undefined while disconnected: the estimates belong to a single connection.
|
|
54
|
-
*
|
|
138
|
+
* Observation requests updates; `peek()` alone is passive.
|
|
139
|
+
* See {@link Session.probe}.
|
|
55
140
|
*/
|
|
56
141
|
probe;
|
|
142
|
+
#probeSource = new Signal(undefined);
|
|
57
143
|
/**
|
|
58
144
|
* Divides this connection's send-rate estimate among the tracks sharing it.
|
|
59
145
|
*
|
|
60
|
-
* The same
|
|
146
|
+
* The same identity across reconnects, so reservations survive a drop. The
|
|
61
147
|
* estimate is `undefined` while disconnected, which tells a sender to hold
|
|
62
|
-
* its rate rather than encode at zero.
|
|
148
|
+
* its rate rather than encode at zero. It is sampled from the transport only
|
|
149
|
+
* while a reservation reads it, so the first reservation after none waits one
|
|
150
|
+
* snapshot for its slice. It stays `undefined` on a transport that cannot
|
|
151
|
+
* report one: the WebSocket fallback, WebTransport without
|
|
152
|
+
* `getStats()`, or Safari's stub, which reads as none.
|
|
153
|
+
*/
|
|
154
|
+
allocator;
|
|
155
|
+
/**
|
|
156
|
+
* Divides this connection's receive estimate among the broadcasts watched over it.
|
|
157
|
+
*
|
|
158
|
+
* The same identity across reconnects, so viewers survive a drop, and every session
|
|
159
|
+
* the loop dials sends their ceilings summed as its PROBE target. A live viewer
|
|
160
|
+
* requests PROBE; viewers report `undefined` while disconnected.
|
|
161
|
+
*/
|
|
162
|
+
viewers;
|
|
163
|
+
/**
|
|
164
|
+
* The auth handle every session of the loop is built on, spanning reconnects.
|
|
165
|
+
*
|
|
166
|
+
* Each session presents every token it holds, so a route naming one keeps it across a
|
|
167
|
+
* reconnect, and its grant follows the live session. It spans URL changes too, so its
|
|
168
|
+
* tokens go to whatever URL the loop dials next. It ends once the loop closes and its
|
|
169
|
+
* sessions finish draining, and aborting it stops the loop at its next reconnect, with the
|
|
170
|
+
* abort's error.
|
|
63
171
|
*/
|
|
64
|
-
|
|
172
|
+
auth = new AuthHandle();
|
|
173
|
+
// The peer's verdict on the latest tokens, across reconnects.
|
|
174
|
+
#verdict;
|
|
175
|
+
/** Protocol versions to offer, most preferred first, kept across retries and redirects. */
|
|
176
|
+
versions;
|
|
177
|
+
/** Whether the URL carries the connection credential as `auth` (not reactive); see {@link ConnectProps.urlAuth}. */
|
|
178
|
+
urlAuth;
|
|
65
179
|
/** WebTransport options applied to each connection attempt (not reactive). */
|
|
66
180
|
webtransport;
|
|
67
181
|
/** WebSocket fallback options applied to each connection attempt (not reactive). */
|
|
68
182
|
websocket;
|
|
69
|
-
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
discovery;
|
|
183
|
+
/** The bound on each connection attempt, or `null` for none. See {@link ConnectProps.timeout}. */
|
|
184
|
+
timeout;
|
|
185
|
+
/** The price of each session's link. See {@link ConnectProps.cost}. */
|
|
186
|
+
cost;
|
|
74
187
|
/**
|
|
75
188
|
* The origin whose broadcasts are served, spanning reconnects (not reactive).
|
|
76
189
|
*
|
|
@@ -83,24 +196,28 @@ export class Reload {
|
|
|
83
196
|
* The origin fed with the peer's announced broadcasts, spanning reconnects (not
|
|
84
197
|
* reactive).
|
|
85
198
|
*
|
|
86
|
-
* The entries a session fed retract when it dies, and the next session
|
|
87
|
-
*
|
|
88
|
-
* reconnect. See the `consume` connect option.
|
|
199
|
+
* The entries a session fed retract when it dies, and the next session asks again for
|
|
200
|
+
* whatever is still watched, so a consumer watching the origin sees offline/online
|
|
201
|
+
* transitions across a reconnect. See the `consume` connect option.
|
|
89
202
|
*/
|
|
90
203
|
consume;
|
|
91
204
|
/** Backoff settings for the reconnect loop; an unset field uses its default. */
|
|
92
|
-
|
|
205
|
+
backoff;
|
|
93
206
|
/** How to react to the peer's GOAWAY (not reactive). */
|
|
94
207
|
goaway;
|
|
95
208
|
/**
|
|
96
209
|
* The URL an accepted GOAWAY redirect assigned, or undefined while the loop dials
|
|
97
210
|
* {@link Reload.url}. Sticky across reconnects: a redirect is an assignment, not a
|
|
98
|
-
* detour. Cleared when a
|
|
211
|
+
* detour. Cleared when a dial to it fails, so the redial returns to {@link Reload.url},
|
|
212
|
+
* or when a new URL or a disable/re-enable starts another sequence.
|
|
99
213
|
*/
|
|
100
214
|
redirect;
|
|
101
215
|
/** The reactive effect scope driving the connect loop; closed by {@link Reload.close}. */
|
|
102
216
|
#signals = new Effect();
|
|
103
217
|
// Sampled from the live session; undefined while disconnected or the transport has none.
|
|
218
|
+
#sample = new Observed(undefined);
|
|
219
|
+
/** The latest transport sample while a reporter or bandwidth reservation needs it. */
|
|
220
|
+
sample = this.#sample;
|
|
104
221
|
#estimate = new Signal(undefined);
|
|
105
222
|
/**
|
|
106
223
|
* Settles once this loop is disposed via {@link Reload.close}: `null` on a clean close,
|
|
@@ -118,69 +235,124 @@ export class Reload {
|
|
|
118
235
|
// A session the peer sent GOAWAY on, serving its groups in flight while the replacement
|
|
119
236
|
// dials. Retired when it closes, at its handover cap, or when the sequence ends.
|
|
120
237
|
#draining;
|
|
121
|
-
//
|
|
238
|
+
// A redirect from the draining fallback's peer, held while a replacement serves.
|
|
239
|
+
#pending;
|
|
240
|
+
// Sessions this loop ended that are still draining, each until its close settles.
|
|
241
|
+
#ending = new Map();
|
|
242
|
+
// The current run of migrations. A redirect back to an endpoint that already sent us away is
|
|
243
|
+
// a loop, however healthy each session looked. Reset when a session ends without a GOAWAY,
|
|
244
|
+
// outlives the capped delay, or a new sequence starts.
|
|
245
|
+
#redirects = new Redirects();
|
|
246
|
+
// Whether a run is dialing: from its start until each connect attempt settles.
|
|
122
247
|
#dialing = false;
|
|
123
248
|
// The current wait between attempts, doubling per failure, and when the retry window expires.
|
|
124
|
-
// Both are undefined between sequences, so a later edit to `
|
|
249
|
+
// Both are undefined between sequences, so a later edit to `backoff` applies to the next one.
|
|
125
250
|
#delay;
|
|
251
|
+
// When the retry window expires, or null when it never does.
|
|
126
252
|
#deadline;
|
|
127
253
|
// The URL the current retry sequence is for. Cleared when disabled, URL-less, or given
|
|
128
254
|
// up, so the next attempt starts a fresh backoff window.
|
|
129
255
|
#sequenceHref;
|
|
130
256
|
// The href that exhausted its retry sequence. Survives a page hide/show so resume does
|
|
131
|
-
// not
|
|
257
|
+
// not restart a sequence that already gave up. Cleared when the URL changes or the
|
|
132
258
|
// loop is disabled.
|
|
133
259
|
#givenUpHref;
|
|
134
|
-
//
|
|
260
|
+
// The configured href a session's peer accepted the credential of or drained with a GOAWAY,
|
|
261
|
+
// or a moq-lite-03/04 session stayed up past the healthy bar for. Until it matches, a failed
|
|
262
|
+
// attempt or a closed session gives up rather than retrying. Kept across a page hide/show and a disable/re-enable, which
|
|
263
|
+
// resume a URL that worked.
|
|
264
|
+
#establishedHref;
|
|
135
265
|
#tick = new Signal(0);
|
|
136
266
|
// True after the browser freezes or hides the page until it visibly resumes.
|
|
137
267
|
#suspended = new Signal(false);
|
|
268
|
+
// Watches the page for #suspended, outliving the loop until the sessions it ended settle.
|
|
269
|
+
#suspension = new Effect();
|
|
138
270
|
// Use the serialized URL as the reactive connection key. URL objects use identity
|
|
139
271
|
// equality, but replacing one with an equivalent instance should not reconnect.
|
|
140
272
|
#url;
|
|
141
273
|
constructor(props) {
|
|
274
|
+
if (props && "discovery" in props)
|
|
275
|
+
throw new TypeError(DISCOVERY_REMOVED);
|
|
142
276
|
this.url = Signal.from(props?.url);
|
|
143
277
|
this.enabled = Signal.from(props?.enabled ?? true);
|
|
144
|
-
|
|
278
|
+
const tokens = props?.tokens ?? [];
|
|
279
|
+
this.#dials = tokens instanceof Dials ? tokens : undefined;
|
|
280
|
+
this.tokens = Signal.from(tokens instanceof Dials ? [] : tokens);
|
|
281
|
+
this.#verdict = new Verdict(this.tokens, this.auth);
|
|
282
|
+
this.backoff = props?.backoff ?? {};
|
|
283
|
+
// Validated here, like the timeout, rather than by every retry.
|
|
284
|
+
pacing(this.backoff);
|
|
145
285
|
this.goaway = props?.goaway ?? {};
|
|
146
286
|
this.redirect = this.#redirect;
|
|
287
|
+
this.versions = normalizeVersions(props);
|
|
288
|
+
this.urlAuth = props?.urlAuth;
|
|
147
289
|
this.webtransport = props?.webtransport;
|
|
148
290
|
this.websocket = props?.websocket;
|
|
149
|
-
|
|
291
|
+
// Validated here, like the versions, rather than by every attempt.
|
|
292
|
+
this.timeout = connectTimeout(props?.timeout);
|
|
293
|
+
checkCost(props?.cost);
|
|
294
|
+
this.cost = props?.cost;
|
|
150
295
|
this.publish = props?.publish;
|
|
151
296
|
this.consume = props?.consume;
|
|
152
|
-
//
|
|
153
|
-
//
|
|
154
|
-
//
|
|
155
|
-
//
|
|
156
|
-
//
|
|
297
|
+
// The consume origin's announcement streams are not synced while no session is there to
|
|
298
|
+
// deliver an initial set, so an empty table before the first connect, or during a
|
|
299
|
+
// reconnect, never reads as nothing being announced. The next session takes its own
|
|
300
|
+
// hold before this one is released. Taken now rather than in the effect, which runs
|
|
301
|
+
// a microtask later, after a watcher created alongside would already have synced.
|
|
157
302
|
if (this.consume) {
|
|
158
|
-
|
|
303
|
+
const consume = wireOf(this.consume);
|
|
304
|
+
let hold = this.enabled.peek() ? consume.snapshot(Path.empty()) : undefined;
|
|
305
|
+
this.#signals.run((effect) => {
|
|
306
|
+
if (effect.get(this.enabled) && !effect.get(this.established)) {
|
|
307
|
+
hold ??= consume.snapshot(Path.empty());
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
hold?.();
|
|
311
|
+
hold = undefined;
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
this.#signals.cleanup(() => hold?.());
|
|
159
315
|
}
|
|
160
316
|
this.error = this.#error;
|
|
317
|
+
this.failure = this.#failure;
|
|
161
318
|
const win = globalThis.window;
|
|
162
319
|
const doc = globalThis.document;
|
|
163
320
|
if (typeof win !== "undefined" && typeof doc !== "undefined") {
|
|
164
|
-
this.#
|
|
165
|
-
this.#
|
|
166
|
-
this.#
|
|
167
|
-
this.#
|
|
321
|
+
this.#suspension.event(win, "pagehide", () => this.#suspended.set(true));
|
|
322
|
+
this.#suspension.event(win, "pageshow", () => this.#suspended.set(false));
|
|
323
|
+
this.#suspension.event(win, "unload", () => this.#suspended.set(true));
|
|
324
|
+
this.#suspension.event(doc, "visibilitychange", () => {
|
|
168
325
|
if (!doc.hidden)
|
|
169
326
|
this.#suspended.set(false);
|
|
170
327
|
});
|
|
328
|
+
// Nothing would run to finish a drain begun before the page went away either.
|
|
329
|
+
this.#suspension.run((effect) => {
|
|
330
|
+
if (!effect.get(this.#suspended))
|
|
331
|
+
return;
|
|
332
|
+
for (const connection of this.#ending.keys())
|
|
333
|
+
connection.abort();
|
|
334
|
+
this.#ending.clear();
|
|
335
|
+
});
|
|
171
336
|
}
|
|
172
|
-
this.probe = this.#
|
|
173
|
-
|
|
174
|
-
|
|
337
|
+
this.probe = new Follow(this.#probeSource);
|
|
338
|
+
this.#signals.run((effect) => {
|
|
339
|
+
effect.set(this.#probeSource, effect.get(this.established)?.probe, undefined);
|
|
175
340
|
});
|
|
176
|
-
this.
|
|
177
|
-
this.#signals.cleanup(() => this.
|
|
178
|
-
//
|
|
179
|
-
//
|
|
341
|
+
this.allocator = new Allocator(this.#estimate);
|
|
342
|
+
this.#signals.cleanup(() => this.allocator.close());
|
|
343
|
+
// Lazy: the registry observes the estimate only while a viewer is live, and only
|
|
344
|
+
// that observation requests PROBE from the current session.
|
|
345
|
+
this.viewers = new Viewers(new Derived([this.probe], (probe) => probe?.estimatedRecvRate));
|
|
346
|
+
this.#signals.cleanup(() => this.viewers.close());
|
|
347
|
+
// Share the allocator's poll with report readers. Skip an overlapping request, and
|
|
348
|
+
// clear the sample when the session changes or the last consumer leaves.
|
|
180
349
|
this.#signals.run((effect) => {
|
|
181
350
|
effect.set(this.#estimate, undefined);
|
|
351
|
+
effect.set(this.#sample, undefined);
|
|
352
|
+
if (!effect.get(reserved(this.allocator)) && !effect.get(this.#sample.wanted))
|
|
353
|
+
return;
|
|
182
354
|
const connection = effect.get(this.established);
|
|
183
|
-
if (!connection)
|
|
355
|
+
if (!connection || !estimates(connection))
|
|
184
356
|
return;
|
|
185
357
|
let pending = false;
|
|
186
358
|
const sample = async () => {
|
|
@@ -188,19 +360,34 @@ export class Reload {
|
|
|
188
360
|
return;
|
|
189
361
|
pending = true;
|
|
190
362
|
try {
|
|
191
|
-
const
|
|
192
|
-
|
|
363
|
+
const at = now();
|
|
364
|
+
const stats = await effect.race([connection.stats()]);
|
|
365
|
+
if (stats) {
|
|
366
|
+
this.#sample.set({ ...stats, at });
|
|
193
367
|
this.#estimate.set(stats.estimatedSendRate);
|
|
368
|
+
}
|
|
194
369
|
}
|
|
195
370
|
finally {
|
|
196
371
|
pending = false;
|
|
197
372
|
}
|
|
198
373
|
};
|
|
199
374
|
void sample();
|
|
200
|
-
|
|
375
|
+
// One page-wide ticker samples every connection in the same wakeup.
|
|
376
|
+
effect.cleanup(tick(BANDWIDTH_POLL, () => void sample()));
|
|
377
|
+
});
|
|
378
|
+
// The live session holds the current tokens on AUTH; a dial picks them up itself.
|
|
379
|
+
this.#signals.run((effect) => {
|
|
380
|
+
const tokens = effect.get(this.tokens);
|
|
381
|
+
// Before the held tokens change, so a token the set kept is judged by what it was.
|
|
382
|
+
this.#verdict.refresh();
|
|
383
|
+
// A signed set belongs to its own dial: another session presenting it would spend it.
|
|
384
|
+
if (this.#dials)
|
|
385
|
+
return;
|
|
386
|
+
const connection = effect.get(this.established);
|
|
387
|
+
if (connection)
|
|
388
|
+
heldOf(connection)?.update(tokens);
|
|
201
389
|
});
|
|
202
390
|
this.#url = this.#signals.computed((effect) => effect.get(this.url)?.href);
|
|
203
|
-
// Create a reactive root so cleanup is easier.
|
|
204
391
|
this.#signals.run(this.#connect.bind(this));
|
|
205
392
|
}
|
|
206
393
|
#connect(effect) {
|
|
@@ -240,84 +427,241 @@ export class Reload {
|
|
|
240
427
|
this.#error.set(undefined);
|
|
241
428
|
this.#givenUpHref = undefined;
|
|
242
429
|
}
|
|
243
|
-
|
|
244
|
-
if (!this.#draining)
|
|
245
|
-
this.status.set("connecting");
|
|
430
|
+
this.#setDialing(true);
|
|
246
431
|
// This run's teardown, handed to connect() so a rerun cancels the attempt in flight.
|
|
247
432
|
const signal = effect.abort;
|
|
248
|
-
// The session this run serves,
|
|
433
|
+
// The session this run serves, ended with the run. A drained one leaves this slot
|
|
249
434
|
// for #draining, which outlives the run.
|
|
250
435
|
let current;
|
|
436
|
+
// Set once the session is live, so #retry can tell a healthy session that
|
|
437
|
+
// later dropped from a connect failure or a peer that flaps immediately.
|
|
438
|
+
let connected;
|
|
251
439
|
effect.cleanup(() => {
|
|
252
440
|
if (current) {
|
|
253
|
-
|
|
441
|
+
// A session torn down while live, as on a page hide, may already have earned it.
|
|
442
|
+
if (connected !== undefined)
|
|
443
|
+
this.#settle(href, current, connected);
|
|
444
|
+
this.#end(current);
|
|
254
445
|
if (this.established.peek() === current)
|
|
255
|
-
this
|
|
446
|
+
this.#serve(undefined);
|
|
256
447
|
current = undefined;
|
|
257
448
|
}
|
|
258
|
-
|
|
259
|
-
this.status.set("disconnected");
|
|
449
|
+
this.#setDialing(false);
|
|
260
450
|
});
|
|
261
451
|
effect.spawn(async () => {
|
|
262
|
-
//
|
|
263
|
-
|
|
264
|
-
let connected;
|
|
452
|
+
// Whether the last failure was a dial to a GOAWAY redirect's target.
|
|
453
|
+
let redirectFailed = false;
|
|
265
454
|
try {
|
|
455
|
+
// The WebTransport session a probe opened, which the next dial finishes its MoQ
|
|
456
|
+
// handshake over instead of racing.
|
|
457
|
+
let reached;
|
|
266
458
|
// Loops only to migrate: a GOAWAY off a healthy session dials its replacement
|
|
267
459
|
// straight away, with no backoff.
|
|
268
460
|
for (;;) {
|
|
269
461
|
const dialing = this.#redirect.peek() ?? url;
|
|
270
|
-
|
|
462
|
+
// The retry window counts from the first dial of a run, so a dial that hangs
|
|
463
|
+
// spends it too.
|
|
464
|
+
this.#deadline ??= this.#window(now());
|
|
465
|
+
this.#setDialing(true);
|
|
466
|
+
this.#verdict.dialing();
|
|
467
|
+
let tokens = reached?.tokens;
|
|
468
|
+
// Signing spends the attempt's own timeout, so a stuck signer fails like a slow dial.
|
|
469
|
+
let timeout = this.timeout;
|
|
470
|
+
if (!tokens && this.#dials) {
|
|
471
|
+
let signed;
|
|
472
|
+
try {
|
|
473
|
+
signed = await this.#sign(this.#dials, dialing, signal, this.#failure.peek());
|
|
474
|
+
}
|
|
475
|
+
catch (err) {
|
|
476
|
+
this.#setDialing(false);
|
|
477
|
+
// A redirect's target left unanswered falls back to the URL, as one that failed does.
|
|
478
|
+
redirectFailed = this.#redirect.peek() !== undefined;
|
|
479
|
+
throw err;
|
|
480
|
+
}
|
|
481
|
+
// A teardown that closed the dials is no refusal.
|
|
482
|
+
if (signal.aborted)
|
|
483
|
+
return;
|
|
484
|
+
if ("refused" in signed) {
|
|
485
|
+
this.#setDialing(false);
|
|
486
|
+
console.warn("dial refused by its signer, not retrying:", signed.refused);
|
|
487
|
+
this.#giveUp(signed.refused);
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
tokens = signed.tokens;
|
|
491
|
+
timeout = signed.left;
|
|
492
|
+
}
|
|
493
|
+
tokens ??= this.tokens.peek();
|
|
494
|
+
// A probe's dial signed its own set too, which `answered()` judges from here.
|
|
495
|
+
if (this.#dials)
|
|
496
|
+
this.tokens.set(tokens);
|
|
271
497
|
let connection;
|
|
498
|
+
const reusing = reached;
|
|
499
|
+
reached = undefined;
|
|
272
500
|
try {
|
|
273
|
-
connection = await
|
|
501
|
+
connection = await establish({
|
|
274
502
|
url: dialing,
|
|
503
|
+
tokens,
|
|
504
|
+
urlAuth: this.urlAuth,
|
|
275
505
|
// A redirect names the relay; a fallback URL pinned for the old one does not follow.
|
|
276
|
-
websocket: this.#redirect.peek()
|
|
506
|
+
websocket: this.#redirect.peek()
|
|
507
|
+
? { ...this.websocket, url: undefined }
|
|
508
|
+
: this.websocket,
|
|
509
|
+
versions: this.versions,
|
|
277
510
|
webtransport: this.webtransport,
|
|
278
|
-
|
|
511
|
+
timeout,
|
|
279
512
|
publish: this.publish,
|
|
280
513
|
consume: this.consume,
|
|
514
|
+
cost: this.cost,
|
|
515
|
+
auth: this.auth,
|
|
516
|
+
viewers: this.viewers,
|
|
281
517
|
signal,
|
|
282
|
-
});
|
|
518
|
+
}, reusing);
|
|
283
519
|
}
|
|
284
|
-
|
|
285
|
-
this.#
|
|
520
|
+
catch (err) {
|
|
521
|
+
this.#setDialing(false);
|
|
522
|
+
redirectFailed = this.#redirect.peek() !== undefined;
|
|
523
|
+
throw err;
|
|
286
524
|
}
|
|
287
|
-
// Hand the connection to the effect
|
|
525
|
+
// Hand the connection to the effect. One that lands after this run is over never
|
|
526
|
+
// served anything, so there is nothing to drain.
|
|
288
527
|
if (signal.aborted) {
|
|
289
|
-
connection.
|
|
528
|
+
connection.abort();
|
|
290
529
|
return;
|
|
291
530
|
}
|
|
292
531
|
current = connection;
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
532
|
+
this.#verdict.connected(connection);
|
|
533
|
+
connected = now();
|
|
534
|
+
// Serve only once the session is established: the peer accepted its credential or
|
|
535
|
+
// drained it with a GOAWAY. On a version that never answers (moq-lite-03/04),
|
|
536
|
+
// staying up past the healthy bar is the only sign, so it counts there alone.
|
|
537
|
+
// Until then it may still be a refusal, which never reads as connected. A close
|
|
538
|
+
// first is handled below.
|
|
539
|
+
const auth = wireOf(connection).auth;
|
|
540
|
+
const bar = this.#pacing().healthy;
|
|
541
|
+
const acceptance = auth.accepted;
|
|
542
|
+
if (!acceptance.peek()) {
|
|
543
|
+
const waiting = new AbortController();
|
|
544
|
+
const waits = [Signal.race(acceptance), connection.closed, connection.draining];
|
|
545
|
+
if (auth.silent)
|
|
546
|
+
waits.push(sleep(bar, { signal: waiting.signal }).catch(() => { }));
|
|
547
|
+
await effect.race(waits).finally(() => waiting.abort());
|
|
548
|
+
if (signal.aborted)
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
if (acceptance.peek() ||
|
|
552
|
+
connection.draining.peek() !== undefined ||
|
|
553
|
+
(auth.silent && now().since(connected).ge(bar))) {
|
|
554
|
+
// The replacement serves now; a predecessor keeps draining its groups in flight.
|
|
555
|
+
this.#serve(connection);
|
|
556
|
+
this.#failure.set(undefined);
|
|
557
|
+
}
|
|
558
|
+
this.#setDialing(false);
|
|
297
559
|
// A cancelled effect resolves undefined, so the sentinel tells the session
|
|
298
560
|
// closing (null for clean, an Error otherwise) apart from this run being
|
|
299
|
-
// torn down. Anything else is the peer's GOAWAY
|
|
300
|
-
|
|
301
|
-
|
|
561
|
+
// torn down. Anything else is the peer's GOAWAY, or WebTransport reachable
|
|
562
|
+
// again under a session on the WebSocket fallback.
|
|
563
|
+
const probing = new AbortController();
|
|
564
|
+
const probe = this.#probe(connection, dialing, probing.signal);
|
|
565
|
+
const first = await effect
|
|
566
|
+
.race([connection.closed, connection.draining, probe])
|
|
567
|
+
.finally(() => probing.abort());
|
|
568
|
+
// The peer's GOAWAY wins over a probe that got through in the same turn, so its
|
|
569
|
+
// redirect is never lost.
|
|
570
|
+
const drain = connection.draining.peek();
|
|
571
|
+
const raced = first instanceof Reached && drain !== undefined ? drain : first;
|
|
572
|
+
// A probe the race did not take still holds an open WebTransport session.
|
|
573
|
+
void probe.then((left) => {
|
|
574
|
+
if (left !== raced)
|
|
575
|
+
left.transport.close();
|
|
576
|
+
});
|
|
577
|
+
if (raced === undefined)
|
|
302
578
|
return;
|
|
579
|
+
// Leaving the fallback is a GOAWAY of our own: the session drains as the
|
|
580
|
+
// predecessor while the replacement finishes its handshake over the probe.
|
|
581
|
+
if (raced instanceof Reached) {
|
|
582
|
+
console.info("WebTransport reachable again; leaving the WebSocket fallback");
|
|
583
|
+
wireOf(connection).leave();
|
|
584
|
+
reached = raced;
|
|
585
|
+
}
|
|
586
|
+
const ended = raced instanceof Reached ? { uri: "" } : raced;
|
|
587
|
+
this.#settle(href, connection, connected);
|
|
303
588
|
if (ended === null || ended instanceof Error) {
|
|
304
|
-
|
|
589
|
+
// Until a session was established, a close stops the URL as a failed attempt
|
|
590
|
+
// does: it is how a relay refuses a live session before accepting its credential.
|
|
591
|
+
// No error kind is read.
|
|
592
|
+
if (this.#establishedHref !== href) {
|
|
593
|
+
console.warn(`connection closed, not retrying: ${ended ? reason(ended) : "no error"}`);
|
|
594
|
+
current = undefined;
|
|
595
|
+
this.#serve(undefined);
|
|
596
|
+
this.#giveUp(ended ?? new Error("connection closed"));
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
console.warn(`connection closed, reconnecting: ${ended ? reason(ended) : "no error"}`);
|
|
600
|
+
this.#redirects.reset();
|
|
601
|
+
current = undefined;
|
|
602
|
+
// A predecessor still draining serves again, so this is no outage.
|
|
305
603
|
if (this.established.peek() === connection)
|
|
306
|
-
this
|
|
604
|
+
this.#serve(this.#draining?.serving());
|
|
605
|
+
this.#applyPending();
|
|
307
606
|
this.#retry(effect, connected, ended ?? undefined);
|
|
308
607
|
return;
|
|
309
608
|
}
|
|
310
609
|
current = undefined;
|
|
610
|
+
// A peer's GOAWAY establishes the URL however soon it came: the peer accepted the
|
|
611
|
+
// session and asked us to move, which a refusal never does, so a page opened while
|
|
612
|
+
// its relay drains rides out the restart. Leaving the fallback is our own.
|
|
613
|
+
if (!reached)
|
|
614
|
+
this.#establishedHref = href;
|
|
311
615
|
// A pinned WebSocket URL can win the race against the primary. Judge the
|
|
312
616
|
// redirect against that endpoint, not the primary we never reached.
|
|
313
617
|
const socket = this.#redirect.peek() ? undefined : this.websocket?.url;
|
|
314
|
-
|
|
618
|
+
const at = dialed(dialing, connection.transport, socket);
|
|
619
|
+
const before = this.#redirect.peek();
|
|
620
|
+
if (!this.#migrate(connection, at, ended)) {
|
|
621
|
+
reached?.transport.close();
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
// Moving off the fallback is no peer's redirect or restart, and the probe
|
|
625
|
+
// backoff already paces it, so its replacement dials at once. A fallback that
|
|
626
|
+
// served past the healthy bar still earns the healthy reset.
|
|
627
|
+
if (reached) {
|
|
628
|
+
this.#follow(connection, at, pinnedTransport(connection.transport, this.#pinned()), href);
|
|
629
|
+
if (now().since(connected).ge(this.#pacing().healthy)) {
|
|
630
|
+
this.#delay = undefined;
|
|
631
|
+
this.#deadline = undefined;
|
|
632
|
+
}
|
|
633
|
+
continue;
|
|
634
|
+
}
|
|
635
|
+
const after = this.#redirect.peek();
|
|
636
|
+
// Two peers that each hold a session past the healthy bar can still bounce us between
|
|
637
|
+
// them forever. Returning to an endpoint that already sent us elsewhere in this
|
|
638
|
+
// run of migrations escalates the backoff, which never resets mid-loop, so the
|
|
639
|
+
// retry window still applies. A one-way rolling restart never revisits one, and
|
|
640
|
+
// a GOAWAY back to the same place is a restart, not a move, so it never counts.
|
|
641
|
+
// A session that outlived the capped delay already redials no faster than the
|
|
642
|
+
// backoff would allow, so it starts a new run: rolling restarts days apart
|
|
643
|
+
// never add up to a loop.
|
|
644
|
+
const { settled, healthy } = this.#pacing();
|
|
645
|
+
const lived = now().since(connected);
|
|
646
|
+
if (lived.ge(settled))
|
|
647
|
+
this.#redirects.reset();
|
|
648
|
+
// Only a redirect this GOAWAY named is a move. An empty or ignored one reconnects
|
|
649
|
+
// in place, even when that reruns the race a WebSocket fallback won.
|
|
650
|
+
const from = destination(at);
|
|
651
|
+
const to = after && after !== before ? destination(after) : from;
|
|
652
|
+
if (to !== from && this.#redirects.move(from, to)) {
|
|
653
|
+
this.#retry(effect, undefined, new Error("redirect loop"));
|
|
315
654
|
return;
|
|
316
|
-
|
|
317
|
-
//
|
|
318
|
-
// so two peers bouncing us between them
|
|
319
|
-
|
|
320
|
-
|
|
655
|
+
}
|
|
656
|
+
// A healthy session's handover is not a failure. One redirected sooner still
|
|
657
|
+
// migrates, but through the backoff, so two peers bouncing us between them
|
|
658
|
+
// escalate to the capped delay. An empty URI is a peer restarting, which drains
|
|
659
|
+
// each new session until it goes; every one serves, so that is no failure either.
|
|
660
|
+
if (lived.lt(healthy)) {
|
|
661
|
+
if (ended.uri === "")
|
|
662
|
+
this.#restart(effect);
|
|
663
|
+
else
|
|
664
|
+
this.#retry(effect, connected, new Error("peer redirected immediately"));
|
|
321
665
|
return;
|
|
322
666
|
}
|
|
323
667
|
this.#delay = undefined;
|
|
@@ -325,24 +669,122 @@ export class Reload {
|
|
|
325
669
|
}
|
|
326
670
|
}
|
|
327
671
|
catch (err) {
|
|
328
|
-
// Treat teardown as cancellation, not a connection failure.
|
|
329
672
|
if (signal.aborted)
|
|
330
673
|
return;
|
|
674
|
+
// An ended auth handle refuses every later session, so no retry can recover.
|
|
675
|
+
const closed = ended(this.auth);
|
|
676
|
+
if (closed) {
|
|
677
|
+
this.#giveUp(closed);
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
// Attempts fail fast until a session was established: a URL whose peer never accepted
|
|
681
|
+
// one is more likely misconfigured than restarting, and only the app can fix that.
|
|
682
|
+
if (this.#establishedHref !== href) {
|
|
683
|
+
console.warn("connection failed, not retrying:", err);
|
|
684
|
+
this.#giveUp(error(err));
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
331
687
|
console.warn("connection error:", err);
|
|
688
|
+
// A redirect target that no longer answers is dropped: the redial returns to the
|
|
689
|
+
// configured URL, which may still answer. Rust's Reconnect follows the same rule.
|
|
690
|
+
if (redirectFailed)
|
|
691
|
+
this.#redirect.set(undefined);
|
|
332
692
|
this.#retry(effect, connected, err);
|
|
333
693
|
}
|
|
334
694
|
});
|
|
335
695
|
}
|
|
696
|
+
/**
|
|
697
|
+
* Ask `dials` for the tokens of a dial to `dialing`, within the connect timeout, which the
|
|
698
|
+
* signing spends: the tokens and the timeout left for the dial, or the app's refusal. Rejects
|
|
699
|
+
* with `ConnectTimeout` once the timeout passes unanswered, or with the teardown once `signal` aborts.
|
|
700
|
+
*/
|
|
701
|
+
async #sign(dials, dialing, signal, failure) {
|
|
702
|
+
const limit = this.timeout;
|
|
703
|
+
const started = now();
|
|
704
|
+
const bound = new AbortController();
|
|
705
|
+
const abort = () => bound.abort(signal.reason);
|
|
706
|
+
if (signal.aborted)
|
|
707
|
+
abort();
|
|
708
|
+
else
|
|
709
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
710
|
+
const disarm = limit === null ? () => { } : after(limit, () => bound.abort(new ConnectTimeout(limit)));
|
|
711
|
+
try {
|
|
712
|
+
const answer = await dials.request(dialing, bound.signal, failure);
|
|
713
|
+
if ("refused" in answer)
|
|
714
|
+
return answer;
|
|
715
|
+
if (limit === null)
|
|
716
|
+
return { tokens: answer.tokens, left: null };
|
|
717
|
+
// Zero is refused as a timeout, so a dial with no time left times out here instead.
|
|
718
|
+
const left = limit.saturatingSub(now().since(started));
|
|
719
|
+
if (left.isZero())
|
|
720
|
+
throw new ConnectTimeout(limit);
|
|
721
|
+
return { tokens: answer.tokens, left };
|
|
722
|
+
}
|
|
723
|
+
finally {
|
|
724
|
+
signal.removeEventListener("abort", abort);
|
|
725
|
+
disarm();
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Resolve with the WebTransport session that reaches `dialing` while `connection` runs on the
|
|
730
|
+
* WebSocket fallback, probing on a jittered backoff from {@link PROBE_INITIAL} up to {@link PROBE_MAX}.
|
|
731
|
+
* Never resolves for a session on another transport, where WebTransport is unsupported, or
|
|
732
|
+
* once `signal` aborts.
|
|
733
|
+
*/
|
|
734
|
+
async #probe(connection, dialing, signal) {
|
|
735
|
+
const never = new Promise(() => { });
|
|
736
|
+
if (connection.transport !== "websocket" || !webTransportDialed(this.webtransport))
|
|
737
|
+
return never;
|
|
738
|
+
try {
|
|
739
|
+
for (let delay = PROBE_INITIAL;; delay = delay.mul(2).min(PROBE_MAX)) {
|
|
740
|
+
await sleep(delay.mul(0.5 + Math.random() / 2), { signal });
|
|
741
|
+
let tokens = this.tokens.peek();
|
|
742
|
+
let timeout = this.timeout;
|
|
743
|
+
if (this.#dials) {
|
|
744
|
+
let signed;
|
|
745
|
+
try {
|
|
746
|
+
// The serving session is fine, so the probe reports no failure.
|
|
747
|
+
signed = await this.#sign(this.#dials, dialing, signal, undefined);
|
|
748
|
+
}
|
|
749
|
+
catch (err) {
|
|
750
|
+
if (signal.aborted)
|
|
751
|
+
throw err;
|
|
752
|
+
console.warn("a probe's tokens timed out:", err);
|
|
753
|
+
continue;
|
|
754
|
+
}
|
|
755
|
+
if ("refused" in signed) {
|
|
756
|
+
console.warn("a probe's dial was refused by its signer:", signed.refused);
|
|
757
|
+
continue;
|
|
758
|
+
}
|
|
759
|
+
tokens = signed.tokens;
|
|
760
|
+
timeout = signed.left;
|
|
761
|
+
}
|
|
762
|
+
const props = {
|
|
763
|
+
tokens,
|
|
764
|
+
urlAuth: this.urlAuth,
|
|
765
|
+
versions: this.versions,
|
|
766
|
+
webtransport: this.webtransport,
|
|
767
|
+
websocket: this.#redirect.peek() ? undefined : this.websocket,
|
|
768
|
+
timeout,
|
|
769
|
+
};
|
|
770
|
+
const reached = await reachable(dialing, props, signal);
|
|
771
|
+
if (reached)
|
|
772
|
+
return reached;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
catch {
|
|
776
|
+
// The sleep rejects once the session ends.
|
|
777
|
+
return never;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
336
780
|
/**
|
|
337
781
|
* Act on the peer's GOAWAY for `connection`, which was dialed at `dialing`: resolve where
|
|
338
782
|
* to go next and leave the old session serving until it drains. Returns false when the
|
|
339
783
|
* redirect is refused, which ends the sequence rather than redialing.
|
|
340
784
|
*/
|
|
341
785
|
#migrate(connection, dialing, drain) {
|
|
342
|
-
const hashes = this.webtransport?.serverCertificateHashes?.length ?? 0;
|
|
343
|
-
const configured = hashes > 0 || this.webtransport?.serverCertificate !== undefined;
|
|
344
786
|
// The pin is a WebTransport option. A WebSocket that won the race never used it.
|
|
345
|
-
const pinned = pinnedTransport(connection.transport,
|
|
787
|
+
const pinned = pinnedTransport(connection.transport, this.#pinned());
|
|
346
788
|
let next;
|
|
347
789
|
try {
|
|
348
790
|
next = target(this.goaway.redirect ?? "same-host", drain.uri, dialing, pinned);
|
|
@@ -351,9 +793,8 @@ export class Reload {
|
|
|
351
793
|
// The peer is leaving and named somewhere we won't go: redialing the old address
|
|
352
794
|
// would ignore it, so stop here.
|
|
353
795
|
console.warn("GOAWAY redirect refused:", err);
|
|
354
|
-
connection
|
|
355
|
-
this
|
|
356
|
-
this.status.set("disconnected");
|
|
796
|
+
this.#end(connection);
|
|
797
|
+
this.#serve(undefined);
|
|
357
798
|
this.#giveUp(error(err));
|
|
358
799
|
return false;
|
|
359
800
|
}
|
|
@@ -363,23 +804,147 @@ export class Reload {
|
|
|
363
804
|
this.#redirectHref = this.#sequenceHref;
|
|
364
805
|
}
|
|
365
806
|
console.info("GOAWAY received; migrating");
|
|
366
|
-
// A newer GOAWAY retires an older predecessor rather than
|
|
367
|
-
this.#
|
|
807
|
+
// A newer GOAWAY retires an older predecessor rather than serving from two.
|
|
808
|
+
this.#retire();
|
|
368
809
|
const cap = handover(this.goaway.handover ?? DEFAULT_HANDOVER, drain.timeout);
|
|
369
810
|
const draining = new Draining(connection, cap, () => {
|
|
370
811
|
if (this.#draining === draining)
|
|
371
812
|
this.#draining = undefined;
|
|
372
813
|
// If nothing replaced it yet, nothing is serving.
|
|
373
|
-
if (this.established.peek()
|
|
374
|
-
|
|
375
|
-
this.established.set(undefined);
|
|
376
|
-
this.status.set(this.#dialing ? "connecting" : "disconnected");
|
|
814
|
+
if (this.established.peek() === connection)
|
|
815
|
+
this.#serve(undefined);
|
|
377
816
|
});
|
|
378
817
|
this.#draining = draining;
|
|
379
818
|
return true;
|
|
380
819
|
}
|
|
381
|
-
|
|
382
|
-
|
|
820
|
+
/** Whether a certificate pin is configured for WebTransport. */
|
|
821
|
+
#pinned() {
|
|
822
|
+
const hashes = this.webtransport?.serverCertificateHashes?.length ?? 0;
|
|
823
|
+
return hashes > 0 || this.webtransport?.serverCertificate !== undefined;
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* Follow a redirect the peer of `connection`, a fallback session we left for a probe that
|
|
827
|
+
* got through, sends while it drains: whenever nothing else serves, the next dial goes where
|
|
828
|
+
* the peer named, and a dial still headed for the leaving peer starts over. A restart in
|
|
829
|
+
* place or a refused redirect is ignored, since we are already leaving. No loop scoring:
|
|
830
|
+
* only a probe that got through leads here, and the probe's backoff paces those.
|
|
831
|
+
*/
|
|
832
|
+
#follow(connection, dialing, pinned, href) {
|
|
833
|
+
void connection.draining.then((drain) => {
|
|
834
|
+
// The peer accepted the fallback session and asked us to move, so its GOAWAY establishes
|
|
835
|
+
// the URL as one off the live session does, while the sequence still targets it.
|
|
836
|
+
if (this.#sequenceHref === href)
|
|
837
|
+
this.#establishedHref = href;
|
|
838
|
+
let next;
|
|
839
|
+
try {
|
|
840
|
+
next = target(this.goaway.redirect ?? "same-host", drain.uri, dialing, pinned);
|
|
841
|
+
}
|
|
842
|
+
catch {
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
if (!next)
|
|
846
|
+
return;
|
|
847
|
+
this.#pending = { connection, next };
|
|
848
|
+
this.#applyPending();
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* Apply the pending redirect once its session is the one serving, which a replacement that
|
|
853
|
+
* closes hands back to; drop it once that session retires.
|
|
854
|
+
*/
|
|
855
|
+
#applyPending() {
|
|
856
|
+
const pending = this.#pending;
|
|
857
|
+
if (!pending)
|
|
858
|
+
return;
|
|
859
|
+
if (this.#draining?.serving() !== pending.connection) {
|
|
860
|
+
this.#pending = undefined;
|
|
861
|
+
return;
|
|
862
|
+
}
|
|
863
|
+
if (this.established.peek() !== pending.connection)
|
|
864
|
+
return;
|
|
865
|
+
this.#pending = undefined;
|
|
866
|
+
console.info("draining fallback peer redirected; following");
|
|
867
|
+
this.#redirect.set(pending.next);
|
|
868
|
+
this.#redirectHref = this.#sequenceHref;
|
|
869
|
+
// A backoff still paces the next dial, which now goes to the new target.
|
|
870
|
+
if (this.#dialing)
|
|
871
|
+
this.#tick.update((prev) => prev + 1);
|
|
872
|
+
}
|
|
873
|
+
/**
|
|
874
|
+
* End a session this loop is done with. Its groups in flight finish within the close
|
|
875
|
+
* deadline, unless the page is going away: nothing would run to finish them, and an abort
|
|
876
|
+
* closes the transport now rather than leaving the browser to sever it.
|
|
877
|
+
*/
|
|
878
|
+
#end(connection) {
|
|
879
|
+
if (this.#suspended.peek()) {
|
|
880
|
+
connection.abort();
|
|
881
|
+
return;
|
|
882
|
+
}
|
|
883
|
+
// A served live track never finishes, so the deadline aborting the rest is the usual end.
|
|
884
|
+
const ending = connection.close().catch(() => { });
|
|
885
|
+
this.#ending.set(connection, ending);
|
|
886
|
+
void ending.then(() => this.#ending.delete(connection));
|
|
887
|
+
}
|
|
888
|
+
/** Serve `connection`, or nothing. */
|
|
889
|
+
#serve(connection) {
|
|
890
|
+
this.established.set(connection);
|
|
891
|
+
this.#report();
|
|
892
|
+
}
|
|
893
|
+
#setDialing(dialing) {
|
|
894
|
+
this.#dialing = dialing;
|
|
895
|
+
this.#report();
|
|
896
|
+
}
|
|
897
|
+
// The one derivation of status: serving, else dialing, else neither. A drained predecessor
|
|
898
|
+
// serves until it retires, so its replacement's dial reads as connected.
|
|
899
|
+
#report() {
|
|
900
|
+
this.status.set(this.established.peek() ? "connected" : this.#dialing ? "connecting" : "disconnected");
|
|
901
|
+
}
|
|
902
|
+
/** Stop serving from a drained predecessor, ending it if still open. */
|
|
903
|
+
#retire() {
|
|
904
|
+
const draining = this.#draining?.retire();
|
|
905
|
+
if (draining)
|
|
906
|
+
this.#end(draining);
|
|
907
|
+
}
|
|
908
|
+
// A session establishes its URL once the peer accepted its credential, which a closed
|
|
909
|
+
// session still reports, or, on a version that never answers the credential
|
|
910
|
+
// (moq-lite-03/04), once it stayed up past the healthy bar.
|
|
911
|
+
#settle(href, session, connected) {
|
|
912
|
+
const auth = wireOf(session).auth;
|
|
913
|
+
if (auth.accepted.peek() || (auth.silent && now().since(connected).ge(this.#pacing().healthy))) {
|
|
914
|
+
this.#establishedHref = href;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
// Resolved per use rather than at construction, so an edit to `backoff` (including one that
|
|
918
|
+
// drops a field back to its default) applies to the next retry.
|
|
919
|
+
#pacing() {
|
|
920
|
+
return pacing(this.backoff ?? {});
|
|
921
|
+
}
|
|
922
|
+
// When a retry window starting `at` expires.
|
|
923
|
+
#window(at) {
|
|
924
|
+
const { timeout } = this.#pacing();
|
|
925
|
+
return timeout === null ? null : at.saturatingAdd(timeout);
|
|
926
|
+
}
|
|
927
|
+
/**
|
|
928
|
+
* Wait out the backoff after a restarting peer drained a session short of the healthy bar.
|
|
929
|
+
* The delay escalates, so the redials cannot hammer it, but the wait never spends the retry
|
|
930
|
+
* window: the window restarts once the wait is over.
|
|
931
|
+
*/
|
|
932
|
+
#restart(effect) {
|
|
933
|
+
const wait = this.#backoff();
|
|
934
|
+
const tick = this.#tick.peek() + 1;
|
|
935
|
+
effect.timer(() => {
|
|
936
|
+
this.#deadline = undefined;
|
|
937
|
+
this.#tick.update((prev) => Math.max(prev, tick));
|
|
938
|
+
}, wait);
|
|
939
|
+
}
|
|
940
|
+
// The jittered wait before the next attempt, escalating the delay for the one after.
|
|
941
|
+
// Equal jitter, so a fleet of tabs knocked offline together doesn't reconnect on the same tick.
|
|
942
|
+
#backoff() {
|
|
943
|
+
const pacing = this.#pacing();
|
|
944
|
+
this.#delay ??= pacing.initial;
|
|
945
|
+
const wait = this.#delay.mul(0.5 + Math.random() / 2);
|
|
946
|
+
this.#delay = pacing.next(this.#delay);
|
|
947
|
+
return wait;
|
|
383
948
|
}
|
|
384
949
|
/**
|
|
385
950
|
* Schedule the next connect attempt after the current backoff, or stop once the retry window
|
|
@@ -387,171 +952,232 @@ export class Reload {
|
|
|
387
952
|
* `cause` the error that killed it, if it died with one.
|
|
388
953
|
*/
|
|
389
954
|
#retry(effect, connected, cause) {
|
|
390
|
-
|
|
391
|
-
//
|
|
392
|
-
//
|
|
393
|
-
//
|
|
394
|
-
|
|
395
|
-
const delay = this.delay ?? {};
|
|
396
|
-
const initial = this.#initial();
|
|
397
|
-
const multiplier = delay.multiplier ?? DEFAULT_DELAY.multiplier;
|
|
398
|
-
const max = delay.max ?? DEFAULT_DELAY.max;
|
|
399
|
-
const timeout = delay.timeout ?? DEFAULT_DELAY.timeout;
|
|
400
|
-
// Report disconnected during the backoff rather than when the retry reruns the
|
|
401
|
-
// effect, unless a drained predecessor still serves until it retires.
|
|
402
|
-
if (this.established.peek() === undefined)
|
|
403
|
-
this.status.set("disconnected");
|
|
404
|
-
// A session that outlived the initial delay was healthy, so clear the backoff and
|
|
405
|
-
// start a fresh retry window: a one-off drop should reconnect promptly. Anything
|
|
406
|
-
// shorter is a peer that accepts and immediately severs, which has to keep
|
|
407
|
-
// escalating or we hammer it forever at the initial delay.
|
|
408
|
-
if (connected !== undefined && performance.now() - connected >= initial) {
|
|
955
|
+
this.#failure.set(cause === undefined ? new Error("connection closed") : error(cause));
|
|
956
|
+
// A healthy session's end clears the backoff and starts a fresh retry window: a one-off
|
|
957
|
+
// drop should reconnect promptly. Anything shorter is a peer that accepts and soon
|
|
958
|
+
// severs, which has to keep escalating or we hammer it forever at the initial delay.
|
|
959
|
+
if (connected !== undefined && now().since(connected).ge(this.#pacing().healthy)) {
|
|
409
960
|
this.#delay = undefined;
|
|
410
961
|
this.#deadline = undefined;
|
|
411
962
|
}
|
|
412
|
-
|
|
413
|
-
//
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
//
|
|
417
|
-
//
|
|
418
|
-
|
|
419
|
-
//
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
console.warn("session rejected as unauthorized, not retrying");
|
|
423
|
-
this.#giveUp(cause);
|
|
424
|
-
return;
|
|
425
|
-
}
|
|
426
|
-
const now = performance.now();
|
|
427
|
-
this.#delay ??= initial;
|
|
428
|
-
this.#deadline ??= timeout > 0 ? now + timeout : Number.POSITIVE_INFINITY;
|
|
429
|
-
if (now >= this.#deadline) {
|
|
963
|
+
const at = now();
|
|
964
|
+
// A healthy session's end starts the window here.
|
|
965
|
+
this.#deadline ??= this.#window(at);
|
|
966
|
+
const wait = this.#backoff();
|
|
967
|
+
// No attempt starts once the window has passed: a wait that reaches the deadline gives up
|
|
968
|
+
// there instead of dialing.
|
|
969
|
+
const deadline = this.#deadline;
|
|
970
|
+
// A graceful close has no error, so report the timeout itself.
|
|
971
|
+
const failure = cause === undefined ? new Error("reconnect timed out") : error(cause);
|
|
972
|
+
const giveUp = () => {
|
|
430
973
|
console.warn("reconnect timed out");
|
|
431
|
-
|
|
432
|
-
|
|
974
|
+
this.#giveUp(failure);
|
|
975
|
+
};
|
|
976
|
+
const left = deadline === null ? undefined : deadline.since(at);
|
|
977
|
+
if (left !== undefined && wait.ge(left)) {
|
|
978
|
+
if (!left.isZero())
|
|
979
|
+
effect.timer(giveUp, left);
|
|
980
|
+
else
|
|
981
|
+
giveUp();
|
|
433
982
|
return;
|
|
434
983
|
}
|
|
435
|
-
// Equal jitter, so a fleet of tabs knocked offline together doesn't reconnect on the same
|
|
436
|
-
// tick, and never past the deadline the retry window promised.
|
|
437
|
-
const wait = Math.min(this.#delay * (0.5 + Math.random() / 2), this.#deadline - now);
|
|
438
|
-
this.#delay = Math.min(this.#delay * multiplier, max);
|
|
439
984
|
const tick = this.#tick.peek() + 1;
|
|
440
|
-
effect.timer(() =>
|
|
985
|
+
effect.timer(() => {
|
|
986
|
+
// Checked again when the wait ends: a timer that fires late, as after the device
|
|
987
|
+
// slept, must not dial past the window.
|
|
988
|
+
if (deadline !== null && now().ge(deadline))
|
|
989
|
+
return giveUp();
|
|
990
|
+
this.#tick.update((prev) => Math.max(prev, tick));
|
|
991
|
+
}, wait);
|
|
441
992
|
}
|
|
442
993
|
#giveUp(cause) {
|
|
994
|
+
this.#verdict.gaveUp(cause);
|
|
443
995
|
this.#error.set(cause);
|
|
444
996
|
this.#givenUpHref = this.#sequenceHref;
|
|
445
997
|
this.#resetSequence();
|
|
446
998
|
}
|
|
447
999
|
#resetSequence() {
|
|
1000
|
+
this.#failure.set(undefined);
|
|
448
1001
|
this.#delay = undefined;
|
|
449
1002
|
this.#deadline = undefined;
|
|
450
1003
|
this.#sequenceHref = undefined;
|
|
451
|
-
this.#
|
|
1004
|
+
this.#redirects.reset();
|
|
1005
|
+
this.#retire();
|
|
452
1006
|
}
|
|
453
1007
|
/**
|
|
454
|
-
*
|
|
1008
|
+
* Resolve once the peer first answers the latest {@link tokens}, like Rust's `Tokens::poll_answered`.
|
|
1009
|
+
* With {@link Dials}, that is the set the latest dial was answered with, none before the first:
|
|
1010
|
+
* read a refusal from the next dial's `failure` instead.
|
|
455
1011
|
*
|
|
456
|
-
*
|
|
457
|
-
* is
|
|
458
|
-
*
|
|
459
|
-
*
|
|
460
|
-
*
|
|
1012
|
+
* It covers the tokens the latest set newly presented, or the initial ones before any set:
|
|
1013
|
+
* each is granted in band, or is the connection credential a dial carried and the peer
|
|
1014
|
+
* accepted. A token the set kept, the connection credential included, counts only once the
|
|
1015
|
+
* peer refuses it, and nothing is re-checked after the answer. Rejects with the peer's refusal,
|
|
1016
|
+
* `Unsupported` when a session cannot carry a token in band, the loop's end, or the failure that
|
|
1017
|
+
* stopped it retrying its URL while no session answered, such as a refused first dial. A set replaced
|
|
1018
|
+
* before its answer moves the wait to the new one.
|
|
461
1019
|
*/
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
// a dead session's entries), so its stream is the same thing with less machinery.
|
|
465
|
-
if (this.consume)
|
|
466
|
-
return this.consume.announced(scope, options);
|
|
467
|
-
const producer = new Announce.Producer();
|
|
468
|
-
const consumer = producer.consume();
|
|
469
|
-
const pump = new Effect();
|
|
470
|
-
pump.run((effect) => {
|
|
471
|
-
const conn = effect.get(this.established);
|
|
472
|
-
if (!conn)
|
|
473
|
-
return;
|
|
474
|
-
// Without discovery the upstream announce stream never yields, so leave the
|
|
475
|
-
// consumer empty rather than opening a subscription that can't be answered.
|
|
476
|
-
if (!conn.discovery)
|
|
477
|
-
return;
|
|
478
|
-
const upstream = conn.announced(scope, options);
|
|
479
|
-
effect.cleanup(() => upstream.close());
|
|
480
|
-
// Track what this connection announced so we can retract it if the connection
|
|
481
|
-
// drops; the last event rides along for the retraction.
|
|
482
|
-
const active = new Map();
|
|
483
|
-
effect.spawn(async () => {
|
|
484
|
-
try {
|
|
485
|
-
for (;;) {
|
|
486
|
-
const entry = await effect.race(upstream.next());
|
|
487
|
-
if (!entry)
|
|
488
|
-
break;
|
|
489
|
-
if (Announce.isActive(entry.kind))
|
|
490
|
-
active.set(entry.prefix, entry);
|
|
491
|
-
else
|
|
492
|
-
active.delete(entry.prefix);
|
|
493
|
-
producer.append(entry);
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
catch {
|
|
497
|
-
// A dropped connection resets the announce stream; the retractions below cover it.
|
|
498
|
-
}
|
|
499
|
-
finally {
|
|
500
|
-
// Retract everything from the connection that just went away, so a per-broadcast
|
|
501
|
-
// watcher tears down instead of clinging to the dead route.
|
|
502
|
-
if (consumer.closed.peek() === undefined) {
|
|
503
|
-
for (const entry of active.values()) {
|
|
504
|
-
producer.append({ ...entry, kind: "retracted" });
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
});
|
|
509
|
-
});
|
|
510
|
-
this.#signals.cleanup(() => pump.close());
|
|
511
|
-
void consumer.closed.then(() => pump.close());
|
|
512
|
-
return consumer;
|
|
1020
|
+
answered() {
|
|
1021
|
+
return this.#verdict.answered();
|
|
513
1022
|
}
|
|
514
|
-
/**
|
|
515
|
-
* Snapshot the live connection's transport counters, or undefined while disconnected.
|
|
516
|
-
* See {@link Established.stats}.
|
|
517
|
-
*/
|
|
518
|
-
async stats() {
|
|
519
|
-
return this.established.peek()?.stats();
|
|
520
|
-
}
|
|
521
|
-
/** Stop reconnecting, close the current connection, and settle {@link Reload.closed}. Idempotent. */
|
|
1023
|
+
/** Stop reconnecting, drain and close the current connection, and settle {@link Reload.closed}. Idempotent. */
|
|
522
1024
|
close(abort) {
|
|
523
1025
|
this.#signals.close();
|
|
524
|
-
this.#
|
|
1026
|
+
this.#retire();
|
|
1027
|
+
// No session will present the tokens again, so they end with the loop, once the sessions
|
|
1028
|
+
// still draining no longer need their grants or a page hide to cut them short.
|
|
1029
|
+
const err = abort ?? new Error("connection closed");
|
|
1030
|
+
const done = () => {
|
|
1031
|
+
this.auth.abort(err);
|
|
1032
|
+
this.#suspension.close();
|
|
1033
|
+
};
|
|
1034
|
+
if (this.#ending.size === 0)
|
|
1035
|
+
done();
|
|
1036
|
+
else
|
|
1037
|
+
void Promise.all(this.#ending.values()).then(done);
|
|
525
1038
|
if (this.#closed.peek() === undefined)
|
|
526
1039
|
this.#closed.set(abort ?? null);
|
|
527
1040
|
}
|
|
528
1041
|
}
|
|
1042
|
+
/**
|
|
1043
|
+
* Pump `upstream` into `producer` for the rest of `effect`'s run: its events, then an `offline`
|
|
1044
|
+
* for each route still active once it closes or the run ends, so nothing clings to a source
|
|
1045
|
+
* that went away. Synced follows the upstream's, and owes those retractions too.
|
|
1046
|
+
*
|
|
1047
|
+
* @internal
|
|
1048
|
+
*/
|
|
1049
|
+
export function pumpAnnounced(effect, upstream, producer) {
|
|
1050
|
+
// The last event per active route rides along for its retraction.
|
|
1051
|
+
const active = new Map();
|
|
1052
|
+
let live = true;
|
|
1053
|
+
const retract = () => {
|
|
1054
|
+
live = false;
|
|
1055
|
+
if (producer.closed.peek() !== undefined || active.size === 0)
|
|
1056
|
+
return;
|
|
1057
|
+
// Behind first, so a reader parked on the stream takes these as owed, not as news.
|
|
1058
|
+
producer.behind();
|
|
1059
|
+
// The source went away, which says nothing of whether the origin ended them.
|
|
1060
|
+
for (const entry of active.values())
|
|
1061
|
+
producer.append({ ...entry, kind: "offline" });
|
|
1062
|
+
active.clear();
|
|
1063
|
+
};
|
|
1064
|
+
// Torn down in reverse: the mirror stops, the retractions land, then the upstream closes,
|
|
1065
|
+
// so its closing never reads as synced.
|
|
1066
|
+
effect.cleanup(() => upstream.close());
|
|
1067
|
+
effect.cleanup(retract);
|
|
1068
|
+
// A new upstream owes its own initial set, and the retractions of the one before.
|
|
1069
|
+
producer.behind();
|
|
1070
|
+
effect.watch(upstream.synced, (synced) => {
|
|
1071
|
+
if (!synced)
|
|
1072
|
+
producer.behind();
|
|
1073
|
+
else if (upstream.closed.peek() === undefined)
|
|
1074
|
+
producer.synced();
|
|
1075
|
+
});
|
|
1076
|
+
effect.spawn(async () => {
|
|
1077
|
+
try {
|
|
1078
|
+
for (;;) {
|
|
1079
|
+
const entry = await effect.race([upstream.next()]);
|
|
1080
|
+
if (!entry || !live || producer.closed.peek() !== undefined)
|
|
1081
|
+
break;
|
|
1082
|
+
if (entry.kind === "end" || entry.kind === "offline")
|
|
1083
|
+
active.delete(entry.prefix);
|
|
1084
|
+
else
|
|
1085
|
+
active.set(entry.prefix, entry);
|
|
1086
|
+
producer.append(entry);
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
catch {
|
|
1090
|
+
// A dropped connection resets the announce stream; the retractions below cover it.
|
|
1091
|
+
}
|
|
1092
|
+
finally {
|
|
1093
|
+
if (live) {
|
|
1094
|
+
// The upstream ended on its own: nothing more comes from it, so once its
|
|
1095
|
+
// retractions are read there is nothing left to wait for.
|
|
1096
|
+
retract();
|
|
1097
|
+
producer.behind();
|
|
1098
|
+
producer.synced();
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
529
1103
|
/**
|
|
530
1104
|
* A session the peer sent GOAWAY on, left serving so its groups in flight finish. It retires
|
|
531
|
-
* when it closes on its own
|
|
1105
|
+
* when it closes on its own, overstays its handover window, or is retired by the loop, and
|
|
1106
|
+
* `onRetire` runs once either way. The window still caps a retired session's close: it is
|
|
1107
|
+
* aborted at the window's end if still open.
|
|
532
1108
|
*/
|
|
533
1109
|
class Draining {
|
|
534
1110
|
#connection;
|
|
535
|
-
#timer;
|
|
1111
|
+
#timer = new AbortController();
|
|
536
1112
|
#onRetire;
|
|
537
1113
|
#retired = false;
|
|
538
1114
|
constructor(connection, handover, onRetire) {
|
|
539
1115
|
this.#connection = connection;
|
|
540
1116
|
this.#onRetire = onRetire;
|
|
541
|
-
this.#timer
|
|
542
|
-
|
|
1117
|
+
void sleep(handover, { signal: this.#timer.signal }).then(() => {
|
|
1118
|
+
if (this.retire())
|
|
1119
|
+
console.warn("old session did not drain in time; closing");
|
|
1120
|
+
connection.abort();
|
|
1121
|
+
}, () => { });
|
|
1122
|
+
void connection.closed.then(() => {
|
|
1123
|
+
this.#timer.abort();
|
|
543
1124
|
this.retire();
|
|
544
|
-
}
|
|
545
|
-
void connection.closed.then(() => this.retire());
|
|
1125
|
+
});
|
|
546
1126
|
}
|
|
547
|
-
/**
|
|
1127
|
+
/** The old session while it still serves, before it retires. */
|
|
1128
|
+
serving() {
|
|
1129
|
+
return this.#retired ? undefined : this.#connection;
|
|
1130
|
+
}
|
|
1131
|
+
/** Stop serving from the old session, returning it the first time for the caller to end. */
|
|
548
1132
|
retire() {
|
|
549
1133
|
if (this.#retired)
|
|
550
|
-
return;
|
|
1134
|
+
return undefined;
|
|
551
1135
|
this.#retired = true;
|
|
552
|
-
clearTimeout(this.#timer);
|
|
553
|
-
this.#connection.close();
|
|
554
1136
|
this.#onRetire();
|
|
1137
|
+
return this.#connection;
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
/**
|
|
1141
|
+
* Where `url` dials, without its userinfo, query, or fragment, where a peer may mint fresh
|
|
1142
|
+
* credentials on every redirect, and with its host as the dial reads it. Two URLs that differ
|
|
1143
|
+
* only there reach the same place.
|
|
1144
|
+
*/
|
|
1145
|
+
function destination(url) {
|
|
1146
|
+
const bare = new URL(parse(url).url);
|
|
1147
|
+
bare.username = "";
|
|
1148
|
+
bare.password = "";
|
|
1149
|
+
bare.search = "";
|
|
1150
|
+
bare.hash = "";
|
|
1151
|
+
return bare.href;
|
|
1152
|
+
}
|
|
1153
|
+
/**
|
|
1154
|
+
* A run of GOAWAY redirects, and whether it has revisited an endpoint. The peer picks every
|
|
1155
|
+
* hop, so remembering them all would grow without bound. Brent's cycle detection instead keeps
|
|
1156
|
+
* one departed endpoint, replaced at doubling intervals, and catches a cycle of any length
|
|
1157
|
+
* within a few laps of it. Once caught, the run stays a loop until reset.
|
|
1158
|
+
*/
|
|
1159
|
+
export class Redirects {
|
|
1160
|
+
#mark;
|
|
1161
|
+
#span = 1;
|
|
1162
|
+
#hops = 0;
|
|
1163
|
+
#loop = false;
|
|
1164
|
+
/** Record leaving `from` for a different endpoint `to`, and return whether this run loops. */
|
|
1165
|
+
move(from, to) {
|
|
1166
|
+
if (to === this.#mark)
|
|
1167
|
+
this.#loop = true;
|
|
1168
|
+
if (++this.#hops === this.#span) {
|
|
1169
|
+
this.#mark = from;
|
|
1170
|
+
this.#span *= 2;
|
|
1171
|
+
this.#hops = 0;
|
|
1172
|
+
}
|
|
1173
|
+
return this.#loop;
|
|
1174
|
+
}
|
|
1175
|
+
/** Start a new run. */
|
|
1176
|
+
reset() {
|
|
1177
|
+
this.#mark = undefined;
|
|
1178
|
+
this.#span = 1;
|
|
1179
|
+
this.#hops = 0;
|
|
1180
|
+
this.#loop = false;
|
|
555
1181
|
}
|
|
556
1182
|
}
|
|
557
1183
|
//# sourceMappingURL=reload.js.map
|