feat: add I2P BitTorrent engine, DHT, and Firefox torrent extension
- 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:
1 parent
14eae00f5c
commit
fbe6818c4e
37 files changed
+8543
-9
No files matched your search
@@ -52,6 +52,12 @@ fn print_usage() -> Unit {
|
||||
" --http-proxy [host:port] Enable HTTP-over-I2P proxy (default when omitted: 127.0.0.1:4444)",
|
||||
)
|
||||
println(" --proxy [host:port] Alias for --http-proxy")
|
||||
println(
|
||||
" --torrent-api [host:port] Enable BitTorrent + I2P DHT HTTP API (default: 127.0.0.1:4445)",
|
||||
)
|
||||
println(
|
||||
" --download-dir <dir> Download folder for I2P torrents (default: ~/Downloads/moon-i2p)",
|
||||
)
|
||||
println(
|
||||
" --ntcp2-host <ip> NTCP2 advertise/bind IP (default: 127.0.0.1)",
|
||||
)
|
||||
@@ -91,6 +97,10 @@ fn main {
|
||||
let mut http_proxy_enabled = false
|
||||
let mut http_proxy_host = "127.0.0.1"
|
||||
let mut http_proxy_port = 4444
|
||||
let mut torrent_api_enabled = false
|
||||
let mut torrent_api_host = "127.0.0.1"
|
||||
let mut torrent_api_port = 4445
|
||||
let mut download_dir = ""
|
||||
let mut ntcp2_host = "127.0.0.1"
|
||||
let mut ntcp2_port = 0
|
||||
let mut floodfill = false
|
||||
@@ -146,6 +156,35 @@ fn main {
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
"--torrent-api" => {
|
||||
torrent_api_enabled = true
|
||||
if i + 1 < args.length() && !args[i + 1].has_prefix("-") {
|
||||
match split_host_port(args[i + 1]) {
|
||||
Some((h, p)) => {
|
||||
torrent_api_host = h
|
||||
torrent_api_port = p
|
||||
i += 2
|
||||
}
|
||||
None =>
|
||||
match parse_port(args[i + 1]) {
|
||||
Some(p) => {
|
||||
torrent_api_port = p
|
||||
i += 2
|
||||
}
|
||||
None => i += 1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
"--download-dir" =>
|
||||
if i + 1 < args.length() {
|
||||
download_dir = args[i + 1]
|
||||
i += 2
|
||||
} else {
|
||||
i += 1
|
||||
}
|
||||
"--ntcp2-port" =>
|
||||
if i + 1 < args.length() {
|
||||
match parse_port(args[i + 1]) {
|
||||
@@ -271,6 +310,21 @@ fn main {
|
||||
}
|
||||
}
|
||||
}
|
||||
if torrent_api_enabled {
|
||||
let _ = r.start_torrent_api(
|
||||
host=torrent_api_host,
|
||||
port=torrent_api_port,
|
||||
download_dir~,
|
||||
) catch {
|
||||
_ => {
|
||||
r.close()
|
||||
println(
|
||||
"error: failed to bind Torrent API on \{torrent_api_host}:\{torrent_api_port}",
|
||||
)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
for pf in peer_files {
|
||||
let _ = r.load_peer_file(pf) catch {
|
||||
_ => {
|
||||
@@ -333,6 +387,11 @@ fn main {
|
||||
if http_proxy_enabled {
|
||||
println(" HTTP Proxy: \{http_proxy_host}:\{r.http_proxy_port()}")
|
||||
}
|
||||
if torrent_api_enabled {
|
||||
println(
|
||||
" Torrent API: \{torrent_api_host}:\{r.torrent_api_port()} (b32=\{r.torrent_b32_address()})",
|
||||
)
|
||||
}
|
||||
println(
|
||||
" NetDB peers: \{r.netdb.router_count()} (floodfills=\{r.netdb.floodfill_count()})",
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user