@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/connection/reload.js
CHANGED
|
@@ -1,34 +1,97 @@
|
|
|
1
|
-
|
|
2
|
-
import { Effect, Once, Signal } from "@moq/signals";
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
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";
|
|
6
7
|
import * as Path from "../path.js";
|
|
7
|
-
import
|
|
8
|
+
import { Follow, Observed } from "../util/observed.js";
|
|
9
|
+
import { after } from "../util/timer.js";
|
|
8
10
|
import { wireOf } from "../wire.js";
|
|
9
|
-
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";
|
|
10
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";
|
|
11
21
|
/**
|
|
12
|
-
* 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.
|
|
13
30
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* 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.
|
|
19
36
|
*/
|
|
20
|
-
const
|
|
21
|
-
initial:
|
|
37
|
+
const DEFAULT_BACKOFF = {
|
|
38
|
+
initial: Duration.millis(1000),
|
|
22
39
|
multiplier: 2,
|
|
23
|
-
max:
|
|
24
|
-
|
|
40
|
+
max: Duration.millis(5000),
|
|
41
|
+
healthy: Duration.millis(1000),
|
|
42
|
+
timeout: null,
|
|
25
43
|
};
|
|
26
|
-
/**
|
|
27
|
-
|
|
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);
|
|
28
84
|
/**
|
|
29
85
|
* The reconnect loop behind a Connection handle: connects, waits for the session to end, then
|
|
30
86
|
* redials with exponential backoff.
|
|
31
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
|
+
*
|
|
32
95
|
* @internal
|
|
33
96
|
*/
|
|
34
97
|
export class Reload {
|
|
@@ -36,12 +99,32 @@ export class Reload {
|
|
|
36
99
|
url;
|
|
37
100
|
/** Whether reconnecting is active. */
|
|
38
101
|
enabled;
|
|
39
|
-
/**
|
|
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
|
+
*/
|
|
40
122
|
status = new Signal("disconnected");
|
|
41
123
|
/**
|
|
42
124
|
* The failure that stopped retrying the current URL, or undefined while the loop is live.
|
|
43
125
|
*
|
|
44
|
-
* 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
|
|
45
128
|
* disable/re-enable starts another sequence, not on a page hide/show. Transient drops
|
|
46
129
|
* that are still being retried leave this empty.
|
|
47
130
|
*/
|
|
@@ -52,26 +135,55 @@ export class Reload {
|
|
|
52
135
|
* The current connection's PROBE estimates, spanning reconnects.
|
|
53
136
|
*
|
|
54
137
|
* Undefined while disconnected: the estimates belong to a single connection.
|
|
55
|
-
*
|
|
138
|
+
* Observation requests updates; `peek()` alone is passive.
|
|
139
|
+
* See {@link Session.probe}.
|
|
56
140
|
*/
|
|
57
141
|
probe;
|
|
142
|
+
#probeSource = new Signal(undefined);
|
|
58
143
|
/**
|
|
59
144
|
* Divides this connection's send-rate estimate among the tracks sharing it.
|
|
60
145
|
*
|
|
61
|
-
* The same
|
|
146
|
+
* The same identity across reconnects, so reservations survive a drop. The
|
|
62
147
|
* estimate is `undefined` while disconnected, which tells a sender to hold
|
|
63
|
-
* 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.
|
|
64
171
|
*/
|
|
65
|
-
|
|
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;
|
|
66
179
|
/** WebTransport options applied to each connection attempt (not reactive). */
|
|
67
180
|
webtransport;
|
|
68
181
|
/** WebSocket fallback options applied to each connection attempt (not reactive). */
|
|
69
182
|
websocket;
|
|
70
|
-
/**
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
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;
|
|
75
187
|
/**
|
|
76
188
|
* The origin whose broadcasts are served, spanning reconnects (not reactive).
|
|
77
189
|
*
|
|
@@ -84,24 +196,28 @@ export class Reload {
|
|
|
84
196
|
* The origin fed with the peer's announced broadcasts, spanning reconnects (not
|
|
85
197
|
* reactive).
|
|
86
198
|
*
|
|
87
|
-
* The entries a session fed retract when it dies, and the next session
|
|
88
|
-
*
|
|
89
|
-
* 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.
|
|
90
202
|
*/
|
|
91
203
|
consume;
|
|
92
204
|
/** Backoff settings for the reconnect loop; an unset field uses its default. */
|
|
93
|
-
|
|
205
|
+
backoff;
|
|
94
206
|
/** How to react to the peer's GOAWAY (not reactive). */
|
|
95
207
|
goaway;
|
|
96
208
|
/**
|
|
97
209
|
* The URL an accepted GOAWAY redirect assigned, or undefined while the loop dials
|
|
98
210
|
* {@link Reload.url}. Sticky across reconnects: a redirect is an assignment, not a
|
|
99
|
-
* 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.
|
|
100
213
|
*/
|
|
101
214
|
redirect;
|
|
102
215
|
/** The reactive effect scope driving the connect loop; closed by {@link Reload.close}. */
|
|
103
216
|
#signals = new Effect();
|
|
104
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;
|
|
105
221
|
#estimate = new Signal(undefined);
|
|
106
222
|
/**
|
|
107
223
|
* Settles once this loop is disposed via {@link Reload.close}: `null` on a clean close,
|
|
@@ -119,69 +235,124 @@ export class Reload {
|
|
|
119
235
|
// A session the peer sent GOAWAY on, serving its groups in flight while the replacement
|
|
120
236
|
// dials. Retired when it closes, at its handover cap, or when the sequence ends.
|
|
121
237
|
#draining;
|
|
122
|
-
//
|
|
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.
|
|
123
247
|
#dialing = false;
|
|
124
248
|
// The current wait between attempts, doubling per failure, and when the retry window expires.
|
|
125
|
-
// 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.
|
|
126
250
|
#delay;
|
|
251
|
+
// When the retry window expires, or null when it never does.
|
|
127
252
|
#deadline;
|
|
128
253
|
// The URL the current retry sequence is for. Cleared when disabled, URL-less, or given
|
|
129
254
|
// up, so the next attempt starts a fresh backoff window.
|
|
130
255
|
#sequenceHref;
|
|
131
256
|
// The href that exhausted its retry sequence. Survives a page hide/show so resume does
|
|
132
|
-
// not
|
|
257
|
+
// not restart a sequence that already gave up. Cleared when the URL changes or the
|
|
133
258
|
// loop is disabled.
|
|
134
259
|
#givenUpHref;
|
|
135
|
-
//
|
|
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;
|
|
136
265
|
#tick = new Signal(0);
|
|
137
266
|
// True after the browser freezes or hides the page until it visibly resumes.
|
|
138
267
|
#suspended = new Signal(false);
|
|
268
|
+
// Watches the page for #suspended, outliving the loop until the sessions it ended settle.
|
|
269
|
+
#suspension = new Effect();
|
|
139
270
|
// Use the serialized URL as the reactive connection key. URL objects use identity
|
|
140
271
|
// equality, but replacing one with an equivalent instance should not reconnect.
|
|
141
272
|
#url;
|
|
142
273
|
constructor(props) {
|
|
274
|
+
if (props && "discovery" in props)
|
|
275
|
+
throw new TypeError(DISCOVERY_REMOVED);
|
|
143
276
|
this.url = Signal.from(props?.url);
|
|
144
277
|
this.enabled = Signal.from(props?.enabled ?? true);
|
|
145
|
-
|
|
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);
|
|
146
285
|
this.goaway = props?.goaway ?? {};
|
|
147
286
|
this.redirect = this.#redirect;
|
|
287
|
+
this.versions = normalizeVersions(props);
|
|
288
|
+
this.urlAuth = props?.urlAuth;
|
|
148
289
|
this.webtransport = props?.webtransport;
|
|
149
290
|
this.websocket = props?.websocket;
|
|
150
|
-
|
|
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;
|
|
151
295
|
this.publish = props?.publish;
|
|
152
296
|
this.consume = props?.consume;
|
|
153
|
-
//
|
|
154
|
-
//
|
|
155
|
-
//
|
|
156
|
-
//
|
|
157
|
-
//
|
|
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.
|
|
158
302
|
if (this.consume) {
|
|
159
|
-
|
|
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?.());
|
|
160
315
|
}
|
|
161
316
|
this.error = this.#error;
|
|
317
|
+
this.failure = this.#failure;
|
|
162
318
|
const win = globalThis.window;
|
|
163
319
|
const doc = globalThis.document;
|
|
164
320
|
if (typeof win !== "undefined" && typeof doc !== "undefined") {
|
|
165
|
-
this.#
|
|
166
|
-
this.#
|
|
167
|
-
this.#
|
|
168
|
-
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", () => {
|
|
169
325
|
if (!doc.hidden)
|
|
170
326
|
this.#suspended.set(false);
|
|
171
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
|
+
});
|
|
172
336
|
}
|
|
173
|
-
this.probe = this.#
|
|
174
|
-
|
|
175
|
-
|
|
337
|
+
this.probe = new Follow(this.#probeSource);
|
|
338
|
+
this.#signals.run((effect) => {
|
|
339
|
+
effect.set(this.#probeSource, effect.get(this.established)?.probe, undefined);
|
|
176
340
|
});
|
|
177
|
-
this.
|
|
178
|
-
this.#signals.cleanup(() => this.
|
|
179
|
-
//
|
|
180
|
-
//
|
|
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.
|
|
181
349
|
this.#signals.run((effect) => {
|
|
182
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;
|
|
183
354
|
const connection = effect.get(this.established);
|
|
184
|
-
if (!connection)
|
|
355
|
+
if (!connection || !estimates(connection))
|
|
185
356
|
return;
|
|
186
357
|
let pending = false;
|
|
187
358
|
const sample = async () => {
|
|
@@ -189,19 +360,34 @@ export class Reload {
|
|
|
189
360
|
return;
|
|
190
361
|
pending = true;
|
|
191
362
|
try {
|
|
192
|
-
const
|
|
193
|
-
|
|
363
|
+
const at = now();
|
|
364
|
+
const stats = await effect.race([connection.stats()]);
|
|
365
|
+
if (stats) {
|
|
366
|
+
this.#sample.set({ ...stats, at });
|
|
194
367
|
this.#estimate.set(stats.estimatedSendRate);
|
|
368
|
+
}
|
|
195
369
|
}
|
|
196
370
|
finally {
|
|
197
371
|
pending = false;
|
|
198
372
|
}
|
|
199
373
|
};
|
|
200
374
|
void sample();
|
|
201
|
-
|
|
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);
|
|
202
389
|
});
|
|
203
390
|
this.#url = this.#signals.computed((effect) => effect.get(this.url)?.href);
|
|
204
|
-
// Create a reactive root so cleanup is easier.
|
|
205
391
|
this.#signals.run(this.#connect.bind(this));
|
|
206
392
|
}
|
|
207
393
|
#connect(effect) {
|
|
@@ -241,84 +427,241 @@ export class Reload {
|
|
|
241
427
|
this.#error.set(undefined);
|
|
242
428
|
this.#givenUpHref = undefined;
|
|
243
429
|
}
|
|
244
|
-
|
|
245
|
-
if (!this.#draining)
|
|
246
|
-
this.status.set("connecting");
|
|
430
|
+
this.#setDialing(true);
|
|
247
431
|
// This run's teardown, handed to connect() so a rerun cancels the attempt in flight.
|
|
248
432
|
const signal = effect.abort;
|
|
249
|
-
// The session this run serves,
|
|
433
|
+
// The session this run serves, ended with the run. A drained one leaves this slot
|
|
250
434
|
// for #draining, which outlives the run.
|
|
251
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;
|
|
252
439
|
effect.cleanup(() => {
|
|
253
440
|
if (current) {
|
|
254
|
-
|
|
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);
|
|
255
445
|
if (this.established.peek() === current)
|
|
256
|
-
this
|
|
446
|
+
this.#serve(undefined);
|
|
257
447
|
current = undefined;
|
|
258
448
|
}
|
|
259
|
-
|
|
260
|
-
this.status.set("disconnected");
|
|
449
|
+
this.#setDialing(false);
|
|
261
450
|
});
|
|
262
451
|
effect.spawn(async () => {
|
|
263
|
-
//
|
|
264
|
-
|
|
265
|
-
let connected;
|
|
452
|
+
// Whether the last failure was a dial to a GOAWAY redirect's target.
|
|
453
|
+
let redirectFailed = false;
|
|
266
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;
|
|
267
458
|
// Loops only to migrate: a GOAWAY off a healthy session dials its replacement
|
|
268
459
|
// straight away, with no backoff.
|
|
269
460
|
for (;;) {
|
|
270
461
|
const dialing = this.#redirect.peek() ?? url;
|
|
271
|
-
|
|
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);
|
|
272
497
|
let connection;
|
|
498
|
+
const reusing = reached;
|
|
499
|
+
reached = undefined;
|
|
273
500
|
try {
|
|
274
|
-
connection = await
|
|
501
|
+
connection = await establish({
|
|
275
502
|
url: dialing,
|
|
503
|
+
tokens,
|
|
504
|
+
urlAuth: this.urlAuth,
|
|
276
505
|
// A redirect names the relay; a fallback URL pinned for the old one does not follow.
|
|
277
|
-
websocket: this.#redirect.peek()
|
|
506
|
+
websocket: this.#redirect.peek()
|
|
507
|
+
? { ...this.websocket, url: undefined }
|
|
508
|
+
: this.websocket,
|
|
509
|
+
versions: this.versions,
|
|
278
510
|
webtransport: this.webtransport,
|
|
279
|
-
|
|
511
|
+
timeout,
|
|
280
512
|
publish: this.publish,
|
|
281
513
|
consume: this.consume,
|
|
514
|
+
cost: this.cost,
|
|
515
|
+
auth: this.auth,
|
|
516
|
+
viewers: this.viewers,
|
|
282
517
|
signal,
|
|
283
|
-
});
|
|
518
|
+
}, reusing);
|
|
284
519
|
}
|
|
285
|
-
|
|
286
|
-
this.#
|
|
520
|
+
catch (err) {
|
|
521
|
+
this.#setDialing(false);
|
|
522
|
+
redirectFailed = this.#redirect.peek() !== undefined;
|
|
523
|
+
throw err;
|
|
287
524
|
}
|
|
288
|
-
// 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.
|
|
289
527
|
if (signal.aborted) {
|
|
290
|
-
connection.
|
|
528
|
+
connection.abort();
|
|
291
529
|
return;
|
|
292
530
|
}
|
|
293
531
|
current = connection;
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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);
|
|
298
559
|
// A cancelled effect resolves undefined, so the sentinel tells the session
|
|
299
560
|
// closing (null for clean, an Error otherwise) apart from this run being
|
|
300
|
-
// torn down. Anything else is the peer's GOAWAY
|
|
301
|
-
|
|
302
|
-
|
|
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)
|
|
303
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);
|
|
304
588
|
if (ended === null || ended instanceof Error) {
|
|
305
|
-
|
|
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.
|
|
306
603
|
if (this.established.peek() === connection)
|
|
307
|
-
this
|
|
604
|
+
this.#serve(this.#draining?.serving());
|
|
605
|
+
this.#applyPending();
|
|
308
606
|
this.#retry(effect, connected, ended ?? undefined);
|
|
309
607
|
return;
|
|
310
608
|
}
|
|
311
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;
|
|
312
615
|
// A pinned WebSocket URL can win the race against the primary. Judge the
|
|
313
616
|
// redirect against that endpoint, not the primary we never reached.
|
|
314
617
|
const socket = this.#redirect.peek() ? undefined : this.websocket?.url;
|
|
315
|
-
|
|
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"));
|
|
316
654
|
return;
|
|
317
|
-
|
|
318
|
-
//
|
|
319
|
-
// so two peers bouncing us between them
|
|
320
|
-
|
|
321
|
-
|
|
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"));
|
|
322
665
|
return;
|
|
323
666
|
}
|
|
324
667
|
this.#delay = undefined;
|
|
@@ -326,24 +669,122 @@ export class Reload {
|
|
|
326
669
|
}
|
|
327
670
|
}
|
|
328
671
|
catch (err) {
|
|
329
|
-
// Treat teardown as cancellation, not a connection failure.
|
|
330
672
|
if (signal.aborted)
|
|
331
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
|
+
}
|
|
332
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);
|
|
333
692
|
this.#retry(effect, connected, err);
|
|
334
693
|
}
|
|
335
694
|
});
|
|
336
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
|
+
}
|
|
337
780
|
/**
|
|
338
781
|
* Act on the peer's GOAWAY for `connection`, which was dialed at `dialing`: resolve where
|
|
339
782
|
* to go next and leave the old session serving until it drains. Returns false when the
|
|
340
783
|
* redirect is refused, which ends the sequence rather than redialing.
|
|
341
784
|
*/
|
|
342
785
|
#migrate(connection, dialing, drain) {
|
|
343
|
-
const hashes = this.webtransport?.serverCertificateHashes?.length ?? 0;
|
|
344
|
-
const configured = hashes > 0 || this.webtransport?.serverCertificate !== undefined;
|
|
345
786
|
// The pin is a WebTransport option. A WebSocket that won the race never used it.
|
|
346
|
-
const pinned = pinnedTransport(connection.transport,
|
|
787
|
+
const pinned = pinnedTransport(connection.transport, this.#pinned());
|
|
347
788
|
let next;
|
|
348
789
|
try {
|
|
349
790
|
next = target(this.goaway.redirect ?? "same-host", drain.uri, dialing, pinned);
|
|
@@ -352,9 +793,8 @@ export class Reload {
|
|
|
352
793
|
// The peer is leaving and named somewhere we won't go: redialing the old address
|
|
353
794
|
// would ignore it, so stop here.
|
|
354
795
|
console.warn("GOAWAY redirect refused:", err);
|
|
355
|
-
connection
|
|
356
|
-
this
|
|
357
|
-
this.status.set("disconnected");
|
|
796
|
+
this.#end(connection);
|
|
797
|
+
this.#serve(undefined);
|
|
358
798
|
this.#giveUp(error(err));
|
|
359
799
|
return false;
|
|
360
800
|
}
|
|
@@ -364,23 +804,147 @@ export class Reload {
|
|
|
364
804
|
this.#redirectHref = this.#sequenceHref;
|
|
365
805
|
}
|
|
366
806
|
console.info("GOAWAY received; migrating");
|
|
367
|
-
// A newer GOAWAY retires an older predecessor rather than
|
|
368
|
-
this.#
|
|
807
|
+
// A newer GOAWAY retires an older predecessor rather than serving from two.
|
|
808
|
+
this.#retire();
|
|
369
809
|
const cap = handover(this.goaway.handover ?? DEFAULT_HANDOVER, drain.timeout);
|
|
370
810
|
const draining = new Draining(connection, cap, () => {
|
|
371
811
|
if (this.#draining === draining)
|
|
372
812
|
this.#draining = undefined;
|
|
373
813
|
// If nothing replaced it yet, nothing is serving.
|
|
374
|
-
if (this.established.peek()
|
|
375
|
-
|
|
376
|
-
this.established.set(undefined);
|
|
377
|
-
this.status.set(this.#dialing ? "connecting" : "disconnected");
|
|
814
|
+
if (this.established.peek() === connection)
|
|
815
|
+
this.#serve(undefined);
|
|
378
816
|
});
|
|
379
817
|
this.#draining = draining;
|
|
380
818
|
return true;
|
|
381
819
|
}
|
|
382
|
-
|
|
383
|
-
|
|
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;
|
|
384
948
|
}
|
|
385
949
|
/**
|
|
386
950
|
* Schedule the next connect attempt after the current backoff, or stop once the retry window
|
|
@@ -388,171 +952,232 @@ export class Reload {
|
|
|
388
952
|
* `cause` the error that killed it, if it died with one.
|
|
389
953
|
*/
|
|
390
954
|
#retry(effect, connected, cause) {
|
|
391
|
-
|
|
392
|
-
//
|
|
393
|
-
//
|
|
394
|
-
//
|
|
395
|
-
|
|
396
|
-
const delay = this.delay ?? {};
|
|
397
|
-
const initial = this.#initial();
|
|
398
|
-
const multiplier = delay.multiplier ?? DEFAULT_DELAY.multiplier;
|
|
399
|
-
const max = delay.max ?? DEFAULT_DELAY.max;
|
|
400
|
-
const timeout = delay.timeout ?? DEFAULT_DELAY.timeout;
|
|
401
|
-
// Report disconnected during the backoff rather than when the retry reruns the
|
|
402
|
-
// effect, unless a drained predecessor still serves until it retires.
|
|
403
|
-
if (this.established.peek() === undefined)
|
|
404
|
-
this.status.set("disconnected");
|
|
405
|
-
// A session that outlived the initial delay was healthy, so clear the backoff and
|
|
406
|
-
// start a fresh retry window: a one-off drop should reconnect promptly. Anything
|
|
407
|
-
// shorter is a peer that accepts and immediately severs, which has to keep
|
|
408
|
-
// escalating or we hammer it forever at the initial delay.
|
|
409
|
-
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)) {
|
|
410
960
|
this.#delay = undefined;
|
|
411
961
|
this.#deadline = undefined;
|
|
412
962
|
}
|
|
413
|
-
|
|
414
|
-
//
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
//
|
|
418
|
-
//
|
|
419
|
-
|
|
420
|
-
//
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
console.warn("session rejected as unauthorized, not retrying");
|
|
424
|
-
this.#giveUp(cause);
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
const now = performance.now();
|
|
428
|
-
this.#delay ??= initial;
|
|
429
|
-
this.#deadline ??= timeout > 0 ? now + timeout : Number.POSITIVE_INFINITY;
|
|
430
|
-
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 = () => {
|
|
431
973
|
console.warn("reconnect timed out");
|
|
432
|
-
|
|
433
|
-
|
|
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();
|
|
434
982
|
return;
|
|
435
983
|
}
|
|
436
|
-
// Equal jitter, so a fleet of tabs knocked offline together doesn't reconnect on the same
|
|
437
|
-
// tick, and never past the deadline the retry window promised.
|
|
438
|
-
const wait = Math.min(this.#delay * (0.5 + Math.random() / 2), this.#deadline - now);
|
|
439
|
-
this.#delay = Math.min(this.#delay * multiplier, max);
|
|
440
984
|
const tick = this.#tick.peek() + 1;
|
|
441
|
-
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);
|
|
442
992
|
}
|
|
443
993
|
#giveUp(cause) {
|
|
994
|
+
this.#verdict.gaveUp(cause);
|
|
444
995
|
this.#error.set(cause);
|
|
445
996
|
this.#givenUpHref = this.#sequenceHref;
|
|
446
997
|
this.#resetSequence();
|
|
447
998
|
}
|
|
448
999
|
#resetSequence() {
|
|
1000
|
+
this.#failure.set(undefined);
|
|
449
1001
|
this.#delay = undefined;
|
|
450
1002
|
this.#deadline = undefined;
|
|
451
1003
|
this.#sequenceHref = undefined;
|
|
452
|
-
this.#
|
|
1004
|
+
this.#redirects.reset();
|
|
1005
|
+
this.#retire();
|
|
453
1006
|
}
|
|
454
1007
|
/**
|
|
455
|
-
*
|
|
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.
|
|
456
1011
|
*
|
|
457
|
-
*
|
|
458
|
-
* is
|
|
459
|
-
*
|
|
460
|
-
*
|
|
461
|
-
*
|
|
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.
|
|
462
1019
|
*/
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
// a dead session's entries), so its stream is the same thing with less machinery.
|
|
466
|
-
if (this.consume)
|
|
467
|
-
return this.consume.announced(scope, options);
|
|
468
|
-
const producer = new Announce.Producer();
|
|
469
|
-
const consumer = producer.consume();
|
|
470
|
-
const pump = new Effect();
|
|
471
|
-
pump.run((effect) => {
|
|
472
|
-
const conn = effect.get(this.established);
|
|
473
|
-
if (!conn)
|
|
474
|
-
return;
|
|
475
|
-
// Without discovery the upstream announce stream never yields, so leave the
|
|
476
|
-
// consumer empty rather than opening a subscription that can't be answered.
|
|
477
|
-
if (!conn.discovery)
|
|
478
|
-
return;
|
|
479
|
-
const upstream = conn.announced(scope, options);
|
|
480
|
-
effect.cleanup(() => upstream.close());
|
|
481
|
-
// Track what this connection announced so we can retract it if the connection
|
|
482
|
-
// drops; the last event rides along for the retraction.
|
|
483
|
-
const active = new Map();
|
|
484
|
-
effect.spawn(async () => {
|
|
485
|
-
try {
|
|
486
|
-
for (;;) {
|
|
487
|
-
const entry = await effect.race(upstream.next());
|
|
488
|
-
if (!entry)
|
|
489
|
-
break;
|
|
490
|
-
if (Announce.isActive(entry.kind))
|
|
491
|
-
active.set(entry.prefix, entry);
|
|
492
|
-
else
|
|
493
|
-
active.delete(entry.prefix);
|
|
494
|
-
producer.append(entry);
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
catch {
|
|
498
|
-
// A dropped connection resets the announce stream; the retractions below cover it.
|
|
499
|
-
}
|
|
500
|
-
finally {
|
|
501
|
-
// Retract everything from the connection that just went away, so a per-broadcast
|
|
502
|
-
// watcher tears down instead of clinging to the dead route.
|
|
503
|
-
if (consumer.closed.peek() === undefined) {
|
|
504
|
-
for (const entry of active.values()) {
|
|
505
|
-
producer.append({ ...entry, kind: "retracted" });
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
});
|
|
510
|
-
});
|
|
511
|
-
this.#signals.cleanup(() => pump.close());
|
|
512
|
-
void consumer.closed.then(() => pump.close());
|
|
513
|
-
return consumer;
|
|
1020
|
+
answered() {
|
|
1021
|
+
return this.#verdict.answered();
|
|
514
1022
|
}
|
|
515
|
-
/**
|
|
516
|
-
* Snapshot the live connection's transport counters, or undefined while disconnected.
|
|
517
|
-
* See {@link Established.stats}.
|
|
518
|
-
*/
|
|
519
|
-
async stats() {
|
|
520
|
-
return this.established.peek()?.stats();
|
|
521
|
-
}
|
|
522
|
-
/** 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. */
|
|
523
1024
|
close(abort) {
|
|
524
1025
|
this.#signals.close();
|
|
525
|
-
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);
|
|
526
1038
|
if (this.#closed.peek() === undefined)
|
|
527
1039
|
this.#closed.set(abort ?? null);
|
|
528
1040
|
}
|
|
529
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
|
+
}
|
|
530
1103
|
/**
|
|
531
1104
|
* A session the peer sent GOAWAY on, left serving so its groups in flight finish. It retires
|
|
532
|
-
* 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.
|
|
533
1108
|
*/
|
|
534
1109
|
class Draining {
|
|
535
1110
|
#connection;
|
|
536
|
-
#timer;
|
|
1111
|
+
#timer = new AbortController();
|
|
537
1112
|
#onRetire;
|
|
538
1113
|
#retired = false;
|
|
539
1114
|
constructor(connection, handover, onRetire) {
|
|
540
1115
|
this.#connection = connection;
|
|
541
1116
|
this.#onRetire = onRetire;
|
|
542
|
-
this.#timer
|
|
543
|
-
|
|
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();
|
|
544
1124
|
this.retire();
|
|
545
|
-
}
|
|
546
|
-
void connection.closed.then(() => this.retire());
|
|
1125
|
+
});
|
|
547
1126
|
}
|
|
548
|
-
/**
|
|
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. */
|
|
549
1132
|
retire() {
|
|
550
1133
|
if (this.#retired)
|
|
551
|
-
return;
|
|
1134
|
+
return undefined;
|
|
552
1135
|
this.#retired = true;
|
|
553
|
-
clearTimeout(this.#timer);
|
|
554
|
-
this.#connection.close();
|
|
555
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;
|
|
556
1181
|
}
|
|
557
1182
|
}
|
|
558
1183
|
//# sourceMappingURL=reload.js.map
|