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,59 @@
#!/usr/bin/env bash
# Phase 6 local platform gate: fixed-buffer recv + SEND_ZC echo integrity.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
ECHO="${1:-$ROOT/build/naut_echo}"
PORT="${NAUT_ECHO_PORT:-39127}"
LOG="$(mktemp /tmp/naut_echo_scale.XXXXXX)"
cleanup() {
[ -n "${server:-}" ] && kill -TERM "$server" 2>/dev/null || true
[ -n "${server:-}" ] && wait "$server" 2>/dev/null || true
rm -f "$LOG"
}
trap cleanup EXIT
NAUT_SQPOLL=1 "$ECHO" "$PORT" >"$LOG" 2>&1 &
server=$!
for _ in $(seq 1 100); do
grep -q "echo listening" "$LOG" && break
kill -0 "$server" 2>/dev/null || {
echo "FAIL: echo server exited"; cat "$LOG"; exit 1;
}
sleep 0.05
done
grep -q "echo listening" "$LOG" || {
echo "FAIL: echo server did not listen"; cat "$LOG"; exit 1;
}
BYTES=$((256 * 1024 * 1024))
CONNS=8
python3 "$ROOT/tests/integration/echo_client.py" "$PORT" "$BYTES" "$CONNS"
kill -TERM "$server"
wait "$server"
server=""
grep -q "bytes echoed" "$LOG" || {
echo "FAIL: echo server did not shut down cleanly"; cat "$LOG"; exit 1;
}
grep "bytes echoed" "$LOG"
# Server-side accounting must match exactly: every byte the client sent was
# echoed back, and no connection was dropped mid-stream. (A truncated echo is
# also caught client-side, but asserting the count here makes a server-side
# drop a hard, deterministic failure rather than a timing-dependent one.)
echoed=$(grep -oE '[0-9]+ bytes echoed' "$LOG" | grep -oE '^[0-9]+')
if [ "$echoed" != "$BYTES" ]; then
echo "FAIL: echoed $echoed bytes, expected $BYTES (a connection was dropped)"
cat "$LOG"; exit 1
fi
conns=$(grep -oE '[0-9]+ conns' "$LOG" | grep -oE '^[0-9]+')
if [ "$conns" != "$CONNS" ]; then
echo "FAIL: served $conns connections, expected $CONNS"; cat "$LOG"; exit 1
fi
# Report whether the SQPOLL path was actually exercised (it falls back cleanly
# where the kernel/privileges disallow it — informational, not a failure).
if grep -q "sqpoll" "$LOG"; then
echo "PASS: io_uring SQPOLL fixed-buffer/SEND_ZC echo path is byte-correct"
else
echo "PASS: io_uring echo path byte-correct (SQPOLL unavailable, used fallback)"
fi