Contact one STUN server and one tracker at a time

Both sides used to contact every STUN server and tracker at once, so each of them learned the IP
address and each tracker that A sent to B.

Connections now use one STUN server: the first in the list that reports a public address to a
throwaway probe connection within 2 s. It stays for the page's lifetime. If a connection gets no
address from it, the next connection probes on from the server after it. A probe runs only while a
session waits for it and stops once none does, STUN is turned off or the list changes.

The sender joins the first tracker that accepts it and moves to the next only once that one rejects
it, can't be reached within 10 s or is lost. The receiver walks the list with one offer each and
stays where a tracker reports a seeder (complete), which is the sender: it always announces before
anyone has the code. Trackers it passed keep its offer. backend/tracker.mjs now sends complete.

wss://tracker.pagequit.net comes first in the default trackers, the public ones are fallbacks.
TODO.md drops the server tasks, they aren't work on this codebase.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SchluffeandClaude Opus 5.5 committed 2026-10-25 18:51:42 +01:00
1 parent 5729ed62f7
commit 840bc3572b
6 files changed
+361 -85

No files matched your search

+17 -1
View File
@@ -107,16 +107,32 @@ test('refuses connections from other origins', async () => {
expect(await open({ origin: '' })).toBeUndefined();
});
test('acknowledges an announce with the interval only', async () => {
test('acknowledges an announce with the interval and the seeders only', async () => {
const client = await open();
const hash = id();
expect(await announce(client, { info_hash: hash, peer_id: id(), left: 0 })).toEqual({
action: 'announce',
interval: 60,
info_hash: hash,
complete: 1,
});
});
test('counts the seeders of the swarm in complete', async () => {
const hash = id();
const receiver = { ...(await open()), id: id() };
const seeders = async () => (await announce(receiver, { info_hash: hash, peer_id: receiver.id, left: 1 })).complete;
expect(await seeders()).toBe(0);
// Another swarm's sender doesn't count.
await announce(await open(), { info_hash: id(), peer_id: id(), left: 0 });
const sender = { ...(await open()), id: id() };
await announce(sender, { info_hash: hash, peer_id: sender.id, left: 0 });
expect(await seeders()).toBe(1);
// Gone once the tracker saw the connection close, which may be after the client did.
sender.ws.close();
await expect.poll(seeders).toBe(0);
});
test('forwards an offer to the sender only, rebuilt from its checked fields', async () => {
const peers = await swarm();
const other = { ...(await open()), id: id() };