webui: replace nautctl web server with a loadable plugin
Drop the web UI that was compiled into nautctl and serve the torrent-ui front end (../torrent-ui/public) from a native plugin (plugins/webui) loaded via `nautd --plugin`. The plugin talks to the engine only through the host call_rpc ABI and adapts the daemon's RPC surface to the qBittorrent-style contract the UI expects (snapshot/SSE, torrent detail tabs, add/delete, cookie auth). Also folds in the daemon refactor that owns per-torrent worker threads and the swarm engine (naut_swarm) used by the plugin's data source. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
50a357968a
commit
8dde48c05a
27 changed files with 2706 additions and 403 deletions
196
CMakeLists.txt
196
CMakeLists.txt
|
|
@ -5,6 +5,11 @@ set(CMAKE_C_STANDARD 11)
|
|||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
option(NAUT_STANDALONE
|
||||
"Statically embed Jansson and Lua in the daemon and client" OFF)
|
||||
option(NAUT_NATIVE
|
||||
"Optimize Release builds for the build machine's CPU" OFF)
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
endif()
|
||||
|
|
@ -12,8 +17,11 @@ endif()
|
|||
add_compile_definitions(_GNU_SOURCE)
|
||||
add_compile_options(-Wall -Wextra -Wshadow -Wvla -Wpointer-arith
|
||||
-fno-omit-frame-pointer)
|
||||
set(CMAKE_C_FLAGS_RELEASE "-O3 -march=native -DNDEBUG")
|
||||
set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
|
||||
set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
|
||||
if(NAUT_NATIVE)
|
||||
add_compile_options($<$<CONFIG:Release>:-march=native>)
|
||||
endif()
|
||||
|
||||
# Sanitizer convenience build: -DNAUT_SAN=address|thread|undefined
|
||||
if(NAUT_SAN)
|
||||
|
|
@ -30,9 +38,80 @@ if(NOT URING_LIB OR NOT URING_INC)
|
|||
message(FATAL_ERROR "liburing not found (install liburing-dev)")
|
||||
endif()
|
||||
find_package(OpenSSL REQUIRED COMPONENTS Crypto)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(JANSSON REQUIRED IMPORTED_TARGET jansson)
|
||||
pkg_check_modules(LUA REQUIRED IMPORTED_TARGET lua)
|
||||
|
||||
if(NAUT_STANDALONE)
|
||||
include(FetchContent)
|
||||
|
||||
# Jansson 2.14.1 predates CMake 4's removal of pre-3.5 policy defaults.
|
||||
set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
|
||||
set(JANSSON_BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
|
||||
set(JANSSON_BUILD_DOCS OFF CACHE BOOL "" FORCE)
|
||||
set(JANSSON_EXAMPLES OFF CACHE BOOL "" FORCE)
|
||||
set(JANSSON_INSTALL OFF CACHE BOOL "" FORCE)
|
||||
FetchContent_Declare(jansson
|
||||
URL https://github.com/akheron/jansson/archive/refs/tags/v2.14.1.tar.gz
|
||||
URL_HASH
|
||||
SHA256=979210eaffdffbcf54cfc34d047fccde13f21b529a381df26db871d886f729a4
|
||||
DOWNLOAD_EXTRACT_TIMESTAMP TRUE)
|
||||
FetchContent_MakeAvailable(jansson)
|
||||
target_include_directories(jansson INTERFACE
|
||||
${jansson_SOURCE_DIR}/src
|
||||
${jansson_BINARY_DIR}/include)
|
||||
|
||||
FetchContent_Declare(lua
|
||||
URL https://www.lua.org/ftp/lua-5.4.8.tar.gz
|
||||
URL_HASH
|
||||
SHA256=4f18ddae154e793e46eeab727c59ef1c0c0c2b744e7b94219710d76f530629ae
|
||||
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
|
||||
SOURCE_SUBDIR cmake-unused)
|
||||
FetchContent_MakeAvailable(lua)
|
||||
set(LUA_SRC_DIR ${lua_SOURCE_DIR}/src)
|
||||
add_library(naut_lua STATIC
|
||||
${LUA_SRC_DIR}/lapi.c
|
||||
${LUA_SRC_DIR}/lauxlib.c
|
||||
${LUA_SRC_DIR}/lbaselib.c
|
||||
${LUA_SRC_DIR}/lcode.c
|
||||
${LUA_SRC_DIR}/lcorolib.c
|
||||
${LUA_SRC_DIR}/lctype.c
|
||||
${LUA_SRC_DIR}/ldblib.c
|
||||
${LUA_SRC_DIR}/ldebug.c
|
||||
${LUA_SRC_DIR}/ldo.c
|
||||
${LUA_SRC_DIR}/ldump.c
|
||||
${LUA_SRC_DIR}/lfunc.c
|
||||
${LUA_SRC_DIR}/lgc.c
|
||||
${LUA_SRC_DIR}/linit.c
|
||||
${LUA_SRC_DIR}/liolib.c
|
||||
${LUA_SRC_DIR}/llex.c
|
||||
${LUA_SRC_DIR}/lmathlib.c
|
||||
${LUA_SRC_DIR}/lmem.c
|
||||
${LUA_SRC_DIR}/loadlib.c
|
||||
${LUA_SRC_DIR}/lobject.c
|
||||
${LUA_SRC_DIR}/lopcodes.c
|
||||
${LUA_SRC_DIR}/loslib.c
|
||||
${LUA_SRC_DIR}/lparser.c
|
||||
${LUA_SRC_DIR}/lstate.c
|
||||
${LUA_SRC_DIR}/lstring.c
|
||||
${LUA_SRC_DIR}/lstrlib.c
|
||||
${LUA_SRC_DIR}/ltable.c
|
||||
${LUA_SRC_DIR}/ltablib.c
|
||||
${LUA_SRC_DIR}/ltm.c
|
||||
${LUA_SRC_DIR}/lundump.c
|
||||
${LUA_SRC_DIR}/lutf8lib.c
|
||||
${LUA_SRC_DIR}/lvm.c
|
||||
${LUA_SRC_DIR}/lzio.c)
|
||||
target_compile_definitions(naut_lua PRIVATE LUA_USE_LINUX)
|
||||
target_include_directories(naut_lua PUBLIC ${LUA_SRC_DIR})
|
||||
target_link_libraries(naut_lua PUBLIC m ${CMAKE_DL_LIBS})
|
||||
|
||||
set(NAUT_JANSSON_TARGET jansson)
|
||||
set(NAUT_LUA_TARGET naut_lua)
|
||||
else()
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(JANSSON REQUIRED IMPORTED_TARGET jansson)
|
||||
pkg_check_modules(LUA REQUIRED IMPORTED_TARGET lua)
|
||||
set(NAUT_JANSSON_TARGET PkgConfig::JANSSON)
|
||||
set(NAUT_LUA_TARGET PkgConfig::LUA)
|
||||
endif()
|
||||
|
||||
# --- core: zero-dependency foundation ---------------------------------------
|
||||
add_library(naut_core STATIC
|
||||
|
|
@ -73,10 +152,13 @@ target_link_libraries(naut_dht PUBLIC naut_bencode naut_tracker)
|
|||
|
||||
# --- peer: wire protocol codec (sans-IO) ------------------------------------
|
||||
add_library(naut_peer STATIC
|
||||
src/peer/wire.c src/peer/extension.c src/peer/metadata.c src/peer/mse.c
|
||||
src/peer/pipeline.c)
|
||||
src/peer/wire.c src/peer/extension.c src/peer/metadata.c src/peer/pipeline.c)
|
||||
target_link_libraries(naut_peer PUBLIC
|
||||
naut_core naut_crypto naut_bencode naut_tracker OpenSSL::Crypto m)
|
||||
naut_core naut_crypto naut_bencode naut_tracker m)
|
||||
|
||||
# MSE is optional at the application boundary and is the only OpenSSL user.
|
||||
add_library(naut_mse STATIC src/peer/mse.c)
|
||||
target_link_libraries(naut_mse PUBLIC naut_peer OpenSSL::Crypto)
|
||||
|
||||
# --- storage: file backend --------------------------------------------------
|
||||
add_library(naut_storage STATIC src/storage/storage.c)
|
||||
|
|
@ -95,6 +177,10 @@ add_library(naut_platform STATIC
|
|||
target_include_directories(naut_platform PUBLIC ${URING_INC})
|
||||
target_link_libraries(naut_platform PUBLIC naut_core ${URING_LIB})
|
||||
|
||||
# CPU topology helpers do not require the io_uring platform backend.
|
||||
add_library(naut_system STATIC src/platform/system.c)
|
||||
target_link_libraries(naut_system PUBLIC naut_core)
|
||||
|
||||
# --- session + extensibility control plane ---------------------------------
|
||||
add_library(naut_session STATIC src/session/event.c)
|
||||
target_link_libraries(naut_session PUBLIC naut_core)
|
||||
|
|
@ -105,36 +191,49 @@ target_link_libraries(naut_torrents PUBLIC naut_storage)
|
|||
|
||||
add_library(naut_rpc STATIC src/rpc/rpc.c)
|
||||
target_link_libraries(naut_rpc PUBLIC
|
||||
naut_session naut_core PkgConfig::JANSSON)
|
||||
naut_session naut_core ${NAUT_JANSSON_TARGET})
|
||||
|
||||
add_library(naut_plugin STATIC src/plugin/plugin.c)
|
||||
target_link_libraries(naut_plugin PUBLIC naut_rpc naut_session dl)
|
||||
|
||||
add_library(naut_script STATIC src/script/script.c)
|
||||
target_link_libraries(naut_script PUBLIC
|
||||
naut_session naut_core PkgConfig::LUA)
|
||||
naut_session naut_core ${NAUT_LUA_TARGET})
|
||||
|
||||
add_library(naut_example MODULE plugins/example/example.c)
|
||||
target_include_directories(naut_example PRIVATE ${CMAKE_SOURCE_DIR}/include)
|
||||
set_target_properties(naut_example PROPERTIES PREFIX "")
|
||||
|
||||
add_library(naut_webui MODULE plugins/webui/webui.c)
|
||||
target_include_directories(naut_webui PRIVATE ${CMAKE_SOURCE_DIR}/include)
|
||||
target_link_libraries(naut_webui PRIVATE ${NAUT_JANSSON_TARGET} pthread)
|
||||
set_target_properties(naut_webui PROPERTIES PREFIX "")
|
||||
|
||||
# --- echo: Phase 1 gate (io_uring echo server on the buffer pool) -----------
|
||||
add_executable(naut_echo apps/echo/main.c)
|
||||
target_link_libraries(naut_echo PRIVATE naut_platform naut_core)
|
||||
# add_executable(naut_echo apps/echo/main.c)
|
||||
# target_link_libraries(naut_echo PRIVATE naut_platform naut_core)
|
||||
|
||||
# --- leech: Phase 3 gate (single-peer download, byte-correct + verified) ----
|
||||
add_executable(naut_leech apps/leech/main.c)
|
||||
target_link_libraries(naut_leech PRIVATE naut_piece naut_peer naut_metainfo)
|
||||
# add_executable(naut_leech apps/leech/main.c)
|
||||
# target_link_libraries(naut_leech PRIVATE
|
||||
# naut_piece naut_peer naut_mse naut_metainfo)
|
||||
|
||||
# --- swarm: Phase 4 gate (multi-peer download, rarest-first + endgame) -------
|
||||
add_executable(naut_swarm apps/swarm/main.c)
|
||||
target_link_libraries(naut_swarm PRIVATE
|
||||
naut_piece naut_peer naut_metainfo naut_tracker naut_dht naut_platform)
|
||||
add_library(naut_swarm_engine STATIC apps/swarm/main.c)
|
||||
target_compile_definitions(naut_swarm_engine PRIVATE NAUT_SWARM_LIBRARY)
|
||||
target_link_libraries(naut_swarm_engine PUBLIC
|
||||
naut_piece naut_peer naut_metainfo naut_tracker naut_dht naut_system
|
||||
naut_session)
|
||||
|
||||
# add_executable(naut_swarm apps/swarm/main.c)
|
||||
# target_link_libraries(naut_swarm PRIVATE
|
||||
# naut_piece naut_peer naut_metainfo naut_tracker naut_dht naut_system
|
||||
# naut_session)
|
||||
|
||||
# --- daemon + CLI: Phase 7 extensibility surface ---------------------------
|
||||
add_executable(nautd apps/nautd/main.c)
|
||||
target_link_libraries(nautd PRIVATE
|
||||
naut_plugin naut_script naut_rpc naut_session naut_torrents naut_metainfo)
|
||||
naut_plugin naut_script naut_rpc naut_session naut_metainfo naut_swarm_engine)
|
||||
|
||||
add_executable(nautctl apps/nautctl/main.c)
|
||||
target_link_libraries(nautctl PRIVATE naut_rpc)
|
||||
|
|
@ -202,7 +301,7 @@ target_link_libraries(test_extension PRIVATE naut_peer)
|
|||
add_test(NAME test_extension COMMAND test_extension)
|
||||
|
||||
add_executable(test_mse tests/unit/test_mse.c)
|
||||
target_link_libraries(test_mse PRIVATE naut_peer)
|
||||
target_link_libraries(test_mse PRIVATE naut_mse)
|
||||
add_test(NAME test_mse COMMAND test_mse)
|
||||
|
||||
add_executable(test_tracker tests/unit/test_tracker.c)
|
||||
|
|
@ -234,38 +333,46 @@ target_link_libraries(test_picker PRIVATE naut_piece)
|
|||
add_test(NAME test_picker COMMAND test_picker)
|
||||
|
||||
# Phase 3 interop gate: download from a real libtorrent seed (SKIPs without it).
|
||||
add_test(NAME interop_leech
|
||||
COMMAND bash ${CMAKE_SOURCE_DIR}/tests/integration/run_interop.sh $<TARGET_FILE:naut_leech>)
|
||||
set_tests_properties(interop_leech PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 180)
|
||||
# These gates exercise the standalone naut_leech/naut_swarm/naut_echo binaries,
|
||||
# which are currently folded into the daemon — register them only when built.
|
||||
if(TARGET naut_leech)
|
||||
add_test(NAME interop_leech
|
||||
COMMAND bash ${CMAKE_SOURCE_DIR}/tests/integration/run_interop.sh $<TARGET_FILE:naut_leech>)
|
||||
set_tests_properties(interop_leech PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 180)
|
||||
|
||||
add_test(NAME interop_mse
|
||||
COMMAND bash ${CMAKE_SOURCE_DIR}/tests/integration/run_mse.sh $<TARGET_FILE:naut_leech>)
|
||||
set_tests_properties(interop_mse PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60)
|
||||
add_test(NAME interop_mse
|
||||
COMMAND bash ${CMAKE_SOURCE_DIR}/tests/integration/run_mse.sh $<TARGET_FILE:naut_leech>)
|
||||
set_tests_properties(interop_mse PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60)
|
||||
endif()
|
||||
|
||||
add_test(NAME interop_magnet_dht
|
||||
COMMAND bash ${CMAKE_SOURCE_DIR}/tests/integration/run_magnet_dht.sh
|
||||
$<TARGET_FILE:naut_swarm>)
|
||||
set_tests_properties(interop_magnet_dht PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60)
|
||||
if(TARGET naut_swarm)
|
||||
add_test(NAME interop_magnet_dht
|
||||
COMMAND bash ${CMAKE_SOURCE_DIR}/tests/integration/run_magnet_dht.sh
|
||||
$<TARGET_FILE:naut_swarm>)
|
||||
set_tests_properties(interop_magnet_dht PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60)
|
||||
|
||||
# Phase 4 interop gate: both libtorrent seeds must contribute to one download.
|
||||
add_test(NAME interop_swarm
|
||||
COMMAND bash ${CMAKE_SOURCE_DIR}/tests/integration/run_swarm.sh $<TARGET_FILE:naut_swarm>)
|
||||
set_tests_properties(interop_swarm PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60)
|
||||
# Phase 4 interop gate: both libtorrent seeds must contribute to one download.
|
||||
add_test(NAME interop_swarm
|
||||
COMMAND bash ${CMAKE_SOURCE_DIR}/tests/integration/run_swarm.sh $<TARGET_FILE:naut_swarm>)
|
||||
set_tests_properties(interop_swarm PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60)
|
||||
|
||||
add_test(NAME interop_tracker_swarm
|
||||
COMMAND bash ${CMAKE_SOURCE_DIR}/tests/integration/run_tracker_swarm.sh
|
||||
$<TARGET_FILE:naut_swarm> http)
|
||||
set_tests_properties(interop_tracker_swarm PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60)
|
||||
add_test(NAME interop_tracker_swarm
|
||||
COMMAND bash ${CMAKE_SOURCE_DIR}/tests/integration/run_tracker_swarm.sh
|
||||
$<TARGET_FILE:naut_swarm> http)
|
||||
set_tests_properties(interop_tracker_swarm PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60)
|
||||
|
||||
add_test(NAME interop_udp_tracker_swarm
|
||||
COMMAND bash ${CMAKE_SOURCE_DIR}/tests/integration/run_tracker_swarm.sh
|
||||
$<TARGET_FILE:naut_swarm> udp)
|
||||
set_tests_properties(interop_udp_tracker_swarm PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60)
|
||||
add_test(NAME interop_udp_tracker_swarm
|
||||
COMMAND bash ${CMAKE_SOURCE_DIR}/tests/integration/run_tracker_swarm.sh
|
||||
$<TARGET_FILE:naut_swarm> udp)
|
||||
set_tests_properties(interop_udp_tracker_swarm PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60)
|
||||
endif()
|
||||
|
||||
add_test(NAME interop_echo_scale
|
||||
COMMAND bash ${CMAKE_SOURCE_DIR}/tests/integration/run_echo_scale.sh
|
||||
$<TARGET_FILE:naut_echo>)
|
||||
set_tests_properties(interop_echo_scale PROPERTIES TIMEOUT 30)
|
||||
if(TARGET naut_echo)
|
||||
add_test(NAME interop_echo_scale
|
||||
COMMAND bash ${CMAKE_SOURCE_DIR}/tests/integration/run_echo_scale.sh
|
||||
$<TARGET_FILE:naut_echo>)
|
||||
set_tests_properties(interop_echo_scale PROPERTIES TIMEOUT 30)
|
||||
endif()
|
||||
|
||||
add_test(NAME phase7_extensibility
|
||||
COMMAND bash ${CMAKE_SOURCE_DIR}/tests/integration/run_phase7.sh
|
||||
|
|
@ -273,6 +380,7 @@ add_test(NAME phase7_extensibility
|
|||
$<TARGET_FILE:naut_example>
|
||||
${CMAKE_SOURCE_DIR}/tests/fixtures/phase7.lua)
|
||||
set_tests_properties(phase7_extensibility PROPERTIES TIMEOUT 15)
|
||||
set_tests_properties(phase7_extensibility PROPERTIES SKIP_RETURN_CODE 77)
|
||||
|
||||
# Example Lua scripts: parser battery + end-to-end sort path building. Only
|
||||
# registered when a standalone lua interpreter is available.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue