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:
commit
2178d6a70c
121 changed files with 12644 additions and 0 deletions
53
tests/unit/test_plugin.c
Normal file
53
tests/unit/test_plugin.c
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#include "naut/event.h"
|
||||
#include "naut/plugin.h"
|
||||
#include "naut/rpc.h"
|
||||
#include "test.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#ifndef NAUT_EXAMPLE_PLUGIN
|
||||
#define NAUT_EXAMPLE_PLUGIN "naut_example.so"
|
||||
#endif
|
||||
|
||||
int main(void) {
|
||||
naut_event_bus *events = naut_event_bus_create();
|
||||
naut_rpc_registry *rpc = naut_rpc_registry_create();
|
||||
naut_plugin_manager *plugins =
|
||||
naut_plugin_manager_create(rpc, events);
|
||||
CHECK(events && rpc && plugins);
|
||||
CHECK(naut_plugin_load(plugins, NAUT_EXAMPLE_PLUGIN) == NAUT_OK);
|
||||
CHECK_EQ(naut_plugin_count(plugins), 1);
|
||||
CHECK(strcmp(naut_plugin_name(plugins, 0), "example") == 0);
|
||||
CHECK_EQ(naut_plugin_storage_count(plugins), 1);
|
||||
|
||||
const naut_storage_backend_v1 *backend =
|
||||
naut_plugin_storage_backend(plugins, "memory");
|
||||
CHECK(backend != NULL);
|
||||
naut_err error;
|
||||
void *storage = backend->open("", &error);
|
||||
CHECK(storage && error == NAUT_OK);
|
||||
const char value[] = "plugin-storage";
|
||||
char result[sizeof value];
|
||||
CHECK(backend->write(storage, 17, value, sizeof value) == NAUT_OK);
|
||||
CHECK(backend->read(storage, 17, result, sizeof result) == NAUT_OK);
|
||||
CHECK(memcmp(value, result, sizeof value) == 0);
|
||||
backend->close(storage);
|
||||
|
||||
naut_event event = {
|
||||
.type = NAUT_EVENT_TORRENT_FINISHED,
|
||||
.torrent_id = 9,
|
||||
};
|
||||
naut_event_emit(events, &event);
|
||||
json_t *reply = naut_rpc_dispatch(
|
||||
rpc, "example.events", json_null(), &error);
|
||||
CHECK(error == NAUT_OK && reply);
|
||||
CHECK(json_integer_value(json_object_get(reply, "finished")) == 1);
|
||||
json_decref(reply);
|
||||
|
||||
naut_plugin_manager_destroy(plugins);
|
||||
reply = naut_rpc_dispatch(rpc, "example.events", json_null(), &error);
|
||||
CHECK(reply == NULL && error == NAUT_ERR_INVAL);
|
||||
naut_rpc_registry_destroy(rpc);
|
||||
naut_event_bus_destroy(events);
|
||||
TEST_MAIN_END();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue