Use compressed connection codes in the transfer panel

Offers and answers now go through the HC1 codec: the sender creates a
ref per session and the answer must echo it, so pasting an offer as the
answer or an answer for another code is rejected with a specific message
while the live offer stays usable. Pasted input may be a full link.

webrtc.ts drops its Base64 JSON signaling and exchanges validated SDP
only; identity hellos travel in the code envelope. Tests, the browser
check, compare-ice and the docs follow the new format.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SchluffeandClaude Opus 5.5 committed 2026-10-19 22:35:44 +02:00
1 parent da2999ed5d
commit 8bd37ac8b1
10 files changed
+68 -89

No files matched your search

+6 -4
View File
@@ -1,6 +1,7 @@
// Dependency-free Chromium integration check. Run after `bun run build`.
import { Readable, Writable } from 'node:stream';
import { installBrowserContext, forceRelay, relayCandidateTypes, simulateSlowDisk } from './browser-context.ts';
import { CODE_PREFIX, decodeCode } from '../src/lib/codes.ts';
import assert from 'node:assert/strict';
import { spawn } from 'node:child_process';
import { createServer } from 'node:http';
@@ -144,6 +145,7 @@ async function connect(sender: string, receiver: string, size: number, changedId
if (turn) { await enableTurn(sender); await enableTurn(receiver); }
await click(sender, 'Create code'); await wait(sender, () => !!document.querySelector('#output-code'));
const offer = await evaluate(sender, () => window.__hellcon.element<HTMLTextAreaElement>('#output-code').value);
assert.ok(offer.startsWith(CODE_PREFIX));
await input(receiver, '#offer-input', 'invalid-code!');
await click(receiver, 'Accept & create answer');
await wait(receiver, () => !!document.querySelector('[role=alert]'));
@@ -152,8 +154,8 @@ async function connect(sender: string, receiver: string, size: number, changedId
await input(receiver, '#offer-input', offer); await click(receiver, 'Accept & create answer');
await wait(receiver, () => !!document.querySelector('#output-code'));
const answer = await evaluate(receiver, () => window.__hellcon.element<HTMLTextAreaElement>('#output-code').value);
await input(sender, '#answer-input', 'invalid-answer!'); await click(sender, 'Connect');
await wait(sender, () => !!document.querySelector('[role=alert]'));
await input(sender, '#answer-input', offer); await click(sender, 'Connect');
await wait(sender, () => document.querySelector('[role=alert]')?.textContent?.includes('not an answer'));
assert.equal(await evaluate(sender, () => window.__hellcon.element<HTMLTextAreaElement>('#output-code')?.value), offer);
assert.equal(await evaluate(sender, () => window.__hellcon.element<HTMLTextAreaElement>('#answer-input').disabled), false);
await input(sender, '#answer-input', answer); await click(sender, 'Connect');
@@ -517,7 +519,7 @@ try {
await evaluate(identitySender, () => window.__hellcon.chooseFile(4096, 'remembered.bin'));
await click(identitySender, 'Create code'); await wait(identitySender, () => !!document.querySelector('#output-code'));
const offer = await evaluate(identitySender, () => window.__hellcon.element<HTMLTextAreaElement>('#output-code').value);
assert.equal(JSON.parse(atob(offer)).version, 4);
assert.ok((await decodeCode(offer)).identity);
await input(identityReceiver, '#offer-input', offer); await click(identityReceiver, 'Accept & create answer');
await wait(identityReceiver, () => !!document.querySelector('#output-code'));
const answer = await evaluate(identityReceiver, () => window.__hellcon.element<HTMLTextAreaElement>('#output-code').value);
@@ -621,7 +623,7 @@ try {
await input(denied, '#stun-provider', 'none'); await click(denied, 'Create code');
await wait(denied, () => !!document.querySelector('#output-code'));
const temporary = await evaluate(denied, () => window.__hellcon.element<HTMLTextAreaElement>('#output-code').value);
assert.equal(JSON.parse(atob(temporary)).version, 3);
assert.equal((await decodeCode(temporary)).identity, undefined);
await click(denied, 'Cancel connection');
console.log('PASS: denied identity storage still allows temporary v3 connection setup.');
+4 -4
View File
@@ -40,8 +40,8 @@ async function run(mode) {
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);
// The original helpers exchange encoded codes; current helpers exchange SDP.
let sdp = mode === 'original' ? api.decodeSignal(await api.createOfferCode(a)) : await api.createOffer(a);
// 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=>{
@@ -49,11 +49,11 @@ async function run(mode) {
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));
const answer = mode === 'original' ? await api.createAnswerCode(b, api.encodeSignal(sdp)) : await api.createAnswer(b, sdp);
log('answer ready');
await new Promise(r=>setTimeout(r,20000));
log('apply answer');
await api.acceptAnswerCode(a,answer);
await (mode === 'original' ? api.acceptAnswerCode(a,answer) : api.acceptAnswer(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'}; }