feat: add BitTorrent protocol support as pluggable DownloadSource#121
Merged
feat: add BitTorrent protocol support as pluggable DownloadSource#121
Conversation
Add a new `library:torrent` module implementing BitTorrent downloads via libtorrent4j. Supports magnet links and .torrent files on Android and JVM, with iOS stubs throwing KetchError.Unsupported (future cinterop work). Core infrastructure: - Add `managesOwnFileIo` property to DownloadSource interface for sources that manage their own file I/O (e.g., libtorrent4j) - Add NoOpFileAccessor stub used when source handles file writes - Update DownloadExecution to skip FileAccessor for self-managed sources New library:torrent module: - TorrentDownloadSource implementing DownloadSource (canHandle, resolve, download, resume) for magnet: URIs and .torrent URLs - TorrentEngine/TorrentSession interfaces in commonMain with Libtorrent4jEngine/Session in jvmAndAndroid source set - Pure Kotlin bencode encoder/decoder, magnet URI parser, info hash, and .torrent metadata parser in commonMain - iOS stubs via expect/actual factory pattern (matching FTP module) - 176 tests across 14 test files Example app integration: - Register TorrentDownloadSource in platform sources (Android, JVM, iOS) - File selector UI for multi-file torrents in AddDownloadDialog - Updated URL placeholder to mention magnet links
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Version 2.1.0-31 only included x86_64 macOS native binary. Version 2.1.0-39 includes arm64, fixing LinkageError on Apple Silicon Macs.
Contributor
The libtorrent4j native library (.dylib/.so/.dll) is bundled inside platform-specific JARs but System.loadLibrary() can't find libraries inside JARs. NativeLibraryLoader extracts the native lib to a temp directory and sets the libtorrent4j.jni.path system property so the SWIG static initializer uses System.load() with the absolute path.
assert() requires @ExperimentalNativeApi opt-in on Kotlin/Native, causing iOS test compilation to fail.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
library:torrentmodule implementing BitTorrent downloads via libtorrent4j (MIT license)managesOwnFileIoextension point toDownloadSourcefor sources that manage their own file I/OChanges
Core infrastructure (
library:core)DownloadSource.managesOwnFileIoproperty (defaultfalse, backward-compatible)NoOpFileAccessorinternal stub for self-managed I/O sourcesDownloadExecutionconditionally skips FileAccessor creation/flush/cleanupNew module (
library:torrent)TorrentDownloadSourceimplementingDownloadSource— handlesmagnet:URIs and.torrentURLsTorrentEngine/TorrentSessioninterfaces in commonMain (KMP-portable types only, designed for future iOS cinterop)Libtorrent4jEngine/Libtorrent4jSessioninjvmAndAndroidintermediate source setKetchError.Unsupported)Example app (
app/shared)TorrentDownloadSourceregistered inplatformAdditionalSources()for Android, JVM, iOSArchitecture decisions
jvmAndAndroidintermediatemanagesOwnFileIoflagKnown limitations
KetchError.Unsupporteduntil native cinterop is implementedTest plan
./gradlew :library:torrent:jvmTest— 176 tests pass./gradlew :library:torrent:compileKotlinIosArm64— iOS compilation succeeds./gradlew :library:torrent:compileKotlinIosSimulatorArm64— iOS simulator compilation succeeds./gradlew :library:core:jvmTest— existing core tests unaffected./gradlew :app:shared:compileKotlinJvm— app integration compiles