Skip to content

feat(torrent): share with peers while downloading by default, on phones only over Wi-Fi - #534

Merged
linroid merged 2 commits into
mainfrom
feat/torrent-upload-defaults
Oct 13, 2026
Merged

linroid merged 2 commits into
mainfrom
feat/torrent-upload-defaults

Conversation

@linroid

@linroid linroid commented Oct 13, 2026

Copy link
Copy Markdown
Owner

What changes for users

  • New default: [torrent] upload is now while-downloading (was off). Torrents share the pieces they have while they download and stop when they finish.
  • Existing app installs keep their setting. The apps write every field to config.toml, so an install that saved off stays off.
  • ketch server, Docker and the CLI change on upgrade. They never write config.toml, so setups without an upload key start uploading while downloading. KETCH_TORRENT_UPLOAD=off or --torrent-upload off turns it off without a config file (flag > variable > config.toml). Docs and the Docker guide say so.
  • Phones: Settings → BitTorrent → Uploading → Only on Wi-Fi ([torrent] uploadWifiOnly, on by default; greyed out while uploading is Off). On mobile data or another metered network, uploads pause at once. They resume after the network has been unmetered for 3 s, because every resume rechecks seeded torrents. Phones start paused off Wi-Fi, so launch never uploads on mobile data. Desktop and the CLI ignore the setting.
  • Seeding survives a pause. Seeders stop but keep their intent, and seed again on Wi-Fi without a restart; a torrent that finishes while paused under Keep seeding seeds once uploads resume.
  • Inspector: a torrent waiting for Wi-Fi to seed shows Stop seeding with "Waiting to seed", so it can be cancelled.

How

  • library:torrent: TorrentDownloadSource(uploadsPaused) + setUploadsPaused(). Pausing hands the engine DISABLED and keeps the configured policy. The sharingResumes counter re-runs the seeding restore walk whenever the effective policy turns to seed, including a live switch to seed. The new SeedingOutcome.UPLOADS_PAUSED stops that walk. Completions while paused are recorded by the source (takeDeferredSharing) and never inferred from taskCompleted. setSeeding(true) while paused saves the intent. The SDK default stays DISABLED.
  • library:torrent-api: TorrentSnapshot.seeding (intent or live; null from older backends). observe also wakes on intent-only changes.
  • app:shared: UploadNetwork.kt (uploadsPaused, followUploadNetwork). InstanceFactory.uploadNetwork/pauseUploads, InstanceManager.followsUploadNetwork. Android unmeteredNetworkChanges/isUnmeteredNow (default network, NOT_METERED, TEMPORARILY_NOT_METERED on API 30+). iOS NWPathMonitor (satisfied, not expensive, not constrained). Settings switch and search entry, strings in all 10 locales.
  • cli: KETCH_TORRENT_UPLOAD, --torrent-upload, startup banner line.
  • Docs: AGENTS.md, torrent, control contract, CLI README, Docker (en/zh-CN), PRIVACY.md (effective date bumped), app store listing.

Snapshots

Phone, Settings → BitTorrent (SettingsDeviceSnapshots): before, the Uploading group had the mode and the limit; after, Only on Wi-Fi sits between them (settings-bittorrent-wifi-*, plus *-upload-off-* showing it dimmed). Images to follow.

Tests

  • :library:torrent:jvmTest (1,240), :library:torrent-api, :library:remote, :library:server, :library:mcp, :config:jvmTest, :app:shared:jvmTest (2,333), :cli:test: all pass.
  • Compiles: wasm, iOS simulator (main + tests), Android direct/play, desktop.
  • checkKotlinAbi passes; UnmeteredNetworkTest passes on the iOS simulator.
  • New: pause/resume/re-seed with real engines (v1 and v2), deferred completion, restore while paused, restoreSeeding = false; UploadNetworkTest on virtual time; InstanceManagerUploadNetworkTest; SeedingControlTest; config default/migration tests; ServerEnvironmentTest.

Known limits

  • A torrent finishing within ~200 ms of uploads resuming may not seed; pressing Seed fixes it.
  • "Wi-Fi" means unmetered: Ethernet and carrier-unmetered 5G upload, and metered Wi-Fi hotspots pause.
  • Row menus offer Stop seeding only while a task seeds now; the inspector covers the waiting case.
  • The iOS Xcode app was not built; the shared framework and test binary link Network.framework.

…es only over Wi-Fi

- [torrent] upload now defaults to while-downloading. Apps that saved "off" keep it;
  ketch server, Docker and the CLI without an upload key now upload while downloading,
  and KETCH_TORRENT_UPLOAD / --torrent-upload turn it off without a config file.
- New [torrent] uploadWifiOnly (on): the Android and iOS apps pause uploads off unmetered
  networks and resume them after 3 s on one (Settings > BitTorrent > Only on Wi-Fi).
- TorrentDownloadSource gains uploadsPaused / setUploadsPaused: the engine runs as
  DISABLED while paused, seeding intents are kept, and kept intents seed again when
  uploads resume or the mode switches to seed, without a restart.
- TorrentSnapshot.seeding reports the intent, so the inspector can stop a seed that waits
  for Wi-Fi ("Waiting to seed").
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T11:02:43.644468Z fc73dbd PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fc73dbdff3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@linroid
linroid merged commit d149f6d into main Oct 13, 2026
11 checks passed
@linroid
linroid deleted the feat/torrent-upload-defaults branch October 13, 2026 11:12
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