feat: persist I2P torrent list to EDN state file across restarts
Rolling Release / Test (MoonBit, Extension, Scripts) (push) Successful in 21s
Rolling Release / Build & Publish Rolling Release (push) Successful in 2m20s

- Save active and paused torrents to torrents.edn on add, remove, pause, resume, and metadata fetch, then restore them on router startup.
- Default path is $MOON_I2P_DATA_DIR, then $XDG_DATA_HOME, then ~/.local/share/moon-i2p-browser. Add --torrent-state <file> to override, or --no-torrent-state to disable.
- Write the state file atomically (temp file, fsync, rename). A corrupt or unsupported file logs a warning and does not block startup.
- Verify restored pieces incrementally in the background for large torrents; these show as state "checking" in /api/torrents.
- Expose state_file in /api/status and the startup banner.
- Add standard RFC 4648 Base64 encode/decode helpers, used for the info-b64 field.
- Add the moonedn dependency and pass --torrent-state from the Android service.
This commit is contained in:
nandi committed 2026-11-29 02:46:23 -08:00
1 parent b803e79199
commit dd5b132b5a
17 files changed
+1105 -39

No files matched your search

+5 -1
View File
@@ -32,8 +32,9 @@ pub fn Router::start_torrent_api(
host~ : String = "127.0.0.1",
port~ : Int32 = 4445,
download_dir~ : String = "",
state_file~ : String = "",
) -> Int32 raise RouterError {
self.enable_torrent_engine(download_dir~)
self.enable_torrent_engine(download_dir~, state_file~)
match self.torrent_api_listener {
Some(l) => return l.port
None => ()
@@ -336,6 +337,7 @@ fn Router::build_api_status_json(self : Router) -> String {
sb.write_string("\"torrent_api_port\":\{self.torrent_api_port()},")
sb.write_string("\"torrent_b32\":\"\{api_json_escape(tb32)}\",")
sb.write_string("\"download_dir\":\"\{api_json_escape(eng.download_dir)}\",")
sb.write_string("\"state_file\":\"\{api_json_escape(eng.state_file)}\",")
sb.write_string("\"torrent_count\":\{eng.torrents.length()},")
sb.write_string("\"active_torrents\":\{active},")
sb.write_string("\"completed_torrents\":\{seeding},")
@@ -426,6 +428,8 @@ fn Router::build_api_torrents_json(self : Router) -> String {
let inflight_bytes = inflight_blocks.to_int64() * 16384L
let state_str = if t.error.length() > 0 {
"error"
} else if t.verify_cursor >= 0 {
"checking"
} else if t.paused {
"paused"
} else if t.completed {