AtlatestRepositorysigil-http3

sigil-http3 / tree / scriptsprepare-continuous-punch.mjs

1// Apply after the trace patch, exclusively to the isolated Linux job tree.
2import { createHash } from 'node:crypto';
3import { readFileSync, writeFileSync, copyFileSync } from 'node:fs';
4import { hostname } from 'node:os';
5const manifest = [];
6function replace(path, before, after) {
7 const source = readFileSync(path, 'utf8');
8 if (source.split(before).length !== 2) throw new Error('Punch patch anchor mismatch: ' + path);
9 const output = source.replace(before, after);
10 const hash = value => createHash('sha256').update(value).digest('hex');
11 manifest.push({ path, before: hash(source), after: hash(output) });
12 writeFileSync(path, output);
14const endpoint = '.deps/sigil-quic/src/sigil/quic/endpoint.sgl';
15replace(endpoint, ' quic-endpoint-step!\n', ' quic-endpoint-step! quic-spike-punch-send!\n');
16replace(endpoint, ' (define (endpoint-now endpoint)', ` ;; Spike-only: send through the endpoint's sole existing listening socket.
17 (define (quic-spike-punch-send! endpoint host port bytes)
18 (unless (and (quic-endpoint? endpoint) (not (quic-endpoint-closed? endpoint))
19 (eq? (quic-endpoint-family endpoint) 'ipv6)
20 (memv port '(40000 40001 40002))
21 (bytevector? bytes) (= (bytevector-length bytes) 8))
22 (error "Invalid spike-only priming send"))
23 (udp-send (quic-endpoint-socket endpoint) bytes host port))
25 (define (endpoint-now endpoint)`);
26const driver = 'tools/interop/src/sigil/http3/interop/preflight.sgl';
27replace(driver, ' (sigil http3 interop observations))',
28 ' (sigil http3 interop observations)\n (sigil http3 interop punch))');
29replace(driver, ' (quic-endpoint-step! endpoint wait-ms: 0)',
30 ' (quic-endpoint-step! endpoint wait-ms: 0)\n (spike-punch-step! endpoint)');
31copyFileSync('tools/trace/punch.sgl', 'tools/interop/src/sigil/http3/interop/punch.sgl');
32writeFileSync('build/spike-echo/punch-manifest.json', JSON.stringify({ scope: 'spike-only', manifest }, null, 2) + '\n');
33console.log('RESULT same-listening-socket-punch-patch=APPLIED max-seconds=180 interval-ms=1000');