feat: add non-blocking NTCP2 sends and Firefox settings sync
check / check (macos-latest) (push) Failing after 26s
check / check (ubuntu-latest) (push) Failing after 27s
check / check (windows-latest) (push) Failing after 30s

- NTCP2: queue outbound data frames and flush them without blocking (send_blocks_nb, send_i2np_nb, flush_nonblocking)
- NTCP2: bound write_all with a deadline and set TCP keepalive and user timeout on peer sockets
- Firefox extension 0.1.3: save settings as a patch, keep unsaved form fields from being overwritten on refresh, add timeouts to router API calls, and honor the interceptTorrents toggle in the content script
This commit is contained in:
nandi committed 2026-11-28 18:39:32 -08:00
1 parent 82aaa9f11e
commit 9aa15f9ae8
18 files changed
+1323 -239

No files matched your search

+131
View File
@@ -721,3 +721,134 @@ test "2-router I2P DHT + BEP 9 Magnet + Streaming torrent download and HTTP API
)
assert_true(nodes_json.contains(router_a.torrent_b32_address()))
}
///|
test "POST /api/torrents/add accepts standard, URL-safe, and rejects invalid Base64" {
let dl_dir = "/tmp/moon_i2p_bt_b64_test"
@ntcp2_net.mkdir_p(dl_dir)
let r = @router.Router::start({
sam_host: "127.0.0.1",
sam_port: 0,
ntcp2_host: "127.0.0.1",
ntcp2_port: 0,
})
defer r.close()
let api_port = r.start_torrent_api(
host="127.0.0.1",
port=0,
download_dir=dl_dir,
)
let rs = [r]
let make_b64 = fn(tbytes : Bytes, to_std : Bool, strip_pad : Bool) -> String {
let i2p_b64 = @encoding.base64_encode(tbytes)
let sb = StringBuilder()
for ch in i2p_b64 {
if strip_pad && ch == '=' {
continue
}
if to_std {
match ch {
'-' => sb.write_char('+')
'~' => sb.write_char('/')
_ => sb.write_char(ch)
}
} else {
match ch {
'~' => sb.write_char('_')
_ => sb.write_char(ch)
}
}
}
sb.to_string()
}
let t1 = @bittorrent.bencode_encode(
BDict([
(b"comment", BBytes(b"\xfb\xff\xbf\xfb\xff")),
(
b"info",
BDict([
(b"length", BInt(16L)),
(b"name", BBytes(b"std-b64.bin")),
(b"piece length", BInt(16384L)),
(b"pieces", BBytes(Bytes::make(20, b'\xfb'))),
]),
),
]),
)
let ih1 = @encoding.hex_encode(@bittorrent.parse_torrent(t1).info_hash)
let std_b64 = make_b64(t1, true, false)
assert_true(std_b64.contains("+"))
assert_true(std_b64.contains("/"))
let resp1 = test_http_api_request(
api_port,
rs,
"POST",
"/api/torrents/add",
"127.0.0.1:\{api_port}",
[("Content-Type", "application/json"), ("X-Moon-I2P", "1")],
"{\"torrent_b64\":\"\{std_b64}\"}",
)
assert_true(resp1.contains("200 OK"))
assert_true(resp1.contains(ih1))
// Unpadded URL-safe Base64 (ensure length % 3 != 0 so stripping '=' exercises padding recovery)
let mut t2 = @bittorrent.bencode_encode(
BDict([
(b"comment", BBytes(b"\xfb\xff\xbf\xfb\xff")),
(
b"info",
BDict([
(b"length", BInt(16L)),
(b"name", BBytes(b"url-b64-a.bin")),
(b"piece length", BInt(16384L)),
(b"pieces", BBytes(Bytes::make(20, b'\xff'))),
]),
),
]),
)
if t2.length() % 3 == 0 {
t2 = @bittorrent.bencode_encode(
BDict([
(b"comment", BBytes(b"\xfb\xff\xbf\xfb\xff")),
(
b"info",
BDict([
(b"length", BInt(16L)),
(b"name", BBytes(b"url-b64-ab.bin")),
(b"piece length", BInt(16384L)),
(b"pieces", BBytes(Bytes::make(20, b'\xff'))),
]),
),
]),
)
}
let ih2 = @encoding.hex_encode(@bittorrent.parse_torrent(t2).info_hash)
let url_b64 = make_b64(t2, false, true)
assert_true(url_b64.contains("-") && url_b64.contains("_"))
assert_true(!url_b64.contains("="))
let resp2 = test_http_api_request(
api_port,
rs,
"POST",
"/api/torrents/add",
"127.0.0.1:\{api_port}",
[("Content-Type", "application/json"), ("X-Moon-I2P", "1")],
"{\"torrent_b64\":\"\{url_b64}\"}",
)
assert_true(resp2.contains("200 OK"))
assert_true(resp2.contains(ih2))
let bad_resp = test_http_api_request(
api_port,
rs,
"POST",
"/api/torrents/add",
"127.0.0.1:\{api_port}",
[("Content-Type", "application/json"), ("X-Moon-I2P", "1")],
"{\"torrent_b64\":\"not*valid*b64!\"}",
)
assert_true(bad_resp.contains("400 Bad Request"))
assert_true(bad_resp.contains("invalid torrent_b64"))
}