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
+15
-3
@@ -446,12 +446,23 @@ fn send_http_proxy_error(
|
||||
status : Int32,
|
||||
reason : String,
|
||||
detail : String,
|
||||
refresh_sec~ : Int32 = 0,
|
||||
) -> Unit {
|
||||
let safe_reason = escape_html(reason)
|
||||
let safe_detail = escape_html(detail)
|
||||
let body = "<!doctype html><html><head><meta charset=\"utf-8\"><title>\{status} \{safe_reason}</title></head><body><h1>\{status} \{safe_reason}</h1><p>\{safe_detail}</p><hr><small>moon-i2p HTTP Proxy</small></body></html>\n"
|
||||
let refresh_meta = if refresh_sec > 0 {
|
||||
"<meta http-equiv=\"refresh\" content=\"\{refresh_sec}\">"
|
||||
} else {
|
||||
""
|
||||
}
|
||||
let refresh_hdr = if refresh_sec > 0 {
|
||||
"Retry-After: \{refresh_sec}\r\n"
|
||||
} else {
|
||||
""
|
||||
}
|
||||
let body = "<!doctype html><html><head><meta charset=\"utf-8\">\{refresh_meta}<title>\{status} \{safe_reason}</title></head><body><h1>\{status} \{safe_reason}</h1><p>\{safe_detail}</p><hr><small>moon-i2p HTTP Proxy</small></body></html>\n"
|
||||
let body_bytes = @encoding.string_to_utf8_bytes(body)
|
||||
let hdr = "HTTP/1.1 \{status} \{reason}\r\nContent-Type: text/html; charset=utf-8\r\nContent-Length: \{body_bytes.length()}\r\nConnection: close\r\n\r\n"
|
||||
let hdr = "HTTP/1.1 \{status} \{reason}\r\nContent-Type: text/html; charset=utf-8\r\nContent-Length: \{body_bytes.length()}\r\n\{refresh_hdr}Connection: close\r\n\r\n"
|
||||
let _ = sock.write_all(@encoding.string_to_utf8_bytes(hdr)) catch {
|
||||
_ => return
|
||||
}
|
||||
@@ -788,7 +799,8 @@ fn Router::step_http_proxy(self : Router) -> Bool {
|
||||
pc.sock,
|
||||
503,
|
||||
"Service Unavailable",
|
||||
"I2P router is still bootstrapping tunnels (inbound=\{self.inbound_tunnel_count()}, outbound=\{self.outbound_tunnel_count()}, peers=\{self.peer_count()}). Retry shortly.",
|
||||
"I2P router is still bootstrapping tunnels (inbound=\{self.inbound_tunnel_count()}, outbound=\{self.outbound_tunnel_count()}, peers=\{self.peer_count()}). Retrying automatically...",
|
||||
refresh_sec=3,
|
||||
)
|
||||
pc.sock.close()
|
||||
pc.closed = true
|
||||
|
||||
Reference in new issue
Block a user