Commit80851913Recorded19 Oct 2026Repositorysigil-http3

Instrument a private QUIC spike for the traced phone rerun

Changed
 scripts/browser-preflight.mjs       |  20 ++++++++++++++++++++
 scripts/generate-spike-tests.mjs    |   7 +++++--
 scripts/phantom-ipv6-trace-run.sh   |   8 ++++++++
 scripts/phantom-spike-echo-check.sh |  17 ++++++++++++++++-
 scripts/prepare-spike-trace.mjs     | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 scripts/vpn-phone-run.mjs           |  18 +++++++++++++++---
 tools/trace/trace.sgl               | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 web/phone.html                      |  21 ++++++++++++++++++---
 8 files changed, 355 insertions(+), 9 deletions(-)
Diff
scripts/browser-preflight.mjsmodified
@@ -2,6 +2,7 @@
2
import { execFileSync, spawn } from 'node:child_process';
3
import { createHash } from 'node:crypto';
4
import { createServer } from 'node:http';
+5
import { createSocket } from 'node:dgram';
6
import { constants, accessSync, readFileSync, writeFileSync, existsSync, unlinkSync } from 'node:fs';
7
import { hostname } from 'node:os';
8
import { join, resolve } from 'node:path';
@@ -286,6 +287,25 @@ try {
287
receipt.pathChangeObserved = serverOutput().includes('HTTP3-PATH-CHANGE ');
288
}
289
receipt.profile = candidateProfile;
+290
if (process.env.HTTP3_SPIKE_TRACE_PROBE === '1') {
+291
if (!['127.0.0.1', '::1'].includes(bindAddress)) throw new Error('Trace probe is loopback only');
+292
const probe = createSocket(bindAddress === '::1' ? 'udp6' : 'udp4');
+293
try {
+294
await new Promise((done, reject) => { probe.once('error', reject); probe.bind(0, bindAddress, done); });
+295
const probePort = probe.address().port;
+296
for (const bytes of [Buffer.from([0xc0]), Buffer.from([0x40, ...Array(31).fill(0xf1)])])
+297
await new Promise((done, reject) => probe.send(bytes, port, bindAddress, error => error ? reject(error) : done()));
+298
await pause(500);
+299
const trace = serverOutput();
+300
const ingress = trace.split('\n').filter(line => line.includes('event=udp-in') && line.includes(`port ${probePort} `));
+301
if (ingress.length !== 2 || !ingress.some(line => line.includes('new-tuple #t')) ||
+302
!trace.includes('reason malformed-header-or-unowned-dcid') || trace.includes('event=trace-exhausted'))
+303
throw new Error('Bounded extra-tuple/drop trace probe failed');
+304
const after = await evaluate("({state:document.getElementById('state').textContent,stream:document.getElementById('stream').textContent})");
+305
if (after.state !== 'open') throw new Error('Diagnostic noise changed the real connection state');
+306
receipt.traceProbe = { packets: 2, port: probePort, newTuple: true, dropRecorded: true, connectionStillOpen: true };
+307
} finally { await new Promise(done => probe.close(done)); }
+308
}
309
const { cssContentSize } = await cdp('Page.getLayoutMetrics', {}, sessionId);
310
const screenshot = await cdp('Page.captureScreenshot', { format: 'png', captureBeyondViewport: true,
311
clip: { x: 0, y: 0, width: cssContentSize.width, height: Math.min(cssContentSize.height, 2400), scale: 1 } }, sessionId);
scripts/generate-spike-tests.mjsmodified
@@ -6,6 +6,8 @@ import { resolve } from 'node:path';
6
const files = ['frame', 'qpack', 'streams', 'control', 'request', 'connection',
7
'webtransport-wire', 'webtransport-session', 'webtransport-router'].map(name => `test/test-${name}.sgl`);
8
files.push(...['profile', 'echo', 'echo-integration', 'observations'].map(name => `tools/interop/test/test-${name}.sgl`));
+9
const traceTests = process.env.HTTP3_TRACE_TESTS === '1';
+10
if (traceTests) files.push('.deps/sigil-quic/test/test-idle-timeout.sgl', '.deps/sigil-quic/test/test-network-receive.sgl');
11
const imports = new Set(['(sigil io)', '(sigil process)']);
12
const manifest = [];
13
let total = 0;
@@ -21,7 +23,8 @@ const bodies = files.map(file => {
23
manifest.push({ file, tests: count, sha256: createHash('sha256').update(text).digest('hex') });
24
return body;
25
});
−24
if (total !== 123) throw new Error('Expected all 123 unchanged test cases, found ' + total);
+26
if ((!traceTests && total !== 123) || (traceTests && manifest.slice(0, 13).reduce((sum, file) => sum + file.tests, 0) !== 123))
+27
throw new Error('Expected all 123 unchanged HTTP3 cases plus selected trace regressions');
28
mkdirSync('build/spike-tests/src/sigil/http3/spike', { recursive: true });
29
writeFileSync('build/spike-echo/test-sources.json', JSON.stringify(manifest, null, 2) + '\n');
30
writeFileSync('build/spike-tests/src/sigil/http3/spike/checks.sgl', `(define-library (sigil http3 spike checks)
@@ -39,7 +42,7 @@ ${bodies.map(body => body.split('\n').map(line => ' ' + line).join('\n')).joi
42
(test-summary-results summary))
43
(println "SPIKE-CHECKS total=~a passed=~a failed=~a"
44
(test-summary-total summary) (test-summary-passed summary) (test-summary-failed summary))
−42
(exit (if (and (= (test-summary-total summary) 123) (= (test-summary-failed summary) 0)) 0 1))))))
+45
(exit (if (and (= (test-summary-total summary) ${total}) (= (test-summary-failed summary) 0)) 0 1))))))
46
`);
47
writeFileSync('build/spike-tests/package.sgl', `(package
48
name: "sigil-http3-spike-checks"
scripts/phantom-ipv6-trace-run.shadded
@@ -0,0 +1,8 @@
+1
#!/usr/bin/env bash
+2
set -euo pipefail
+3
cd "$(dirname "$0")/.."
+4
export HTTP3_SPIKE_SDK_JOB=http3-example
+5
export HTTP3_SPIKE_TRACE_BUILD=1 HTTP3_SPIKE_TRACE=1 HTTP3_TRACE_TESTS=1 HTTP3_SPIKE_TRACE_PROBE=1
+6
bash scripts/phantom-spike-echo-check.sh
+7
export HTTP3_VERIFIED_NATIVE_JOB=http3-example HTTP3_PHONE_SCOPE=ipv6-direct HTTP3_PHONE_TRACE=1
+8
exec node scripts/vpn-phone-run.mjs run
scripts/phantom-spike-echo-check.shmodified
@@ -24,6 +24,9 @@ sha256sum "$sdk_source/build/boot/bin/sigil" "$sdk_source/packages/sigil-lib/src
24
bash scripts/prepare-nat-dependency.sh
25
bash scripts/prepare-quic.sh
26
test "$(git -C .deps/sigil-quic rev-parse HEAD)" = "$(cat quic.rev)"
+27
if [ "${HTTP3_SPIKE_TRACE_BUILD:-0}" = 1 ]; then
+28
node scripts/prepare-spike-trace.mjs
+29
fi
30
export SIGIL_JOBS=1
31
unset SIGIL_REDIRECTS SIGIL_LIB SIGIL_LIB_PATH
32
node scripts/generate-spike-tests.mjs > "$results/generate-tests.log" 2>&1
@@ -44,6 +47,8 @@ writeFileSync('build/spike-native-workspace/package.sgl', `;; SPIKE ONLY: no pro
47
bundle?: #t output-dir: "build/native")))
48
`);
49
const sources = ['preflight', 'observations'].map(name => resolve(`tools/interop/src/sigil/http3/interop/${name}.sgl`));
+50
if (process.env.HTTP3_SPIKE_TRACE_BUILD === '1') sources.push(...['connection.sgl', 'endpoint.sgl', 'spike/trace.sgl']
+51
.map(name => resolve('.deps/sigil-quic/src/sigil/quic/' + name)));
52
writeFileSync('build/spike-echo/read-source.sgl', `(import (sigil io))
53
(for-each
54
(lambda (path)
@@ -73,7 +78,14 @@ cp "$workspace/.sigil/deps.index" "$results/deps.index"
78
(cd "$workspace" && timeout --foreground 600 "$builder" build sigil-http3-spike-checks --config native) \
79
> "$results/test-build.log" 2>&1
80
timeout --foreground 180 "$workspace/build/native/bin/http3-spike-checks" > "$results/tests.log" 2>&1
−76
rg -q '^SPIKE-CHECKS total=123 passed=123 failed=0$' "$results/tests.log"
+81
expected_tests=$(node -e 'const f=require("./build/spike-echo/test-sources.json"); console.log(f.reduce((n,x)=>n+x.tests,0))')
+82
rg -q "^SPIKE-CHECKS total=$expected_tests passed=$expected_tests failed=0$" "$results/tests.log"
+83
if [ "${HTTP3_SPIKE_TRACE_BUILD:-0}" = 1 ]; then
+84
rg -q 'event=connection-close.*idle-expired #t' "$results/tests.log"
+85
rg -q 'event=packet-drop' "$results/tests.log"
+86
rg -q 'event=frame.*type 26' "$results/tests.log"
+87
rg -q 'event=frame.*type 27' "$results/tests.log"
+88
fi
89
(cd "$workspace" && timeout --foreground 600 "$builder" build sigil-http3-interop --config native) \
90
> "$results/native-build.log" 2>&1
91
mkdir -p tools/interop/build/native/bin
@@ -96,3 +108,6 @@ bash scripts/phantom-lifecycle-check.sh
108
git -C "$sdk_source" diff --exit-code > "$results/sdk-source-after.diff"
109
git diff --exit-code -- sigil.lock tools/interop/sigil.lock > "$results/product-locks-after.diff"
110
printf 'RESULT spike-echo-native-v4-v6-and-lifecycle=PASS\n' | tee -a "$results/result.txt"
+111
if [ "${HTTP3_SPIKE_TRACE_BUILD:-0}" = 1 ]; then
+112
printf 'RESULT private-trace-native-browser-regressions=PASS\n' > "$results/trace-result.txt"
+113
fi
scripts/prepare-spike-trace.mjsadded
@@ -0,0 +1,153 @@
+1
// Apply only to the private Linux dependency; keep the committed pin intact.
+2
import { execFileSync } from 'node:child_process';
+3
import { createHash } from 'node:crypto';
+4
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
+5
import { resolve } from 'node:path';
+6
+7
const root = resolve('.deps/sigil-quic');
+8
const pin = readFileSync('quic.rev', 'utf8').trim();
+9
if (execFileSync('git', ['-C', root, 'rev-parse', 'HEAD'], { encoding: 'utf8' }).trim() !== pin)
+10
throw new Error('Trace base pin mismatch');
+11
execFileSync('git', ['-C', root, 'diff', '--exit-code'], { stdio: 'inherit' });
+12
const originals = new Map();
+13
const sources = new Map();
+14
function change(file, before, after) {
+15
const path = root + '/src/sigil/quic/' + file;
+16
const source = sources.get(path) ?? readFileSync(path, 'utf8');
+17
originals.set(path, originals.get(path) ?? source);
+18
if (source.split(before).length !== 2) throw new Error('Trace anchor must occur once: ' + file + ' ' + before.slice(0, 80));
+19
sources.set(path, source.replace(before, after));
+20
}
+21
for (const file of ['connection.sgl', 'endpoint.sgl'])
+22
change(file, ' (import (sigil crypto)', ' (import (sigil quic spike trace)\n (sigil crypto)');
+23
+24
change('endpoint.sgl', '(let* ((processed? #f)\n (host',
+25
'(let* ((processed? #f)\n (raw (string->utf8 (car received)))\n (host');
+26
change('endpoint.sgl', ' (when (and address\n', ` (spike-ingress! raw host port
+27
(and (quic-endpoint-connection endpoint)
+28
(bytevector-length (quic-local-id (quic-endpoint-connection endpoint)))))
+29
(unless (and address
+30
(eq? (quic-address-family address) (quic-endpoint-family endpoint))
+31
(receive-peer? endpoint (quic-address-host address) port))
+32
(spike-trace! 'udp-drop '(reason invalid-address-family-or-preconfirmation-source)))
+33
(when (and address
+34
`);
+35
change('endpoint.sgl', '(let ((bytes (string->utf8 (car received))))', '(let ((bytes raw))');
+36
change('endpoint.sgl', ' (when (<= 1 (bytevector-length bytes) packet-datagram-limit)',
+37
` (unless (<= 1 (bytevector-length bytes) packet-datagram-limit)
+38
(spike-trace! 'udp-drop '(reason datagram-size-limit)))
+39
(when (<= 1 (bytevector-length bytes) packet-datagram-limit)`);
+40
change('endpoint.sgl', ' (admit! endpoint bytes address now))',
+41
` (admit! endpoint bytes address now)
+42
(unless (quic-endpoint-connection endpoint)
+43
(spike-trace! 'admission-no-connection
+44
'(reason initial-not-admitted-or-retry-sent see-retry-out))))`);
+45
change('endpoint.sgl', ' (cond\n ((and sent',
+46
` (spike-trace! 'udp-out
+47
(list 'host (car target) 'port (cdr target) 'bytes (bytevector-length packet)
+48
'sent (or sent 0) 'dcid (spike-hex (quic-output-id output))))
+49
(cond
+50
((and sent`);
+51
change('endpoint.sgl', ' (when (and sent (not (= sent (bytevector-length packet))))',
+52
` (spike-trace! 'retry-out
+53
(list 'host (quic-address-host address) 'port (quic-address-port address)
+54
'sent (or sent 0) 'bytes (bytevector-length packet)))
+55
(when (and sent (not (= sent (bytevector-length packet))))`);
+56
+57
change('connection.sgl', ' (let ((pto (connection-pto connection)))\n (set-quic-connection-ready!',
+58
` (spike-close! failure peer? silent? (quic-idle-expired? connection) (quic-connection-now connection))
+59
(let ((pto (connection-pto connection)))
+60
(set-quic-connection-ready!`);
+61
change('connection.sgl', ' (set-quic-connection-idle-expired?! connection #t)',
+62
` (spike-trace! 'idle-expiry
+63
(list 'now (quic-connection-now connection) 'start start 'duration duration
+64
'pto (connection-pto connection)))
+65
(set-quic-connection-idle-expired?! connection #t)`);
+66
change('connection.sgl', ' (packet-space-record-sent! space number size now tracked?)',
+67
` (spike-frame! 'tx-sealed frame target-address now)
+68
(packet-space-record-sent! space number size now tracked?)`);
+69
change('connection.sgl', " ((eq? opened 'discard) #f)",
+70
` ((eq? opened 'discard)
+71
(spike-trace! 'packet-drop '(reason packet-open-exception-before-authentication))
+72
(spike-reset-check! datagram)
+73
#f)`);
+74
change('connection.sgl', ' (set-quic-connection-failed-packets! connection (+ 1 (quic-connection-failed-packets connection)))',
+75
` (spike-trace! 'packet-drop '(reason current-and-next-key-authentication-failed))
+76
(spike-reset-check! datagram)
+77
(set-quic-connection-failed-packets! connection (+ 1 (quic-connection-failed-packets connection)))`);
+78
change('connection.sgl', ' (unless (packet-space-discarded? space)\n (if (not (connection-level-read-keys state))',
+79
` (when (packet-space-discarded? space)
+80
(spike-trace! 'packet-drop (list 'reason 'discarded-packet-space 'level level)))
+81
(unless (packet-space-discarded? space)
+82
(if (not (connection-level-read-keys state))`);
+83
// Keep defer semantics intact and distinguish it from a failed decrypt.
+84
change('connection.sgl', ' (let ((size (- (quic-header-end header) (quic-header-start header))))\n (when',
+85
` (let ((size (- (quic-header-end header) (quic-header-start header))))
+86
(spike-trace! 'packet-deferred
+87
(list 'reason 'read-keys-not-ready 'bytes size
+88
'budget-available (and (< (length (connection-level-deferred state)) 16)
+89
(<= (+ (connection-level-deferred-bytes state) size) 65536))))
+90
(when`);
+91
change('connection.sgl', " (status (packet-space-received-status space number)))",
+92
` (status (packet-space-received-status space number)))
+93
(spike-trace! 'packet-authenticated
+94
(list 'level level 'number number 'replay-status status))
+95
(when frames
+96
(for-each (lambda (frame)
+97
(spike-frame! 'rx-decoded frame source (quic-connection-now connection))) frames))
+98
(unless frames (spike-trace! 'packet-drop '(reason authenticated-frame-work-limit)))
+99
(when (and frames (not (quic-connection-frame-handler connection))
+100
(any frame-needs-handler? frames))
+101
(spike-trace! 'packet-drop '(reason application-handler-not-attached)))`);
+102
change('connection.sgl', ' (observe-received! connection source level number frames status credit))',
+103
` (let ((accepted? (observe-received! connection source level number frames status credit)))
+104
(unless accepted?
+105
(spike-trace! 'packet-drop
+106
(list 'reason 'authenticated-path-policy-or-replay 'number number 'status status)))
+107
accepted?))`);
+108
change('connection.sgl', ' (when (and (not (quic-closed? connection)) (<= 1 (bytevector-length datagram) packet-datagram-limit))',
+109
` (when (quic-closed? connection)
+110
(spike-trace! 'packet-drop (list 'reason 'already-closed 'idle-expired (quic-idle-expired? connection))))
+111
(when (and (not (quic-closed? connection)) (<= 1 (bytevector-length datagram) packet-datagram-limit))`);
+112
change('connection.sgl', ' (when header\n (when (and (eq? (quic-header-kind header)',
+113
` (unless header
+114
(spike-trace! 'packet-drop '(reason malformed-header-or-unowned-dcid))
+115
(spike-reset-check! datagram))
+116
(when header
+117
(spike-trace! 'packet-header
+118
(list 'kind (quic-header-kind header) 'offset offset
+119
'dcid (spike-hex (quic-header-destination-id header))))
+120
(when (and (eq? (quic-header-kind header)`);
+121
change('connection.sgl', ' (when admitted?\n (unless (quic-connection-started connection)',
+122
` (unless admitted?
+123
(spike-trace! 'packet-drop
+124
(list 'reason
+125
(cond
+126
((not (memq (quic-header-kind header) '(initial handshake application))) 'unsupported-header-kind)
+127
((not (receive-source? connection address (quic-header-kind header))) 'source-not-eligible-before-confirmation)
+128
((not (routed-header? connection header)) 'dcid-or-source-id-route-mismatch)
+129
(else 'undersized-client-initial)))))
+130
(when admitted?
+131
(unless (quic-connection-started connection)`);
+132
// Remember an authenticated peer transport reset token without printing it.
+133
change('connection.sgl', ' (set-quic-connection-network! connection\n',
+134
` (let ((token (assoc 2 (quic-peer-parameters connection))))
+135
(when token (spike-remember-reset! (cdr token))))
+136
(set-quic-connection-network! connection
+137
`);
+138
+139
const digest = text => createHash('sha256').update(text).digest('hex');
+140
const manifest = [];
+141
for (const [path, source] of sources) {
+142
writeFileSync(path, source);
+143
manifest.push({ path, before: digest(originals.get(path)), after: digest(source) });
+144
}
+145
const modulePath = root + '/src/sigil/quic/spike/trace.sgl';
+146
mkdirSync(root + '/src/sigil/quic/spike', { recursive: true });
+147
const trace = readFileSync('tools/trace/trace.sgl', 'utf8');
+148
writeFileSync(modulePath, trace);
+149
manifest.push({ path: modulePath, after: digest(trace) });
+150
mkdirSync('build/spike-echo', { recursive: true });
+151
writeFileSync('build/spike-echo/trace-manifest.json', JSON.stringify({ scope: 'spike-only', base: pin, manifest }, null, 2) + '\n');
+152
writeFileSync('build/spike-echo/trace.patch', execFileSync('git', ['-C', root, 'diff'], { encoding: 'utf8' }));
+153
console.log('RESULT private-quic-trace-patch=APPLIED base=' + pin);
scripts/vpn-phone-run.mjsmodified
@@ -35,6 +35,7 @@ async function unusedPort(kind, address) {
35
async function runVpnPhone() {
36
37
const direct = process.env.HTTP3_PHONE_SCOPE === 'ipv6-direct';
+38
const traced = process.env.HTTP3_PHONE_TRACE === '1';
39
const bindAddress = direct ? process.env.HTTP3_IPV6_ADDRESS : (process.env.HTTP3_IPV4_ADDRESS ?? '127.0.0.1');
40
if (direct) check(Object.values(networkInterfaces()).flat().some(address =>
41
address?.family === 'IPv6' && address.address === bindAddress && !address.internal),
@@ -54,9 +55,17 @@ async function runVpnPhone() {
55
check(['configurableBind', 'retry', 'antiAmplification', 'boundedAdmission', 'peerAddressLogging',
56
'pathChangeLogging', 'cidChangeLogging', 'echoOnly'].every(key => receipt.server?.[key] === true),
57
'Reviewed server capability gate missing');
−57
const originalBinary = verified + '/src/tools/interop/build/native/bin/http3-preflight';
+58
if (traced) {
+59
check(direct && receipt.traceProbe?.newTuple === true && receipt.traceProbe?.dropRecorded === true,
+60
'Traced loopback probe receipt missing');
+61
check(readFileSync('build/spike-echo/trace-result.txt', 'utf8').includes('private-trace-native-browser-regressions=PASS'),
+62
'Private traced native/browser gate missing');
+63
check(json(resolve('build/spike-echo/trace-manifest.json')).base === receipt.quicRevision,
+64
'Private trace base pin mismatch');
+65
}
+66
const originalBinary = traced ? resolve('tools/interop/build/native/bin/http3-preflight') : verified + '/src/tools/interop/build/native/bin/http3-preflight';
67
const originalCertificate = direct ? resolve('build/browser') : verified + '/src/build/browser';
−59
check(receipt.binarySha256 === nativeReceipt.binarySha256 && digest(originalBinary) === receipt.binarySha256 &&
+68
check((traced || receipt.binarySha256 === nativeReceipt.binarySha256) && digest(originalBinary) === receipt.binarySha256 &&
69
digest(originalCertificate + '/cert.der') === receipt.certificateSha256, 'Verified input hash mismatch');
70
71
mkdirSync('build', { recursive: true, mode: 0o700 });
@@ -73,7 +82,10 @@ async function runVpnPhone() {
82
chmodSync(binary, 0o700);
83
privateJson(join(directory, 'interop.json'), receipt);
84
const pageBindAddress = (process.env.HTTP3_IPV4_ADDRESS ?? '127.0.0.1');
−76
const lifetimeSeconds = direct ? 2700 : 5400; // Direct window fits within the already-open firewall guard.
+85
const requestedLifetime = direct ? 2700 : 5400;
+86
const lifetimeSeconds = process.env.HTTP3_PHONE_DEADLINE ? Math.min(requestedLifetime,
+87
Math.floor((Date.parse(process.env.HTTP3_PHONE_DEADLINE) - Date.now()) / 1000)) : requestedLifetime;
+88
check(Number.isInteger(lifetimeSeconds) && lifetimeSeconds >= 120, 'Phone window deadline is too close or invalid');
89
const cancellation = new AbortController();
90
const deadline = Date.now() + lifetimeSeconds * 1000;
91
const timer = setTimeout(() => cancellation.abort(), lifetimeSeconds * 1000);
tools/trace/trace.sgladded
@@ -0,0 +1,120 @@
+1
;;; Diagnostic-only module copied into a private QUIC clone for this spike.
+2
;;; No packet acceptance, cryptography, migration or close policy is changed.
+3
(define-library (sigil quic spike trace)
+4
(import (sigil io)
+5
(sigil time)
+6
(sigil process)
+7
(sigil quic bytes)
+8
(sigil quic address)
+9
(sigil quic frame)
+10
(sigil quic error))
+11
(export spike-trace! spike-ingress! spike-frame! spike-close! spike-hex
+12
spike-remember-reset! spike-reset-check!)
+13
(begin
+14
(define enabled? (equal? (getenv "HTTP3_SPIKE_TRACE") "1"))
+15
(define origin (current-jiffy))
+16
(define records 0)
+17
(define tuples '())
+18
(define reset-tokens '())
+19
+20
(define (hex-prefix bytes maximum)
+21
(if (bytevector? bytes)
+22
(let ((text (make-string (* 2 (min maximum (bytevector-length bytes))) #\0))
+23
(digits "0123456789abcdef"))
+24
(do ((index 0 (+ index 1))) ((= index (quotient (string-length text) 2)) text)
+25
(let ((byte (bytevector-u8-ref bytes index)))
+26
(string-set! text (* 2 index) (string-ref digits (quotient byte 16)))
+27
(string-set! text (+ (* 2 index) 1) (string-ref digits (modulo byte 16))))))
+28
"unknown"))
+29
+30
(define (spike-hex bytes) (hex-prefix bytes 20))
+31
+32
(define (spike-trace! kind fields)
+33
(when (and enabled? (<= records 8192))
+34
(let ((now (current-second)))
+35
(if (= records 8192)
+36
(println "QUIC-SPIKE utc=~aT~aZ event=trace-exhausted limit=8192"
+37
(format-date now #t) (format-time now #t))
+38
(println "QUIC-SPIKE utc=~aT~aZ mono-ms=~a seq=~a event=~a fields=~a"
+39
(format-date now #t) (format-time now #t)
+40
(quotient (* 1000 (- (current-jiffy) origin)) (jiffies-per-second))
+41
records kind fields))
+42
(set! records (+ records 1)))))
+43
+44
(define (spike-ingress! bytes host port short-length)
+45
(when enabled?
+46
(let* ((tuple (list host port))
+47
(new? (not (member tuple tuples)))
+48
(size (bytevector-length bytes))
+49
(long? (and (> size 0) (>= (bytevector-u8-ref bytes 0) 128)))
+50
(cid-size (if long?
+51
(and (>= size 6) (bytevector-u8-ref bytes 5))
+52
short-length))
+53
(start (if long? 6 1))
+54
(dcid (and cid-size (<= 0 cid-size 20) (<= (+ start cid-size) size)
+55
(bytevector-copy bytes start (+ start cid-size)))))
+56
(when (and new? (< (length tuples) 32))
+57
(set! tuples (cons tuple tuples)))
+58
(spike-trace! 'udp-in
+59
(list 'host host 'port port 'new-tuple new? 'bytes size
+60
'header (if long? 'long 'short) 'dcid (hex-prefix dcid 20)
+61
'short-dcid-length-source (if short-length 'current-local-id 'unknown))))))
+62
+63
(define (spike-remember-reset! token)
+64
(when (and enabled? (bytevector? token) (= (bytevector-length token) 16)
+65
(< (length reset-tokens) 16)
+66
(not (any (lambda (old) (bytes=? old token)) reset-tokens)))
+67
(set! reset-tokens (cons (bytevector-copy token) reset-tokens))))
+68
+69
(define (spike-reset-check! bytes)
+70
(when (and enabled? (>= (bytevector-length bytes) 21)
+71
(< (bytevector-u8-ref bytes 0) 128))
+72
(let ((tail (bytevector-copy bytes (- (bytevector-length bytes) 16))))
+73
(spike-trace! 'stateless-reset-diagnostic
+74
(list 'known-peer-tokens (length reset-tokens)
+75
'known-token-match (any (lambda (token) (bytes=? token tail)) reset-tokens)
+76
'handling 'diagnostic-only-stack-reset-handling-unsupported)))))
+77
+78
(define (spike-frame! direction frame address now)
+79
(when (and enabled? (memv (quic-frame-type frame) '(24 25 26 27 28 29)))
+80
(let* ((type (quic-frame-type frame))
+81
(details
+82
(case type
+83
((24)
+84
(when (eq? direction 'rx-decoded)
+85
(spike-remember-reset! (frame-ref frame 'token)))
+86
(list 'sequence (frame-ref frame 'sequence)
+87
'retire-prior-to (frame-ref frame 'retire-prior-to)
+88
'cid (hex-prefix (frame-ref frame 'connection-id) 20)))
+89
((25) (list 'sequence (frame-ref frame 'sequence)))
+90
((26 27) (list 'data (hex-prefix (frame-ref frame 'data) 8)))
+91
((28 29)
+92
(list 'error (frame-ref frame 'error)
+93
'trigger (and (= type 28) (frame-ref frame 'frame-type))
+94
'reason-hex-prefix (hex-prefix (frame-ref frame 'reason) 48))))))
+95
(spike-trace! 'frame
+96
(list 'direction direction 'type type 'connection-ms now
+97
'host (and address (guard (exn (else 'opaque-address)) (quic-address-host address)))
+98
'port (and address (guard (exn (else #f)) (quic-address-port address))) 'details details)))))
+99
+100
(define (spike-close! failure peer? silent? idle? now)
+101
(spike-trace! 'connection-close
+102
(list 'connection-ms now 'peer-close peer? 'silent silent? 'idle-expired idle?
+103
'reason
+104
(cond
+105
(idle? 'idle-expiry)
+106
((quic-error? failure) (list 'transport-error (quic-error-code failure)
+107
'reason-hex (hex-prefix (string->utf8 (quic-error-reason failure)) 48)))
+108
((quic-application-error? failure)
+109
(list 'application-error (quic-application-error-code failure)
+110
'reason-hex (hex-prefix (string->utf8 (quic-application-error-reason failure)) 48)))
+111
((quic-frame? failure) (list 'peer-frame (quic-frame-type failure)
+112
'error (frame-ref failure 'error)))
+113
((error-object? failure)
+114
(list 'exception-hex (hex-prefix (string->utf8 (error-object-message failure)) 48)))
+115
(silent? 'explicit-abort)
+116
(else 'other)))))
+117
+118
(spike-trace! 'capabilities
+119
'(limit 8192 tuple-inventory 32 reset-token-inventory 16
+120
stateless-reset-send unsupported stateless-reset-receive diagnostic-token-match-only))))
web/phone.htmlmodified
@@ -123,9 +123,11 @@
123
window.__result = { kind, milliseconds: performance.now() - started,
124
secureContext: isSecureContext, userAgent: navigator.userAgent, ...details };
125
}
−126
function network() {
+126
function network(change) {
127
const hint = { online: navigator.onLine, effectiveType: navigator.connection?.effectiveType ?? 'unknown',
−128
visibility: document.visibilityState };
+128
type: navigator.connection?.type ?? 'unknown', rtt: navigator.connection?.rtt ?? null,
+129
downlink: navigator.connection?.downlink ?? null, saveData: navigator.connection?.saveData ?? null,
+130
visibility: document.visibilityState, source: change?.type ?? 'initial' };
131
element('network').textContent = JSON.stringify(hint);
132
event('browser-network-hint', hint);
133
}
@@ -219,12 +221,18 @@
221
render();
222
}
223
function failed(run, error) {
+224
event('webtransport-error', { attempt: run.attempt, error: errorDetails(error) });
225
if (!usable(run)) return;
226
const detail = `${error.name}: ${error.message}`;
227
if (!run.ready) reportPage('failed', run.started, { name: error.name, message: error.message });
228
finish(run, 'failed', detail);
229
run.transport.close();
230
}
+231
function errorDetails(error) {
+232
return { name: error?.name ?? null, message: String(error?.message ?? error).slice(0, 1024),
+233
source: error?.source ?? null, streamErrorCode: error?.streamErrorCode ?? null,
+234
closeCode: error?.closeCode ?? null, reason: error?.reason ?? null };
+235
}
236
function packet(run, kind) {
237
if (run.pending.size >= 128) { event('ping-skipped', { reason: 'pending limit', channel: kind }); return null; }
238
const id = ++sequence;
@@ -386,7 +394,14 @@
394
element('path-log').textContent = '';
395
state('connecting'); controls(); render();
396
event('connect-attempt', { attempt: run.attempt, url: url.href, hash: hash.toLowerCase(), datagrams: element('datagrams').checked });
−389
transport.closed.then(info => finish(run, 'closed', info), error => failed(run, error));
+397
transport.closed.then(info => {
+398
const detail = { closeCode: info?.closeCode ?? null, reason: info?.reason ?? null };
+399
event('webtransport-closed', { attempt: run.attempt, ...detail });
+400
finish(run, 'closed', detail);
+401
}, error => {
+402
event('webtransport-closed-rejected', { attempt: run.attempt, error: errorDetails(error) });
+403
failed(run, error);
+404
});
405
run.readyTimer = setTimeout(() => failed(run, new Error('Session ready deadline (18 seconds)')), 18000);
406
await transport.ready;
407
if (!usable(run)) return;