Add self-hosted WebTorrent tracker container and reconnect plan
Build a WebSocket-only tracker from the official Node image and a locked bittorrent-tracker 11.2.3, run via compose.tracker.yaml and the tracker:up/tracker:down/test:tracker scripts. A small wrapper disables scrape and stats and bounds input: frame validation, per-IP connection and message limits (IPv6 grouped per /64), origin checks, a fixed peer ID and at most four swarms per socket (tracked synchronously, so pipelined frames cannot bypass it), swarm and peer caps, idle-socket timeout and explicit expiry of stale swarm memberships. Forwarded addresses are taken from the rightmost X-Forwarded-For entry and only from trusted proxies. Integration tests use only Node built-ins. Document the planned tracker reconnect design; the app still uses manual connection codes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8665d04f2c
commit
e3af2de051
13 files changed
+2003
-2
No files matched your search
@@ -0,0 +1,125 @@
|
||||
# HellCon WebTorrent tracker container
|
||||
|
||||
Our Dockerfile builds directly from the official Node image and the upstream
|
||||
`bittorrent-tracker` npm package. The Node base is pinned by digest, the tracker
|
||||
by version (11.2.3), and transitive dependencies by `package-lock.json`. There
|
||||
is no third-party tracker image, Trystero dependency or browser package change.
|
||||
|
||||
The tracker container is implemented. HellCon's automatic reconnect UI and
|
||||
client adapter are still [planned](../docs/webtorrent-reconnect.md); starting
|
||||
this service does not change the app's current manual-code connection flow.
|
||||
|
||||
## Local development
|
||||
|
||||
Start Docker, then run from the repository root:
|
||||
|
||||
```sh
|
||||
bun run tracker:up
|
||||
bun run test:tracker
|
||||
docker compose -f compose.tracker.yaml logs --tail=30 tracker
|
||||
bun run tracker:down
|
||||
```
|
||||
|
||||
The service listens at `ws://127.0.0.1:8000`. Choose a different host port with
|
||||
`TRACKER_PORT=8001 bun run tracker:up`. Compose builds our Dockerfile and waits for
|
||||
its health check; it does not start coturn or require `.env.development`. Vite
|
||||
continues to run on the host. No service is enabled at boot and the development
|
||||
container has no automatic restart policy.
|
||||
|
||||
`test:tracker` builds the Dockerfile's test target and runs native Node WebSocket
|
||||
clients against the actual tracker server. It tests both arrival orders, counts
|
||||
in announce replies, a 64 KiB code after AES-GCM/base64 encoding, answer routing,
|
||||
disconnect cleanup, graceful termination, disabled HTTP and WebSocket scrape,
|
||||
malformed/oversized messages, swarm/rate limits, per-socket swarm and peer ID
|
||||
limits (including pipelined frames), idle timeouts, origins, untrusted and
|
||||
trusted forwarded IP headers and IPv6 prefix grouping. Tests do not depend on public trackers. They establish tracker
|
||||
interoperability, not a complete browser reconnect or Internet NAT test.
|
||||
|
||||
If you started Docker only for these checks, stop it afterward:
|
||||
|
||||
```sh
|
||||
sudo systemctl stop docker.service docker.socket containerd.service
|
||||
```
|
||||
|
||||
## VPS deployment
|
||||
|
||||
Use the same Dockerfile and `compose.tracker.yaml`. The service binds its host
|
||||
port to loopback; an HTTPS reverse proxy on the host terminates TLS and forwards
|
||||
WebSocket upgrades to port 8000. A Caddy example for a dedicated hostname:
|
||||
|
||||
```caddyfile
|
||||
tracker.example.com {
|
||||
reverse_proxy 127.0.0.1:8000
|
||||
}
|
||||
```
|
||||
|
||||
Clients then use `wss://tracker.example.com`. Keep access logging disabled for
|
||||
this endpoint, including any logging configured elsewhere. If the proxy is
|
||||
containerized, use a shared private Docker network and the service name instead
|
||||
of the proxy container's loopback address.
|
||||
|
||||
Set `TRACKER_ALLOWED_ORIGINS=https://your-app.example` for browser origin checks.
|
||||
These checks are not client authentication. The wrapper rate-limits the socket's
|
||||
source IP by default. For a proxy deployment, set `TRACKER_TRUSTED_PROXY_IPS` to
|
||||
the exact source addresses the tracker sees from your proxy. The wrapper uses
|
||||
the rightmost `X-Forwarded-For` entry, which must be the address your proxy saw;
|
||||
proxies that replace the header (Caddy's default) or append to it both work.
|
||||
Docker bridge addresses can differ from `127.0.0.1`. Without this configuration, all proxied
|
||||
clients share the proxy IP's limits. Never expose the backend directly while
|
||||
trusting arbitrary forwarded headers.
|
||||
|
||||
Production restart behavior is an explicit operator choice. For example, add a
|
||||
Compose override containing `services: {tracker: {restart: unless-stopped}}` and
|
||||
pass it after `-f compose.tracker.yaml`. This does not change local development's
|
||||
no-restart policy. This repository does not deploy DNS, TLS or the proxy for you.
|
||||
|
||||
## Configuration
|
||||
|
||||
Pass these environment variables to the container. The Compose file exposes
|
||||
the origin/proxy settings through the `TRACKER_` variables above; use an override
|
||||
file for the other container settings.
|
||||
|
||||
| Variable | Default | Purpose |
|
||||
| --- | --- | --- |
|
||||
| `PORT` | `8000` | Internal HTTP/WebSocket port; keep Compose mapping in sync |
|
||||
| `ANNOUNCE_INTERVAL_SECONDS` | `5` | Interval advertised to WebSocket clients |
|
||||
| `MAX_PAYLOAD_BYTES` | `131072` | Maximum WebSocket message size |
|
||||
| `MAX_CONNECTIONS` | `200` | Global WebSocket connection cap |
|
||||
| `MAX_CONNECTIONS_PER_IP` | `8` | Connections per effective source IP; IPv6 per /64 |
|
||||
| `MESSAGES_PER_MINUTE` | `120` | Handshake attempts and incoming messages per IP or /64 |
|
||||
| `MAX_SWARMS` | `1000` | Discovery identifiers admitted at once |
|
||||
| `MAX_PEERS_PER_SWARM` | `32` | Upstream LRU peer-cache bound; excess peers evict older entries |
|
||||
| `PEER_TTL_SECONDS` | `300` | Idle socket timeout and peer cache lifetime |
|
||||
| `ALLOWED_ORIGINS` | empty | Comma-separated browser origins; empty permits all |
|
||||
| `TRUSTED_PROXY_IPS` | empty | Exact proxy source IPs allowed to supply forwarded addresses |
|
||||
|
||||
The container runs as the unprivileged Node user. Compose applies a read-only
|
||||
filesystem, drops capabilities, prevents privilege escalation and bounds CPU,
|
||||
memory and process count. No persistent volume is required. Stale sockets,
|
||||
expired swarm memberships, empty swarms and expired rate buckets are cleaned
|
||||
periodically. `/healthz` returns 204; other ordinary HTTP routes return 404.
|
||||
UDP and HTTP tracker APIs,
|
||||
public statistics and WebSocket scrape requests are disabled.
|
||||
|
||||
The wrapper emits a startup line and generic fatal server errors, not peer IDs,
|
||||
IPs, payloads or upstream warning text. Leave `DEBUG` empty. The operator can
|
||||
still observe connection metadata; this is not an anonymity service.
|
||||
|
||||
## Updating
|
||||
|
||||
Update `tracker/package.json` deliberately, regenerate the lockfile, and rerun
|
||||
`bun run test:tracker` before rebuilding the runtime image. With npm available:
|
||||
|
||||
```sh
|
||||
npm install --package-lock-only --ignore-scripts --prefix tracker
|
||||
```
|
||||
|
||||
Alternatively run npm inside the official Node image with this directory mounted
|
||||
as its workdir. The image build uses `npm ci --omit=dev --omit=optional
|
||||
--ignore-scripts`; native client components and optional accelerators are not
|
||||
needed by the server entry point. The wrapper uses pinned upstream connection
|
||||
hooks, so review those hooks when upgrading the tracker. Update the official
|
||||
Node image digest in both Dockerfile stages for base-image security updates.
|
||||
|
||||
Sources: [upstream tracker](https://github.com/webtorrent/bittorrent-tracker),
|
||||
[official Node container](https://github.com/nodejs/docker-node).
|
||||
Reference in new issue
Block a user