Salt the tracker swarm with the clock or an own salt

The code used to be derived with a fixed salt, so a tracker could compute a
table from swarm to code ahead of time, once for every share. Now the salt
is the UTC 6 minute window the share was made in, and the code's new 11th
character names that window, so the receiver finds it even with a clock
hours off. Use own salt adds a salt both sides agree on, which nobody can
guess ahead for; Generate makes a random one. The salt is locked while a
tracker share or search runs, and a receiver that finds no sender is told
to check the salt too.

Settings are no longer kept in localStorage: a remembered list or salt that
differs from the other side's would silently break shares. The core now
reports when a share expires and until when it lasts, and the session owns
a tracker's timers, so a socket still closing after an abort announces
nothing more. Header options line up with the cards, disabled switches look
disabled, and sizes, percents and times don't wrap. postcss 8.5.32.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SchluffeandClaude Opus 5.5 committed 2026-10-28 01:14:27 +01:00
1 parent e3a2b348d6
commit 2e47b55901
7 files changed
+462 -142

No files matched your search

+80 -49
View File
@@ -8,36 +8,27 @@ import {
DEFAULT_STUN_SERVERS,
DEFAULT_TRACKERS,
type Events,
formatTime,
type Incoming,
type Phase,
type ReceiveEvents,
randomCode,
receiveViaTracker,
type SendEvents,
sendViaTracker,
TRACKER_WAIT,
} from './core';
const SETTINGS_KEY = 'hellcon:settings';
// Same object as the core's, so the core sees every change.
// Same object as the core's, so the core sees every change. Nothing is kept, a reload brings back the
// defaults.
const settings = reactive(coreSettings);
// Kept in this browser only. Storage can be blocked or hold something old, then the defaults stay.
try {
const saved = JSON.parse(localStorage.getItem(SETTINGS_KEY) ?? '{}');
if (typeof saved.stun === 'boolean') settings.stun = saved.stun;
if (Array.isArray(saved.stunServers)) settings.stunServers = saved.stunServers;
if (Array.isArray(saved.trackers)) settings.trackers = saved.trackers;
} catch {}
watch(
settings,
() => {
try {
localStorage.setItem(SETTINGS_KEY, JSON.stringify(settings));
} catch {}
},
{ deep: true },
);
// Instead of the clock's, while on. Not kept either, a forgotten one would break every later share.
const ownSalt = reactive({ on: false, text: '' });
// Empty is no salt, Share and Receive wait for one.
const saltMissing = computed(() => ownSalt.on && !ownSalt.text.trim());
const salt = () => (ownSalt.on ? ownSalt.text : undefined);
// From the code's alphabet, 16 characters are about 95 bits.
const onGenerateSalt = () => (ownSalt.text = randomCode(16));
// RTCPeerConnection and WebSocket throw on a URL they don't accept, so only valid lines reach the core.
// For STUN the browser decides, e.g. Firefox rejects stuns: and both a port beyond 65535. A connection
@@ -69,7 +60,7 @@ function serverList(key: 'stunServers' | 'trackers', valid: (url: string) => boo
.filter(Boolean),
);
const invalid = computed(() => lines.value.filter((line) => !valid(line)));
// Immediate, a saved list may hold lines this browser rejects.
// Immediate, a default may be a line this browser rejects.
watch(lines, (lines) => (settings[key] = lines.filter(valid)), { immediate: true });
// Unwraps both refs, so the template can bind them as plain properties.
return reactive({ text, invalid });
@@ -89,10 +80,10 @@ const shared = ref<File>();
const offer = ref('');
const answerInput = ref('');
const sendCode = ref('');
// Until when a receiver can find the share with its code, the time shown and whether it passed.
const sendUntil = ref('');
// Until when a receiver can find the share with its code, whether with an own salt and whether that
// passed, as the core tells.
const sendUntil = ref(0);
const sendExpired = ref(false);
let sendTimer: number | undefined;
const offerInput = ref('');
const answer = ref('');
@@ -126,7 +117,11 @@ const events: Omit<Events, 'progress'> = {
type Progress = { read: number; size: number };
const sent = ref<Progress>();
const sendEvents: Events = { ...events, progress: (read, size) => (sent.value = { read, size }) };
const sendEvents: SendEvents = {
...events,
progress: (read, size) => (sent.value = { read, size }),
expired: () => (sendExpired.value = true),
};
const incoming = ref<Incoming>();
const received = ref<Progress>();
@@ -186,12 +181,15 @@ let acceptAnswer: ((answer: string) => Promise<void>) | undefined;
// the one before: its connections close and what it showed goes, so nothing else can write here.
let session: AbortController | undefined;
const side = ref<'send' | 'receive'>();
// Whether the session is a tracker share or search, which runs with the salt it started with.
const viaTracker = ref(false);
// what goes into the log, so the sessions in it can be told apart.
function begin(on: 'send' | 'receive', what: string) {
function begin(on: 'send' | 'receive', what: string, tracker = false) {
session?.abort();
session = new AbortController();
side.value = on;
viaTracker.value = tracker;
events.log(`--- ${what} ---`);
error.value = '';
status.value = undefined;
@@ -202,7 +200,6 @@ function begin(on: 'send' | 'receive', what: string) {
received.value = undefined;
sendCode.value = '';
sendExpired.value = false;
clearTimeout(sendTimer);
offer.value = '';
answer.value = '';
acceptAnswer = undefined;
@@ -238,7 +235,7 @@ function formatSize(bytes: number) {
bytes /= 1024;
unit++;
}
return `${bytes.toFixed(unit ? 1 : 0)} ${units[unit]}`;
return `${bytes.toFixed(unit ? 1 : 0)}\u00a0${units[unit]}`;
}
async function onCreateOffer() {
@@ -263,13 +260,12 @@ async function onCreateAnswer() {
}
async function onShare() {
const signal = begin('send', `share ${file.value!.name} via tracker`);
const signal = begin('send', `share ${file.value!.name} via tracker`, true);
shared.value = file.value;
const code = await attempt(signal, sendViaTracker(file.value!, sendEvents, signal));
if (!code) return;
sendCode.value = code;
sendUntil.value = new Date(Date.now() + TRACKER_WAIT).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
sendTimer = window.setTimeout(() => (sendExpired.value = true), TRACKER_WAIT);
const result = await attempt(signal, sendViaTracker(file.value!, sendEvents, signal, salt()));
if (!result) return;
sendCode.value = result.code;
sendUntil.value = result.until;
}
// Also once the transfer started, which closes the trackers, and once the share failed: every error on
@@ -277,20 +273,52 @@ async function onShare() {
const codeGone = computed(() => sendExpired.value || !!sent.value || !!error.value);
function onReceive() {
const signal = begin('receive', 'receive via tracker');
attempt(signal, receiveViaTracker(receiveCode.value, receiveEvents, signal));
const signal = begin('receive', 'receive via tracker', true);
attempt(signal, receiveViaTracker(receiveCode.value, receiveEvents, signal, salt()));
}
// The salt stays as it is while a tracker share or search runs: it found or waits in the swarm of the
// salt it started with, another one shown would be the wrong one to give the receiver.
const saltLocked = computed(() => viaTracker.value && !['error', 'done', 'stopped'].includes(phase.value!));
</script>
<template>
<header>
<img src="/HellNet_alt.png" alt="" width="40" height="40" />
<h1>HellCon</h1>
<label>
<!-- biome-ignore lint/a11y/useAriaPropsForRole: a checkbox reports its own state, aria-checked on it is not allowed -->
<input id="stun" v-model="settings.stun" type="checkbox" role="switch" />
Use STUN
</label>
<div>
<img src="/HellNet_alt.png" alt="" width="40" height="40" />
<h1>HellCon</h1>
</div>
<div id="options">
<div>
<label>
<!-- biome-ignore lint/a11y/useAriaPropsForRole: a checkbox reports its own state, aria-checked on it is not allowed -->
<input id="stun" v-model="settings.stun" type="checkbox" role="switch" />
Use STUN
</label>
<label>
<!-- biome-ignore lint/a11y/useAriaPropsForRole: a checkbox reports its own state, aria-checked on it is not allowed -->
<input id="own-salt" v-model="ownSalt.on" type="checkbox" role="switch" :disabled="saltLocked" />
Use own salt
</label>
</div>
<div v-if="ownSalt.on" role="group">
<input
id="salt"
v-model="ownSalt.text"
aria-label="Own salt"
placeholder="Same salt on both sides"
:aria-invalid="saltMissing"
:disabled="saltLocked"
autocapitalize="off"
autocomplete="off"
autocorrect="off"
spellcheck="false"
/>
<button id="generate-salt" type="button" data-copy :disabled="saltLocked" @click="onGenerateSalt">
Generate
</button>
</div>
</div>
</header>
<main>
@@ -340,18 +368,21 @@ function onReceive() {
<p v-if="error" id="send-error" role="alert">{{ error }}</p>
<p v-else role="status">
<span id="send-status">{{ status!.text }}</span>
<span v-if="sent">{{ percent(sent) }} %</span>
<span v-if="sent">{{ percent(sent) }}&nbsp;%</span>
</p>
</div>
<section>
<h3>Tracker</h3>
<button id="share" type="button" :disabled="!file || !settings.trackers.length" @click="onShare">
<button id="share" type="button" :disabled="!file || !settings.trackers.length || saltMissing" @click="onShare">
Share via tracker
</button>
<template v-if="sendCode">
<label v-if="codeGone" for="send-code">Code, no longer valid:</label>
<label v-else for="send-code">Code, give this to the receiver, valid until {{ sendUntil }}:</label>
<label v-else for="send-code">
Code, give this {{ ownSalt.on ? 'and your salt ' : '' }}to the receiver, valid until
{{ formatTime(sendUntil) }}:
</label>
<div role="group">
<output id="send-code" :data-expired="codeGone || undefined">{{ sendCode }}</output>
<button
@@ -410,7 +441,7 @@ function onReceive() {
<p v-if="error" id="receive-error" role="alert">{{ error }}</p>
<p v-else role="status">
<span id="receive-status">{{ status!.text }}</span>
<span v-if="received">{{ percent(received) }} %</span>
<span v-if="received">{{ percent(received) }}&nbsp;%</span>
</p>
</div>
@@ -429,7 +460,7 @@ function onReceive() {
<button
id="receive"
type="button"
:disabled="!settings.trackers.length || !receiveCode.trim()"
:disabled="!settings.trackers.length || !receiveCode.trim() || saltMissing"
@click="onReceive"
>
Receive