fix timeout issue (maybe?)

This commit is contained in:
Schluffe committed 2026-10-16 12:01:43 +02:00
1 parent 95e4a879b9
commit b7f47531b7
7 files changed
+397 -5

No files matched your search

+10
View File
@@ -200,6 +200,13 @@ try {
return { length: bytes.length, valid: bytes.every(b => b === 123) };
});
assert.deepEqual(data, { length: 2 * 1024 * 1024 + 7, valid: true });
await wait(sender, () => window.__hellcon.element<HTMLTextAreaElement>('#connection-diagnostics').value.includes('pairs='));
const diagnostics = await evaluate(sender, () => window.__hellcon.element<HTMLTextAreaElement>('#connection-diagnostics').value);
assert.match(diagnostics, /local code: host=\d+/);
assert.match(diagnostics, /remote code: host=\d+/);
assert.match(diagnostics, /requestsSent=/);
assert.match(diagnostics, /transfer done/);
assert.doesNotMatch(diagnostics, /browser-test\.bin|a=candidate:|a=ice-pwd:|a=fingerprint:|\.local\b/);
console.log('PASS: real two-page WebRTC flow; full fingerprints; no metadata before both confirmations; exact file and receipt.');
console.log('PASS: invalid offers can be replaced; invalid answers can be corrected without losing the live offer.');
await click(sender, 'Reset'); await click(receiver, 'Reset');
@@ -213,6 +220,9 @@ try {
await click(sender, 'Receive');
await wait(receiver, () => window.__hellcon.aborted);
assert.equal(await evaluate(receiver, () => !!document.querySelector('a.download')), false);
await wait(receiver, () => window.__hellcon.element<HTMLTextAreaElement>('#connection-diagnostics').value.includes('pairs='));
assert.match(await evaluate(receiver, () => window.__hellcon.element<HTMLTextAreaElement>('#connection-diagnostics').value), /session failed/);
console.log('PASS: privacy-safe candidate/check diagnostics remain available after completion and failure.');
console.log('PASS: switching away from Send closes the connection and aborts the receiver’s pending disk write.');
await click(sender, 'Send'); await click(receiver, 'Reset');
await connect(sender, receiver, 2048);
+87
View File
@@ -0,0 +1,87 @@
import { createServer } from 'node:http';
import { readFile, mkdtemp, rm } from 'node:fs/promises';
import { execFileSync, spawn } from 'node:child_process';
import { stripTypeScriptTypes } from 'node:module';
import { createSocket } from 'node:dgram';
import { fileURLToPath } from 'node:url';
import { join } from 'node:path';
import { tmpdir } from 'node:os';
// A controlled ICE experiment, not a cross-device transfer test. Reads the
// original signaling helpers from git without checking out or editing files.
const root = fileURLToPath(new URL('..', import.meta.url));
const legacy = execFileSync('git', ['show', 'd198332:src/lib/webrtc.js'], { cwd: root, encoding: 'utf8' });
const current = stripTypeScriptTypes(await readFile(root + '/src/lib/webrtc.ts', 'utf8'));
const validation = stripTypeScriptTypes(await readFile(root + '/src/lib/validation.ts', 'utf8'));
const udp = createSocket('udp4');
await new Promise(resolve => udp.bind(0, '127.0.0.1', resolve));
const stunUrl = process.argv.includes('--slow-stun') ? 'stun:127.0.0.1:' + udp.address().port : null;
const rewritePorts = !process.argv.includes('--normal-candidates');
const browserCode = String.raw`
import * as old from '/old.js';
import * as current from '/current.js';
async function run(mode) {
const api = mode === 'original' ? old : current;
const start = performance.now();
const events = [];
const log = (event) => events.push([Math.round(performance.now()-start),event]);
const {stunUrl,rewritePorts} = await (await fetch('/config')).json();
const a = api.createPeerConnection(mode === 'original' ? stunUrl : {stunUrl});
const b = api.createPeerConnection(mode === 'original' ? stunUrl : {stunUrl});
if(mode !== 'original') { a.setConfiguration(current.iceConfiguration({stunUrl})); b.setConfiguration(current.iceConfiguration({stunUrl})); }
let received = false;
for(const [role,pc] of [['sender',a],['receiver',b]]) {
pc.oniceconnectionstatechange = () => log(role + ' ICE ' + pc.iceConnectionState);
pc.onconnectionstatechange = () => {
log(role + ' PC ' + pc.connectionState);
if(mode === 'current' && pc.connectionState === 'failed') pc.close();
};
}
const dc = a.createDataChannel('file');
dc.onopen = () => { log('sender channel open'); dc.send('exact-file-bytes'); };
b.ondatachannel = e => { e.channel.onmessage = e => { received = e.data === 'exact-file-bytes'; log('receiver bytes '+received); }; };
try {
const offer = await api.createOfferCode(a);
let sdp = api.decodeSignal(offer);
// Deliberately unusable advertised ports: only sender-initiated checks
// after the answer can discover the real sender. No host firewall changes.
if(rewritePorts) sdp = sdp.split('\r\n').filter(l=>!/^a=candidate:.* tcp /i.test(l)).map(l=>{
if(!l.startsWith('a=candidate:'))return l;
const fields=l.split(' '); fields[5]='9'; return fields.join(' ');
}).join('\r\n');
log('offer ready; end-of-candidates='+sdp.includes('a=end-of-candidates'));
const answer = await api.createAnswerCode(b, api.encodeSignal(sdp));
log('answer ready');
await new Promise(r=>setTimeout(r,20000));
log('apply answer');
await api.acceptAnswerCode(a,answer);
await new Promise(r=>setTimeout(r,12000));
return {mode,received,events};
} catch { return {mode,received,events,error:'Signaling failed; raw browser error omitted'}; }
finally {a.close();b.close();}
}
const results = await Promise.all(['original','current','current-keep'].map(run));
await fetch('/result',{method:'POST',body:JSON.stringify(results)});
`;
let done;
const finished = new Promise(resolve=>done=resolve);
const server = createServer(async(req,res)=>{
if(req.url === '/config') { res.setHeader('Content-Type','application/json');res.end(JSON.stringify({stunUrl,rewritePorts}));return; }
if(req.url === '/result') {let body=''; for await(const part of req)body+=part; console.log(body);res.end('ok');done();return;}
res.setHeader('Content-Type',req.url==='/'?'text/html':'text/javascript');
res.end(({'/':'<script type="module" src="/run.js"></script>','/old.js':legacy,'/current.js':current,'/validation.ts':validation,'/run.js':browserCode})[req.url] || '');
});
await new Promise(resolve=>server.listen(0,'127.0.0.1',resolve));
const profile=await mkdtemp(join(tmpdir(), 'hellcon-ice-comparison-'));
const name=process.argv[2] || 'firefox';
const url='http://127.0.0.1:'+server.address().port;
const args=name==='firefox'?['--headless','--no-remote','--profile',profile,url]:['--headless','--no-sandbox','--disable-gpu','--no-first-run','--user-data-dir='+profile,url];
const child=spawn('/usr/bin/'+name,args,{stdio:['ignore','ignore','pipe']});
child.on('error',()=>{console.error('Could not launch browser');process.exitCode=1;done();});
let errors='';child.stderr.on('data',chunk=>errors+=chunk);
const timer=setTimeout(()=>{console.log('Comparison timed out');process.exitCode=1;done();},85000);
try {await finished;} finally {
clearTimeout(timer);child.kill();
if(child.pid && child.exitCode===null && child.signalCode===null) await new Promise(resolve=>child.once('exit',resolve));
server.closeAllConnections();server.close();udp.close();
await rm(profile,{recursive:true,force:true,maxRetries:3});
}