From 4041d75011d3a8bed96189df85442b54c561aade Mon Sep 17 00:00:00 2001 From: "Luis Guzman (AppDevForAll)" Date: Fri, 20 Nov 2026 10:07:30 -0600 Subject: [PATCH 1/5] K2GO-588 fix(download): the rootfs download is HTTP only, never BitTorrent The published .meta4 carries a torrent , and aria2 turned the download into a BitTorrent session (it ended in the SEED state on a 7T). --follow-torrent=false does not stop it (ADR-K2GO-554 A4). The app now gives aria2 a local copy of the .meta4 without the metaurl (MetalinkHttpOnly), and runs it with DHT, LPD and peer exchange off. The IPv4 profiler uses the same copy. A .meta4 that cannot be read is reported as a network problem, and a stop latched in that window is still honored. --- .../org/appdevforall/k2go/Aria2Manager.java | 90 +++++++++++++------ .../k2go/Aria2NetworkProfiler.java | 15 ++-- .../download/domain/MetalinkHttpOnly.java | 34 +++++++ .../download/domain/MetalinkHttpOnlyTest.java | 64 +++++++++++++ 4 files changed, 169 insertions(+), 34 deletions(-) create mode 100644 controller/app/src/main/java/org/appdevforall/k2go/download/domain/MetalinkHttpOnly.java create mode 100644 controller/app/src/test/java/org/appdevforall/k2go/download/domain/MetalinkHttpOnlyTest.java diff --git a/controller/app/src/main/java/org/appdevforall/k2go/Aria2Manager.java b/controller/app/src/main/java/org/appdevforall/k2go/Aria2Manager.java index 552763ee8..c6d92fd05 100644 --- a/controller/app/src/main/java/org/appdevforall/k2go/Aria2Manager.java +++ b/controller/app/src/main/java/org/appdevforall/k2go/Aria2Manager.java @@ -188,11 +188,8 @@ public void startDownload(Context context, String url, RootfsManifest.Target sig File downloadDir = new File(SystemStateEvaluator.rootfsBaseDir(context), "downloads"); if (!downloadDir.exists()) downloadDir.mkdirs(); - // Secure DHT file within our app (avoids the com.termux crash) - File dhtFile = new File(context.getFilesDir(), "dht.dat"); - if (!dhtFile.exists()) { - try { dhtFile.createNewFile(); } catch (Exception e) { Log.w(TAG, "Could not create dht.dat"); } - } + // K2GO-588: no BitTorrent any more; remove the DHT state that older builds kept. + new File(context.getFilesDir(), "dht.dat").delete(); // --- Extract SSL Certificate from assets --- File caCertFile = new File(context.getFilesDir(), "cacert.pem"); @@ -213,7 +210,25 @@ public void startDownload(Context context, String url, RootfsManifest.Target sig // --split mirror count, and reconciling whatever is already on disk so that // stopping and restarting a download is safe (no wasted re-download, and the // network profiler never trips over a leftover completed file). - MetalinkFile mf = MetalinkSplit.isMetalinkUrl(url) ? fetchMetalink(url) : null; + // K2GO-588 (ADR-K2GO-554 A4): aria2 gets a local copy of the .meta4 without its + // , so the download is HTTP only. Without that copy aria2 would read the URL + // and turn the torrent metaurl into a BitTorrent session, so a failed read stops here. + File httpOnlyMeta = new File(context.getCacheDir(), "rootfs-http-only.meta4"); + MetalinkFile mf = null; + String source = url; + if (MetalinkSplit.isMetalinkUrl(url)) { + mf = fetchMetalink(url, httpOnlyMeta); + if (mf == null) { + if (postLatchedStop(mainHandler, listener)) return; + // The same answer aria2 gives for a network problem (exit 6), so the caller + // offers a retry as before. + mainHandler.post(() -> listener.onError( + org.appdevforall.k2go.download.domain.Aria2Exit.label(6), + org.appdevforall.k2go.download.domain.Aria2Exit.Kind.TRANSIENT)); + return; + } + source = "--metalink-file=" + httpOnlyMeta.getAbsolutePath(); + } // resumeOrRepair: an existing (partial or complete-but-corrupt) file is on // disk. Keep it and let the main aria2 run below salvage it via // --check-integrity against the .meta4 piece hashes (re-downloading only the @@ -274,7 +289,7 @@ public void startDownload(Context context, String url, RootfsManifest.Target sig // right, only the preamble was wasted. boolean resuming = resumeOrRepair || hasControlFile(downloadDir); boolean forceIpv4 = resuming ? false - : Aria2NetworkProfiler.shouldForceIpv4(aria2Bin, downloadDir, dhtFile, url, mainHandler, listener); + : Aria2NetworkProfiler.shouldForceIpv4(aria2Bin, downloadDir, source, mainHandler, listener); // ---------------------------------------------------- // 3. Build the command dynamically. @@ -283,9 +298,9 @@ public void startDownload(Context context, String url, RootfsManifest.Target sig // "Get more" downloads. Keep both aligned so behaviour matches; if you change flags // here, mirror them there (and note any intentional divergence). Known divergences: // the server uses Debian's system CA (no bundled cacert), the container resolver - // (--async-dns=false) instead of ApplyDnsUseCase + the IPv4 profiler, and has no - // DHT/BitTorrent yet; only this app path pre-reconciles/resumes via MetalinkSplit + - // DownloadVerifier before invoking aria2. + // (--async-dns=false) instead of ApplyDnsUseCase + the IPv4 profiler. Neither path + // uses BitTorrent (K2GO-588). Only this app path pre-reconciles/resumes via + // MetalinkSplit + DownloadVerifier before invoking aria2. java.util.List command = new java.util.ArrayList<>(); command.add(aria2Bin.getAbsolutePath()); command.add("--dir=" + downloadDir.getAbsolutePath()); @@ -305,10 +320,12 @@ public void startDownload(Context context, String url, RootfsManifest.Target sig // while downloading. On mismatch aria2 exits non-zero, so onError fires // and the archive is never extracted/executed. command.add("--check-integrity=true"); - command.add("--enable-dht=true"); - command.add("--dht-file-path=" + dhtFile.getAbsolutePath()); - command.add("--bt-enable-lpd=true"); - command.add("--seed-time=0"); + // K2GO-588: HTTP only. The metaurl is gone from the .meta4 above; these keep aria2 + // from any peer traffic even so (its default is DHT on). + command.add("--enable-dht=false"); + command.add("--enable-dht6=false"); + command.add("--bt-enable-lpd=false"); + command.add("--enable-peer-exchange=false"); // --- Apply SSL Certificate Validation (D6: always strict; cacert // presence was already enforced above, so there is no insecure path) --- @@ -375,7 +392,7 @@ public void startDownload(Context context, String url, RootfsManifest.Target sig command.add("--disable-ipv6=true"); } - command.add(url); + command.add(source); ProcessBuilder pb = new ProcessBuilder(command); @@ -384,16 +401,7 @@ public void startDownload(Context context, String url, RootfsManifest.Target sig // null, so a stop arriving in that window latches the reason and kills nothing. // Without this the caller's cleanup could delete the download directory and aria2 // would then start, recreate it and write fresh residue behind it. - if (stopRequest == Stop.CANCEL) { - Log.d(TAG, "Download cancelled before aria2 was started."); - mainHandler.post(listener::onCancelled); - return; - } - if (stopRequest == Stop.PAUSE) { - Log.d(TAG, "Download paused before aria2 was started."); - mainHandler.post(listener::onPaused); - return; - } + if (postLatchedStop(mainHandler, listener)) return; // Redirect errors to the same input stream pb.redirectErrorStream(true); @@ -613,8 +621,23 @@ private void requestStop(Stop reason) { /** * Helper method to copy files from the APK assets folder to internal storage. */ + /** ADFA-5119: a stop latched before aria2 started; reports it and returns true. */ + private boolean postLatchedStop(Handler mainHandler, DownloadListener listener) { + if (stopRequest == Stop.CANCEL) { + Log.d(TAG, "Download cancelled before aria2 was started."); + mainHandler.post(listener::onCancelled); + return true; + } + if (stopRequest == Stop.PAUSE) { + Log.d(TAG, "Download paused before aria2 was started."); + mainHandler.post(listener::onPaused); + return true; + } + return false; + } + /** ADFA-4676: fetch + parse the .meta4 into a verifiable MetalinkFile, or null on any error. */ - private MetalinkFile fetchMetalink(String url) { + private MetalinkFile fetchMetalink(String url, File httpOnlyCopy) { HttpURLConnection conn = null; try { conn = (HttpURLConnection) new URL(url).openConnection(); @@ -624,9 +647,22 @@ private MetalinkFile fetchMetalink(String url) { if (conn.getResponseCode() != 200) { return null; } + byte[] raw; try (InputStream in = conn.getInputStream()) { - return MetalinkFile.parse(in); + java.io.ByteArrayOutputStream buf = new java.io.ByteArrayOutputStream(); + byte[] chunk = new byte[16384]; + int n; + while ((n = in.read(chunk)) > 0) buf.write(chunk, 0, n); + raw = buf.toByteArray(); + } + MetalinkFile mf = MetalinkFile.parse(new java.io.ByteArrayInputStream(raw)); + // K2GO-588: the copy that aria2 reads, without the BitTorrent metaurl. + try (java.io.Writer w = new java.io.OutputStreamWriter( + new java.io.FileOutputStream(httpOnlyCopy), java.nio.charset.StandardCharsets.UTF_8)) { + w.write(org.appdevforall.k2go.download.domain.MetalinkHttpOnly.of( + new String(raw, java.nio.charset.StandardCharsets.UTF_8))); } + return mf; } catch (Exception e) { Log.w(TAG, "fetchMetalink fallback (" + e.getMessage() + ")"); return null; diff --git a/controller/app/src/main/java/org/appdevforall/k2go/Aria2NetworkProfiler.java b/controller/app/src/main/java/org/appdevforall/k2go/Aria2NetworkProfiler.java index b89d4da2a..c5a720c00 100644 --- a/controller/app/src/main/java/org/appdevforall/k2go/Aria2NetworkProfiler.java +++ b/controller/app/src/main/java/org/appdevforall/k2go/Aria2NetworkProfiler.java @@ -29,18 +29,18 @@ public class Aria2NetworkProfiler { * Runs a real-world speed test by downloading the target file for a few seconds. * Returns TRUE if IPv4 proves to be more stable and faster. */ - public static boolean shouldForceIpv4(File aria2Bin, File downloadDir, File dhtFile, String targetUrl, Handler mainHandler, Aria2Manager.DownloadListener listener) { + public static boolean shouldForceIpv4(File aria2Bin, File downloadDir, String source, Handler mainHandler, Aria2Manager.DownloadListener listener) { Log.i(TAG, "Starting Network Profiling (Time-Boxed Race)..."); // 1. Test IPv4 (Forced) mainHandler.post(() -> listener.onProgress(0, "Test IPv4", "Wait")); Log.i(TAG, "=== TEST 1: FORCED IPv4 ROUTE ==="); - double speedIpv4 = runTimeBoxedTest(aria2Bin, downloadDir, dhtFile, targetUrl, true); + double speedIpv4 = runTimeBoxedTest(aria2Bin, downloadDir, source, true); // 2. Test Default (Usually IPv6 preferred) mainHandler.post(() -> listener.onProgress(0, "Test IPv6", "Wait")); Log.i(TAG, "=== TEST 2: DEFAULT ROUTE (IPv6 Preferred) ==="); - double speedDefault = runTimeBoxedTest(aria2Bin, downloadDir, dhtFile, targetUrl, false); + double speedDefault = runTimeBoxedTest(aria2Bin, downloadDir, source, false); Log.i(TAG, "=== FINAL PROFILING RESULTS ==="); Log.i(TAG, String.format("Sustained Speed IPv4: %.2f KB/s", speedIpv4)); @@ -66,7 +66,7 @@ public static boolean shouldForceIpv4(File aria2Bin, File downloadDir, File dhtF return forceIpv4; } - private static double runTimeBoxedTest(File aria2Bin, File downloadDir, File dhtFile, String url, boolean forceIpv4) { + private static double runTimeBoxedTest(File aria2Bin, File downloadDir, String source, boolean forceIpv4) { Process process = null; double lastRecordedSpeedKB = 0.0; @@ -80,8 +80,9 @@ private static double runTimeBoxedTest(File aria2Bin, File downloadDir, File dht // Match your baseline configuration command.add("--max-connection-per-server=4"); command.add("--split=4"); - command.add("--enable-dht=true"); - command.add("--dht-file-path=" + dhtFile.getAbsolutePath()); + // K2GO-588: HTTP only, like the real download (Aria2Manager). + command.add("--enable-dht=false"); + command.add("--enable-dht6=false"); command.add("--check-certificate=false"); if (forceIpv4) { @@ -91,7 +92,7 @@ private static double runTimeBoxedTest(File aria2Bin, File downloadDir, File dht command.add("--console-log-level=warn"); command.add("--summary-interval=1"); // Need speed output every second command.add("--download-result=hide"); - command.add(url); + command.add(source); ProcessBuilder pb = new ProcessBuilder(command); pb.redirectErrorStream(true); diff --git a/controller/app/src/main/java/org/appdevforall/k2go/download/domain/MetalinkHttpOnly.java b/controller/app/src/main/java/org/appdevforall/k2go/download/domain/MetalinkHttpOnly.java new file mode 100644 index 000000000..8713f11f2 --- /dev/null +++ b/controller/app/src/main/java/org/appdevforall/k2go/download/domain/MetalinkHttpOnly.java @@ -0,0 +1,34 @@ +/* + * ============================================================================ + * Name : MetalinkHttpOnly.java + * Author : AppDevForAll + * Copyright : Copyright (c) 2026 AppDevForAll + * Description : K2GO-588 (ADR-K2GO-554 A4). A Metalink with its elements + * removed, so aria2 downloads over HTTP only, never BitTorrent. + * ============================================================================ + */ +package org.appdevforall.k2go.download.domain; + +import java.util.regex.Pattern; + +/** + * aria2 turns a Metalink that carries a {@code } into a BitTorrent + * session, and {@code --follow-torrent=false} does not stop it (measured, ADR-K2GO-554 A4). So the + * app gives aria2 a copy of the Metalink without the metaurl elements. The {@code } mirrors, + * size and hashes stay unchanged. + */ +public final class MetalinkHttpOnly { + + // A ... element or a self-closing , with its leading space. + private static final Pattern METAURL = Pattern.compile( + "[ \\t]*]*?(?:/>|>.*?)[ \\t]*\\r?\\n?", + Pattern.DOTALL | Pattern.CASE_INSENSITIVE); + + private MetalinkHttpOnly() {} + + /** The same Metalink text without any {@code } element. */ + public static String of(String metalinkXml) { + if (metalinkXml == null) return null; + return METAURL.matcher(metalinkXml).replaceAll(""); + } +} diff --git a/controller/app/src/test/java/org/appdevforall/k2go/download/domain/MetalinkHttpOnlyTest.java b/controller/app/src/test/java/org/appdevforall/k2go/download/domain/MetalinkHttpOnlyTest.java new file mode 100644 index 000000000..f56103ff4 --- /dev/null +++ b/controller/app/src/test/java/org/appdevforall/k2go/download/domain/MetalinkHttpOnlyTest.java @@ -0,0 +1,64 @@ +package org.appdevforall.k2go.download.domain; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.nio.charset.StandardCharsets; + +import org.junit.Test; + +public class MetalinkHttpOnlyTest { + + private static final String PUBLISHED = + "\n" + + "\n" + + " \n" + + " 1590750919\n" + + " 28173c20010e4bf54e3b276cb0dd68201e2e473422704bfae85b8ed7e24d3560\n" + + " https://example.org/k2go_2026.321_basic_c746edd_arm64-v8a.tar.gz\n" + + " k2go_2026.321_basic_c746edd_arm64-v8a.tar.gz.torrent\n" + + " \n" + + "\n"; + + @Test + public void removesTheTorrentMetaurlAndKeepsEverythingElse() { + String out = MetalinkHttpOnly.of(PUBLISHED); + assertFalse(out.contains("metaurl")); + assertFalse(out.contains(".torrent")); + assertEquals(PUBLISHED.replaceAll(" \n" + + "\n x.torrent\n\n\n"; + assertEquals("\nhttps://a/x\n\n", MetalinkHttpOnly.of(in)); + } + + @Test + public void aMetalinkWithoutMetaurlIsUnchanged() { + String in = PUBLISHED.replaceAll(" ")); + } + + @Test + public void nullStaysNull() { + assertNull(MetalinkHttpOnly.of(null)); + } +} From f55d44cb44800db4e59ee400776596a785c37b17 Mon Sep 17 00:00:00 2001 From: "Luis Guzman (AppDevForAll)" Date: Fri, 20 Nov 2026 10:07:31 -0600 Subject: [PATCH 2/5] K2GO-588 chore(rootfs): new bakes publish an HTTP-only .meta4 and no .torrent The builder deletes the mkmetalink .torrent and removes the line before the bake signs the .meta4. Old .torrent files on R2 are pruned with their tarball. --- .github/workflows/rootfs-2-bake.yml | 5 +++-- tools/rootfs-builder/build-iiab-rootfs.sh | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/rootfs-2-bake.yml b/.github/workflows/rootfs-2-bake.yml index 562cb9215..efba88bb3 100644 --- a/.github/workflows/rootfs-2-bake.yml +++ b/.github/workflows/rootfs-2-bake.yml @@ -307,8 +307,8 @@ jobs: source "$GITHUB_WORKSPACE/tools/rootfs-builder/r2-cp.sh" # s3cp: aws s3 cp with retries cd dist - # Big artifacts first, then their per-artifact sidecars (.meta4/.sha256/.installed/ - # .torrent). Pointers, logs and the queue stay for the publish job. + # Big artifacts first, then their per-artifact sidecars (.meta4/.sha256/.installed). + # No .torrent since K2GO-588. Pointers, logs and the queue stay for the publish job. shopt -s nullglob for f in k2go_*.tar.gz; do echo ">> upload artifact $f" @@ -412,6 +412,7 @@ jobs: if (( n > KEEP )); then for key in "${keys[@]:0:n-KEEP}"; do echo ">> prune $key (+ sidecars)" + # .torrent: older bakes published one (before K2GO-588); prune it with its tarball. for ext in '' .meta4 .sha256 .installed .torrent .minisig; do aws s3 rm "s3://${BUCKET_NAME}/${key}${ext}" --endpoint-url "$ENDPOINT" || true done diff --git a/tools/rootfs-builder/build-iiab-rootfs.sh b/tools/rootfs-builder/build-iiab-rootfs.sh index a75ba74f9..94e3921ed 100755 --- a/tools/rootfs-builder/build-iiab-rootfs.sh +++ b/tools/rootfs-builder/build-iiab-rootfs.sh @@ -23,7 +23,7 @@ # # Output: # - k2go____.tar.gz (top-level = installed-rootfs/iiab/) -# - k2go_<...>.tar.gz.meta4 / .torrent (per-artifact, mkmetalink) +# - k2go_<...>.tar.gz.meta4 (per-artifact, mkmetalink; HTTP only) # - latest__.meta4 (STABLE pointer the APK requests; a copy of the # per-artifact .meta4. Inside it, mirrors point at the full-named tarball, # so this stable name always resolves to the newest build.) @@ -922,6 +922,8 @@ cp -f "${OUTDIR}/${ARTIFACT}.installed" "${OUTDIR}/${INSTALLED}" # ----------------------------- 5) Generate .meta4 (Metalink, via mkmetalink) -- # mkmetalink (Go) builds a valid Metalink v4 (.meta4) + matching .torrent. # https://github.com/chapmanjacobd/mkmetalink +# K2GO-588 (ADR-K2GO-554 A4): the downloads are HTTP only. The .torrent is deleted and the +# line is removed from the .meta4, else aria2 turns the download into BitTorrent. # We pass the publish + mirror base URLs so the .meta4 carries the same # entries the APK/aria2 expect (priority 10 = primary, 11 = mirror). It names its # output after the artifact; the APK requests a STABLE name, so we copy it to @@ -942,10 +944,12 @@ done || die "mkmetalink failed to generate the metalink." GEN_META4="${OUTDIR}/${ARTIFACT}.meta4" [[ -f "$GEN_META4" ]] || die "mkmetalink did not produce ${GEN_META4}" +sed -i '/]/d' "$GEN_META4" +grep -q ' is still in ${GEN_META4}" +rm -f "${OUTDIR}/${ARTIFACT}.torrent" cp -f "$GEN_META4" "${OUTDIR}/${META4}" ok "Metalink ready: ${OUTDIR}/${META4} (copy of ${ARTIFACT}.meta4)" ok "Sources in .meta4: primary ${PUBLISH_URL%/}/ + ${#MIRRORS[@]} mirror(s)." -ok "(also produced: ${ARTIFACT}.torrent in ${OUTDIR})" # ----------------------------- Summary ---------------------------------------- echo From 2479d02cc562c953518937cc3ff33953a550b5a9 Mon Sep 17 00:00:00 2001 From: "Luis Guzman (AppDevForAll)" Date: Fri, 20 Nov 2026 10:07:31 -0600 Subject: [PATCH 3/5] K2GO-588 docs(adr): ADR-K2GO-554 Amendment 3, BitTorrent removed (supersedes A4) --- ...ADR-K2GO-554-signed-rootfs-skip-listing.md | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/controller/docs/ADR-K2GO-554-signed-rootfs-skip-listing.md b/controller/docs/ADR-K2GO-554-signed-rootfs-skip-listing.md index 953ed0b55..fc58a59bd 100644 --- a/controller/docs/ADR-K2GO-554-signed-rootfs-skip-listing.md +++ b/controller/docs/ADR-K2GO-554-signed-rootfs-skip-listing.md @@ -1,6 +1,6 @@ # ADR-K2GO-554 : Signed official rootfs skips the second archive pass -- Status: Accepted (2026-11-12, with Amendment 1) +- Status: Accepted (2026-11-12, with Amendment 1; Amendment 3 on 2026-11-20) - Date: 2026-11-07 - Ticket: K2GO-554 (relates to K2GO-555, K2GO-372, K2GO-511, K2GO-457, ADFA-5110) - Author: AppDevForAll @@ -262,6 +262,7 @@ Instrumented tests in the app process (same ART and BouncyCastle as production). A3 this is not an identity gap. To use only HTTP, the app must give aria2 a meta4 without the metaurl (the same local-meta4 handoff as A6), or the builder must stop writing the metaurl. DHT and LPD were enabled in 2026-05 with no recorded reason. + Superseded by C1 (Amendment 3, K2GO-588): BitTorrent is removed. - A5. Trusted import (amends D7). An import needs the tarball and its `.minisig` (2 files). Identity: A2. Integrity: one SHA-256 pass of the tarball against the manifest `sha256` and `size`. Then the import skips the listing and the treehash. @@ -309,6 +310,39 @@ manifest (only the `-t` value changes); (3) new bakes carry the manifest. An old A restore picks one file; the app finds `X.tar.json` or `X.tar.gz.minisig` next to it by name (`ArchivePair`). +## Amendment 3 (2026-11-20, K2GO-588): BitTorrent removed (supersedes A4) + +Context: K2GO-588 makes "Keep offline" mean real network silence, and the app sends +nothing to third parties that the user did not start (privacy by default). A +BitTorrent session announces the phone to a tracker and to peers, and DHT and LPD +add more traffic. On 2026-11-20 a OnePlus 7T download of +`latest_basic_arm64-v8a.meta4` (build 2026.321) ended in the aria2 state `SEED`, +which exists only for BitTorrent: the published meta4 still carries the torrent +metaurl. + +- C1. The rootfs download is HTTP only. Both measures apply, so neither alone is + load-bearing: + - The app (`Aria2Manager`) gives aria2 a local copy of the meta4 without the + `` elements (`--metalink-file`, `MetalinkHttpOnly`). This is the + local-meta4 handoff of A4/A6. It covers the meta4 files that are already + published. The IPv4 profiler uses the same copy. If the app cannot read the + meta4, it reports a network problem (as aria2 exit 6) and does not fall back to + the URL. + - aria2 runs with `--enable-dht=false --enable-dht6=false --bt-enable-lpd=false + --enable-peer-exchange=false` (the aria2 default is DHT on). `--seed-time=0` and + the `dht.dat` file are removed; the app deletes a leftover `dht.dat`. + - The builder deletes the `.torrent` and removes the `` line from the + meta4 before the bake signs it, so new meta4 files are HTTP only and their + sha-256 in the signed manifest matches the copy that aria2 reads (A6 stays + possible). +- C2. Integrity does not change: aria2 checks the meta4 SHA-256 pieces + (`--check-integrity`), then DownloadVerifier checks the file (A3). +- C3. Cost: no peer download. The HTTP mirrors (R2 and its mirror) carry all the + traffic, which is what the measured downloads already used. +- C4. The box (dash-node) aria2 for ZIM, maps and other content has no BitTorrent + flags, and the Kiwix meta4 files have no metaurl (checked 2026-11-20). No change. +- C5. Old `.torrent` files on R2 are pruned with their tarball (`rootfs-2-bake.yml`). + ## Out of scope - Replacing the meta4 or the aria2 download path. The signature is additive. From faa6f0a6b4be22654d06cc4369f401259c741d97 Mon Sep 17 00:00:00 2001 From: "Luis Guzman (AppDevForAll)" Date: Sun, 22 Nov 2026 05:32:28 -0600 Subject: [PATCH 4/5] K2GO-588 fix(download): review fixes for the HTTP-only rootfs download - Android 7.0 does not trust ISRG Root X1, the root of the R2 host. The app now adds that root to the system store, so its own .meta4 and .minisig reads work there (before, a failed read fell back to aria2, which is the BitTorrent path). - aria2 also gets --follow-torrent=false, --bt-exclude-tracker=* and --seed-time=0: DHT/LPD/PEX off does not stop a tracker announce. One list, HTTP_ONLY_FLAGS, is used by the download and the IPv4 profiler. - The app refuses a .meta4 that still has metaurl text after the strip, and the strip also handles a namespace prefix. The builder check is case-insensitive. - An HTTP 4xx, a body over 1 MiB or a body that is not a .meta4 fails at once (exit 3) instead of three "network problem" retries. - --allow-piece-length-change=true lets a partial file from an older build continue over HTTP. - The HTTP-only copy lives in filesDir, not in the purgeable cache. - ADR-K2GO-554 Amendment 3 and R2_LAYOUT updated. --- .../org/appdevforall/k2go/Aria2Manager.java | 92 +++++++++++++------ .../k2go/Aria2NetworkProfiler.java | 3 +- .../download/domain/MetalinkHttpOnly.java | 12 ++- .../app/src/main/res/raw/isrg_root_x1.pem | 27 ++++++ .../main/res/xml/network_security_config.xml | 10 +- .../download/domain/MetalinkHttpOnlyTest.java | 17 ++++ ...ADR-K2GO-554-signed-rootfs-skip-listing.md | 38 +++++--- controller/docs/R2_LAYOUT.md | 2 +- tools/rootfs-builder/build-iiab-rootfs.sh | 4 +- 9 files changed, 157 insertions(+), 48 deletions(-) create mode 100644 controller/app/src/main/res/raw/isrg_root_x1.pem diff --git a/controller/app/src/main/java/org/appdevforall/k2go/Aria2Manager.java b/controller/app/src/main/java/org/appdevforall/k2go/Aria2Manager.java index c6d92fd05..4a6183ccf 100644 --- a/controller/app/src/main/java/org/appdevforall/k2go/Aria2Manager.java +++ b/controller/app/src/main/java/org/appdevforall/k2go/Aria2Manager.java @@ -39,6 +39,23 @@ public class Aria2Manager { private static final String TAG = "IIAB-Aria2-Native"; /** K2GO-554: upper bound for a signature sidecar read; a minisig is about 300 bytes. */ private static final int SIDECAR_MAX_BYTES = 16 * 1024; + /** K2GO-588: a real .meta4 is a few KiB; a larger body is not one. */ + private static final int METALINK_MAX_BYTES = 1024 * 1024; + + /** + * K2GO-588: aria2 options that keep a download HTTP only. The .meta4 copy has no metaurl; these + * are the second barrier if one ever got through (aria2 has DHT on by default, and DHT/LPD/PEX + * off does not stop a tracker announce). + */ + static final String[] HTTP_ONLY_FLAGS = { + "--follow-torrent=false", + "--enable-dht=false", + "--enable-dht6=false", + "--bt-enable-lpd=false", + "--enable-peer-exchange=false", + "--bt-exclude-tracker=*", + "--seed-time=0", + }; /** * ADFA-4895: volatile for the same reason as the flag below, and it is the more important of * the two. It is assigned on the download thread and read by {@code stopDownload()} on the @@ -210,21 +227,23 @@ public void startDownload(Context context, String url, RootfsManifest.Target sig // --split mirror count, and reconciling whatever is already on disk so that // stopping and restarting a download is safe (no wasted re-download, and the // network profiler never trips over a leftover completed file). - // K2GO-588 (ADR-K2GO-554 A4): aria2 gets a local copy of the .meta4 without its - // , so the download is HTTP only. Without that copy aria2 would read the URL - // and turn the torrent metaurl into a BitTorrent session, so a failed read stops here. - File httpOnlyMeta = new File(context.getCacheDir(), "rootfs-http-only.meta4"); + // K2GO-588 (ADR-K2GO-554 Amendment 3): aria2 gets a local copy of the .meta4 without + // its , so the download is HTTP only. Without that copy aria2 would read the + // URL and turn the torrent metaurl into a BitTorrent session, so a failed read stops. + File httpOnlyMeta = new File(context.getFilesDir(), "rootfs-http-only.meta4"); MetalinkFile mf = null; String source = url; if (MetalinkSplit.isMetalinkUrl(url)) { - mf = fetchMetalink(url, httpOnlyMeta); + int[] failExit = {6}; + mf = fetchMetalink(url, httpOnlyMeta, failExit); if (mf == null) { if (postLatchedStop(mainHandler, listener)) return; - // The same answer aria2 gives for a network problem (exit 6), so the caller - // offers a retry as before. + // Answer as aria2 would: exit 6 (network) offers a retry; exit 3 (not found, + // or not a usable .meta4) fails at once. + int code = failExit[0]; mainHandler.post(() -> listener.onError( - org.appdevforall.k2go.download.domain.Aria2Exit.label(6), - org.appdevforall.k2go.download.domain.Aria2Exit.Kind.TRANSIENT)); + org.appdevforall.k2go.download.domain.Aria2Exit.label(code), + org.appdevforall.k2go.download.domain.Aria2Exit.kindOf(code))); return; } source = "--metalink-file=" + httpOnlyMeta.getAbsolutePath(); @@ -320,12 +339,10 @@ public void startDownload(Context context, String url, RootfsManifest.Target sig // while downloading. On mismatch aria2 exits non-zero, so onError fires // and the archive is never extracted/executed. command.add("--check-integrity=true"); - // K2GO-588: HTTP only. The metaurl is gone from the .meta4 above; these keep aria2 - // from any peer traffic even so (its default is DHT on). - command.add("--enable-dht=false"); - command.add("--enable-dht6=false"); - command.add("--bt-enable-lpd=false"); - command.add("--enable-peer-exchange=false"); + java.util.Collections.addAll(command, HTTP_ONLY_FLAGS); + // K2GO-588: a partial file from an older build has a BitTorrent control file whose + // piece length can differ from the HTTP .meta4; continue (aria2 re-checks the pieces). + command.add("--allow-piece-length-change=true"); // --- Apply SSL Certificate Validation (D6: always strict; cacert // presence was already enforced above, so there is no insecure path) --- @@ -618,9 +635,6 @@ private void requestStop(Stop reason) { } } - /** - * Helper method to copy files from the APK assets folder to internal storage. - */ /** ADFA-5119: a stop latched before aria2 started; reports it and returns true. */ private boolean postLatchedStop(Handler mainHandler, DownloadListener listener) { if (stopRequest == Stop.CANCEL) { @@ -636,15 +650,21 @@ private boolean postLatchedStop(Handler mainHandler, DownloadListener listener) return false; } - /** ADFA-4676: fetch + parse the .meta4 into a verifiable MetalinkFile, or null on any error. */ - private MetalinkFile fetchMetalink(String url, File httpOnlyCopy) { + /** + * ADFA-4676: fetch + parse the .meta4 into a verifiable MetalinkFile, or null on any error. On + * null, {@code failExit[0]} is the aria2 exit code that matches: 6 for a network problem, 3 for + * an HTTP 4xx or a body that is not a usable HTTP-only .meta4. + */ + private MetalinkFile fetchMetalink(String url, File httpOnlyCopy, int[] failExit) { HttpURLConnection conn = null; try { conn = (HttpURLConnection) new URL(url).openConnection(); conn.setConnectTimeout(10000); conn.setReadTimeout(10000); conn.setRequestProperty("User-Agent", "K2Go"); - if (conn.getResponseCode() != 200) { + int status = conn.getResponseCode(); + if (status != 200) { + failExit[0] = (status >= 400 && status < 500) ? 3 : 6; return null; } byte[] raw; @@ -652,15 +672,35 @@ private MetalinkFile fetchMetalink(String url, File httpOnlyCopy) { java.io.ByteArrayOutputStream buf = new java.io.ByteArrayOutputStream(); byte[] chunk = new byte[16384]; int n; - while ((n = in.read(chunk)) > 0) buf.write(chunk, 0, n); + while ((n = in.read(chunk)) > 0) { + buf.write(chunk, 0, n); + if (buf.size() > METALINK_MAX_BYTES) { + failExit[0] = 3; + return null; + } + } raw = buf.toByteArray(); } - MetalinkFile mf = MetalinkFile.parse(new java.io.ByteArrayInputStream(raw)); - // K2GO-588: the copy that aria2 reads, without the BitTorrent metaurl. + MetalinkFile mf; + String httpOnly; + try { + mf = MetalinkFile.parse(new java.io.ByteArrayInputStream(raw)); + httpOnly = org.appdevforall.k2go.download.domain.MetalinkHttpOnly.of( + new String(raw, java.nio.charset.StandardCharsets.UTF_8)); + } catch (Exception e) { + Log.w(TAG, "fetchMetalink: not a usable .meta4 (" + e.getMessage() + ")"); + failExit[0] = 3; + return null; + } + // K2GO-588: fail closed if any metaurl is left; never hand aria2 a BitTorrent source. + if (!org.appdevforall.k2go.download.domain.MetalinkHttpOnly.isHttpOnly(httpOnly)) { + Log.w(TAG, "fetchMetalink: metaurl left after the strip; refusing " + url); + failExit[0] = 3; + return null; + } try (java.io.Writer w = new java.io.OutputStreamWriter( new java.io.FileOutputStream(httpOnlyCopy), java.nio.charset.StandardCharsets.UTF_8)) { - w.write(org.appdevforall.k2go.download.domain.MetalinkHttpOnly.of( - new String(raw, java.nio.charset.StandardCharsets.UTF_8))); + w.write(httpOnly); } return mf; } catch (Exception e) { diff --git a/controller/app/src/main/java/org/appdevforall/k2go/Aria2NetworkProfiler.java b/controller/app/src/main/java/org/appdevforall/k2go/Aria2NetworkProfiler.java index c5a720c00..2983bbaee 100644 --- a/controller/app/src/main/java/org/appdevforall/k2go/Aria2NetworkProfiler.java +++ b/controller/app/src/main/java/org/appdevforall/k2go/Aria2NetworkProfiler.java @@ -81,8 +81,7 @@ private static double runTimeBoxedTest(File aria2Bin, File downloadDir, String s command.add("--max-connection-per-server=4"); command.add("--split=4"); // K2GO-588: HTTP only, like the real download (Aria2Manager). - command.add("--enable-dht=false"); - command.add("--enable-dht6=false"); + java.util.Collections.addAll(command, Aria2Manager.HTTP_ONLY_FLAGS); command.add("--check-certificate=false"); if (forceIpv4) { diff --git a/controller/app/src/main/java/org/appdevforall/k2go/download/domain/MetalinkHttpOnly.java b/controller/app/src/main/java/org/appdevforall/k2go/download/domain/MetalinkHttpOnly.java index 8713f11f2..4daf34609 100644 --- a/controller/app/src/main/java/org/appdevforall/k2go/download/domain/MetalinkHttpOnly.java +++ b/controller/app/src/main/java/org/appdevforall/k2go/download/domain/MetalinkHttpOnly.java @@ -3,7 +3,7 @@ * Name : MetalinkHttpOnly.java * Author : AppDevForAll * Copyright : Copyright (c) 2026 AppDevForAll - * Description : K2GO-588 (ADR-K2GO-554 A4). A Metalink with its elements + * Description : K2GO-588 (ADR-K2GO-554 Amendment 3). A Metalink with its elements * removed, so aria2 downloads over HTTP only, never BitTorrent. * ============================================================================ */ @@ -13,15 +13,16 @@ /** * aria2 turns a Metalink that carries a {@code } into a BitTorrent - * session, and {@code --follow-torrent=false} does not stop it (measured, ADR-K2GO-554 A4). So the + * session, and {@code --follow-torrent=false} does not stop it (measured, ADR-K2GO-554 Amendment 3). So the * app gives aria2 a copy of the Metalink without the metaurl elements. The {@code } mirrors, * size and hashes stay unchanged. */ public final class MetalinkHttpOnly { // A ... element or a self-closing , with its leading space. + // A namespace prefix () is allowed, as the Metalink parser accepts it. private static final Pattern METAURL = Pattern.compile( - "[ \\t]*]*?(?:/>|>.*?)[ \\t]*\\r?\\n?", + "[ \\t]*<(?:[\\w.-]+:)?metaurl\\b[^>]*?(?:/>|>.*?)[ \\t]*\\r?\\n?", Pattern.DOTALL | Pattern.CASE_INSENSITIVE); private MetalinkHttpOnly() {} @@ -31,4 +32,9 @@ public static String of(String metalinkXml) { if (metalinkXml == null) return null; return METAURL.matcher(metalinkXml).replaceAll(""); } + + /** False when any metaurl text is left: the caller must not give that Metalink to aria2. */ + public static boolean isHttpOnly(String metalinkXml) { + return metalinkXml != null && !metalinkXml.toLowerCase(java.util.Locale.ROOT).contains("metaurl"); + } } diff --git a/controller/app/src/main/res/raw/isrg_root_x1.pem b/controller/app/src/main/res/raw/isrg_root_x1.pem new file mode 100644 index 000000000..4d6f390c4 --- /dev/null +++ b/controller/app/src/main/res/raw/isrg_root_x1.pem @@ -0,0 +1,27 @@ +-----BEGIN CERTIFICATE----- +MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAwTzELMAkGA1UE +BhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2VhcmNoIEdyb3VwMRUwEwYDVQQD +EwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQG +EwJVUzEpMCcGA1UEChMgSW50ZXJuZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMT +DElTUkcgUm9vdCBYMTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54r +Vygch77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+0TM8ukj1 +3Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6UA5/TR5d8mUgjU+g4rk8K +b4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sWT8KOEUt+zwvo/7V3LvSye0rgTBIlDHCN +Aymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyHB5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ +4Q7e2RCOFvu396j3x+UCB5iPNgiV5+I3lg02dZ77DnKxHZu8A/lJBdiB3QW0KtZB6awBdpUKD9jf +1b0SHzUvKBds0pjBqAlkd25HN7rOrFleaJ1/ctaJxQZBKT5ZPt0m9STJEadao0xAH0ahmbWnOlFu +hjuefXKnEgV4We0+UXgVCwOPjdAvBbI+e0ocS3MFEvzG6uBQE3xDk3SzynTnjh8BCNAw1FtxNrQH +usEwMFxIt4I7mKZ9YIqioymCzLq9gwQbooMDQaHWBfEbwrbwqHyGO0aoSCqI3Haadr8faqU9GY/r +OPNk3sgrDQoo//fb4hVC1CLQJ13hef4Y53CIrU7m2Ys6xt0nUW7/vGT1M0NPAgMBAAGjQjBAMA4G +A1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBR5tFnme7bl5AFzgAiIyBpY +9umbbjANBgkqhkiG9w0BAQsFAAOCAgEAVR9YqbyyqFDQDLHYGmkgJykIrGF1XIpu+ILlaS/V9lZL +ubhzEFnTIZd+50xx+7LSYK05qAvqFyFWhfFQDlnrzuBZ6brJFe+GnY+EgPbk6ZGQ3BebYhtF8GaV +0nxvwuo77x/Py9auJ/GpsMiu/X1+mvoiBOv/2X/qkSsisRcOj/KKNFtY2PwByVS5uCbMiogziUwt +hDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJw +TdwJx4nLCgdNbOhdjsnvzqvHu7UrTkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nx +e5AW0wdeRlN8NwdCjNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZA +JzVcoyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq4RgqsahD +YVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPAmRGunUHBcnWEvgJBQl9n +JEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57demyPxgcYxn/eR44/KJ4EBs+lVDR3veyJ +m+kXQ99b21/+jh5Xos1AnX5iItreGCc= +-----END CERTIFICATE----- diff --git a/controller/app/src/main/res/xml/network_security_config.xml b/controller/app/src/main/res/xml/network_security_config.xml index 381c73e22..4e8c43fd3 100644 --- a/controller/app/src/main/res/xml/network_security_config.xml +++ b/controller/app/src/main/res/xml/network_security_config.xml @@ -11,7 +11,15 @@ which is the minimum that lets a device pull from an ad-hoc peer : HTTPS would need a shared certificate the on-the-spot QR pairing has no way to provision. HTTPS stays available everywhere (e.g. the OTA self-update). Native aria2 downloads run in a separate process, not governed here. + K2GO-588: Android 7.0 (API 24) does not trust ISRG Root X1, the root of the R2 download host + (Let's Encrypt). The app reads the rootfs .meta4 and .minisig itself, so it adds that one root to + the system store. aria2 uses the bundled cacert.pem, which has the same root. --> - + + + + + + diff --git a/controller/app/src/test/java/org/appdevforall/k2go/download/domain/MetalinkHttpOnlyTest.java b/controller/app/src/test/java/org/appdevforall/k2go/download/domain/MetalinkHttpOnlyTest.java index f56103ff4..8b6f249d5 100644 --- a/controller/app/src/test/java/org/appdevforall/k2go/download/domain/MetalinkHttpOnlyTest.java +++ b/controller/app/src/test/java/org/appdevforall/k2go/download/domain/MetalinkHttpOnlyTest.java @@ -61,4 +61,21 @@ public void aMetalinkWithoutMetaurlIsUnchanged() { public void nullStaysNull() { assertNull(MetalinkHttpOnly.of(null)); } + + @Test + public void removesANamespacePrefixedMetaurl() { + String in = "\n x.torrent\n" + + " https://m/a\n\n"; + String out = MetalinkHttpOnly.of(in); + assertTrue(MetalinkHttpOnly.isHttpOnly(out)); + assertTrue(out.contains("https://m/a")); + } + + @Test + public void isHttpOnlyFailsClosed() { + assertTrue(MetalinkHttpOnly.isHttpOnly(MetalinkHttpOnly.of(PUBLISHED))); + assertFalse(MetalinkHttpOnly.isHttpOnly(PUBLISHED)); + assertFalse(MetalinkHttpOnly.isHttpOnly("\n\n")); + assertFalse(MetalinkHttpOnly.isHttpOnly(null)); + } } diff --git a/controller/docs/ADR-K2GO-554-signed-rootfs-skip-listing.md b/controller/docs/ADR-K2GO-554-signed-rootfs-skip-listing.md index fc58a59bd..5ed1989f6 100644 --- a/controller/docs/ADR-K2GO-554-signed-rootfs-skip-listing.md +++ b/controller/docs/ADR-K2GO-554-signed-rootfs-skip-listing.md @@ -320,21 +320,33 @@ add more traffic. On 2026-11-20 a OnePlus 7T download of which exists only for BitTorrent: the published meta4 still carries the torrent metaurl. -- C1. The rootfs download is HTTP only. Both measures apply, so neither alone is - load-bearing: +- C1. The rootfs download is HTTP only. Each measure alone stops BitTorrent: - The app (`Aria2Manager`) gives aria2 a local copy of the meta4 without the - `` elements (`--metalink-file`, `MetalinkHttpOnly`). This is the - local-meta4 handoff of A4/A6. It covers the meta4 files that are already - published. The IPv4 profiler uses the same copy. If the app cannot read the - meta4, it reports a network problem (as aria2 exit 6) and does not fall back to - the URL. - - aria2 runs with `--enable-dht=false --enable-dht6=false --bt-enable-lpd=false - --enable-peer-exchange=false` (the aria2 default is DHT on). `--seed-time=0` and - the `dht.dat` file are removed; the app deletes a leftover `dht.dat`. + `` elements (`--metalink-file`, `MetalinkHttpOnly`, also with a namespace + prefix). This is the local-meta4 handoff of A4/A6. It covers the meta4 files that + are already published. The IPv4 profiler uses the same copy. If any metaurl text + is left after the strip, the app refuses the meta4 (fail closed). If the app + cannot read the meta4, it reports a network problem (aria2 exit 6) for a network + error or an HTTP 5xx, and "resource not found" (exit 3, fails at once) for an + HTTP 4xx, a body over 1 MiB, or a body that is not a meta4. It does not fall back + to the URL. + - aria2 runs with `--follow-torrent=false --enable-dht=false --enable-dht6=false + --bt-enable-lpd=false --enable-peer-exchange=false --bt-exclude-tracker=* + --seed-time=0` (`Aria2Manager.HTTP_ONLY_FLAGS`). DHT, LPD and PEX off do not stop + a tracker announce; `--bt-exclude-tracker=*` does, and `--seed-time=0` ends a + session at 100%. The `dht.dat` file is removed; the app deletes a leftover one. + `--allow-piece-length-change=true` lets a partial file from an older build (its + control file came from the BitTorrent session) continue over HTTP. - The builder deletes the `.torrent` and removes the `` line from the - meta4 before the bake signs it, so new meta4 files are HTTP only and their - sha-256 in the signed manifest matches the copy that aria2 reads (A6 stays - possible). + meta4 before the bake signs it, and fails the bake if any metaurl text is left. + New meta4 files are HTTP only and their sha-256 in the signed manifest matches + the copy that aria2 reads. Older bakes signed the meta4 with the metaurl, so A6, + when it lands, must hash the raw bytes that it fetched, not the local copy. +- C1a. The app reads the meta4 and the `.minisig` with the Android trust store. Android + 7.0 (API 24) does not trust ISRG Root X1, the root of the R2 host, so + `network_security_config.xml` adds that root (`res/raw/isrg_root_x1.pem`) to the + system store. Before this amendment a failed app read fell back to aria2, which uses + the bundled `cacert.pem`; that fallback is the BitTorrent path, so it is gone. - C2. Integrity does not change: aria2 checks the meta4 SHA-256 pieces (`--check-integrity`), then DownloadVerifier checks the file (A3). - C3. Cost: no peer download. The HTTP mirrors (R2 and its mirror) carry all the diff --git a/controller/docs/R2_LAYOUT.md b/controller/docs/R2_LAYOUT.md index b694011cc..9b7e38821 100644 --- a/controller/docs/R2_LAYOUT.md +++ b/controller/docs/R2_LAYOUT.md @@ -37,7 +37,7 @@ Public at the R2 dev URL in the repository variable `ROOTFS_PUBLIC_BASE` | Key | Content | Written by | Lifecycle | |-----|---------|------------|-----------| -| `k2go_*__.tar.gz` (+ `.meta4`, `.sha256`, `.installed`, `.torrent`) | Dated rootfs images | `rootfs-2-bake.yml` | Newest 7 per tier and ABI; older ones are deleted | +| `k2go_*__.tar.gz` (+ `.meta4`, `.sha256`, `.installed`; older images also have a `.torrent`, no longer built since K2GO-588) | Dated rootfs images | `rootfs-2-bake.yml` | Newest 7 per tier and ABI; older ones are deleted | | `latest__.meta4`, `latest__.installed` | Stable pointers to the current image | `rootfs-2-bake.yml` | Overwritten, last | | `build--.log`, `PUBLISH_QUEUE.tsv` | Installer logs (input for the size catalogs) and the publish queue | `rootfs-2-bake.yml` | Overwritten | | `proot-distro-v/` | Debian base from the proot-distro release (+ `.sha256`) | `rootfs-2-bake.yml` (seeded once) | Static | diff --git a/tools/rootfs-builder/build-iiab-rootfs.sh b/tools/rootfs-builder/build-iiab-rootfs.sh index 94e3921ed..929cf0d08 100755 --- a/tools/rootfs-builder/build-iiab-rootfs.sh +++ b/tools/rootfs-builder/build-iiab-rootfs.sh @@ -922,7 +922,7 @@ cp -f "${OUTDIR}/${ARTIFACT}.installed" "${OUTDIR}/${INSTALLED}" # ----------------------------- 5) Generate .meta4 (Metalink, via mkmetalink) -- # mkmetalink (Go) builds a valid Metalink v4 (.meta4) + matching .torrent. # https://github.com/chapmanjacobd/mkmetalink -# K2GO-588 (ADR-K2GO-554 A4): the downloads are HTTP only. The .torrent is deleted and the +# K2GO-588 (ADR-K2GO-554 Amendment 3): the downloads are HTTP only. The .torrent is deleted and the # line is removed from the .meta4, else aria2 turns the download into BitTorrent. # We pass the publish + mirror base URLs so the .meta4 carries the same # entries the APK/aria2 expect (priority 10 = primary, 11 = mirror). It names its @@ -945,7 +945,7 @@ done GEN_META4="${OUTDIR}/${ARTIFACT}.meta4" [[ -f "$GEN_META4" ]] || die "mkmetalink did not produce ${GEN_META4}" sed -i '/]/d' "$GEN_META4" -grep -q ' is still in ${GEN_META4}" +grep -qi 'metaurl' "$GEN_META4" && die "metaurl text is still in ${GEN_META4} (a multi-line or prefixed element?)" rm -f "${OUTDIR}/${ARTIFACT}.torrent" cp -f "$GEN_META4" "${OUTDIR}/${META4}" ok "Metalink ready: ${OUTDIR}/${META4} (copy of ${ARTIFACT}.meta4)" From 171ef13b5d2f4f83a3d7c487bbe8bc0dbc7813ee Mon Sep 17 00:00:00 2001 From: "Luis Guzman (AppDevForAll)" Date: Sun, 22 Nov 2026 05:53:29 -0600 Subject: [PATCH 5/5] K2GO-588 docs(adr): Amendment 3 says which measure was measured --- controller/docs/ADR-K2GO-554-signed-rootfs-skip-listing.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/controller/docs/ADR-K2GO-554-signed-rootfs-skip-listing.md b/controller/docs/ADR-K2GO-554-signed-rootfs-skip-listing.md index 5ed1989f6..15bf12306 100644 --- a/controller/docs/ADR-K2GO-554-signed-rootfs-skip-listing.md +++ b/controller/docs/ADR-K2GO-554-signed-rootfs-skip-listing.md @@ -320,7 +320,8 @@ add more traffic. On 2026-11-20 a OnePlus 7T download of which exists only for BitTorrent: the published meta4 still carries the torrent metaurl. -- C1. The rootfs download is HTTP only. Each measure alone stops BitTorrent: +- C1. The rootfs download is HTTP only. Two measures; each one is meant to stop BitTorrent alone (only the + metaurl strip was measured on a device, 2026-11-20): - The app (`Aria2Manager`) gives aria2 a local copy of the meta4 without the `` elements (`--metalink-file`, `MetalinkHttpOnly`, also with a namespace prefix). This is the local-meta4 handoff of A4/A6. It covers the meta4 files that