Commit graph

42 commits

Author SHA1 Message Date
ookami125
8ca1cf3371 docker: run as configurable PUID/PGID (default 99:100 for unraid)
The image ran as a hardcoded uid 1000, which doesn't match NAS shares
(unraid files are nobody:users = 99:100), so moving completed files onto
the share failed with EACCES (surfaced as a generic "i/o error").

Drop the baked-in user and instead start the entrypoint as root, chown
the daemon's own state (/data, /run/naut) to PUID:PGID, then gosu down to
that uid:gid before exec'ing nautd. The downloads share is left untouched
so its ownership comes from the host/NFS export. PUID/PGID default to
99:100 so writes to /mnt/user shares work out of the box; override per
your storage owner.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 01:14:37 -04:00
ookami125
eb226b4af3 docker: ship anime_sort.lua but don't load a script by default
Bundle the example Lua scripts under /app/scripts and have the entrypoint
load one only when NAUT_SCRIPT is set. NAUT_SCRIPT is left unset by
default, so the daemon starts with no script; set it (e.g.
/app/scripts/anime_sort.lua) to opt in.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 00:30:21 -04:00
ookami125
6107846fc9 build: use https submodule URLs instead of ssh
Switch the three submodules (torrent-peer, torrent-tracker, torrent-ui)
from ssh://git@git.cieric.com to https://git.cieric.com so a fresh
clone + submodule init works without SSH credentials.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-25 23:14:24 -04:00
ookami125
d87603fbbe build: add Dockerfile to compile and run Naut from source
Multi-stage build that compiles nautd, nautctl, and the webui plugin
(plus the external engine submodules) at image build time, so a rebuild
is the only thing that changes the running version. The runtime stage
ships only the binaries, the two submodule shared libs, the static
torrent-ui assets, and the runtime shared libraries, running as a
non-root user.

Defaults bind the web UI on 0.0.0.0:8080 with data under /data (state +
webui.db) and downloads under /downloads, both as volumes; all tunables
are overridable via -e. A .dockerignore keeps build output, VCS data,
and local downloads/databases out of the context.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-25 23:10:30 -04:00
ookami125
66ca7d4321 chore: ignore local agent git tools 2026-06-25 00:25:38 -04:00
ookami125
6c6c69d758 docs: remove local issues tracker 2026-06-25 00:03:28 -04:00
ookami125
bc1eb5a08e build: vendor dependencies as submodules 2026-06-24 23:51:21 -04:00
ookami125
252bc8140b Merge webui-plugin into main 2026-06-24 23:02:32 -04:00
ookami125
067b62c23a webui: persist login sessions so they survive restarts
Sessions lived in an in-memory array, so every daemon restart wiped them
and forced a re-login. Move them into the webui DB:

- New sessions table storing a SHA-256 of the bearer token (never the
  raw token, so a DB read can't be replayed), the user, role, and an
  absolute expiry.
- create/lookup/touch/delete + per-user delete + prune in webui_store.
- Login persists the session; auth checks validate against the DB with a
  throttled sliding expiry (re-extended at most hourly to avoid a write
  per request); logout and admin reset/delete drop the rows. Expired
  rows are reaped lazily on lookup and pruned at startup.
- TTL is configurable via NAUT_SESSION_TTL (default 7 days) and drives
  the cookie Max-Age. Removes the in-memory session array + auth_lock.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24 21:00:36 -04:00
ookami125
096535292d swarm: re-announce promptly when the swarm is starved
The peer top-up loop re-announced to trackers only at the full advertised
interval (~30 min), so a torrent that dropped to a handful of peers would
sit there for up to half an hour with only the 5-minute DHT refresh to
help — looking like the re-announce system was dead.

Now, when fewer than LOW_PEER_THRESHOLD (10) peers are connected, the next
tracker announce is scheduled at the tracker's min_interval floor (never
below 60s) instead of the full interval, so a thin swarm actually tries to
recover. Once peers recover the full interval is used again. Capture the
tracker's min_interval (was being dropped) to stay announce-compliant.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24 20:04:24 -04:00
ookami125
a0265cc1ea webui: normalize the RSS schema (articles + rule_feeds tables)
Replace the JSON-blob columns (feeds.articles, rules.affected_feeds)
with proper relational tables:

- articles(feed,key,…,is_read,grabbed) with UNIQUE(feed,key) and indexes,
  so dedup and grabbed become INSERT OR IGNORE / WHERE-key queries and a
  poll inserts only new rows instead of rewriting the whole feed blob.
- rule_feeds(rule,feed) join table for a rule's feed scope.

The webui RSS engine now operates on rows via a row-level store API
(feed/article/rule/indexer upsert/list/etc.) instead of holding the
feeds/rules/indexers in memory and saving whole lists; the in-memory
copies and rss_save/rss_load are gone. The poller, the auto-download
rules, force-run, manual download, refresh and search all read/write the
DB directly. A one-time migration upgrades an existing webui.db in place
(moving the old JSON blobs into the new tables, preserving article
read/grabbed flags and rule scoping, then dropping the legacy columns).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24 01:59:36 -04:00
ookami125
91d4b99aee webui: store RSS feeds/rules/indexers in the webui DB
Move RSS persistence out of the daemon blob store and into the webui's
own SQLite DB (feeds, rules, indexers tables; articles + affectedFeeds
held as JSON columns). Remove the now-unused daemon blob store
(set/get_webui_blob, blob_lock, data_dir).

With this, all webui-owned state — accounts, taxonomy, RSS — lives in
the webui DB; the daemon only keeps naut's own data (per-torrent labels
still flow through set_labels for Lua).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 22:11:17 -04:00
ookami125
9474e6f31a webui: store category/tag taxonomy in the webui DB
Move the category + tag lists out of the daemon (labels.json + the
get/set_label_taxonomy RPCs) and into the webui's own SQLite DB
(categories, tags tables). The daemon no longer persists webui taxonomy;
per-torrent labels still flow through set_labels for Lua.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 22:05:22 -04:00
ookami125
1b79fe8079 webui: rename auth_store → webui_store
The plugin's SQLite store will own more than accounts (taxonomy, RSS),
so give it a general name. Mechanical rename of files + symbols; default
DB filename is now webui.db. No behavior change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 21:59:30 -04:00
ookami125
ab51774554 ISSUES: real login system backed by a database done (#18)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 21:48:05 -04:00
ookami125
a4ec585aed webui: real multi-user accounts (SQLite + PBKDF2)
Replace the single env/generated password with a proper account system,
owned entirely by the webui plugin:

- auth_store: SQLite users table, PBKDF2-HMAC-SHA256 password hashing
  (per-user salt, 210k iterations) via OpenSSL. DB at NAUT_WEBUI_DB or
  an XDG default. Thread-safe (serialized connection).
- Login verifies against the DB; sessions now carry the username + role.
  First run bootstraps an admin from NAUT_AUTH_USER/PASSWORD or a
  generated password (logged once).
- Admin-only user management: GET/POST /api/users, /api/users/delete,
  /api/users/password, /api/users/role. Self-service POST
  /api/account/password. Guards the last admin and invalidates a user's
  sessions on delete or password reset.
- /api/auth/status and /api/login now return the role.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 21:43:24 -04:00
ookami125
ab733cb573 webui: name RSS downloads after the article title
Auto/manual RSS downloads now forward the article (or search result)
title as the torrent's display name, so fetched .torrent enclosures no
longer show as "upload-XXXXXX". Threaded the title through rss_download
/ rss_grab_article and set the web-layer display name on success.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 20:59:06 -04:00
ookami125
66ec5d6c3d ISSUES: RSS download button + rule match preview done
The backend link/Atom-href source fix landed in 15905c2; record the two
new issues (manual download button, show current matches) as resolved.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 20:51:08 -04:00
ookami125
15905c2f35 webui: handle RSS link torrent URLs 2026-06-23 02:12:53 -04:00
ookami125
0249ce330d webui: RSS manual download, repull, and rule re-run (#13–#15)
- Articles now carry a `grabbed` flag; manually downloading one (or an
  auto/forced rule grab) marks it, persisted across restarts, so the UI
  shows it as added and re-runs skip it.
- POST /api/rss/refresh {name?} synchronously re-polls one feed (or all)
  for an on-demand repull.
- POST /api/rss/rules/run {name} re-applies a rule to every existing
  article (not just newly-seen ones), grabbing ungrabbed matches —
  useful after editing a rule. Returns matched/grabbed counts.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 01:45:49 -04:00
ookami125
223354eff9 webui: manual add-from-feed/search endpoint; close RSS+Search (#6)
Add POST /api/rss/download so the UI can grab a torrent from a feed
article or a search result (magnet or .torrent URL) via the same tested
add path as the auto-downloader. Marks ISSUES #6 done.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 01:01:36 -04:00
ookami125
d6e0e51175 webui: RSS auto-download + Torznab search backend
Add a real backend behind the RSS and Search tabs:

- nautd gains a generic web-UI blob store (set/get_webui_blob) so the
  web layer can persist RSS feeds, auto-download rules and indexer
  config under <state_dir>/webui_<key>.json.
- The webui plugin runs a background poller that fetches each feed over
  HTTP(S), parses RSS 2.0 / Atom items (title, link, enclosure, size,
  pubDate, magnet incl. torrent:magnetURI), dedupes, and stores articles.
- Auto-download rules (substring or POSIX regex, mustContain/
  mustNotContain, per-feed scope) fire on newly-seen items and add the
  torrent via the daemon — from a magnet, or by fetching a .torrent
  enclosure and uploading its bytes — applying category/save path/paused.
- Search queries every enabled Torznab indexer and merges results
  (name, size, seeders, leechers, magnet/.torrent), exposed as
  searchPlugins in /api/meta.

New endpoints: GET/POST /api/rss(+/delete), /api/rss/rules(+/delete),
/api/indexers(+/delete), GET /api/search?q=.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 00:56:04 -04:00
ookami125
0393ed429b net: add blocking HTTP/HTTPS GET client
A small libssl-backed client (naut_http_get) that fetches a URL over
plain HTTP or TLS, follows 3xx redirects, and decodes Content-Length
and chunked bodies. Foundation for the RSS poller and Torznab search.
Built as a PIC static lib so it can link into the webui plugin module.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 00:41:31 -04:00
ookami125
dbd0d6f78e ISSUES: mark category default location (#4) done
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 00:33:35 -04:00
ookami125
f6c933fd1c webui: edit categories (rename + save path, incl. Uncategorized)
Add POST /api/categories/edit. Renames a category, updating its save
path and reassigning every torrent that referenced the old name; the
empty-named Uncategorized pseudo-category can have its save path set
but not renamed. Changes persist via the daemon taxonomy.

Closes ISSUES #2.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 00:29:16 -04:00
ookami125
4708db151d nautd: hash-check paused torrents (check-only worker)
A paused torrent never ran a worker, so it never verified on-disk data
and showed no progress. Add a one-shot check-only swarm mode (open +
resume scan + report, no peers/engine/download). The reconciler runs it
for a paused torrent flagged needs_check (set on paused-add and recheck);
the worker stays paused afterward. New TORRENT_CHECKING state -> webui
checkingDL/UP. Mark #11 done.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-22 01:22:10 -04:00
ookami125
7bbc1ee22c nautd: block adding a torrent that would overlap existing data
spawn_torrent parses each torrent's file list (at add and restore) and
refuses an add whose files would write where a registered torrent's data
lives (NAUT_ERR_EXIST). Magnets are checked once metadata is known is
out of scope; restore skips the check. webui surfaces it as HTTP 409.
Mark #10 done.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-22 01:01:50 -04:00
ookami125
187e8f2db2 swarm: populate per-peer stats for the web UI peers tab
report_progress now fills peer_stats via engine_peer_list, so the peer
list (ip, progress, dl rate, state) shows again. Mark #12 done.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-22 00:35:23 -04:00
ookami125
1e469a0483 ISSUES: mark add-tags (#7) done
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-22 00:29:37 -04:00
ookami125
36c8acc83a webui: add tags when adding a torrent
api_add forwards tags to the daemon, assigns them to the new torrent,
and registers any new tag names in the persisted taxonomy. Mark #7 done.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-22 00:02:11 -04:00
ookami125
8295b8522c webui: apply category on add + allow no category
api_add now forwards the chosen category to the daemon (and fixes a
use-after-free reading it from the freed request). Mark issues #3, #8, #9
done in ISSUES.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-21 23:34:50 -04:00
ookami125
b633b7d216 nautd/webui: scripting, labels, settings, set-location, pause fix
Session checkpoint on webui-plugin:
- engine dump (nautctl dump) + engine endgame integration
- per-file move locations persistence; torrent-level "Set location"
  with reset/keep-relative/leave-separate handling + residual prune
- Lua: naut.get_labels, define_settings/get_setting (script_host struct)
- daemon-owned labels (category+tags) + taxonomy persistence; webui write-through
- fix: pausing a completed/seeding torrent now sticks (stop wins over result)
- automation tab responsive layout; anime_sort label gating + settings

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-21 23:19:41 -04:00
ookami125
6dc711cf57 Limit active pieces and expose file list 2026-06-17 02:23:15 -04:00
ookami125
ff8e0f5f5b Exclude torrents folder 2026-06-17 02:14:37 -04:00
ookami125
6ec5b19a73 Expose real tracker state to web UI 2026-06-17 02:14:10 -04:00
ookami125
6be239943a Improve swarm peer saturation 2026-06-17 01:52:30 -04:00
ookami125
6ae72907b0 Expose peer and piece state to web UI 2026-06-17 01:29:44 -04:00
ookami125
f4f4e86be4 webui: fix add-torrent crash, add categories/tags, real names
The daemon segfaulted the moment any torrent existed: map_torrent built
its JSON with one 30-key json_pack whose format string had drifted out of
sync with the argument list, so json_pack misread an int as a char* and
crashed in the next snapshot build (an empty fleet hid it). Rebuild the
object field-by-field with json_object_set_new so it can't drift again.

Add a web-layer category/tag store (in memory, like qBittorrent's own Web
API) so the UI can actually create categories and tags and assign them:
- /api/categories[/delete] and /api/tags[/delete] persist and return them
- /api/meta returns the stored categories/tags
- /api/action handles setCategory/addTags/removeTags (still 501 for
  engine-level verbs the daemon can't do)
- map_torrent fills each torrent's category/tags from the store

Uploaded torrents kept their temp upload path as the display name; keep
the name the UI sends at add time and prefer it in the grid.

Fix a use-after-free in api_action that read the action string after
freeing the request, which corrupted the error body into a 500.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-17 00:43:26 -04:00
ookami125
41ed172272 webui: real speeds, honest actions, and hardening
Address the review of the webui plugin:

- Live download rates. A background sampler polls the daemon once per
  second, derives per-torrent dlspeed from successive byte counts (EWMA
  smoothed), and computes a real ETA. dl_info_speed now aggregates the
  fleet instead of reporting a hardcoded 0.

- Single shared snapshot. The sampler publishes one cached snapshot that
  /api/snapshot, /api/torrents and every SSE stream serve, so N browser
  tabs no longer each poll the engine and race the speed table. SSE
  waiters block on a condition and wake promptly on shutdown.

- Honest /api/action. The engine has no pause/resume/recheck/queue verbs,
  so the endpoint returns 501 with an explanatory message instead of
  claiming success.

- Reject oversized uploads with 413 instead of silently truncating a
  torrent into garbage.

- Auth hardening: constant-time credential comparison, CSPRNG-only token
  generation via getrandom (fail closed, no weak fallback), oldest-session
  eviction instead of clobbering slot 0, and a warning when bound to a
  non-loopback address.

- Cap concurrent connections (503 beyond the limit) so a client can't
  spawn unbounded threads.

- nautd: tear down plugins (joining the webui's threads) before freeing
  torrent tasks, closing a shutdown-time use-after-free window where an
  in-flight request could touch freed state.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-17 00:29:52 -04:00
ookami125
8dde48c05a 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>
2026-06-17 00:21:48 -04:00
ookami125
50a357968a examples: anime library sorter + pure-Lua Anitomy parser
Add a worked nautd scripting example that files each anime episode into a
media-server-friendly library the moment its file finishes verifying:

    <SORTED_ROOT>/<Title>/Season NN/<Title> - SNNENN.<ext>

- examples/anitomy.lua: a compact, dependency-free reimplementation of Anitomy
  (title/season/episode/release-group/resolution/year) in pure Lua — no
  require/io/os, so it embeds in the sandbox.
- examples/anime_sort.lua: on_file_complete hook that parses the filename and
  calls naut.move_file(); the embedded parser is a verbatim copy of anitomy.lua.
- examples/test_anitomy.lua, test_anime_sort.lua: parser battery + end-to-end
  path-building test with an embedded-vs-module drift guard. Wired into ctest as
  example_anitomy / example_anime_sort when a lua interpreter is present.
- docs: examples/README.md plus pointers from README and docs/scripting.md.

Verified end to end against a live nautd: file_complete -> move_file -> on-disk
relocate into the sorted tree.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-15 12:25:23 -04:00
ookami125
2178d6a70c 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>
2026-06-15 12:12:00 -04:00