feat: add Android APK with embedded I2P browser and torrent manager
check / check (ubuntu-latest) (push) Failing after 26s
check / check (macos-latest) (push) Failing after 29s
check / check (windows-latest) (push) Failing after 26s

- Add an Android app (org.mooni2p.browser) with an I2P WebView browser defaulting to insulaocculta.i2p, bookmarks, and a diagnostics dialog.
- Run the router in a foreground service and add a Torrents & DHT tab backed by the router API (manager.html).
- Handle magnet links and .torrent files from intents, the file picker, and .i2p downloads.
- Add scripts/build_apk.py and a `just apk` target that builds arm64-v8a and x86_64 APKs.
- Document the APK build and install steps in the README.
- Include related bittorrent, router, streaming, and ntcp2_net updates.
This commit is contained in:
nandi committed 2026-11-28 17:55:42 -08:00
1 parent fbe6818c4e
commit 7a1b4325f9
16 files changed
+3041 -78

No files matched your search

+65 -29
View File
@@ -101,32 +101,62 @@ fn StreamConnection::queue_packet(
}
///|
fn StreamConnection::current_nacks(self : StreamConnection) -> Array[UInt32] {
fn StreamConnection::wire_ack_and_nacks(
self : StreamConnection,
) -> (UInt32, Array[UInt32]) {
if self.ooo_recv.length() == 0 {
return []
return (self.ack_through, [])
}
let mut max_seen = self.next_recv_seq
let seqs : Array[UInt32] = []
for entry in self.ooo_recv {
if entry.0 > max_seen {
max_seen = entry.0
let s = entry.0
if s < self.next_recv_seq {
continue
}
}
let nacks : Array[UInt32] = []
let mut s = self.next_recv_seq
while s < max_seen && nacks.length() < 32 {
let mut found = false
for entry in self.ooo_recv {
if entry.0 == s {
found = true
let mut dup = false
for existing in seqs {
if existing == s {
dup = true
break
}
}
if !found {
nacks.push(s)
if !dup {
seqs.push(s)
}
s = s + 1U
}
nacks
if seqs.length() == 0 {
return (self.ack_through, [])
}
for i = 1; i < seqs.length(); i = i + 1 {
let key = seqs[i]
let mut j = i
while j > 0 && seqs[j - 1] > key {
seqs[j] = seqs[j - 1]
j -= 1
}
seqs[j] = key
}
let mut best_ack = self.ack_through
let nacks : Array[UInt32] = []
let mut cursor = self.next_recv_seq
for s in seqs {
if s < cursor {
continue
}
let gap = s - cursor
if gap <= 32U && nacks.length() + gap.reinterpret_as_int() <= 32 {
let mut m = cursor
while m < s {
nacks.push(m)
m = m + 1U
}
best_ack = s
cursor = s + 1U
} else {
break
}
}
(best_ack, nacks)
}
///|
@@ -354,12 +384,13 @@ fn StreamConnection::send_ack(
self : StreamConnection,
now_ms : UInt64,
) -> Unit raise StreamingError {
let (wire_ack, wire_nacks) = self.wire_ack_and_nacks()
let ack_pkt : StreamingPacket = {
send_stream_id: self.remote_stream_id,
recv_stream_id: self.local_stream_id,
sequence_num: 0U,
ack_through: self.ack_through,
nacks: self.current_nacks(),
ack_through: wire_ack,
nacks: wire_nacks,
resend_delay: b'\x00',
flags: 0U,
delay_requested: None,
@@ -479,8 +510,7 @@ pub fn StreamConnection::on_packet(
}
let seq = pkt.sequence_num
let has_data = pkt.payload.length() > 0 || (pkt.flags & flag_close) != 0U
if seq > 0U && has_data {
if seq > 0U && (pkt.flags & flag_synchronize) == 0U {
if seq == self.next_recv_seq {
for i = 0; i < pkt.payload.length(); i = i + 1 {
self.recv_buf.push(pkt.payload[i])
@@ -513,10 +543,14 @@ pub fn StreamConnection::on_packet(
self.send_ack(now_ms)
acked = true
}
if !acked && (pkt.flags & flag_delay_requested) != 0U {
match pkt.delay_requested {
Some(d) if d == 0U => self.send_ack(now_ms)
_ => ()
if !acked {
if (pkt.flags & flag_echo) != 0U {
self.send_ack(now_ms)
} else if (pkt.flags & flag_delay_requested) != 0U {
match pkt.delay_requested {
Some(d) if d == 0U => self.send_ack(now_ms)
_ => ()
}
}
}
}
@@ -543,12 +577,13 @@ pub fn StreamConnection::write(
let seq = self.next_send_seq
self.next_send_seq = seq + 1U
let flags = if self.has_recv_syn { 0U } else { flag_no_ack }
let (wire_ack, wire_nacks) = self.wire_ack_and_nacks()
let pkt : StreamingPacket = {
send_stream_id: self.remote_stream_id,
recv_stream_id: self.local_stream_id,
sequence_num: seq,
ack_through: self.ack_through,
nacks: self.current_nacks(),
ack_through: wire_ack,
nacks: wire_nacks,
resend_delay: b'\x00',
flags,
delay_requested: None,
@@ -592,12 +627,13 @@ pub fn StreamConnection::close(
}
let seq = self.next_send_seq
self.next_send_seq = seq + 1U
let (wire_ack, wire_nacks) = self.wire_ack_and_nacks()
let pkt : StreamingPacket = {
send_stream_id: self.remote_stream_id,
recv_stream_id: self.local_stream_id,
sequence_num: seq,
ack_through: self.ack_through,
nacks: self.current_nacks(),
ack_through: wire_ack,
nacks: wire_nacks,
resend_delay: b'\x00',
flags: flag_close |
flag_signature_included |
+77
View File
@@ -353,3 +353,80 @@ test "StreamManager dispatches protocol 17 repliable and protocol 18 raw datagra
assert_eq(bob_mgr.incoming_raw_dgrams[0].0.from_port, 6882U)
assert_eq(bob_mgr.incoming_raw_dgrams[0].1, b"dht-reply")
}
///|
test "Streaming SACK wire_ack_and_nacks invariant on out-of-order and large gaps" {
let (alice_dest, alice_seed) = make_test_identity(b'\x71')
let (bob_dest, bob_seed) = make_test_identity(b'\x72')
let alice_mgr = @streaming.StreamManager::new(
alice_dest,
alice_seed,
initial_stream_id=500U,
)
let bob_mgr = @streaming.StreamManager::new(
bob_dest,
bob_seed,
initial_stream_id=600U,
)
let a_stream = alice_mgr.connect(bob_dest.hash(), 1000UL)
for msg in a_stream.drain_outbound() {
let _ = bob_mgr.handle_incoming_i2cp(msg, 1005UL)
}
let b_stream = match bob_mgr.accept_next() {
Some(s) => s
None => fail("expected accept_next")
}
for msg in b_stream.drain_outbound() {
let _ = alice_mgr.handle_incoming_i2cp(msg, 1010UL)
}
let _ = alice_mgr.streams[0].drain_outbound()
fn make_data_pkt(seq : UInt32, payload : Bytes) -> Bytes {
let p : @streaming.StreamingPacket = {
send_stream_id: 600U,
recv_stream_id: 500U,
sequence_num: seq,
ack_through: 0U,
nacks: [],
resend_delay: b'\x00',
flags: 0U,
delay_requested: None,
from_dest: None,
max_packet_size: None,
offline_sig: None,
signature: None,
payload,
}
try! @streaming.encode_i2cp_streaming(p)
}
// Deliver seq 1, skip 2, deliver 3 and 4 -> ack_through must be 4, nacks == [2]
let _ = bob_mgr.handle_incoming_i2cp(make_data_pkt(1U, b"a"), 1020UL)
let _ = b_stream.drain_outbound()
let _ = bob_mgr.handle_incoming_i2cp(make_data_pkt(3U, b"c"), 1021UL)
let acks1 = b_stream.drain_outbound()
let (_, ack_dec1) = @streaming.decode_i2cp_streaming(acks1[0])
assert_eq(ack_dec1.ack_through, 3U)
assert_eq(ack_dec1.nacks, [2U])
let _ = bob_mgr.handle_incoming_i2cp(make_data_pkt(4U, b"d"), 1022UL)
let acks2 = b_stream.drain_outbound()
let (_, ack_dec2) = @streaming.decode_i2cp_streaming(acks2[0])
assert_eq(ack_dec2.ack_through, 4U)
assert_eq(ack_dec2.nacks, [2U])
// Deliver seq 50 (gap from cursor=5 to 50 is 45 > 32): ack_through must stay 4 and nacks stay [2]
let _ = bob_mgr.handle_incoming_i2cp(make_data_pkt(50U, b"z"), 1023UL)
let acks3 = b_stream.drain_outbound()
let (_, ack_dec3) = @streaming.decode_i2cp_streaming(acks3[0])
assert_eq(ack_dec3.ack_through, 4U)
assert_eq(ack_dec3.nacks, [2U])
// Empty seq=2 fills the gap -> drains 2,3,4 cleanly
let _ = bob_mgr.handle_incoming_i2cp(make_data_pkt(2U, b"b"), 1024UL)
let acks4 = b_stream.drain_outbound()
let (_, ack_dec4) = @streaming.decode_i2cp_streaming(acks4[0])
assert_eq(ack_dec4.ack_through, 4U)
assert_eq(ack_dec4.nacks, [])
assert_eq(b_stream.read_available(), b"abcd")
}