Skip to content

feat(torrent): change a remote device's BitTorrent settings - #645

Merged
linroid merged 3 commits into
mainfrom
feat/remote-torrent-settings
Oct 24, 2026
Merged

linroid merged 3 commits into
mainfrom
feat/remote-torrent-settings

Conversation

@linroid

@linroid linroid commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Summary

Settings → BitTorrent showed nothing but a note for a remote device (a ketch server, or a desktop or Android app sharing its downloads): its upload mode and limit, encryption, uTP, port mapping, local discovery, extra trackers and tracker lists lived only in that device's config.toml and were applied in process. Now a phone or desktop app changes all of them, they apply live, and the device saves them, so they survive its restart. Devices whose Ketch is older keep a note, now "Update Ketch on X to change these settings here."

API (protocol-neutral; library:api and library:core unchanged)

  • library:torrent-api: TorrentEngineSettings (with TorrentUploadSetting and TorrentEncryptionSetting; unknown wire values decode as off and preferred, as config does) and TorrentSettingsChange, whose null fields keep the instance's, so two clients changing different settings never undo each other. TorrentController.settings() / updateSettings(change), advertised by the new settings capability; local-discovery says the engine can run BEP 14 (not iOS), so the app gates that switch on the remote device, not on its own platform. Listen port and Wi-Fi only stay the host's.
  • GET/PUT /api/torrents/settings (Torrents.Settings), behind the token and startup gate. Malformed bodies and too many or malformed URLs answer invalid_input, without echoing values (trackers may hold passkeys).
  • RemoteTorrentController fails closed without the capability, sending nothing, and drops its cached capabilities after a change, as seeding follows the upload mode.

Engine and persistence

  • TorrentDownloadSource.settings: StateFlow<TorrentEngineSettings> is the truth; the setters, the new applySettings and the controller change it, once per change and only for the fields that differ. TorrentConfig.withSettings builds a config from them, and TorrentConfig.trackerListsEnabled keeps lists that are switched off.
  • config: TorrentSettings.engineSettings / withEngineSettings (keeps listenPort, uploadWifiOnly and a 0.3.0 trackerListUrl while its address stays). The desktop, Android, iOS and CLI hosts now build and apply torrent settings through them instead of four copies of the mode mappings.
  • ketch server and ketch mcp --standalone: TorrentSettingsSaver writes each change over [torrent] of the config file as it is then, only the fields that changed since start, so --torrent-upload / KETCH_TORRENT_UPLOAD are never baked into the file; an unreadable file is left alone and the change retried with the next.
  • Apps: InstanceFactory.torrentEngineSettings → InstanceSettingsController.followEngineTorrent saves what other devices change on the embedded engine through AppSettingsController.saveTorrent, so it shows in this device's Settings and outlives a restart.

App

  • InstanceSettingsController.loadTorrent() reads a remote device's settings when it lists settings; edits send only the changed fields (TorrentSettingsChange.between) and a refusal shows what the device last confirmed. BitTorrentSettings shows Uploading, Connections, Trackers and Tracker lists for it, with loading and error states; Only on Wi-Fi (also in Settings search) stays the embedded device's, and tracker list status is omitted for remote devices.
  • settings_torrent_remote reworded in all ten languages.

Tests

  • TorrentContractsTest (wire names, lenient decoding, between/applyTo), TorrentSourceSettingsTest (config round trip, setters, one publish per change, controller apply and validation), TorrentDownloadSourceTest capabilities.
  • TorrentRoutesTest (GET/PUT, malformed bodies, token), RemoteTorrentSettingsTest (a real KetchServer and RemoteKetch: only set fields reach the server; older servers fail closed without a request), RemoteTorrentControllerTest.
  • config TorrentSettingsTest, cli TorrentSettingsSaverTest, InstanceSettingsControllerTest (remote load, edits, refusal, older device, adopting changes made elsewhere).
  • Ran: :library:torrent-api:jvmTest :library:torrent:jvmTest :library:server:test :library:remote:jvmTest :config:jvmTest :cli:test :app:shared:jvmTest, and compiled :app:android:compileDirectDebugKotlin :app:shared:compileKotlinIosSimulatorArm64.

Snapshots

A remote NAS on a phone, light (SettingsDeviceSnapshots):

Before After: NAS with this version After: older NAS

The new scenario in the Settings window's page pane, light and dark:

Light Dark

Notes

  • fix: save download settings changed over the REST API #644 (saving download settings changed over the API) touches InstanceSettingsController, AppState, cli/Main.kt, the hosts' localServerFactory and AGENTS.md too; whichever merges second resolves the conflicts. Its ServerConfigFile and this PR's TorrentSettingsSaver follow the same field-by-field rule and can be folded into one generalized saver later, which would also bring its warning for fields a flag or variable pins (--torrent-upload).
  • ServeDaemonTest's "cannot listen" case leaks Ktor's BindException to the global coroutine handler, which runTest in a later CLI test reports; TorrentSettingsSaverTest avoids runTest for that reason. Fixing the leak is left for a follow-up.

Settings > BitTorrent showed only a note for a remote device, as its torrent settings lived in
its own config.toml and no API carried them.

- torrent-api: TorrentEngineSettings and TorrentSettingsChange (null fields keep the
  instance's), TorrentController.settings() and updateSettings(), and the settings and
  local-discovery capabilities.
- GET and PUT /api/torrents/settings, and RemoteTorrentController, which fails closed against
  older servers and reads capabilities again after a change.
- TorrentDownloadSource.settings is a StateFlow the setters, applySettings and the controller
  change; TorrentConfig.withSettings and trackerListsEnabled build it from config, and
  TorrentSettings.engineSettings / withEngineSettings map config both ways.
- ketch server and ketch mcp --standalone save what clients change to [torrent] of their
  config file, field by field; the apps save changes made through their own server.
- The app loads and edits a remote device's settings, gating local discovery on the device's
  capability and keeping Only on Wi-Fi local; older devices get "Update Ketch on X".
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 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-24T03:18:43.734399Z 542f3a4 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: 542f3a47d5

ℹ️ 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".

- TorrentDownloadSource.changeSettings runs under NonCancellable once it holds the lock, so a
  caller cancelled midway, such as a client that left, never leaves the engine on settings
  that `settings` does not report.
- The app keeps a remote device's pending edits field by field and shows them over what the
  device confirmed, so an edit queued behind one in flight never sends back a setting another
  device changed meanwhile.
@github-actions

Copy link
Copy Markdown
Contributor

Test Results

 2 214 files  + 6   2 242 suites  +6   56m 27s ⏱️ - 1m 34s
15 483 tests +53  15 214 ✅ +52  269 💤 +1  0 ❌ ±0 
18 862 runs  +65  18 593 ✅ +64  269 💤 +1  0 ❌ ±0 

Results for commit 570d7eb. ± Comparison against base commit 18d1de8.

This pull request removes 3 and adds 56 tests. Note that renamed tests count towards both.
com.linroid.ketch.app.InstanceSettingsControllerTest ‑ remote instances offer no torrent settings[jvm]
com.linroid.ketch.cli.TorrentUploadSettingsTest ‑ everyUploadModeMapsToADistinctPolicy
iosSimulatorArm64Test.com.linroid.ketch.app.InstanceSettingsControllerTest ‑ remote instances offer no torrent settings[iosSimulatorArm64]
com.linroid.ketch.app.InstanceSettingsControllerTest ‑ followEngineTorrent_changedByAnotherDevice_isSavedKeepingTheHosts[jvm]
com.linroid.ketch.app.InstanceSettingsControllerTest ‑ loadTorrent_olderRemote_isUnsupportedWithoutAsking[jvm]
com.linroid.ketch.app.InstanceSettingsControllerTest ‑ loadTorrent_remoteWithoutTorrentControls_isUnsupported[jvm]
com.linroid.ketch.app.InstanceSettingsControllerTest ‑ updateTorrent_editQueuedWhileOneIsSent_keepsWhatAnotherDeviceChanged[jvm]
com.linroid.ketch.app.InstanceSettingsControllerTest ‑ updateTorrent_remoteRefuses_showsWhatItConfirmed[jvm]
com.linroid.ketch.app.InstanceSettingsControllerTest ‑ updateTorrent_remote_sendsOnlyTheEditAndShowsWhatItSaved[jvm]
com.linroid.ketch.app.snapshot.SettingsDeviceSnapshots ‑ remote_bitTorrent_changesTheDevicesOwnSettings[jvm]
com.linroid.ketch.cli.TorrentSettingsSaverTest ‑ change_savesOnlyWhatChanged_overWhatTheFileSays
com.linroid.ketch.cli.TorrentSettingsSaverTest ‑ unreadableFile_isLeftAlone_andTheChangeSavedWithTheNext
com.linroid.ketch.config.TorrentSettingsTest ‑ a list saved by 0_3_0 stays written as it was while its address stays[jvm]
…

@linroid
linroid enabled auto-merge (squash) October 24, 2026 06:58
…ettings

# Conflicts:
#	AGENTS.md
#	app/shared/src/commonMain/kotlin/com/linroid/ketch/app/state/InstanceSettingsController.kt
#	app/shared/src/commonTest/kotlin/com/linroid/ketch/app/InstanceSettingsControllerTest.kt
@linroid
linroid merged commit be3a16e into main Oct 24, 2026
11 checks passed
@linroid
linroid deleted the feat/remote-torrent-settings branch October 24, 2026 07:03
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