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>
41 lines
1.8 KiB
C
41 lines
1.8 KiB
C
/* session.h — minimal torrent registry for the control plane.
|
|
*
|
|
* The control plane (RPC / plugins / scripts) refers to torrents by a stable
|
|
* uint64 id; the engine refers to them by their storage. This registry is the
|
|
* single map between the two, so a script-driven command like move_file can be
|
|
* resolved to a concrete naut_storage and acted on.
|
|
*
|
|
* Threading: the registry is *owner-thread confined*. In nautd every call
|
|
* (add/remove/move, all from RPC handlers and the move-drain) runs on the
|
|
* daemon's main thread, so no internal locking is needed. Commands originating
|
|
* on other threads (e.g. a script's naut.move_file) must be marshalled onto the
|
|
* owner thread first — which is exactly what nautd's bounded move queue does.
|
|
*/
|
|
#ifndef NAUT_SESSION_H
|
|
#define NAUT_SESSION_H
|
|
|
|
#include "naut/common.h"
|
|
#include "naut/storage.h"
|
|
|
|
typedef struct naut_session naut_session;
|
|
|
|
naut_session *naut_session_create(void);
|
|
/* Closes every storage still registered. */
|
|
void naut_session_destroy(naut_session *s);
|
|
|
|
/* Register `storage` under `id`; the session takes ownership and will close it
|
|
* on remove/destroy. Fails with NAUT_ERR_INVAL if `id` is already present. */
|
|
naut_err naut_session_add(naut_session *s, uint64_t id, naut_storage *storage);
|
|
|
|
/* Close and forget the torrent. NAUT_ERR_NOTFOUND if unknown. */
|
|
naut_err naut_session_remove(naut_session *s, uint64_t id);
|
|
|
|
bool naut_session_has(const naut_session *s, uint64_t id);
|
|
size_t naut_session_count(const naut_session *s);
|
|
|
|
/* Resolve `id` and relocate one completed file to `dest` (the storage half of
|
|
* "move files as they finish"). NAUT_ERR_NOTFOUND if the torrent is unknown. */
|
|
naut_err naut_session_move_file(naut_session *s, uint64_t id,
|
|
uint32_t file_index, const char *dest);
|
|
|
|
#endif /* NAUT_SESSION_H */
|