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>
40 lines
1.6 KiB
Python
40 lines
1.6 KiB
Python
import libtorrent as lt, os, hashlib, shutil
|
|
|
|
root = "tests/fixtures"
|
|
data = os.path.join(root, "data")
|
|
shutil.rmtree(data, ignore_errors=True)
|
|
os.makedirs(os.path.join(data, "multi", "sub"), exist_ok=True)
|
|
|
|
# deterministic content
|
|
with open(os.path.join(data, "single.bin"), "wb") as f:
|
|
f.write(bytes((i*131+7) & 0xff for i in range(200000)))
|
|
with open(os.path.join(data, "multi", "a.txt"), "wb") as f:
|
|
f.write(b"hello naut " * 5000)
|
|
with open(os.path.join(data, "multi", "sub", "b.dat"), "wb") as f:
|
|
f.write(bytes((i*7) & 0xff for i in range(90000)))
|
|
|
|
def make(name, src, flags):
|
|
fs = lt.file_storage()
|
|
lt.add_files(fs, src)
|
|
t = lt.create_torrent(fs, piece_size=16384, flags=flags)
|
|
parent = os.path.dirname(src) if os.path.isfile(src) else os.path.dirname(src.rstrip("/"))
|
|
t.add_tracker("http://tracker.example.com:8080/announce", 0)
|
|
t.add_tracker("udp://tracker.example.com:8080", 1)
|
|
lt.set_piece_hashes(t, parent)
|
|
ent = t.generate()
|
|
blob = lt.bencode(ent)
|
|
path = os.path.join(root, name)
|
|
with open(path, "wb") as f: f.write(blob)
|
|
ti = lt.torrent_info(ent)
|
|
ih = ti.info_hashes()
|
|
v1 = str(ih.v1) if ih.has_v1() else "-"
|
|
v2 = str(ih.v2) if ih.has_v2() else "-"
|
|
print(f"{name}\tv1={v1}\tv2={v2}\tpieces={ti.num_pieces()}\tsize={ti.total_size()}")
|
|
return path
|
|
|
|
V1 = lt.create_torrent.v1_only
|
|
V2 = lt.create_torrent.v2_only
|
|
make("single_v1.torrent", os.path.join(data, "single.bin"), V1)
|
|
make("multi_v1.torrent", os.path.join(data, "multi"), V1)
|
|
make("hybrid.torrent", os.path.join(data, "multi"), 0)
|
|
make("v2.torrent", os.path.join(data, "multi"), V2)
|