Add experimental tracker reconnect for paired devices

During a session authenticated by both device identities, one person
proposes a WebTorrent tracker and the other confirms it. Both contribute
a nonce over the data channel; HKDF binds both device keys, the session
fingerprints and the tracker URL into a non-extractable base key stored
with the connection. Forget device, a replaced paired device and Turn
off reconnect clear it.

Reconnect joins a daily swarm derived from that key. Offers, answers and
codeless wakes travel as AES-GCM envelopes bound to the tracker routing
fields. The lower device key offers; the other device wakes it when it
arrives second. Retries are spaced and capped, one attempt per slot runs
under a Web Lock, and fresh device proofs still authenticate the session.

Checked against tracker.openwebtorrent.com and tracker.webtorrent.dev
with the new opt-in browser check (--tracker=<url>). Signaling v5,
midnight rollover, clock skew, CSP and real-network checks remain open.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SchluffeandClaude Opus 5.5 committed 2026-10-20 20:51:05 +02:00
1 parent a5935a8324
commit 3659956967
17 files changed
+930 -28

No files matched your search

+45
View File
@@ -17,6 +17,8 @@ const turn = process.argv.includes('--turn');
const transport = process.argv.includes('--tcp') ? 'tcp' : 'udp';
const streaming = process.argv.includes('--stream-download');
const connections = process.argv.includes('--connections');
// Opt-in: tracker reconnect against a real WebSocket tracker, e.g. --tracker=wss://tracker.example
const trackerUrl = process.argv.find(arg => arg.startsWith('--tracker='))?.slice('--tracker='.length) ?? '';
const screenshotDirectory = process.env.BROWSER_SCREENSHOT_DIR || (process.argv.includes('--screenshots') ? join(tmpdir(), 'hellcon-layout') : '');
const vite = turn ? await (await import('vite')).createServer({ server: { middlewareMode: true }, appType: 'spa' }) : null;
const profile = await mkdtemp(join(tmpdir(), 'hellcon-browser-'));
@@ -598,6 +600,49 @@ try {
assert.deepEqual(rememberedBytes, { length: 4096, valid: true });
console.log('PASS: identities and paired connections persist across reload; fresh mutual proofs authenticate the paired device and transfer exact bytes without manual reconfirmation.');
if (trackerUrl) {
const both = [identitySender, identityReceiver];
await input(identitySender, '#tracker-url', trackerUrl);
await click(identitySender, 'Set up reconnect');
await wait(identityReceiver, () => document.body.textContent?.includes('proposes reconnecting through'));
await checkAccessibility(identityReceiver, 'reconnect proposal');
if (screenshotDirectory) await evaluate(identityReceiver, () => window.__hellcon.element('.reconnect-setup').scrollIntoView({ block: 'center' }));
await screenshot(identityReceiver, 'reconnect-proposal');
await click(identityReceiver, 'Accept');
for (const session of both) await wait(session, () => document.body.textContent?.includes('Reconnect is set up'));
if (screenshotDirectory) await evaluate(identitySender, () => window.__hellcon.element('.reconnect-setup').scrollIntoView({ block: 'center' }));
await screenshot(identitySender, 'reconnect-set-up');
await click(identitySender, 'Disconnect');
await wait(identityReceiver, () => !document.querySelector('.incoming'));
for (const [session, url] of [[identitySender, origin], [identityReceiver, receiverOrigin]]) {
await call('Page.navigate', { url }, session);
await wait(session, () => !!document.querySelector('#stun-provider'));
}
await click(identityReceiver, 'Receive');
for (const session of both) {
await input(session, '#stun-provider', 'none');
await wait(session, () => [...document.querySelectorAll('button')].some(button => button.textContent === 'Reconnect' && !button.disabled));
}
await click(identitySender, 'Reconnect');
await wait(identitySender, () => document.body.textContent?.includes('Waiting for your peer on'));
await checkAccessibility(identitySender, 'reconnect waiting');
if (screenshotDirectory) await evaluate(identitySender, () => [...document.querySelectorAll('button')].find(button => button.textContent === 'Reconnect')?.scrollIntoView({ block: 'start' }));
await screenshot(identitySender, 'reconnect-waiting');
await click(identityReceiver, 'Reconnect');
for (const session of both) await wait(session, () => document.body.textContent?.includes('Paired device authenticated'));
assert.equal(await evaluate(identitySender, () => !!document.querySelector('#output-code')), false, 'No code is shown on reconnect');
for (const [from, to, size] of [[identitySender, identityReceiver, 5000], [identityReceiver, identitySender, 6000]] as const) {
await evaluate(from, (size: number) => window.__hellcon.chooseFile(size, 'reconnected.bin'), size);
await wait(to, () => !!document.querySelector('.incoming button.primary'));
await click(to, 'Accept file');
await wait(to, () => !!document.querySelector('a.download'));
await wait(from, () => document.body.textContent?.includes('The receiver confirmed the complete file.'));
const bytes = await evaluate(to, async () => { const link = window.__hellcon.element<HTMLAnchorElement>('a.download'); const data = new Uint8Array(await (await fetch(link.href)).arrayBuffer()); return { length: data.length, valid: data.every(byte => byte === 123) }; });
assert.deepEqual(bytes, { length: size, valid: true });
}
console.log(`PASS: tracker reconnect through ${new URL(trackerUrl).host}: pairing setup with peer confirmation, reload, Reconnect on both pages without codes, device proofs, exact bytes in both directions.`);
}
await click(identitySender, 'Disconnect');
await wait(identityReceiver, () => !document.querySelector('.incoming'));
await click(identitySender, 'Reset'); await click(identityReceiver, 'Reset');