feat: add Android APK with embedded I2P browser and torrent manager
- 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:
1 parent
fbe6818c4e
commit
7a1b4325f9
16 files changed
+3041
-78
No files matched your search
@@ -0,0 +1,420 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title>Moon I2P Torrents & DHT</title>
|
||||
<style>
|
||||
:root {
|
||||
color-scheme: dark;
|
||||
--bg: #0b1120;
|
||||
--card: #131c31;
|
||||
--border: #23304d;
|
||||
--text: #e2e8f0;
|
||||
--muted: #94a3b8;
|
||||
--accent: #6d5dfc;
|
||||
--teal: #14b8a6;
|
||||
--danger: #ef4444;
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 12px;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font-family: system-ui, -apple-system, sans-serif;
|
||||
font-size: 14px;
|
||||
line-height: 1.45;
|
||||
}
|
||||
.card {
|
||||
background: var(--card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
padding: 12px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
h2 {
|
||||
margin: 0 0 10px 0;
|
||||
font-size: 12px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.06em;
|
||||
color: var(--muted);
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 8px;
|
||||
}
|
||||
.stat {
|
||||
background: rgba(15, 23, 42, 0.65);
|
||||
border: 1px solid rgba(255, 255, 255, 0.06);
|
||||
border-radius: 8px;
|
||||
padding: 8px;
|
||||
}
|
||||
.stat-label { font-size: 11px; color: var(--muted); }
|
||||
.stat-val { font-size: 13px; font-weight: 600; word-break: break-all; }
|
||||
.mono { font-family: ui-monospace, monospace; font-size: 11px; }
|
||||
.row { display: flex; gap: 8px; align-items: center; }
|
||||
input[type="text"], input[type="number"] {
|
||||
width: 100%;
|
||||
background: #0b1222;
|
||||
color: var(--text);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
padding: 9px 10px;
|
||||
font-size: 13px;
|
||||
}
|
||||
button {
|
||||
background: var(--accent);
|
||||
color: #fff;
|
||||
border: 0;
|
||||
border-radius: 8px;
|
||||
padding: 9px 13px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
}
|
||||
button.secondary {
|
||||
background: #1e293b;
|
||||
color: var(--text);
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
button.danger {
|
||||
background: rgba(239, 68, 68, 0.22);
|
||||
color: #fca5a5;
|
||||
border: 1px solid rgba(239, 68, 68, 0.4);
|
||||
}
|
||||
.pill {
|
||||
display: inline-block;
|
||||
padding: 2px 9px;
|
||||
border-radius: 999px;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
background: #1e293b;
|
||||
color: var(--muted);
|
||||
}
|
||||
.pill.online { background: rgba(20, 184, 166, 0.2); color: #5eead4; }
|
||||
.pill.offline { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
|
||||
.torrent-item {
|
||||
padding: 10px 0;
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.08);
|
||||
}
|
||||
.torrent-item:first-child { border-top: 0; padding-top: 0; }
|
||||
.track {
|
||||
width: 100%;
|
||||
height: 7px;
|
||||
background: #0b1222;
|
||||
border-radius: 999px;
|
||||
overflow: hidden;
|
||||
margin: 6px 0;
|
||||
}
|
||||
.fill {
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, var(--accent), var(--teal));
|
||||
}
|
||||
.msg { font-size: 12px; margin-top: 8px; min-height: 16px; color: #5eead4; }
|
||||
.msg.err { color: #fca5a5; }
|
||||
pre {
|
||||
margin: 8px 0 0 0;
|
||||
background: #0b1222;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
padding: 8px;
|
||||
font-size: 11px;
|
||||
max-height: 220px;
|
||||
overflow: auto;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<section class="card">
|
||||
<h2>
|
||||
<span>moon-i2p Router Status</span>
|
||||
<span id="status-pill" class="pill offline">Starting...</span>
|
||||
</h2>
|
||||
<div class="grid">
|
||||
<div class="stat">
|
||||
<div class="stat-label">NetDB / Tunnels</div>
|
||||
<div id="net-summary" class="stat-val">--</div>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<div class="stat-label">Download Folder</div>
|
||||
<div id="dl-dir" class="stat-val mono">--</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat" style="margin-top:8px;">
|
||||
<div class="stat-label">Torrent Session .b32.i2p</div>
|
||||
<div class="row" style="margin-top:4px;">
|
||||
<div id="torrent-b32" class="stat-val mono" style="flex:1;">--</div>
|
||||
<button id="copy-b32-btn" class="secondary" type="button">Copy</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<h2>
|
||||
<span>I2P Kademlia DHT (Proto 17 / 18)</span>
|
||||
<span id="dht-summary" class="mono">0 nodes</span>
|
||||
</h2>
|
||||
<div class="grid">
|
||||
<div class="stat">
|
||||
<div class="stat-label">DHT Node ID (20B)</div>
|
||||
<div id="dht-node-id" class="stat-val mono">--</div>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<div class="stat-label">Sent / Recv / Peers</div>
|
||||
<div id="dht-stats" class="stat-val">0 / 0 / 0</div>
|
||||
</div>
|
||||
</div>
|
||||
<form id="bootstrap-form" class="row" style="margin-top:10px;">
|
||||
<input id="bootstrap-b32" type="text" placeholder="Bootstrap node .b32.i2p" />
|
||||
<input id="bootstrap-port" type="number" value="6881" style="width:82px;" />
|
||||
<button type="submit" class="secondary">Ping</button>
|
||||
</form>
|
||||
<div id="dht-nodes" class="mono" style="margin-top:8px;color:var(--muted);">No DHT nodes yet.</div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<h2><span>Add I2P Torrent</span></h2>
|
||||
<form id="magnet-form" class="row">
|
||||
<input id="magnet-uri" type="text" placeholder="magnet:?xt=urn:btih:..." />
|
||||
<button type="submit">Add</button>
|
||||
</form>
|
||||
<div class="row" style="margin-top:8px;">
|
||||
<button id="pick-file-btn" class="secondary" type="button" style="width:100%;">
|
||||
Open .torrent File
|
||||
</button>
|
||||
<input id="torrent-file" type="file" accept=".torrent" style="display:none;" />
|
||||
</div>
|
||||
<div id="status-msg" class="msg"></div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<h2>
|
||||
<span>Active Torrents</span>
|
||||
<span id="torrent-count" class="mono">0</span>
|
||||
</h2>
|
||||
<div id="torrents-list" style="color:var(--muted);">No torrents added yet.</div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<h2>
|
||||
<span>Diagnostics & Verbose Logs</span>
|
||||
<span class="row">
|
||||
<button id="copy-diag-btn" type="button">Copy Diagnostics</button>
|
||||
<button id="refresh-log-btn" class="secondary" type="button">Refresh</button>
|
||||
</span>
|
||||
</h2>
|
||||
<pre id="router-log" class="mono">Loading diagnostics...</pre>
|
||||
</section>
|
||||
|
||||
<script>
|
||||
"use strict";
|
||||
const $ = (id) => document.getElementById(id);
|
||||
|
||||
function fmtBytes(n) {
|
||||
if (!n || n <= 0) return "0 B";
|
||||
const units = ["B", "KiB", "MiB", "GiB"];
|
||||
let u = 0;
|
||||
let v = n;
|
||||
while (v >= 1024 && u < units.length - 1) {
|
||||
v /= 1024;
|
||||
u++;
|
||||
}
|
||||
return v.toFixed(u === 0 ? 0 : 1) + " " + units[u];
|
||||
}
|
||||
|
||||
function escapeHtml(s) {
|
||||
return String(s || "").replace(/[&<>"']/g, (c) => ({
|
||||
"&": "&",
|
||||
"<": "<",
|
||||
">": ">",
|
||||
'"': """,
|
||||
"'": "'",
|
||||
})[c]);
|
||||
}
|
||||
|
||||
function setMsg(text, isErr) {
|
||||
const el = $("status-msg");
|
||||
el.textContent = text;
|
||||
el.className = isErr ? "msg err" : "msg";
|
||||
}
|
||||
|
||||
function bytesToBase64(bytes) {
|
||||
let bin = "";
|
||||
const chunk = 0x8000;
|
||||
for (let i = 0; i < bytes.length; i += chunk) {
|
||||
bin += String.fromCharCode(...bytes.subarray(i, i + chunk));
|
||||
}
|
||||
return btoa(bin);
|
||||
}
|
||||
|
||||
async function api(path, method, bodyObj) {
|
||||
const headers = {};
|
||||
const opts = { method: method || "GET", headers: headers, cache: "no-store" };
|
||||
if (method === "POST") {
|
||||
headers["X-Moon-I2P"] = "1";
|
||||
headers["Content-Type"] = "application/json";
|
||||
opts.body = JSON.stringify(bodyObj || {});
|
||||
}
|
||||
const resp = await fetch(path, opts);
|
||||
return await resp.json();
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
try {
|
||||
const [st, tl, dn] = await Promise.all([
|
||||
api("/api/status", "GET"),
|
||||
api("/api/torrents", "GET"),
|
||||
api("/api/dht/nodes", "GET"),
|
||||
]);
|
||||
const pill = $("status-pill");
|
||||
if (st && st.ok) {
|
||||
pill.textContent = "Online";
|
||||
pill.className = "pill online";
|
||||
$("net-summary").textContent =
|
||||
(st.netdb_routers || 0) + " peers · " +
|
||||
(st.inbound_tunnels || 0) + "in/" + (st.outbound_tunnels || 0) + "out";
|
||||
$("dl-dir").textContent = st.download_dir || "--";
|
||||
$("torrent-b32").textContent = st.torrent_b32 || "--";
|
||||
const d = st.dht || {};
|
||||
$("dht-summary").textContent = (d.routing_table_nodes || 0) + " nodes";
|
||||
$("dht-node-id").textContent = d.node_id_hex || "--";
|
||||
$("dht-stats").textContent =
|
||||
(d.queries_sent || 0) + " / " + (d.responses_recv || 0) + " / " + (d.peers_discovered || 0);
|
||||
} else {
|
||||
pill.textContent = "Offline";
|
||||
pill.className = "pill offline";
|
||||
}
|
||||
|
||||
const nodes = (dn && dn.nodes) || [];
|
||||
$("dht-nodes").innerHTML = nodes.length === 0
|
||||
? "No DHT nodes yet."
|
||||
: nodes.map((n) => "<div>" + escapeHtml(n.b32) + ":" + n.port + "</div>").join("");
|
||||
|
||||
const list = (tl && tl.torrents) || [];
|
||||
$("torrent-count").textContent = String(list.length);
|
||||
$("torrents-list").innerHTML = list.length === 0
|
||||
? "No torrents added yet."
|
||||
: list.map((t) => {
|
||||
const pct = Number(t.progress_pct || 0);
|
||||
const act = t.paused ? "resume" : "pause";
|
||||
const label = t.paused ? "Resume" : "Pause";
|
||||
const infTxt = t.inflight_blocks > 0 ? " (+" + t.inflight_blocks + " blks)" : "";
|
||||
const peerRows = (t.peers || []).map((p) => {
|
||||
const tag = p.client ? " [" + p.client + "]" : "";
|
||||
const ch = p.choking ? "choked" : "unchoked";
|
||||
return "<div>peer " + escapeHtml(p.b32) + escapeHtml(tag) + " · st=" + p.state + " " + ch + " · " + p.pieces + " pcs · inf=" + p.in_flight + " · blks=" + p.blocks_recv + "</div>";
|
||||
}).join("");
|
||||
return (
|
||||
'<div class="torrent-item">' +
|
||||
'<div class="row" style="justify-content:space-between;">' +
|
||||
"<strong>" + escapeHtml(t.name) + "</strong>" +
|
||||
'<span class="pill ' + (t.completed ? "online" : "") + '">' + escapeHtml(t.state) + " · " + pct + "%</span>" +
|
||||
"</div>" +
|
||||
'<div class="track"><div class="fill" style="width:' + pct + '%"></div></div>' +
|
||||
'<div class="row" style="justify-content:space-between;font-size:12px;color:var(--muted);">' +
|
||||
"<span>" + fmtBytes(t.downloaded_bytes) + " / " + fmtBytes(t.total_length) + " · " + t.have_pieces + "/" + t.num_pieces + " pcs" + infTxt + " · " + t.connected_peers + "/" + t.known_peers + " peers (" + (t.unchoked_peers || 0) + " unchoked)</span>" +
|
||||
'<span class="row">' +
|
||||
'<button type="button" class="secondary act-btn" data-act="' + act + '" data-ih="' + escapeHtml(t.info_hash) + '">' + label + "</button>" +
|
||||
'<button type="button" class="danger act-btn" data-act="remove" data-ih="' + escapeHtml(t.info_hash) + '">Remove</button>' +
|
||||
"</span>" +
|
||||
"</div>" +
|
||||
(t.last_tracker_status ? '<div class="mono" style="margin-top:4px;color:var(--muted);">Tracker: ' + escapeHtml(t.last_tracker_status) + "</div>" : "") +
|
||||
(t.error ? '<div class="mono" style="margin-top:4px;color:#fca5a5;">Error: ' + escapeHtml(t.error) + "</div>" : "") +
|
||||
(peerRows ? '<div class="mono" style="margin-top:4px;color:var(--muted);">' + peerRows + "</div>" : "") +
|
||||
"</div>"
|
||||
);
|
||||
}).join("");
|
||||
} catch (_e) {
|
||||
$("status-pill").textContent = "Starting...";
|
||||
$("status-pill").className = "pill offline";
|
||||
}
|
||||
}
|
||||
|
||||
$("copy-b32-btn").addEventListener("click", () => {
|
||||
const b32 = $("torrent-b32").textContent || "";
|
||||
if (window.MoonAndroid && b32 && b32 !== "--") {
|
||||
window.MoonAndroid.copyText(b32);
|
||||
setMsg("Copied .b32.i2p address", false);
|
||||
}
|
||||
});
|
||||
|
||||
$("bootstrap-form").addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
const b32 = $("bootstrap-b32").value.trim();
|
||||
const port = Number($("bootstrap-port").value) || 6881;
|
||||
if (!b32) return;
|
||||
const res = await api("/api/dht/bootstrap", "POST", { b32, port });
|
||||
setMsg(res && res.ok ? "Sent DHT ping to " + res.b32 : "DHT error: " + (res?.error || "failed"), !res?.ok);
|
||||
refresh();
|
||||
});
|
||||
|
||||
$("magnet-form").addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
const uri = $("magnet-uri").value.trim();
|
||||
if (!uri) return;
|
||||
const res = await api("/api/torrents/magnet", "POST", { uri });
|
||||
if (res && res.ok) {
|
||||
$("magnet-uri").value = "";
|
||||
setMsg("Added magnet " + res.info_hash.slice(0, 12) + "...", false);
|
||||
} else {
|
||||
setMsg("Magnet error: " + (res?.error || "router starting"), true);
|
||||
}
|
||||
refresh();
|
||||
});
|
||||
|
||||
$("pick-file-btn").addEventListener("click", () => {
|
||||
if (window.MoonAndroid && window.MoonAndroid.pickTorrentFile) {
|
||||
window.MoonAndroid.pickTorrentFile();
|
||||
} else {
|
||||
$("torrent-file").click();
|
||||
}
|
||||
});
|
||||
|
||||
$("torrent-file").addEventListener("change", async () => {
|
||||
const f = $("torrent-file").files[0];
|
||||
if (!f) return;
|
||||
const buf = new Uint8Array(await f.arrayBuffer());
|
||||
const res = await api("/api/torrents/add", "POST", { torrent_b64: bytesToBase64(buf) });
|
||||
setMsg(res && res.ok ? "Added " + f.name : "Add failed: " + (res?.error || "error"), !res?.ok);
|
||||
refresh();
|
||||
});
|
||||
|
||||
$("torrents-list").addEventListener("click", async (e) => {
|
||||
const btn = e.target.closest(".act-btn");
|
||||
if (!btn) return;
|
||||
await api("/api/torrents/" + btn.dataset.act, "POST", { info_hash: btn.dataset.ih });
|
||||
refresh();
|
||||
});
|
||||
|
||||
function refreshLog() {
|
||||
if (window.MoonAndroid && window.MoonAndroid.getDiagnosticsReport) {
|
||||
$("router-log").textContent = window.MoonAndroid.getDiagnosticsReport() || "(empty)";
|
||||
} else if (window.MoonAndroid && window.MoonAndroid.getRouterLog) {
|
||||
$("router-log").textContent = window.MoonAndroid.getRouterLog() || "(empty)";
|
||||
}
|
||||
}
|
||||
|
||||
$("copy-diag-btn").addEventListener("click", () => {
|
||||
if (window.MoonAndroid && window.MoonAndroid.copyDiagnostics) {
|
||||
const rep = window.MoonAndroid.copyDiagnostics();
|
||||
if (rep) $("router-log").textContent = rep;
|
||||
setMsg("Copied full diagnostics report to clipboard", false);
|
||||
}
|
||||
});
|
||||
|
||||
$("refresh-log-btn").addEventListener("click", refreshLog);
|
||||
|
||||
refresh();
|
||||
refreshLog();
|
||||
setInterval(refresh, 2000);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user