Initial commit: Naut-Torrent — from-scratch 10 GbE BitTorrent client

A maintainable, extensible BitTorrent client (C11, Linux/io_uring) targeting
10 GbE saturation. All torrent functionality is built from scratch; liburing
is the only linked third-party dependency on the data path.

Implements Phases 1-7 of the roadmap:
- core: page-aligned buffer pool, MPMC/Treiber queues, bitfields, worker pool
- crypto: SHA-1/256 (SHA-NI + scalar), Merkle (BEP-52), RC4 (MSE)
- bencode/metainfo: zero-copy parser, v1/v2/hybrid .torrent + magnet
- peer: sans-IO wire codec, MSE/PE handshake state machine, BEP-10, ut_metadata, PEX
- piece/storage: block-level multi-peer engine, rarest-first + endgame,
  per-file completion events + single-file relocate (move-as-you-finish)
- tracker/dht: HTTP + UDP (BEP-15) trackers, BEP-5 KRPC iterative lookup
- platform: io_uring reactor (SQPOLL, registered buffers, SEND_ZC)
- surface: versioned RPC, native plugin ABI, sandboxed Lua scripting, nautd/nautctl

Verified against libtorrent (single/multi/hybrid, MSE, magnet-via-DHT, swarm);
unit + interop tests green; ASan/UBSan/TSan clean. Scripting reference in
docs/scripting.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
ookami125 2026-06-15 12:12:00 -04:00
commit 2178d6a70c
121 changed files with 12644 additions and 0 deletions

View file

@ -0,0 +1,69 @@
#!/usr/bin/env bash
# Phase 4 interop gate: download one torrent concurrently from two independent
# libtorrent seeds and require both peers to contribute blocks.
set -u
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
SWARM="${1:-$ROOT/build/naut_swarm}"
SEEDER="$ROOT/tests/integration/seeder.py"
TOR="$ROOT/tests/fixtures/single_v1.torrent"
DATA="$ROOT/tests/fixtures/data"
python3 -c 'import libtorrent' 2>/dev/null || {
echo "SKIP: python libtorrent not available"
exit 77
}
[ -x "$SWARM" ] || { echo "FAIL: $SWARM not built"; exit 1; }
out="$(mktemp -d /tmp/naut_swarm.XXXXXX)"
log1="$(mktemp /tmp/naut_seed1.XXXXXX)"
log2="$(mktemp /tmp/naut_seed2.XXXXXX)"
slog="$(mktemp /tmp/naut_swarm_log.XXXXXX)"
seed1=""
seed2=""
cleanup() {
[ -n "$seed1" ] && kill "$seed1" 2>/dev/null || true
[ -n "$seed2" ] && kill "$seed2" 2>/dev/null || true
rm -rf "$out" "$log1" "$log2" "$slog"
}
trap cleanup EXIT
python3 "$SEEDER" "$TOR" "$DATA" > "$log1" 2>&1 &
seed1=$!
python3 "$SEEDER" "$TOR" "$DATA" > "$log2" 2>&1 &
seed2=$!
port1=""
port2=""
for _ in $(seq 1 100); do
port1="$(grep -oP 'PORT \K[0-9]+' "$log1" 2>/dev/null || true)"
port2="$(grep -oP 'PORT \K[0-9]+' "$log2" 2>/dev/null || true)"
[ -n "$port1" ] && [ "$port1" != 0 ] &&
[ -n "$port2" ] && [ "$port2" != 0 ] && break
sleep 0.1
done
if [ -z "$port1" ] || [ "$port1" = 0 ] ||
[ -z "$port2" ] || [ "$port2" = 0 ]; then
echo "FAIL: seeders did not start"
cat "$log1" "$log2"
exit 1
fi
if ! timeout 30 "$SWARM" "$TOR" "$out" \
"127.0.0.1:$port1" "127.0.0.1:$port2" > "$slog" 2>&1; then
echo "FAIL: swarm download did not complete"
cat "$slog"
exit 1
fi
if ! diff -r "$out/single.bin" "$DATA/single.bin" >/dev/null; then
echo "FAIL: content mismatch"
exit 1
fi
contributors="$(grep -Ec 'delivered [1-9][0-9]* blocks' "$slog" || true)"
if [ "$contributors" -lt 2 ]; then
echo "FAIL: expected both peers to contribute"
cat "$slog"
exit 1
fi
echo "PASS: two-peer swarm produced byte-identical output"