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

+28
View File
@@ -170,6 +170,15 @@ extern "C" fn c_read_file_at(
max_len : Int32,
) -> Int32 = "moon_i2p_net_read_file_at"
///|
#borrow(path, data)
extern "C" fn c_write_file_atomic(
path : Bytes,
path_len : Int32,
data : Bytes,
data_len : Int32,
) -> Int32 = "moon_i2p_net_write_file_atomic"
///|
#borrow(dst)
extern "C" fn c_home_dir(dst : FixedArray[Byte], max_len : Int32) -> Int32 = "moon_i2p_net_home_dir"
@@ -320,6 +329,25 @@ pub fn read_file_at(
Bytes::from_array(buf)[:got].to_owned()
}
///|
/// Atomically replaces `path` with `data` via temp-file write + `fsync` + `rename`.
pub fn write_file_atomic(
path : String,
data : Bytes,
) -> Unit raise Ntcp2NetError {
let pb = @encoding.string_to_utf8_bytes(path)
if c_write_file_atomic(pb, pb.length(), data, data.length()) < 0 {
raise IoError("write_file_atomic(\{path}) failed: \{last_os_error()}")
}
}
///|
/// Returns `true` if `path` exists and can be `stat`ed.
pub fn file_exists(path : String) -> Bool {
let pb = @encoding.string_to_utf8_bytes(path)
c_file_size(pb, pb.length()) >= 0
}
///|
/// Returns the `HOME` directory path, or empty string if unset.
pub fn get_home_dir() -> String {