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

47
include/naut/list.h Normal file
View file

@ -0,0 +1,47 @@
/* list.h — intrusive circular doubly-linked list (header-only).
*
* Zero allocation: the node lives inside your struct. Recover the owner with
* NAUT_CONTAINER_OF. This is the workhorse list for peer sets, freelists of
* objects, timer wheels, etc.
*/
#ifndef NAUT_LIST_H
#define NAUT_LIST_H
#include "naut/common.h"
typedef struct naut_list {
struct naut_list *prev;
struct naut_list *next;
} naut_list;
NAUT_INLINE void naut_list_init(naut_list *l) { l->prev = l; l->next = l; }
NAUT_INLINE bool naut_list_empty(const naut_list *l) { return l->next == l; }
NAUT_INLINE void naut__link(naut_list *n, naut_list *p, naut_list *x) {
n->prev = p; n->next = x; p->next = n; x->prev = n;
}
/* insert n at head / tail of list l */
NAUT_INLINE void naut_list_push_front(naut_list *l, naut_list *n) { naut__link(n, l, l->next); }
NAUT_INLINE void naut_list_push_back(naut_list *l, naut_list *n) { naut__link(n, l->prev, l); }
NAUT_INLINE void naut_list_del(naut_list *n) {
n->prev->next = n->next;
n->next->prev = n->prev;
n->prev = n->next = n; /* safe to del again / detect detached */
}
NAUT_INLINE naut_list *naut_list_front(const naut_list *l) { return l->next; }
NAUT_INLINE naut_list *naut_list_back(const naut_list *l) { return l->prev; }
#define naut_list_entry(ptr, type, member) NAUT_CONTAINER_OF(ptr, type, member)
#define naut_list_for_each(it, l) \
for ((it) = (l)->next; (it) != (l); (it) = (it)->next)
/* safe against deletion of the current node */
#define naut_list_for_each_safe(it, tmp, l) \
for ((it) = (l)->next, (tmp) = (it)->next; \
(it) != (l); (it) = (tmp), (tmp) = (it)->next)
#endif /* NAUT_LIST_H */