feat: add I2P BitTorrent engine, DHT, and Firefox torrent extension
check / check (macos-latest) (push) Failing after 29s
check / check (ubuntu-latest) (push) Failing after 29s
check / check (windows-latest) (push) Failing after 30s

- Add pure-MoonBit bittorrent package: bencode codec, metainfo/magnet parsing with path traversal checks, peer wire protocol (BEP 10/9), and I2P Kademlia DHT with KRPC and 54-byte compact nodes
- Add SHA-1 primitive in crypto for torrent info hashes
- Add router torrent API and engine, enabled with --torrent-api (default 127.0.0.1:4445) and --download-dir
- Add Firefox WebExtension torrent manager with native messaging host and packed .xpi
- Add scripts to build a standalone Firefox + router AppImage and install the native host
- Add just targets (proxy, appimage, extension), README docs, and ignore .cache/ and dist/
This commit is contained in:
nandi committed 2026-11-28 13:19:03 -08:00
1 parent 14eae00f5c
commit fbe6818c4e
37 files changed
+8543 -9

No files matched your search

+82
View File
@@ -140,6 +140,34 @@ extern "C" fn c_fetch_https(
max_len : Int32,
) -> Int32 = "moon_i2p_net_fetch_https"
///|
#borrow(path)
extern "C" fn c_mkdir_p(path : Bytes, path_len : Int32) -> Int32 = "moon_i2p_net_mkdir_p"
///|
#borrow(path, data)
extern "C" fn c_write_file_at(
path : Bytes,
path_len : Int32,
offset : Int64,
data : Bytes,
data_len : Int32,
) -> Int32 = "moon_i2p_net_write_file_at"
///|
#borrow(path, dst)
extern "C" fn c_read_file_at(
path : Bytes,
path_len : Int32,
offset : Int64,
dst : FixedArray[Byte],
max_len : Int32,
) -> Int32 = "moon_i2p_net_read_file_at"
///|
#borrow(dst)
extern "C" fn c_home_dir(dst : FixedArray[Byte], max_len : Int32) -> Int32 = "moon_i2p_net_home_dir"
///|
fn last_os_error() -> String {
let n = c_last_error_len()
@@ -245,6 +273,60 @@ pub fn read_file_bytes(path : String) -> Bytes raise Ntcp2NetError {
Bytes::from_array(buf)[:got].to_owned()
}
///|
/// Creates directory `path` and any missing parent directories (`mkdir -p`).
pub fn mkdir_p(path : String) -> Unit raise Ntcp2NetError {
let pb = @encoding.string_to_utf8_bytes(path)
if c_mkdir_p(pb, pb.length()) < 0 {
raise IoError("mkdir_p(\{path}) failed: \{last_os_error()}")
}
}
///|
/// Writes `data` at byte `offset` into `path` (creating the file if missing).
pub fn write_file_at(
path : String,
offset : Int64,
data : Bytes,
) -> Unit raise Ntcp2NetError {
let pb = @encoding.string_to_utf8_bytes(path)
if c_write_file_at(pb, pb.length(), offset, data, data.length()) < 0 {
raise IoError("write_file_at(\{path}) failed: \{last_os_error()}")
}
}
///|
/// Reads up to `len` bytes starting at byte `offset` from `path`.
pub fn read_file_at(
path : String,
offset : Int64,
len : Int32,
) -> Bytes raise Ntcp2NetError {
if len <= 0 {
return b""
}
let pb = @encoding.string_to_utf8_bytes(path)
let buf = FixedArray::make(len, b'\x00')
let got = c_read_file_at(pb, pb.length(), offset, buf, len)
if got < 0 {
raise IoError("read_file_at(\{path}) failed: \{last_os_error()}")
}
Bytes::from_array(buf)[:got].to_owned()
}
///|
/// Returns the `HOME` directory path, or empty string if unset.
pub fn get_home_dir() -> String {
let buf = FixedArray::make(1024, b'\x00')
let n = c_home_dir(buf, 1024)
if n <= 0 {
return ""
}
@encoding.utf8_bytes_to_string(Bytes::from_array(buf)[:n].to_owned()) catch {
_ => ""
}
}
///|
/// Native POSIX TCP socket wrapper with exact-length reads and line reading.
pub struct TcpSocket {