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

+57 -2
View File
@@ -1,4 +1,4 @@
# WebTorrent tracker reconnect (planned, not implemented)
# WebTorrent tracker reconnect (experimental concept)
This replaces the custom rendezvous server proposal. HellCon will exchange fresh
connection codes through a configurable WebTorrent-compatible WebSocket tracker,
@@ -8,7 +8,8 @@ client to HellCon. Nostr is outside this plan.
The [repository-owned tracker container](../tracker/README.md) now provides the
development/deployment foundation, using an official Node base and a locked
upstream package. Browser pairing, settings and automatic reconnect remain planned.
upstream package. A first browser implementation exists to prove the concept;
see [Concept status](#concept-status) for what it covers and what is still open.
Client independence takes priority: anyone can clone, fork, self-host or modify
HellCon and choose their own tracker. The client must work with any compatible
@@ -269,6 +270,60 @@ behavior, and the small HellCon adapter. Keep a reproducible local tracker fixtu
so upgrades can run the same interoperability and reconnect checks. Supporting
additional discovery protocols would add independent maintenance and test paths.
## Concept status
Implemented in `src/lib/reconnect.ts` (pairing derivation, discovery identifier,
sealed envelopes), `src/lib/tracker.ts` (WebSocket adapter and attempt logic) and
`TransferPanel.vue`:
- Setup runs over a verified session whose peer proved the paired device key.
Either person proposes a tracker URL; the peer sees the host and accepts or
declines. Both contribute 32 random bytes; the HKDF context binds both device
keys, both fingerprints of that session and the tracker URL. The proposer
stores first, then the acceptor. The base key is a non-extractable CryptoKey
in the connection record, which Forget device, a replaced paired device and
**Turn off reconnect** clear. A changed local identity blocks the attempt.
- The discovery identifier is derived per UTC day; envelopes are AES-256-GCM with
a random IV, the role, info_hash, offer ID, source and destination peer IDs
as associated data, and a two-minute lifetime with five minutes' tolerance.
The decrypted code passes the usual `decodeCode` checks, and the peer's
identity key must equal the paired key; fresh device proofs then authenticate
the session as before.
- Roles differ from the plan above: the lower device key always offers and
creates the data channel, so there is no glare. If the other device arrives
second, it announces a sealed, codeless **wake** that makes the initiator
offer at once. Swarm counts from announce responses (which include the
announcing peer) trigger the same. Offers and wakes are spaced 15 seconds apart
and capped at 12; each offer uses a fresh peer connection. Envelopes that do
not open are ignored, so other clients in a swarm cannot disturb it beyond
receiving offers they cannot read.
- One attempt per slot and browser profile via Web Locks, a five-minute
deadline, a 15-second keepalive announce, `stopped` and socket close on
success, cancel, reset, failure and unmount.
Checked on 2026-10-20 with `node scripts/browser-check.ts --tracker=<url>` against
`wss://tracker.openwebtorrent.com` and `wss://tracker.webtorrent.dev`: pairing
setup, reload of both pages, Reconnect without codes, device proofs and exact
bytes in both directions, both roles. Both trackers report swarm counts, route
binary 20-byte identifiers unchanged and remove peers on `stopped`.
tracker.openwebtorrent.com relayed 56 KB payloads, tracker.webtorrent.dev 12 KB;
typical sealed codes are a few KB. Neither tracker is bundled.
Still open before this can ship:
- Signaling v5: pairing messages ride the v3 session protocol, so an older
peer rejects them as unexpected, and the device proof does not bind the
reconnect version.
- Joining adjacent day identifiers around UTC midnight, clock-skew detection,
and a frozen envelope encoding with published test vectors.
- The **Connection discovery** settings section: the tracker URL is entered in
the setup section (prefilled from `VITE_TRACKER_URL`), and changing it means
setting up again over a live session.
- Storage acknowledgement: each side stores without confirming the write to
the other, so a storage failure can leave one side configured.
- `connect-src` for the hosted CSP, Firefox and real separate-device networks,
tracker outage and cross-tab behavior (step 5), and the deployment checks.
## References
- [WebTorrent tracker server and client](https://github.com/webtorrent/bittorrent-tracker)