nish 0.36.0 → 0.37.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/docs/AI.md +43 -4
- package/docs/INSTALL.md +67 -58
- package/package.json +9 -5
- package/runtime/async.d.mts +2 -0
- package/runtime/async.mjs +7 -0
- package/runtime/nish.d.ts +736 -499
- package/runtime/nish.h +25 -0
- package/runtime/page.d.ts +53 -0
- package/runtime/page.mjs +146 -0
- package/runtime/runtime-async.c +557 -0
- package/runtime/runtime-wasm.c +63 -7
- package/scripts/build.sh +147 -5
- package/scripts/fuzz.sh +1 -0
- package/scripts/undocumented.txt +14 -0
- package/std/README.md +107 -82
- package/std/bytes.ts +23 -19
- package/std/compress/checksum.ts +1 -1
- package/std/crypto/aes.ts +48 -43
- package/std/crypto/base64url.ts +7 -5
- package/std/crypto/bcrypt-batch.ts +13 -13
- package/std/crypto/bcrypt.ts +33 -27
- package/std/crypto/chacha20poly1305.ts +16 -14
- package/std/crypto/ed25519.ts +19 -16
- package/std/crypto/hmac.ts +7 -6
- package/std/crypto/jwt.ts +23 -20
- package/std/crypto/p256.ts +63 -56
- package/std/crypto/p384.ts +23 -20
- package/std/crypto/pki.ts +18 -15
- package/std/crypto/rsa.ts +23 -19
- package/std/crypto/x25519.ts +11 -10
- package/std/crypto/x509.ts +69 -62
- package/std/host/ring.ts +124 -0
- package/std/json-equal.ts +12 -11
- package/std/json-number.ts +12 -12
- package/std/json-tokenizer.ts +26 -22
- package/std/json-typed.ts +92 -78
- package/std/json-value.ts +38 -33
- package/std/json.ts +32 -28
- package/std/net/fetch.ts +1117 -230
- package/std/net/handler.ts +18 -0
- package/std/net/hpack.ts +29 -26
- package/std/net/http-compress.ts +27 -21
- package/std/net/http1-client-codec.ts +29 -25
- package/std/net/http1-codec.ts +44 -87
- package/std/net/http1-server.ts +66 -54
- package/std/net/http2-frame.ts +17 -16
- package/std/net/http2-tls.ts +17 -15
- package/std/net/http2.ts +67 -54
- package/std/net/http3-frame.ts +11 -10
- package/std/net/http3-server.ts +36 -35
- package/std/net/http3.ts +70 -58
- package/std/net/postgres.ts +178 -160
- package/std/net/prefork.ts +38 -34
- package/std/net/qpack.ts +15 -14
- package/std/net/quic-conn-ack.ts +1 -0
- package/std/net/quic-conn-cid.ts +11 -0
- package/std/net/quic-conn-params.ts +41 -14
- package/std/net/quic-datagram.ts +7 -0
- package/std/net/quic-frame.ts +48 -12
- package/std/net/quic-listener.ts +61 -44
- package/std/net/quic-packet.ts +71 -52
- package/std/net/quic-recovery.ts +59 -21
- package/std/net/quic-stream.ts +83 -55
- package/std/net/quic.ts +204 -152
- package/std/net/tls/client.ts +1 -0
- package/std/net/tls/codec.ts +81 -12
- package/std/net/tls/record-client.ts +30 -18
- package/std/net/tls/record-server.ts +74 -46
- package/std/net/tls/record.ts +33 -24
- package/std/net/tls/ticket.ts +2 -0
- package/std/net/tls/verify.ts +8 -7
- package/std/net/tls-tcp.ts +58 -50
- package/std/net/tls.ts +55 -43
- package/std/net/url.ts +12 -9
- package/std/net/websocket.ts +23 -19
- package/std/net/webtransport.ts +24 -18
- package/std/random.ts +8 -6
- package/std/regex.ts +70 -59
- package/std/sync/ring.ts +24 -21
- package/std/sync/shm.ts +9 -7
- package/std/term-io.ts +17 -14
- package/std/term-probe.ts +11 -10
- package/std/term-rate.ts +71 -61
- package/std/term.ts +73 -59
- package/std/text.ts +11 -10
- package/std/threads.ts +19 -15
- package/std/yaml-json.ts +17 -15
- package/std/yaml-write.ts +21 -14
package/std/regex.ts
CHANGED
|
@@ -17,51 +17,59 @@
|
|
|
17
17
|
* }
|
|
18
18
|
*
|
|
19
19
|
* **The syntax is JavaScript's**, with the `u` flag's strictness: literals,
|
|
20
|
-
* `.`, classes `[a-z]` and `[^…]`, `\d \w \s` and their negations, `\b \B ^
|
|
21
|
-
*
|
|
22
|
-
* {n
|
|
20
|
+
* `.`, classes `[a-z]` and `[^…]`, `\d \w \s` and their negations, `\b \B ^ $`,
|
|
21
|
+
* groups `(…)`, `(?:…)` and `(?<name>…)`, `|`, and the quantifiers `* + ? {n}
|
|
22
|
+
* {n,} {n,m}` with their lazy `?` forms. Escapes are `\n \r \t \f \v \0`,
|
|
23
23
|
* `\cX`, `\xHH`, `\uHHHH`, `\u{H…}` and a backslash before any syntax
|
|
24
|
-
* character; a `{`, `}` or `]` that does not belong to a quantifier or a
|
|
25
|
-
*
|
|
26
|
-
* `\P{…}` are Unicode 16.0's properties as JavaScript names them: a
|
|
27
|
-
* General_Category value (`L`, `Lu`, `Letter`, `gc=Nd`), `Script=` or
|
|
28
|
-
* `Script_Extensions=` a script (`sc=Grek`, `scx=Deva`), or a binary property
|
|
29
|
-
* (`Alphabetic`, `Emoji`, `ASCII`, `Any`, `Assigned`). The flags are `i`, `m`
|
|
30
|
-
* (`^` and `$` at line terminators), `s` (`.` matches them too) and `u`,
|
|
31
|
-
* which changes nothing. `i` folds A-Z to a-z, and above ASCII follows
|
|
32
|
-
* Unicode's simple case folding, so `σ` matches `Σ` and `ς` and `[α-ω]` the
|
|
33
|
-
* capitals; unlike JavaScript nothing folds across ASCII, so the Kelvin sign
|
|
34
|
-
* and `ſ` match no `k` or `s`, though under `i` both are word characters to
|
|
35
|
-
* `\w`, `\W`, `\b` and `\B`, as with JavaScript's `iu`. **Backreferences and
|
|
36
|
-
* lookaround are refused at compile time**: they are what makes a matcher
|
|
37
|
-
* backtrack, and this one never does. A repeat count is at most 1,000, a
|
|
38
|
-
* pattern at most 100,000 instructions once its repeats are written out,
|
|
39
|
-
* 1,024 capturing groups and 10,000 ranges in one class, and its property
|
|
40
|
-
* escapes and case folding add at most 100,000 ranges to its classes.
|
|
24
|
+
* character; a `{`, `}` or `]` that does not belong to a quantifier or a class
|
|
25
|
+
* is an error rather than a literal, so write `\{`.
|
|
41
26
|
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
27
|
+
* `\p{…}` and `\P{…}` are Unicode 16.0's properties as JavaScript names them: a
|
|
28
|
+
* General_Category value (`L`, `Lu`, `Letter`, `gc=Nd`), `Script=` or
|
|
29
|
+
* `Script_Extensions=` a script (`sc=Grek`, `scx=Deva`), or a binary property
|
|
30
|
+
* (`Alphabetic`, `Emoji`, `ASCII`, `Any`, `Assigned`). The flags are `i`, `m`
|
|
31
|
+
* (`^` and `$` at line terminators), `s` (`.` matches them too) and `u`, which
|
|
32
|
+
* changes nothing.
|
|
33
|
+
*
|
|
34
|
+
* `i` folds A-Z to a-z, and above ASCII follows Unicode's simple case folding,
|
|
35
|
+
* so `σ` matches `Σ` and `ς` and `[α-ω]` the capitals; unlike JavaScript
|
|
36
|
+
* nothing folds across ASCII, so the Kelvin sign and `ſ` match no `k` or `s`,
|
|
37
|
+
* though under `i` both are word characters to `\w`, `\W`, `\b` and `\B`, as
|
|
38
|
+
* with JavaScript's `iu`. **Backreferences and lookaround are refused at
|
|
39
|
+
* compile time**: they are what makes a matcher backtrack, and this one never
|
|
40
|
+
* does.
|
|
41
|
+
*
|
|
42
|
+
* A repeat count is at most 1,000, a pattern at most 100,000 instructions once
|
|
43
|
+
* its repeats are written out, 1,024 capturing groups and 10,000 ranges in one
|
|
44
|
+
* class, and its property escapes and case folding add at most 100,000 ranges
|
|
45
|
+
* to its classes.
|
|
46
|
+
*
|
|
47
|
+
* **Matching never backtracks.** A search runs a lazy DFA first: it builds its
|
|
48
|
+
* states from the compiled program as the text needs them, so it reads a byte
|
|
49
|
+
* per step and the leftmost-first match's end comes from a table lookup. A
|
|
50
|
+
* reverse DFA, run back from that end, finds where the match starts, and a Pike
|
|
51
|
+
* VM, the construction RE2, Go's `regexp` and Rust's `regex` use, runs from
|
|
52
|
+
* that start only when a group's capture is wanted.
|
|
53
|
+
*
|
|
54
|
+
* A pattern with a literal no match can avoid, such as `\w+@example`, is
|
|
55
|
+
* searched for by that literal and the match grown both ways from it. Every
|
|
56
|
+
* engine follows every alternative at once, so a match costs O(pattern × input)
|
|
57
|
+
* at worst and `(a+)+$` against a thousand `a`s and a `b` is as quick as `a+$`.
|
|
58
|
+
*
|
|
59
|
+
* Finding every match (`findAll`, `count`, `replaceAll`, `split`) is one search
|
|
60
|
+
* per match, so it is quadratic when a preferred branch reads far ahead before
|
|
61
|
+
* a short one wins: `<[^>]*>|<` over a text of `<`s rereads the rest of the
|
|
62
|
+
* text for each, as it does in RE2 and Rust's `regex`. Which match is found is
|
|
63
|
+
* the one JavaScript finds — the leftmost, and of those the one the first
|
|
64
|
+
* alternative and the greediest quantifier prefer — and a group inside a
|
|
65
|
+
* quantifier keeps only its last iteration's capture, as in JavaScript.
|
|
66
|
+
*
|
|
67
|
+
* An iteration past a quantifier's minimum that matches empty is rejected, as
|
|
68
|
+
* JavaScript rejects it. The VM keeps one thread per instruction, position and
|
|
69
|
+
* set of iterations begun, so `(a*?)+?$` on "aa" captures "a", as JavaScript
|
|
70
|
+
* does; past three such quantifiers nested in one another the deeper ones share
|
|
71
|
+
* their threads, and a capture there can be a different iteration's than
|
|
72
|
+
* JavaScript's.
|
|
65
73
|
*
|
|
66
74
|
* **Strings are UTF-8 and offsets are bytes**, like `s.length`. The VM steps
|
|
67
75
|
* a code point at a time, so `.` and `[^a]` consume a whole character; a byte
|
|
@@ -70,24 +78,27 @@
|
|
|
70
78
|
* JavaScript; `\s` is JavaScript's whitespace, U+FEFF and U+3000 included.
|
|
71
79
|
* After an empty match `findAll`, `replaceAll` and `split` step one character.
|
|
72
80
|
*
|
|
73
|
-
* **What a call costs.** The VM's two thread lists, its capture tables and
|
|
74
|
-
*
|
|
81
|
+
* **What a call costs.** The VM's two thread lists, its capture tables and its
|
|
82
|
+
* stack are allocated once by `regexCompile`. `test` tracks no captures,
|
|
75
83
|
* `findAll` and a `replace` whose template names no group track only the
|
|
76
84
|
* match's bounds, and only `exec`, `find`, `split` and a template with `$1` or
|
|
77
|
-
* `$<name>` pay for every group.
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
85
|
+
* `$<name>` pay for every group.
|
|
86
|
+
*
|
|
87
|
+
* A pattern that starts with a literal is searched for with `s.indexOf`; one
|
|
88
|
+
* whose first few bytes are each one of a set rare enough to be worth it, like
|
|
89
|
+
* `[A-Z][a-z]` or `cat|dog`, is searched for those bytes by a runtime kernel
|
|
90
|
+
* that tests sixteen or thirty-two starts at a time; any other whose first
|
|
91
|
+
* characters are known skips the bytes that cannot start a match with a
|
|
92
|
+
* 128-entry table; and a pattern that is nothing but a literal never starts an
|
|
93
|
+
* engine at all.
|
|
94
|
+
*
|
|
95
|
+
* The DFA's states are built as searches need them and kept, so only a search
|
|
96
|
+
* that meets new states allocates, and only up to a bound: its table holds at
|
|
97
|
+
* most 2,048 states and 262,144 transitions (1 MiB), and a search that fills it
|
|
98
|
+
* clears it and goes on; one that keeps clearing it without reading at least 10
|
|
99
|
+
* bytes per state hands the rest of the text to the VM, which is slower but
|
|
100
|
+
* never needs more memory. Because the scratch memory lives in the `Regex`, one
|
|
101
|
+
* `Regex` is used by one thread at a time.
|
|
91
102
|
*/
|
|
92
103
|
|
|
93
104
|
import { uncheckedGet } from "nish:unsafe"
|
package/std/sync/ring.ts
CHANGED
|
@@ -48,22 +48,24 @@
|
|
|
48
48
|
* ring.tryPop(buf, 0) // none, or one peek cannot lend
|
|
49
49
|
* }
|
|
50
50
|
*
|
|
51
|
-
* A window is a `SharedRegion.lend` window: the ring keeps one for its
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
51
|
+
* A window is a `SharedRegion.lend` window: the ring keeps one for its producer
|
|
52
|
+
* and one for its consumer and re-points them on every call, so neither path
|
|
53
|
+
* allocates or makes a system call. `commit`, `abandon` and `release` give the
|
|
54
|
+
* window back, which empties it: a reference kept past them indexes nothing
|
|
55
|
+
* (each index panics) until the next `reserve` or `peek` re-points it, and then
|
|
56
|
+
* sees that call's record.
|
|
57
|
+
*
|
|
58
|
+
* A reserved record is always contiguous: when the rest of the lap is too
|
|
59
|
+
* short, `commit` writes a skip marker there (a length word of -1, "the rest of
|
|
60
|
+
* this lap is padding") and the record starts at the next lap. Every pop steps
|
|
61
|
+
* over a marker.
|
|
62
|
+
*
|
|
63
|
+
* A record `tryPush` wrapped across the end cannot be lent, so `peek` answers
|
|
64
|
+
* an empty window for it and `tryPop` takes it, as it does for a record of
|
|
65
|
+
* length 0. A reservation is at most `capacity / 2 - 4` bytes, so a ring of 8
|
|
66
|
+
* can never reserve (it panics) and one of 16 allows 4. The reserved bytes are
|
|
67
|
+
* not zeroed: `commit` only what was written. A consumer that polls `peek` on a
|
|
68
|
+
* doorbell ring has no wait call yet (`popWait` takes records, not windows).
|
|
67
69
|
*
|
|
68
70
|
* **The format keeps its magic.** A ring no producer `reserve`s into is
|
|
69
71
|
* byte for byte what it was, and a consumer built before the marker that
|
|
@@ -84,11 +86,12 @@
|
|
|
84
86
|
* the header and sleeps on Linux's futex, and a push rings it only when that
|
|
85
87
|
* flag is set (one `SEQ_CST` store and load on each side, so neither can miss
|
|
86
88
|
* the other). A busy ring makes no system calls; an idle one makes two per
|
|
87
|
-
* record, the consumer's wait and the producer's wake.
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
89
|
+
* record, the consumer's wait and the producer's wake.
|
|
90
|
+
*
|
|
91
|
+
* Without the doorbell a push is a release store and `popWait` answers
|
|
92
|
+
* `SHM_UNSUPPORTED`, as it does off Linux, where the consumer polls `tryPop`.
|
|
93
|
+
* `popWait` reads the monotonic clock for its deadline, so a program that
|
|
94
|
+
* imports this module reaches the `clock` capability as well as `ffi`.
|
|
92
95
|
*
|
|
93
96
|
* Private helpers share the importing program's flat symbol namespace
|
|
94
97
|
* (`docs/wp26-stdlib.md` §3e), which is why each one carries the module's name.
|
package/std/sync/shm.ts
CHANGED
|
@@ -16,13 +16,15 @@
|
|
|
16
16
|
* **A region is a named POSIX shared-memory object** (`/dev/shm/<name>` on
|
|
17
17
|
* Linux, `shm_open("/<name>")` on Darwin) mapped shared, so every process that
|
|
18
18
|
* opens the name sees the same bytes. A name is 1 to 30 of `A-Z a-z 0-9 . _ -`,
|
|
19
|
-
* not starting with `.`.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
19
|
+
* not starting with `.`.
|
|
20
|
+
*
|
|
21
|
+
* `createRegion` makes it with mode 0600 and refuses a name that exists
|
|
22
|
+
* (`SHM_EXISTS`), so a name another user planted is never adopted; `openRegion`
|
|
23
|
+
* refuses a region this user does not own, that anyone else may read or write,
|
|
24
|
+
* or (on Linux) that is not a regular file or has a second hard link
|
|
25
|
+
* (`SHM_ACCESS`). The name stays until `unlinkRegion`, even after every process
|
|
26
|
+
* has exited, which is how a process that starts later finds it; the mapping
|
|
27
|
+
* goes away with `close` or with the process.
|
|
26
28
|
*
|
|
27
29
|
* **Why named, and no anonymous region made before `fork`.** A Nish program
|
|
28
30
|
* has no `fork`: `spawn` and `nish/net/prefork` start a program with `exec`,
|
package/std/term-io.ts
CHANGED
|
@@ -22,24 +22,27 @@
|
|
|
22
22
|
* terminal has: the kitty keyboard protocol (`CSI > 11 u`: key releases and
|
|
23
23
|
* Ctrl-C as a key), mouse reports (1000, 1002 or 1003, in SGR form 1006, with
|
|
24
24
|
* pixel coordinates 1016 when the terminal has them), bracketed paste (2004)
|
|
25
|
-
* and focus reports (1004).
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
25
|
+
* and focus reports (1004).
|
|
26
|
+
*
|
|
27
|
+
* Before each change reaches the terminal, the runtime's restore string
|
|
28
|
+
* (`setTerminalRestore`) is set to undo everything — cancel any half-written
|
|
29
|
+
* escape (CAN), end synchronized output, delete the kitty image, pop the kitty
|
|
30
|
+
* keyboard flags, turn mouse, paste and focus reports off, reset the style,
|
|
31
|
+
* show the cursor and leave the alternate screen — so a panic or a signal
|
|
32
|
+
* leaves the terminal as it was.
|
|
31
33
|
*
|
|
32
34
|
* `present()` draws the `Screen` and the `Framebuffer`, if the options gave
|
|
33
35
|
* one, with the best backend the terminal has capped by the controller
|
|
34
36
|
* (`min(caps.graphics, decision.backendCap)`), at the controller's resolution
|
|
35
|
-
* divisor and palette, wrapped in synchronized output when the terminal has
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
37
|
+
* divisor and palette, wrapped in synchronized output when the terminal has it,
|
|
38
|
+
* as one write. It follows the frame with a DSR 5 query (`CSI 5 n`), whose
|
|
39
|
+
* answer (`CSI 0 n`) acknowledges the frame to the controller and marks the
|
|
40
|
+
* input before it as delivered to `KeyState`.
|
|
41
|
+
*
|
|
42
|
+
* No answer from the terminal reaches the program: one that arrives after the
|
|
43
|
+
* probe gave up (a slow link) is taken, and a cell size among them is learned.
|
|
44
|
+
* `close` reads the acknowledgements still in flight before it leaves raw mode,
|
|
45
|
+
* so none is echoed onto the shell's line.
|
|
43
46
|
*
|
|
44
47
|
* A frame's cost to the controller is the program's `update` and `render`
|
|
45
48
|
* since the last frame plus encoding it, not the write: a write that blocks
|
package/std/term-probe.ts
CHANGED
|
@@ -63,19 +63,20 @@
|
|
|
63
63
|
* "ascii"), `name` and `overrides`; each field's comment says where it
|
|
64
64
|
* comes from.
|
|
65
65
|
*
|
|
66
|
-
* The environment decides where the terminal cannot answer, and where the
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* `256color` in it means 256 colours, and anything else 16. `TERM=linux` is
|
|
70
|
-
*
|
|
66
|
+
* The environment decides where the terminal cannot answer, and where the user
|
|
67
|
+
* says so: `COLORTERM=truecolor` or `24bit` means true colour, as does a
|
|
68
|
+
* DECRQSS that reads the 24-bit background back; otherwise a `TERM` with
|
|
69
|
+
* `256color` in it means 256 colours, and anything else 16. `TERM=linux` is the
|
|
70
|
+
* Linux console: 16 colours, ASCII graphics, no kitty keyboard and no
|
|
71
71
|
* synchronized output, whatever it answered. `NO_COLOR` set to anything
|
|
72
72
|
* (no-color.org) means 16 colours and touches nothing but colour.
|
|
73
|
+
*
|
|
73
74
|
* `NISH_TERM_GRAPHICS` names a graphics backend to use instead of the one the
|
|
74
|
-
* answers pick; a pixel backend the terminal did not answer for is refused
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* `
|
|
75
|
+
* answers pick; a pixel backend the terminal did not answer for is refused when
|
|
76
|
+
* it would come out as garbage or nothing — on the Linux console, under a
|
|
77
|
+
* multiplexer, or when the terminal answered nothing at all. `overrides` says
|
|
78
|
+
* what each variable did, refusals included. The match is exact: `kitty`,
|
|
79
|
+
* `sixel`, `halfblock` or `ascii`, lower case, nothing around it.
|
|
79
80
|
*
|
|
80
81
|
* Under a multiplexer the probe sees the multiplexer first. tmux and screen
|
|
81
82
|
* answer DA1 themselves, so `done()` comes on their answer, before any reply
|
package/std/term-rate.ts
CHANGED
|
@@ -24,12 +24,14 @@
|
|
|
24
24
|
* **The acknowledgement.** A frame is acknowledged when the terminal answers a
|
|
25
25
|
* status query sent right after it: the terminal answers in order, so the
|
|
26
26
|
* answer means every byte before it has been read and drawn. The query to send
|
|
27
|
-
* is DSR 5, `CSI 5 n`, answered `CSI 0 n`.
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
27
|
+
* is DSR 5, `CSI 5 n`, answered `CSI 0 n`.
|
|
28
|
+
*
|
|
29
|
+
* It is preferred over the cursor position report (DSR 6, `CSI 6 n`, answered
|
|
30
|
+
* `CSI row ; col R`) because its answer is one fixed string, and because a
|
|
31
|
+
* cursor report is the same bytes as F3 with modifiers in the legacy key
|
|
32
|
+
* encoding (`CSI 1 ; mods R`), which a key decoder would have to guess between.
|
|
33
|
+
* Two relays answer the query from their own emulator, not from the terminal at
|
|
34
|
+
* the end of the link:
|
|
33
35
|
*
|
|
34
36
|
* - tmux (commit 939e8e65) answers in `input.c` lines 1737–1747, the
|
|
35
37
|
* `INPUT_CSI_DSR` case, which replies `\033[0n` to 5 and the position to 6
|
|
@@ -50,62 +52,70 @@
|
|
|
50
52
|
* **What is measured.** Four running averages (exponentially weighted, so
|
|
51
53
|
* recent frames count most and none is stored): the round trip from a frame's
|
|
52
54
|
* send to its acknowledgement (weight 1/8, as TCP smooths its round trip, so
|
|
53
|
-
* one late answer moves it little); the bytes a second the link delivered;
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* to its own: its bytes over that
|
|
60
|
-
* onto an idle link makes a trip, kept
|
|
61
|
-
* against the quickest kept trip, one twice
|
|
62
|
-
*
|
|
63
|
-
* part of.
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
55
|
+
* one late answer moves it little); the bytes a second the link delivered; the
|
|
56
|
+
* cost to build a frame and the bytes in one (weight 1/4 each, so a change of
|
|
57
|
+
* scene shows within a few frames). The bandwidth and the latency are kept
|
|
58
|
+
* apart, so neither can take the other's share of a round trip.
|
|
59
|
+
*
|
|
60
|
+
* A frame sent before the previous answer, and answered more than the latency
|
|
61
|
+
* after it, kept the link busy from that answer to its own: its bytes over that
|
|
62
|
+
* time measure the bandwidth. A frame sent onto an idle link makes a trip, kept
|
|
63
|
+
* with the last 16 and the probe's: against the quickest kept trip, one twice
|
|
64
|
+
* its bytes or half, 2 ms or more apart, measures the bandwidth from the
|
|
65
|
+
* difference, which the latency is no part of.
|
|
66
|
+
*
|
|
67
|
+
* Both kinds smooth the bytes and the time apart (weight 1/4 each), so answers
|
|
68
|
+
* arriving in a burst, each taking almost no time, do not read as unbounded
|
|
69
|
+
* bandwidth; answers under 2 ms apart measure nothing this way.
|
|
70
|
+
*
|
|
71
|
+
* A sample counts for the decisions for 5 seconds with no newer one, so a link
|
|
72
|
+
* that narrows is not held to its old rate; the bandwidth reported keeps it
|
|
73
|
+
* until a newer sample, which starts the average afresh, replaces it, or three
|
|
74
|
+
* trips in a row take over twice what it and the quickest trip kept when it was
|
|
75
|
+
* taken predict.
|
|
76
|
+
*
|
|
77
|
+
* The figure is at least the most of the last 16 answers' bytes over their
|
|
78
|
+
* whole round trips, since the bytes took no longer than that, so a link that
|
|
79
|
+
* widens shows on its first quick answer; but that bound counts the latency as
|
|
80
|
+
* bytes' time, so alone it never makes the bandwidth known to the decisions.
|
|
81
|
+
*
|
|
82
|
+
* The base latency is the least, over the kept trips, of the round trip less
|
|
83
|
+
* the trip's bytes at the bandwidth: the probe's round trip (`probeRttMs`: the
|
|
84
|
+
* status query alone is a few bytes, so its round trip is the latency) counts
|
|
85
|
+
* from the start, the frames' once the bandwidth is known. The kept trips roll
|
|
86
|
+
* over, so a changed route shows within 16 trips.
|
|
87
|
+
*
|
|
88
|
+
* With frames of one size sent one at a time onto an idle link and no probe the
|
|
89
|
+
* latency and the bytes cannot be told apart: the bandwidth is then not known,
|
|
90
|
+
* its load counts as 0, and the trip load governs on the frame's measured round
|
|
91
|
+
* trip: a cut is taken to shorten none of it and a restore to lengthen all of
|
|
92
|
+
* it, so detail is neither cut for a gain nor restored at a cost that may not
|
|
93
|
+
* be there. Acknowledgements match sent frames oldest first.
|
|
94
|
+
*
|
|
95
|
+
* A frame due while the unacknowledged limit is reached is dropped and counted;
|
|
96
|
+
* one not answered within `rateAckTimeoutMs` plus four round trips is given up
|
|
97
|
+
* and counted as lost, so a lost answer stalls drawing for seconds, not for
|
|
98
|
+
* ever. Its answer may still come late, and would otherwise be matched to the
|
|
99
|
+
* next frame, so after a give-up no frame is drawn until as many answers have
|
|
100
|
+
* arrived, or one more timeout has passed without them. A time, cost or size
|
|
101
|
+
* that is not a finite number, or is negative, is not measured, and an empty
|
|
102
|
+
* frame says nothing about bandwidth.
|
|
103
|
+
*
|
|
104
|
+
* **What is decided.**
|
|
105
|
+
*
|
|
106
|
+
* The frame rate is a tier: 120 (only with `allow120` and a `maxFps` of 120),
|
|
107
|
+
* 60, 30, 20, 15, 10 or 5. A tier fits when three loads are all at most 1: the
|
|
108
|
+
* frame cost over 70% of the frame time, the bytes a second the tier needs over
|
|
109
|
+
* 70% of the bytes a second the link delivers, and the tier's frames times the
|
|
110
|
+
* round trip over 70% of the time the unacknowledged limit allows (a link that
|
|
111
|
+
* answers in 100 ms carries at most ten frames a second one at a time).
|
|
95
112
|
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* ten frames a second one at a time). The 30% left over absorbs a slow frame
|
|
103
|
-
* without a dropped one. The rate falls to the best fitting tier after half a
|
|
104
|
-
* second continuously over, and rises one tier after three seconds
|
|
105
|
-
* continuously under the next tier's loads with a fifth to spare; after any
|
|
106
|
-
* change it holds for a second, so the averages see the new rate before the
|
|
107
|
-
* next decision. Falling fast and rising slowly keeps a flickering link from
|
|
108
|
-
* flipping the rate.
|
|
113
|
+
* The 30% left over absorbs a slow frame without a dropped one. The rate falls
|
|
114
|
+
* to the best fitting tier after half a second continuously over, and rises one
|
|
115
|
+
* tier after three seconds continuously under the next tier's loads with a
|
|
116
|
+
* fifth to spare; after any change it holds for a second, so the averages see
|
|
117
|
+
* the new rate before the next decision. Falling fast and rising slowly keeps a
|
|
118
|
+
* flickering link from flipping the rate.
|
|
109
119
|
*
|
|
110
120
|
* It starts at the best tier on a local terminal: the probe answered under
|
|
111
121
|
* 5 ms, or no `SSH_*` hint and no slow answer. Falling costs half a second and
|