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

+18
View File
@@ -194,3 +194,21 @@ test "PendingNtcp2Dial/Accept stay non-blocking and Ntcp2Conn::send_blocks_nb tr
bob_conn.close()
listener.close()
}
///|
test "write_file_atomic and file_exists replace longer files cleanly" {
let rand_hex = @encoding.hex_encode(@ntcp2_net.random_bytes(4))
let dir = "/tmp/moon_i2p_atomic_test_\{rand_hex}"
@ntcp2_net.mkdir_p(dir)
let path = "\{dir}/torrents.edn"
assert_true(!@ntcp2_net.file_exists(path))
let long_bytes = b"0123456789abcdef0123456789abcdef-long-payload"
@ntcp2_net.write_file_atomic(path, long_bytes)
assert_true(@ntcp2_net.file_exists(path))
assert_eq(@ntcp2_net.read_file_bytes(path), long_bytes)
let short_bytes = b"{:version 1}\n"
@ntcp2_net.write_file_atomic(path, short_bytes)
assert_eq(@ntcp2_net.read_file_bytes(path), short_bytes)
}