Keep tracker shares alive for 6 minutes, then let them go

Both default trackers closed the socket of a peer that announced only
once, after about 2 and 3 minutes, and the card then wrongly said no
tracker was reachable. Sender and receiver now announce again on the
interval the tracker names (at least 30 s apart, whatever it names), the
receiver with its same offer.

A share, or a receiver looking for one, gives up after 6 minutes without
a download: its tracker sockets close and the card says nobody came. A
peer connected by then still gets its turn, the transfer itself has no
time limit. The sender's code shows until when it is valid and is marked
no longer valid, without Copy, once it expired or the share failed.

A receiver that lost every tracker now closes its peer connections too,
and the expiry timer goes with the session when it is cancelled, fails
or the download starts.

Tests fast-forward the page clock: re-announcing and expiry on both sides
against mocked trackers, no timer or connection left after cancelled and
failed sessions, and a live download after the deadline passed during
the security check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SchluffeandClaude Opus 5.5 committed 2026-10-24 17:55:45 +02:00
1 parent a35bd71ca7
commit 2167b528b2
5 files changed
+242 -21

No files matched your search

+20 -4
View File
@@ -8,6 +8,7 @@ import {
receiveViaTracker,
sendViaTracker,
settings as coreSettings,
TRACKER_WAIT,
type Check,
type Events,
type Incoming,
@@ -80,6 +81,10 @@ const file = 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('');
const sendExpired = ref(false);
let sendTimer: number | undefined;
const offerInput = ref('');
const answer = ref('');
@@ -162,6 +167,8 @@ function begin(on: 'send' | 'receive') {
incoming.value = undefined;
received.value = undefined;
sendCode.value = '';
sendExpired.value = false;
clearTimeout(sendTimer);
offer.value = '';
answer.value = '';
acceptAnswer = undefined;
@@ -223,9 +230,15 @@ async function onCreateAnswer() {
async function onShare() {
const signal = begin('send');
const code = await attempt(signal, sendViaTracker(file.value!, sendEvents, signal));
if (code) sendCode.value = code;
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);
}
// Also once the share failed, every error on the tracker ends it.
const codeGone = computed(() => sendExpired.value || !!error.value);
function onReceive() {
const signal = begin('receive');
attempt(signal, receiveViaTracker(receiveCode.value, receiveEvents, signal));
@@ -285,10 +298,13 @@ function onReceive() {
<h3>Tracker</h3>
<button id="share" :disabled="!file || !settings.trackers.length" @click="onShare">Share via tracker</button>
<template v-if="sendCode">
<label for="send-code">Code, give this to the receiver:</label>
<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>
<div role="group">
<output id="send-code">{{ sendCode }}</output>
<button id="copy-send-code" data-copy @click="onCopy(sendCode)">{{ copied === sendCode ? 'Copied' : 'Copy' }}</button>
<output id="send-code" :data-expired="codeGone || undefined">{{ sendCode }}</output>
<button id="copy-send-code" data-copy :disabled="codeGone" @click="onCopy(sendCode)">
{{ copied === sendCode ? 'Copied' : 'Copy' }}
</button>
</div>
</template>
</section>