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

+2
View File
@@ -110,6 +110,8 @@ pub struct StreamManager {
streams : Array[StreamConnection]
pending_accept : Array[StreamConnection]
incoming_datagrams : Array[RepliableDatagram]
incoming_repliable_dgrams : Array[(@encoding.I2cpGzipHeader, RepliableDatagram)]
incoming_raw_dgrams : Array[(@encoding.I2cpGzipHeader, Bytes)]
}
pub fn StreamManager::accept_next(Self) -> StreamConnection?
pub fn StreamManager::connect(Self, @common.Hash, UInt64, from_port? : UInt32, to_port? : UInt32) -> StreamConnection raise StreamingError
+11
View File
@@ -657,6 +657,10 @@ pub struct StreamManager {
streams : Array[StreamConnection]
pending_accept : Array[StreamConnection]
incoming_datagrams : Array[RepliableDatagram]
incoming_repliable_dgrams : Array[
(@encoding.I2cpGzipHeader, RepliableDatagram),
]
incoming_raw_dgrams : Array[(@encoding.I2cpGzipHeader, Bytes)]
}
///|
@@ -672,6 +676,8 @@ pub fn StreamManager::new(
streams: [],
pending_accept: [],
incoming_datagrams: [],
incoming_repliable_dgrams: [],
incoming_raw_dgrams: [],
}
}
@@ -736,9 +742,14 @@ pub fn StreamManager::handle_incoming_i2cp(
let dg = RepliableDatagram::decode(raw)
if dg.verify() {
self.incoming_datagrams.push(dg)
self.incoming_repliable_dgrams.push((hdr, dg))
}
return None
}
if hdr.protocol == b'\x12' {
self.incoming_raw_dgrams.push((hdr, raw))
return None
}
if hdr.protocol != b'\x06' {
return None
}
+27
View File
@@ -326,3 +326,30 @@ test "Streaming caches offline transient key from SYN-ACK to verify CLOSE withou
assert_eq(a_stream.read_available(), b"HTTP/1.0 200 OK\r\n\r\nhi")
assert_eq(a_stream.is_eof(), true)
}
///|
test "StreamManager dispatches protocol 17 repliable and protocol 18 raw datagrams with ports" {
let (alice_dest, alice_seed) = make_test_identity(b'\x61')
let (bob_dest, bob_seed) = make_test_identity(b'\x62')
let bob_mgr = @streaming.StreamManager::new(bob_dest, bob_seed)
let rep = @streaming.RepliableDatagram::sign_ed25519(
alice_dest, alice_seed, b"dht-query",
)
let _ = bob_mgr.handle_incoming_i2cp(
rep.to_i2cp_bytes(from_port=6881U, to_port=6881U),
100UL,
)
assert_eq(bob_mgr.incoming_datagrams.length(), 1)
assert_eq(bob_mgr.incoming_repliable_dgrams.length(), 1)
assert_eq(bob_mgr.incoming_repliable_dgrams[0].0.from_port, 6881U)
assert_eq(bob_mgr.incoming_repliable_dgrams[0].0.to_port, 6881U)
assert_eq(bob_mgr.incoming_repliable_dgrams[0].1.payload, b"dht-query")
let _ = bob_mgr.handle_incoming_i2cp(
@streaming.encode_raw_datagram(b"dht-reply", from_port=6882U, to_port=6882U),
101UL,
)
assert_eq(bob_mgr.incoming_raw_dgrams.length(), 1)
assert_eq(bob_mgr.incoming_raw_dgrams[0].0.from_port, 6882U)
assert_eq(bob_mgr.incoming_raw_dgrams[0].1, b"dht-reply")
}