Repository navigation
feat(torrent): change a remote device's BitTorrent settings - #645
Conversation
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".
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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.
Test Results 2 214 files + 6 2 242 suites +6 56m 27s ⏱️ - 1m 34s 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. |
…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
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'sconfig.tomland 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:apiandlibrary:coreunchanged)library:torrent-api:TorrentEngineSettings(withTorrentUploadSettingandTorrentEncryptionSetting; unknown wire values decode asoffandpreferred, as config does) andTorrentSettingsChange, whosenullfields keep the instance's, so two clients changing different settings never undo each other.TorrentController.settings()/updateSettings(change), advertised by the newsettingscapability;local-discoverysays 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 answerinvalid_input, without echoing values (trackers may hold passkeys).RemoteTorrentControllerfails closed without the capability, sending nothing, and drops its cached capabilities after a change, asseedingfollows the upload mode.Engine and persistence
TorrentDownloadSource.settings: StateFlow<TorrentEngineSettings>is the truth; the setters, the newapplySettingsand the controller change it, once per change and only for the fields that differ.TorrentConfig.withSettingsbuilds a config from them, andTorrentConfig.trackerListsEnabledkeeps lists that are switched off.config:TorrentSettings.engineSettings/withEngineSettings(keepslistenPort,uploadWifiOnlyand a 0.3.0trackerListUrlwhile 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 serverandketch mcp --standalone:TorrentSettingsSaverwrites each change over[torrent]of the config file as it is then, only the fields that changed since start, so--torrent-upload/KETCH_TORRENT_UPLOADare never baked into the file; an unreadable file is left alone and the change retried with the next.InstanceFactory.torrentEngineSettings→InstanceSettingsController.followEngineTorrentsaves what other devices change on the embedded engine throughAppSettingsController.saveTorrent, so it shows in this device's Settings and outlives a restart.App
InstanceSettingsController.loadTorrent()reads a remote device's settings when it listssettings; edits send only the changed fields (TorrentSettingsChange.between) and a refusal shows what the device last confirmed.BitTorrentSettingsshows 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_remotereworded 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),TorrentDownloadSourceTestcapabilities.TorrentRoutesTest(GET/PUT, malformed bodies, token),RemoteTorrentSettingsTest(a realKetchServerandRemoteKetch: only set fields reach the server; older servers fail closed without a request),RemoteTorrentControllerTest.configTorrentSettingsTest, cliTorrentSettingsSaverTest,InstanceSettingsControllerTest(remote load, edits, refusal, older device, adopting changes made elsewhere).: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):The new scenario in the Settings window's page pane, light and dark:
Notes
InstanceSettingsController,AppState,cli/Main.kt, the hosts'localServerFactoryand AGENTS.md too; whichever merges second resolves the conflicts. ItsServerConfigFileand this PR'sTorrentSettingsSaverfollow 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'sBindExceptionto the global coroutine handler, whichrunTestin a later CLI test reports;TorrentSettingsSaverTestavoidsrunTestfor that reason. Fixing the leak is left for a follow-up.