Skip to content

K2GO-588 fix(download): the rootfs download is HTTP only, never BitTorrent - #813

Merged
luisguzman-adfa merged 5 commits into
mainfrom
chore/K2GO-588-remove-bittorrent
Nov 22, 2026
Merged

luisguzman-adfa merged 5 commits into
mainfrom
chore/K2GO-588-remove-bittorrent

Conversation

@luisguzman-adfa

@luisguzman-adfa luisguzman-adfa commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

What changes

The rootfs download is HTTP only. No BitTorrent, no DHT, no LPD, no peer exchange.

  • App (Aria2Manager): the app already fetches the .meta4 once. It now writes a local copy without the <metaurl> elements (MetalinkHttpOnly, pure domain) and gives aria2 that copy (--metalink-file), so aria2 does not read the URL again. aria2 runs with --enable-dht=false --enable-dht6=false --bt-enable-lpd=false --enable-peer-exchange=false. --seed-time=0 and dht.dat are removed; a leftover dht.dat is deleted. The IPv4 profiler uses the same copy and flags.
  • A .meta4 that cannot be read is reported as a network problem (Aria2Exit 6, TRANSIENT), so the caller offers a retry as before. It does not fall back to the URL, because that path is BitTorrent. A stop that the user latched in that window is still honored (shared postLatchedStop).
  • Builder: deletes the mkmetalink .torrent and removes the <metaurl> line before the bake signs the .meta4. New bakes publish an HTTP-only .meta4, so its sha-256 in the signed manifest matches the copy that aria2 reads (ADR A6 stays possible).
  • Workflow: comments only; old .torrent files on R2 are still pruned with their tarball.
  • ADR-K2GO-554 Amendment 3 (supersedes A4).

Why

K2GO-588: no data leaves the phone except what the user starts. The published .meta4 carries <metaurl mediatype="torrent">, and aria2 turns the download into a BitTorrent session (tracker announce, DHT, LPD). --follow-torrent=false does not stop this (measured in ADR A4).

Steps to QA

  1. Clear the app data, run the wizard, Internet download, Basic.
  2. adb logcat | grep IIAB-Aria2: the progress lines have no SD: field and the run never shows SEED. The log ends with Integrity verified ... sha-256 OK and Signature check ...: TRUSTED.
  3. Pause and resume the download: it resumes from the control file.
  4. Turn off the network before the download starts: the error is the "network problem" retry, not a fatal error.

Verifications

  • :app:lintStandardDebug, :app:testStandardDebugUnitTest, :app:assembleStandardDebug, :app:compileFdroidDebugJavaWithJavac: pass.
  • New unit test MetalinkHttpOnlyTest (5 cases: the published metaurl, the parsed result keeps mirrors/size/hash, self-closing and multiline metaurls, no metaurl, null).
  • Two-pass code review done. Pass 1 found that the early return on a failed .meta4 read would drop a latched pause or cancel; fixed with a shared helper. Pass 2: no new state (the local copy is rewritten for each download, in the cache); the .meta4 is fetched once instead of twice.
  • Before and after on a OnePlus 7T (Android 16), the app's bundled aria2, 12 s each, latest_basic_arm64-v8a.meta4 (build 2026.321):
    • Before (URL + old flags): [#70181c 537MiB/1.4GiB(35%) CN:1 SD:0 DL:48MiB]. The SD: field exists only in a BitTorrent session. An earlier full download with the old build ended in SEED(0.0).
    • After (HTTP-only copy + new flags): [#cfc8b4 562MiB/1.4GiB(37%) CN:1 DL:49MiB]. Same speed, no SD:.
  • End to end with this build on the 7T (data cleared, wizard, Basic): 0 progress lines with SD:, aria2 exit 0, Integrity verified ... (1590750919 bytes, sha-256 OK), Signature check ...: TRUSTED usize=2924728320.
  • The box (dash-node) aria2 for ZIM and maps has no BitTorrent flags, and the Kiwix .meta4 files have no metaurl (checked 2026-11-20). No change there.
  • 2026-11-22: merges into current main with no conflict; built and installed together with K2GO-588 feat(privacy): one choice for usage data, crash reports and automatic connections #815 and K2GO-588 feat(privacy): with Keep offline, actions ask once, box services stay off, catalogs follow the choice #814 on the 7T (lint of both flavors, unit tests, APK and F-Droid compile pass).

Notes

Review fixes (2026-11-22)

A code review of this PR found two problems; both are fixed (faa6f0a, 171ef13):

  • Android 7.0 (API 24) does not trust ISRG Root X1, the root of the R2 host. Before this PR, a failed app read of the .meta4 fell back to aria2 (bundled cacert.pem); that fallback is the BitTorrent path, so it is gone. network_security_config.xml now adds ISRG Root X1 (res/raw/isrg_root_x1.pem, SHA-256 96:BC:EC:...:C6, from the bundled cacert.pem) to the system store.
  • DHT/LPD/PEX off does not stop a tracker announce. aria2 now also gets --follow-torrent=false --bt-exclude-tracker=* --seed-time=0. One list, Aria2Manager.HTTP_ONLY_FLAGS, is used by the download and the IPv4 profiler.

Also:

  • The app refuses a .meta4 that still has metaurl text after the strip (fail closed); the strip also handles a namespace prefix.
  • 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 (BitTorrent control file) continue over HTTP.
  • The HTTP-only copy lives in filesDir, not in the purgeable cache.
  • The builder check is case-insensitive. ADR-K2GO-554 Amendment 3 (new C1a) and R2_LAYOUT.md updated; the ADR says that only the metaurl strip was measured on a device.
  • New MetalinkHttpOnlyTest cases: namespace prefix, fail closed.

Verifications for the fixes: lint (both flavors), unit tests, APK, F-Droid compile; a second review pass on the fixes found no bug here. Not tested on a device: an Android 7.0 phone, and resuming a download started on v1.2.0.

…rrent

The published .meta4 carries a torrent <metaurl>, 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.
….torrent

The builder deletes the mkmetalink .torrent and removes the <metaurl> line
before the bake signs the .meta4. Old .torrent files on R2 are pruned with
their tarball.
- 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.
@luisguzman-adfa
luisguzman-adfa merged commit 8158b25 into main Nov 22, 2026
4 checks passed
@luisguzman-adfa
luisguzman-adfa deleted the chore/K2GO-588-remove-bittorrent branch November 22, 2026 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant