Commit1cebec56Recorded18 Oct 2026Repositorysigil-http3

Integrate configured phone endpoints and authenticated path observations

Changed
 scripts/browser-preflight.mjs                          |  21 ++++++++++++++++++--
 scripts/echo-lifecycle.mjs                             |  19 +++++++++++++-----
 scripts/phantom-browser-preflight.sh                   |   2 +-
 scripts/phantom-lifecycle-check.sh                     |   2 +-
 scripts/phantom-spike-echo-check.sh                    |  94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 test/test-echo-lifecycle.mjs                           |  12 ++++++++++++
 tools/interop/src/sigil/http3/interop/observations.sgl |  47 ++++++++++++++++++++++++++++++++++++++++++++
 tools/interop/src/sigil/http3/interop/preflight.sgl    | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
 tools/interop/test/test-observations.sgl               |  33 +++++++++++++++++++++++++++++++
 9 files changed, 336 insertions(+), 40 deletions(-)
Diff
scripts/browser-preflight.mjsmodified
@@ -14,6 +14,8 @@ const certificate = JSON.parse(readFileSync(join(directory, 'certificate.json'),
14
const abort = new AbortController();
15
const httpsPage = process.env.HTTP3_PREFLIGHT_HTTPS_PAGE === '1';
16
const queryTarget = process.env.HTTP3_PREFLIGHT_QUERY === '1';
+17
const bindAddress = process.env.HTTP3_PREFLIGHT_HOST ?? '127.0.0.1';
+18
const authorityHost = bindAddress.includes(':') ? `[${bindAddress}]` : bindAddress;
19
const deadline = setTimeout(() => abort.abort(new Error('Browser preflight overall deadline')), httpsPage ? 60000 : 45000);
20
process.once('SIGTERM', () => abort.abort(new Error('Preflight received SIGTERM')));
21
process.once('SIGINT', () => abort.abort(new Error('Preflight received SIGINT')));
@@ -144,6 +146,7 @@ const receipt = { schema: 1, mode: requireEcho ? 'webtransport-echo' : 'capabili
146
chromePath, certificate: { ...certificate, bytes: undefined }, candidateProfile,
147
sourceRevision: execFileSync('git', ['rev-parse', 'HEAD'], { encoding: 'utf8' }).trim(),
148
quicRevision: readFileSync('quic.rev', 'utf8').trim(),
+149
spikeSdkRevision: process.env.HTTP3_SPIKE_SDK_JOB ? readFileSync('spike-sdk.rev', 'utf8').trim() : undefined,
150
binarySha256: createHash('sha256').update(readFileSync(binary)).digest('hex'),
151
certificateSha256: certificate.sha256, ready: false,
152
bidirectionalEcho: false, unidirectionalEcho: false, datagramEcho: false,
@@ -188,12 +191,12 @@ try {
191
};
192
const port = await startProbe(0);
193
receipt.udpPort = port;
−191
const url = `https://127.0.0.1:${port}/echo`;
+194
const url = `https://${authorityHost}:${port}/echo`;
195
browser = launch(chromePath, [
196
'--headless=new', '--no-sandbox', '--disable-gpu', '--no-first-run', '--no-default-browser-check',
197
'--disable-background-networking', '--disable-breakpad', '--disable-crash-reporter',
198
'--remote-debugging-pipe', `--user-data-dir=${join(directory, 'profile')}`, '--enable-quic',
−196
`--origin-to-force-quic-on=127.0.0.1:${port}`, `--log-net-log=${join(directory, 'netlog.json')}`,
+199
`--origin-to-force-quic-on=${authorityHost}:${port}`, `--log-net-log=${join(directory, 'netlog.json')}`,
200
'--net-log-capture-mode=Default',
201
], { stdio: ['ignore', 'ignore', 'pipe', 'pipe', 'pipe'] });
202
browserError = capture(browser.child.stderr);
@@ -268,6 +271,20 @@ try {
271
throw new Error('Real echo samples are missing from the live RTT graph');
272
if (!receipt.echo.serverObservations)
273
throw new Error('Real server observation channel did not deliver its status');
+274
if (process.env.HTTP3_SPIKE_SDK_JOB) {
+275
const contract = serverOutput().split('\n').find(line => line.startsWith('HTTP3-SERVER-CONTRACT ')) ?? '';
+276
const observed = receipt.echo.serverObservations;
+277
if (!serverOutput().includes('HTTP3-PEER ') || !observed.includes('"status":"available"') ||
+278
!observed.includes('"type":"peer"') || !observed.includes('"localCid":') || !observed.includes('"peerCid":'))
+279
throw new Error('Configured endpoint did not deliver actual peer/CID observations');
+280
// These flags combine actual echo/peer evidence with the reviewed driver
+281
// contract. They assert logging support, not that migration occurred.
+282
Object.assign(receipt.server, { configurableBind: contract.includes('configurable-bind=true'),
+283
antiAmplification: contract.includes('anti-amplification=true'),
+284
boundedAdmission: contract.includes('admissions=8') && contract.includes('step-delay-ms=10'),
+285
peerAddressLogging: true, pathChangeLogging: serverOutput().includes('path-events=available') });
+286
receipt.pathChangeObserved = serverOutput().includes('HTTP3-PATH-CHANGE ');
+287
}
288
receipt.profile = candidateProfile;
289
const { cssContentSize } = await cdp('Page.getLayoutMetrics', {}, sessionId);
290
const screenshot = await cdp('Page.captureScreenshot', { format: 'png', captureBeyondViewport: true,
scripts/echo-lifecycle.mjsmodified
@@ -43,14 +43,22 @@ export function inspectPlan(configPath) {
43
for (const name of ['binary', 'certificateDirectory', 'runDirectory', 'interopReceipt']) {
44
check(typeof config[name] === 'string' && isAbsolute(config[name]), `${name} must be an absolute path`);
45
}
−46
check(isIP(config.bindAddress) === 4, 'Choose an explicit IPv4 bind address');
+46
const family = isIP(config.bindAddress);
+47
check(family !== 0, 'Choose an explicit numeric bind address');
+48
const scope = config.scope ?? 'test-loopback';
+49
check((scope === 'test-loopback' && ['127.0.0.1', '::1'].includes(config.bindAddress)) ||
+50
(scope === 'vpn' && config.bindAddress === (process.env.HTTP3_IPV4_ADDRESS ?? '127.0.0.1')) ||
+51
(scope === 'ipv6-direct' && family === 6 && /^[23][0-9a-f]{0,3}:/i.test(config.bindAddress) &&
+52
!config.bindAddress.includes('%')), 'Bind address exceeds the configured run scope');
53
check(Number.isInteger(config.port) && config.port >= 1024 && config.port <= 65535, 'Choose an unprivileged UDP port');
−48
check(Number.isInteger(config.lifetimeSeconds) && config.lifetimeSeconds >= 1 && config.lifetimeSeconds <= 900,
−49
'Test lifetime must be between 1 and 900 seconds');
+54
check(Number.isInteger(config.lifetimeSeconds) && config.lifetimeSeconds >= 1 && config.lifetimeSeconds <= 7200,
+55
'Test lifetime must be between 1 and 7200 seconds');
56
const authority = new URL(`https://${config.authority}`);
57
check(authority.host === config.authority && authority.pathname === '/' && !authority.search && !authority.hash &&
58
!authority.username && !authority.password, 'Invalid exact echo authority');
−53
check(Array.isArray(config.origins) && config.origins.length >= 1 && config.origins.length <= 4 &&
+59
const expectedAuthority = family === 6 ? `[${config.bindAddress}]:${config.port}` : `${config.bindAddress}:${config.port}`;
+60
check(authority.href === new URL(`https://${expectedAuthority}`).href, 'Echo authority must name the admitted bind and port');
+61
check(Array.isArray(config.origins) && config.origins.length === 1 &&
62
config.origins.every(origin => {
63
if (origin === 'null') return true; // Explicit local-file page policy.
64
const url = new URL(origin);
@@ -148,7 +156,8 @@ export async function runTest(configPath) {
156
child = spawn(config.binary, [], { cwd: config.runDirectory, shell: false, env: { ...process.env,
157
HTTP3_TEST_ID: config.testId, HTTP3_BIND_ADDRESS: config.bindAddress, HTTP3_PORT: String(config.port),
158
HTTP3_LIFETIME_SECONDS: String(config.lifetimeSeconds), HTTP3_CERTIFICATE_DIR: config.certificateDirectory,
−151
HTTP3_AUTHORITY: config.authority, HTTP3_ORIGINS: JSON.stringify(config.origins), HTTP3_READY_FILE: readyPath },
+159
HTTP3_AUTHORITY: config.authority, HTTP3_ORIGINS: JSON.stringify(config.origins), HTTP3_ORIGIN: config.origins[0],
+160
HTTP3_CERTIFICATE_SHA256: plan.certificateSha256, HTTP3_READY_FILE: readyPath },
161
stdio: ['ignore', 'pipe', 'pipe'] });
162
done = new Promise(resolveDone => {
163
child.once('error', error => { childError = error; });
scripts/phantom-browser-preflight.shmodified
@@ -35,7 +35,7 @@ chmod 600 build/browser/key.pem
35
timeout --foreground 180 "${openssl_command[@]}" req \
36
-new -x509 -key build/browser/key.pem -out build/browser/cert.pem \
37
-days 13 -sha256 -subj /CN=localhost \
−38
-addext subjectAltName=IP:127.0.0.1,DNS:localhost
+38
-addext "subjectAltName=${HTTP3_PREFLIGHT_SAN:-IP:127.0.0.1,DNS:localhost}"
39
node scripts/prepare-certificate.mjs "$PWD/build/browser"
40
if [ "${HTTP3_PREFLIGHT_PREBUILT:-0}" = 1 ]; then
41
test -x tools/interop/build/native/bin/http3-preflight
scripts/phantom-lifecycle-check.shmodified
@@ -9,7 +9,7 @@ record_result() {
9
}
10
trap record_result EXIT
11
printf 'RESULT lifecycle-fixture=socket-free-not-interop page-host=loopback-https-only\n' | tee "$lifecycle_result"
−12
bash scripts/prepare-quic.sh
+12
if [ ! -e .deps/sigil-quic ]; then bash scripts/prepare-quic.sh; fi
13
test "$(git -C .deps/sigil-quic rev-parse HEAD)" = "$(cat quic.rev)"
14
openssl_command=(openssl)
15
if ! command -v openssl >/dev/null; then
scripts/phantom-spike-echo-check.shadded
@@ -0,0 +1,94 @@
+1
#!/usr/bin/env bash
+2
# Build and validate with an explicitly supplied socket-capable SDK.
+3
set -euo pipefail
+4
cd "$(dirname "$0")/.."
+5
umask 077
+6
source_root="$PWD"
+7
results="$PWD/build/spike-echo"
+8
workspace="$PWD/build/spike-native-workspace"
+9
mkdir -p "$results" "$workspace" .deps
+10
record_result() {
+11
local job_rc=$?
+12
printf 'RESULT spike-echo rc=%s\n' "$job_rc" | tee -a "$results/result.txt"
+13
}
+14
trap record_result EXIT
+15
printf 'RESULT scope=spike-only-local-sdk no-phone-window\n' | tee "$results/result.txt"
+16
test -n "${HTTP3_SPIKE_SDK_SOURCE:-}"
+17
sdk_source="${HTTP3_SPIKE_SDK_SOURCE:?Set HTTP3_SPIKE_SDK_SOURCE}"
+18
test "$(git -C "$sdk_source" rev-parse HEAD)" = "$(cat spike-sdk.rev)"
+19
test -z "$(git -C "$sdk_source" status --porcelain)"
+20
test -x "$sdk_source/build/boot/bin/sigil"
+21
git -C "$sdk_source" rev-parse HEAD HEAD^{tree} > "$results/sdk-revision.txt"
+22
sha256sum "$sdk_source/build/boot/bin/sigil" "$sdk_source/packages/sigil-lib/src/socket.c" \
+23
"$sdk_source/packages/sigil-stdlib/src/sigil/socket.sgl" > "$results/sdk-inputs.sha256"
+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
export SIGIL_JOBS=1
+28
unset SIGIL_REDIRECTS SIGIL_LIB SIGIL_LIB_PATH
+29
HTTP3_SDK_SOURCE="$sdk_source" node --input-type=module <<'WORKSPACE'
+30
import { writeFileSync } from 'node:fs';
+31
import { resolve } from 'node:path';
+32
const sdk = process.env.HTTP3_SDK_SOURCE;
+33
const members = ['sigil-lib', 'sigil-stdlib', 'sigil-test'].map(name => `${sdk}/packages/${name}`);
+34
members.push(resolve('.deps/sigil-quic'), resolve('.deps/sigil-nat'), resolve('.'), resolve('tools/interop'));
+35
writeFileSync('build/spike-native-workspace/package.sgl', `;; SPIKE ONLY: no product dependency locks or released pins are changed.
+36
(workspace
+37
name: "http3-spike-local-sdk"
+38
version: "0.22.17"
+39
packages: (list ${members.map(path => JSON.stringify(path)).join('\n ')})
+40
configs: (list
+41
(config name: 'native backend: 'native debug?: #f optimize: 2
+42
bundle?: #t output-dir: "build/native")))
+43
`);
+44
const sources = ['preflight', 'observations'].map(name => resolve(`tools/interop/src/sigil/http3/interop/${name}.sgl`));
+45
writeFileSync('build/spike-echo/read-source.sgl', `(import (sigil io))
+46
(for-each
+47
(lambda (path)
+48
(call-with-input-file path
+49
(lambda (port)
+50
(let loop ((count 0))
+51
(let ((form (read port)))
+52
(if (eof-object? form)
+53
(unless (= count 1) (error "Expected one library form" path))
+54
(loop (+ count 1))))))))
+55
(list ${sources.map(path => JSON.stringify(path)).join(' ')}))
+56
(println "RESULT spike-source-reader=PASS")
+57
`);
+58
WORKSPACE
+59
cp "$workspace/package.sgl" "$results/workspace-package.sgl"
+60
timeout --foreground 30 "$sdk_source/build/boot/bin/sigil" -L "$sdk_source/build/boot/lib" \
+61
boot-eval "(load \"$results/read-source.sgl\")" > "$results/source-reader.log" 2>&1
+62
builder=${SIGIL_BUILDER:-sigil}
+63
"$builder" --version > "$results/builder-version.txt"
+64
(cd "$workspace" && timeout --foreground 300 "$builder" deps install) > "$results/deps.log" 2>&1
+65
for package in sigil-lib sigil-stdlib sigil-test; do
+66
actual=$(readlink -f "$workspace/.sigil/deps/$package")
+67
test "$actual" = "$sdk_source/packages/$package"
+68
printf '%s %s\n' "$package" "$actual"
+69
done > "$results/local-dependency-paths.txt"
+70
cp "$workspace/.sigil/deps.index" "$results/deps.index"
+71
(cd "$workspace" && timeout --foreground 600 "$builder" test \
+72
"$source_root"/test/*.sgl "$source_root"/tools/interop/test/*.sgl) > "$results/tests.log" 2>&1
+73
(cd "$workspace" && timeout --foreground 600 "$builder" build sigil-http3-interop --config native) \
+74
> "$results/native-build.log" 2>&1
+75
mkdir -p tools/interop/build/native/bin
+76
cp "$workspace/build/native/bin/http3-preflight" tools/interop/build/native/bin/http3-preflight
+77
sha256sum tools/interop/build/native/bin/http3-preflight > "$results/binary.sha256"
+78
+79
# Keep assigned interfaces private; emit no literal address to the diagnostic output.
+80
ip_tool=$(command -v ip || true)
+81
if [ -z "$ip_tool" ]; then ip_tool=/run/current-system/profile/sbin/ip; fi
+82
"$ip_tool" -4 -o addr show > "$results/interfaces-v4.txt"
+83
"$ip_tool" -6 -o addr show scope global > "$results/interfaces-v6.txt"
+84
global_ipv6=$(awk '$4 ~ /^[23]/ && $0 !~ /tentative|deprecated|dadfailed/ {sub(/\/.*/, "", $4); print $4; exit}' "$results/interfaces-v6.txt")
+85
test -n "$global_ipv6"
+86
export HTTP3_PREFLIGHT_SAN="IP:127.0.0.1,IP:::1,IP:${HTTP3_IPV4_ADDRESS:-127.0.0.1},IP:$global_ipv6,DNS:localhost"
+87
export HTTP3_PREFLIGHT_PREBUILT=1 HTTP3_PREFLIGHT_HTTPS_PAGE=1 HTTP3_PREFLIGHT_QUERY=1
+88
HTTP3_PREFLIGHT_HOST=127.0.0.1 bash scripts/phantom-browser-preflight.sh
+89
mv build/browser build/browser-ipv4
+90
HTTP3_PREFLIGHT_HOST=::1 bash scripts/phantom-browser-preflight.sh
+91
bash scripts/phantom-lifecycle-check.sh
+92
git -C "$sdk_source" diff --exit-code > "$results/sdk-source-after.diff"
+93
git diff --exit-code -- sigil.lock tools/interop/sigil.lock > "$results/product-locks-after.diff"
+94
printf 'RESULT spike-echo-native-v4-v6-and-lifecycle=PASS\n' | tee -a "$results/result.txt"
test/test-echo-lifecycle.mjsmodified
@@ -92,6 +92,18 @@ test('plan is read-only and rejects capability-only or unproved admission', () =
92
const f = fixture();
93
assert.equal(inspectPlan(f.path).ready, true);
94
assert.equal(existsSync(f.config.runDirectory), false);
+95
f.config.lifetimeSeconds = 7200; f.save();
+96
assert.equal(inspectPlan(f.path).ready, true, 'A two-hour plan remains read-only');
+97
f.config.lifetimeSeconds = 7201; f.save();
+98
assert.throws(() => inspectPlan(f.path), /7200/);
+99
f.config.lifetimeSeconds = 2;
+100
f.config.bindAddress = '0.0.0.0'; f.save();
+101
assert.throws(() => inspectPlan(f.path), /configured run scope/);
+102
f.config.bindAddress = '::1'; f.config.authority = '[::1]:54433'; f.save();
+103
assert.equal(inspectPlan(f.path).ready, true);
+104
f.config.authority = '[::1]:54435'; f.save();
+105
assert.throws(() => inspectPlan(f.path), /admitted bind and port/);
+106
f.config.bindAddress = '127.0.0.1'; f.config.authority = '127.0.0.1:54433'; f.save();
107
f.receipt.mode = 'capability-preflight'; f.save();
108
assert.equal(inspectPlan(f.path).ready, false);
109
f.receipt.mode = 'webtransport-echo'; f.receipt.server.retry = false; f.save();
tools/interop/src/sigil/http3/interop/observations.sgladded
@@ -0,0 +1,47 @@
+1
;;; Bounded, ASCII-only server observations for the private phone test.
+2
(define-library (sigil http3 interop observations)
+3
(import (sigil quic address))
+4
(export interop-peer-text interop-json-token interop-observation-json)
+5
(begin
+6
(define (interop-peer-text address)
+7
(if (not address)
+8
"none"
+9
(let ((host (quic-address-host address)))
+10
(string-append
+11
(if (eq? (quic-address-family address) 'ipv6)
+12
(string-append "[" host "]")
+13
host)
+14
":" (number->string (quic-address-port address))))))
+15
+16
;; Inputs are internal numeric peers, hex CIDs, fixed labels and UTC time.
+17
;; Reject an unexpected string instead of inserting unescaped JSON text.
+18
(define (interop-json-token text)
+19
(unless (and (string? text) (<= (string-length text) 256)
+20
(every
+21
(lambda (character)
+22
(and (<= 32 (char->integer character) 126)
+23
(not (memv character '(#\" #\\)))))
+24
(string->list text)))
+25
(error "Invalid bounded observation token"))
+26
(string-append "\"" text "\""))
+27
+28
(define (interop-observation-json type sequence timestamp fields)
+29
(unless (and (member type '("observation" "peer" "path-change" "path-validated" "path-rejected" "cid-change"))
+30
(integer? sequence) (exact? sequence) (<= 0 sequence 4095)
+31
(list? fields) (<= (length fields) 8)
+32
(every
+33
(lambda (field)
+34
(and (pair? field)
+35
(member (car field) '("peer" "before" "after" "localCid" "peerCid" "status" "detail"))))
+36
fields))
+37
(error "Invalid observation envelope"))
+38
(apply string-append
+39
(append
+40
(list "{\"type\":" (interop-json-token type)
+41
",\"seq\":" (number->string sequence)
+42
",\"serverTime\":" (interop-json-token timestamp))
+43
(map
+44
(lambda (field)
+45
(string-append "," (interop-json-token (car field)) ":" (interop-json-token (cdr field))))
+46
fields)
+47
(list "}"))))))
tools/interop/src/sigil/http3/interop/preflight.sglmodified
@@ -1,5 +1,5 @@
−1
;;; Bounded loopback browser echo probe. Public/phone listener policy remains
−2
;;; separate; the upstream endpoint still pins its peer address and port.
+1
;;; Echo-only browser/phone driver. Deployment scope and owned-PID lifecycle
+2
;;; belong to the supervisor; this process bounds its own sockets and work.
3
(define-library (sigil http3 interop preflight)
4
(import (sigil io)
5
(sigil fs)
@@ -16,7 +16,8 @@
16
(sigil http3 transport streams)
17
(sigil http3 webtransport wire)
18
(sigil http3 interop echo)
−19
(sigil http3 interop profile))
+19
(sigil http3 interop profile)
+20
(sigil http3 interop observations))
21
(export main)
22
(begin
23
(define (required name)
@@ -46,33 +47,88 @@
47
(bytevector-u8-set! header 1 (modulo size 256))
48
(bytes-append header bytes)))
49
−49
(define (main . arguments)
−50
(let* ((directory (required "HTTP3_PREFLIGHT_DIR"))
−51
(page-origin (required "HTTP3_PREFLIGHT_ORIGIN"))
+50
(define (environment-number name fallback minimum maximum)
+51
(let* ((text (getenv name))
+52
(value (if text (string->number text) fallback)))
+53
(unless (and (integer? value) (exact? value) (<= minimum value maximum))
+54
(error "Invalid bounded HTTP/3 numeric environment" name))
+55
value))
+56
+57
(define (run-listener remaining run-deadline)
+58
(let* ((live? (and (getenv "HTTP3_TEST_ID") #t))
+59
(directory (or (getenv "HTTP3_CERTIFICATE_DIR") (required "HTTP3_PREFLIGHT_DIR")))
+60
(page-origin (or (getenv "HTTP3_ORIGIN") (required "HTTP3_PREFLIGHT_ORIGIN")))
+61
(host (or (getenv "HTTP3_BIND_ADDRESS") (getenv "HTTP3_PREFLIGHT_HOST") "127.0.0.1"))
+62
(lifetime (if live? (environment-number "HTTP3_LIFETIME_SECONDS" 0 1 7200) 25))
+63
(requested-port (if live?
+64
(environment-number "HTTP3_PORT" 0 1024 65535)
+65
(environment-number "HTTP3_PREFLIGHT_PORT" 0 0 65535)))
66
(certificate (read-bounded (string-append directory "/cert.der") 65536))
67
(private (read-bounded (string-append directory "/private.raw") 32))
68
(endpoint
−55
(open-quic-endpoint
−56
port: (let ((port (getenv "HTTP3_PREFLIGHT_PORT")))
−57
(if port (string->number port) 0))))
+69
(open-quic-endpoint host: host port: requested-port))
+70
(authority (or (getenv "HTTP3_AUTHORITY") (getenv "HTTP3_PREFLIGHT_AUTHORITY")
+71
(string-append
+72
(if (eq? (quic-endpoint-family endpoint) 'ipv6)
+73
(string-append "[" (quic-endpoint-host endpoint) "]")
+74
(quic-endpoint-host endpoint))
+75
":" (number->string (quic-endpoint-port endpoint)))))
76
(adapter #f)
77
(echo #f)
78
(authenticated? #f)
79
(local-cid #f)
80
(peer-cid #f)
+81
(peer #f)
+82
(admissions 0)
+83
(observation-output #f)
+84
(observation-sequence 0)
85
(origin (current-jiffy))
−64
(deadline (+ origin (* 25 (jiffies-per-second)))))
+86
(deadline (or run-deadline (+ origin (* lifetime (jiffies-per-second))))))
87
(define (timestamp)
88
(let ((now (current-second)))
89
(string-append (format-date now #t) "T" (format-time now #t)
90
"Z elapsed-ms="
91
(number->string
92
(quotient (* 1000 (- (current-jiffy) origin)) (jiffies-per-second))))))
+93
(define (current-peer)
+94
(interop-peer-text (quic-endpoint-peer-address endpoint)))
+95
(define (observe type fields)
+96
(when (and observation-output (< observation-sequence 4096)
+97
adapter (not (quic-closed? (quic-endpoint-connection endpoint))))
+98
(h3-server-send! adapter observation-output
+99
(observation-frame
+100
(interop-observation-json type observation-sequence (timestamp) fields)))
+101
(set! observation-sequence (+ observation-sequence 1))))
+102
(define (path-observations connection)
+103
(for-each
+104
(lambda (event)
+105
(let ((kind (vector-ref event 0))
+106
(address (interop-peer-text (vector-ref event 1)))
+107
(reason (symbol->string (vector-ref event 2))))
+108
(println "HTTP3-PATH-EVENT time=~a kind=~a peer=~a reason=~a"
+109
(timestamp) kind address reason)
+110
(case kind
+111
((path-validated)
+112
(observe "path-validated" (list (cons "peer" address) (cons "detail" reason))))
+113
((path-failed)
+114
(observe "path-rejected" (list (cons "peer" address) (cons "detail" reason)))))))
+115
(quic-endpoint-take-path-events! endpoint))
+116
(let ((next-peer (current-peer)))
+117
(unless (equal? peer next-peer)
+118
(println "HTTP3-PATH-CHANGE time=~a before=~a after=~a"
+119
(timestamp) peer next-peer)
+120
(observe "path-change" (list (cons "before" peer) (cons "after" next-peer)))
+121
(set! peer next-peer))))
122
(dynamic-wind
123
(lambda () #t)
124
(lambda ()
125
(quic-endpoint-accept-retry! endpoint
126
(lambda (original source retry)
+127
(set! admissions (+ admissions 1))
+128
(when (> admissions 8) (error "Echo Retry admission budget exceeded"))
+129
(set! authenticated? #f)
+130
(set! observation-output #f)
+131
(set! observation-sequence 0)
132
(println "HTTP3-RETRY-VALIDATED time=~a original-cid=~a client-cid=~a retry-cid=~a"
133
(timestamp) (hex-bytes original) (hex-bytes source) (hex-bytes retry))
134
(let* ((streams (make-server-streams))
@@ -101,7 +157,7 @@
157
(interop-echo-input! echo id bytes eof?))))
158
(set! echo
159
(make-interop-echo
−104
authority: (string-append "127.0.0.1:" (number->string (quic-endpoint-port endpoint)))
+160
authority: authority
161
origins: (list page-origin)
162
send-stream: (lambda (id bytes fin?) (h3-server-send! adapter id bytes fin?: fin?))
163
open-uni: (lambda () (h3-server-open-uni! adapter))
@@ -116,48 +172,66 @@
172
(lambda (event)
173
(println "HTTP3-ECHO time=~a event=~a" (timestamp) event)
174
(when (eq? (vector-ref event 0) 'session-open)
−119
(let ((output (h3-server-open-uni! adapter)))
−120
(if output
−121
(h3-server-send! adapter output
+175
(set! observation-output (h3-server-open-uni! adapter))
+176
(if observation-output
+177
(begin
+178
(h3-server-send! adapter observation-output
179
(bytes-append
180
(encode-webtransport-prefix (vector-ref event 1) #t)
−124
#u8(83 71 69 49)
−125
(observation-frame
−126
(string-append
−127
"{\"type\":\"observation\",\"seq\":0,\"serverTime\":\"" (timestamp)
−128
"\",\"status\":\"unavailable\",\"detail\":\"fixed-loopback\"}"))))
−129
(println "HTTP3-OBSERVATION-UNAVAILABLE time=~a reason=no-uni-credit"
−130
(timestamp))))))))
+181
#u8(83 71 69 49)))
+182
(observe "observation" (list (cons "status" "available")))
+183
(observe "peer"
+184
(list (cons "peer" (current-peer))
+185
(cons "localCid" (hex-bytes (quic-local-id connection)))
+186
(cons "peerCid" (hex-bytes (quic-peer-id connection))))))
+187
(println "HTTP3-OBSERVATION-UNAVAILABLE time=~a reason=no-uni-credit"
+188
(timestamp)))))))
189
connection)))
−132
(call-with-output-file (string-append directory "/port")
−133
(lambda (output) (display (quic-endpoint-port endpoint) output)))
−134
(println "HTTP3-READY time=~a address=127.0.0.1 port=~a"
−135
(timestamp) (quic-endpoint-port endpoint))
−136
(println "HTTP3-OBSERVABILITY path-changes=unavailable endpoint=fixed-loopback cid-values=hex")
+190
(if live?
+191
(let* ((path (required "HTTP3_READY_FILE"))
+192
(temporary (string-append path ".next")))
+193
(write-file-string temporary
+194
(string-append "{\"testId\":" (interop-json-token (required "HTTP3_TEST_ID"))
+195
",\"bindAddress\":" (interop-json-token (quic-endpoint-host endpoint))
+196
",\"port\":" (number->string (quic-endpoint-port endpoint))
+197
",\"certificateSha256\":" (interop-json-token (required "HTTP3_CERTIFICATE_SHA256"))
+198
",\"retry\":true,\"antiAmplification\":true}"))
+199
(rename-file temporary path))
+200
(call-with-output-file (string-append directory "/port")
+201
(lambda (output) (display (quic-endpoint-port endpoint) output))))
+202
(println "HTTP3-READY time=~a address=~a port=~a"
+203
(timestamp) (quic-endpoint-host endpoint) (quic-endpoint-port endpoint))
+204
(println "HTTP3-OBSERVABILITY peer=actual path-events=available cid-values=hex")
+205
(println "HTTP3-SERVER-CONTRACT configurable-bind=true retry=true anti-amplification=true admissions=8 step-delay-ms=10 echo-only=true")
206
(println "HTTP3-CAPABILITY candidate=draft02 webtransport-setting=727725890 h3-datagram=51 max-datagram-frame-size=1100 retry=required")
207
(flush-output-port (current-output-port))
208
(let loop ()
209
(when (and (< (current-jiffy) deadline) (not (quic-endpoint-closed? endpoint)))
−141
(quic-endpoint-step! endpoint wait-ms: 5)
−142
(when adapter
+210
(quic-endpoint-step! endpoint wait-ms: 0)
+211
(when (and adapter (quic-endpoint-connection endpoint))
212
(let ((connection (quic-endpoint-connection endpoint)))
213
(when (and (quic-complete? connection) (not authenticated?))
214
(set! authenticated? #t)
215
(set! local-cid (hex-bytes (quic-local-id connection)))
216
(set! peer-cid (hex-bytes (quic-peer-id connection)))
+217
(set! peer (current-peer))
+218
(println "HTTP3-PEER time=~a peer=~a" (timestamp) peer)
219
(println "HTTP3-AUTHENTICATED time=~a alpn=~a local-cid=~a peer-cid=~a"
220
(timestamp) (hex-bytes (quic-negotiated-alpn connection))
221
local-cid peer-cid)
222
(println "HTTP3-PEER-PARAMETERS time=~a values=~a"
223
(timestamp) (quic-peer-parameters connection)))
−153
(when authenticated?
+224
(when (and authenticated? (not (quic-closed? connection)))
+225
(path-observations connection)
226
(let ((new-local (hex-bytes (quic-local-id connection)))
227
(new-peer (hex-bytes (quic-peer-id connection))))
228
(unless (and (equal? local-cid new-local) (equal? peer-cid new-peer))
229
(println "HTTP3-CID-CHANGE time=~a local-before=~a local-after=~a peer-before=~a peer-after=~a"
230
(timestamp) local-cid new-local peer-cid new-peer)
231
(set! local-cid new-local)
−160
(set! peer-cid new-peer))))
+232
(set! peer-cid new-peer)
+233
(observe "cid-change"
+234
(list (cons "localCid" new-local) (cons "peerCid" new-peer))))))
235
(unless (quic-closed? connection)
236
(guard (exn
237
((h3-error? exn)
@@ -175,10 +249,20 @@
249
(drain (- remaining 1)))))))
250
(unless (quic-closed? connection) (h3-server-step! adapter)))))
251
(flush-output-port (current-output-port))
+252
;; Bound receive/Retry work even while UDP stays readable.
+253
(sleep 0.01)
254
(loop)))
255
(println "HTTP3-PREFLIGHT-END time=~a authenticated=~a failure=~a"
256
(timestamp) authenticated? (quic-endpoint-failure endpoint)))
257
(lambda ()
258
(quic-endpoint-close! endpoint)
259
(do ((index 0 (+ index 1))) ((= index (bytevector-length private)))
−184
(bytevector-u8-set! private index 0))))))))
+260
(bytevector-u8-set! private index 0))))
+261
;; A manual reconnect gets a fresh connection on the same admitted port.
+262
;; The original monotonic deadline survives every reopen.
+263
(when (and live? (> remaining 1) (< (current-jiffy) deadline))
+264
(sleep 0.2)
+265
(run-listener (- remaining 1) deadline))))
+266
+267
(define (main . arguments)
+268
(run-listener 8 #f))))
tools/interop/test/test-observations.sgladded
@@ -0,0 +1,33 @@
+1
(import (sigil test)
+2
(sigil quic address)
+3
(sigil http3 interop observations))
+4
+5
(test-group "Phone server observations"
+6
(test "actual endpoint tuples preserve IPv4 and bracket IPv6"
+7
(assert-equal "127.0.0.1:51000" (interop-peer-text (quic-address "127.0.0.1" 51000)))
+8
(assert-equal "[::1]:52000" (interop-peer-text (quic-address "::1" 52000))))
+9
+10
(test "path records preserve distinct before and after tuples"
+11
(assert-equal
+12
"{\"type\":\"path-change\",\"seq\":3,\"serverTime\":\"2026-10-18T20:00:00Z\",\"before\":\"[::1]:51000\",\"after\":\"[::1]:52000\"}"
+13
(interop-observation-json "path-change" 3 "2026-10-18T20:00:00Z"
+14
'(("before" . "[::1]:51000") ("after" . "[::1]:52000")))))
+15
+16
(test "unexpected control characters and JSON syntax never enter tokens"
+17
(for-each
+18
(lambda (text)
+19
(assert-true
+20
(guard (exn (else #t))
+21
(interop-json-token text)
+22
#f)))
+23
(list "bad\npeer" "bad\"peer" "bad\\peer" (make-string 257 #\a))))
+24
+25
(test "envelope rejects exhausted sequence numbers and unknown fields"
+26
(assert-true
+27
(guard (exn (else #t))
+28
(interop-observation-json "peer" 4096 "UTC" '(("peer" . "[::1]:51000")))
+29
#f))
+30
(assert-true
+31
(guard (exn (else #t))
+32
(interop-observation-json "peer" 0 "UTC" '(("unexpected" . "value")))
+33
#f))))