By the FrostWire team · github.com/frostwire/frostwire-jlibtorrent
We are happy to ship jlibtorrent 2.1.3.0, the latest Java/JNI bindings for libtorrent’s RC_2_1 branch. This release rebases on the libtorrent v2.1.3 tag (f29e8b533) plus a few more security fixes committed after it, and it fixes a batch of long-standing bugs in the hand-written Java wrapper, bugs that turned up while we raised test coverage of that code to 95.8% of lines.
Most of the fixes are in the wrapper, so most apps will see them even without touching the new libtorrent. One change affects how numbers are bencoded, so read the Entry note below before upgrading.
Upgrade everything together. The Java side refuses to load a native library of another version, so move the core jar and every native jar you ship, or the Android AAR, to 2.1.3.0 in one step. Java stays at 17.
// Android (one AAR)implementation 'com.frostwire:jlibtorrent-android:2.1.3.0'// Desktopimplementation 'com.frostwire:jlibtorrent:2.1.3.0'
What’s new in libtorrent 2.1.3
jlibtorrent 2.1.2.x was built from RC_2_1 plus a few fixes. This release rebases on the v2.1.3 tag and the 2.0.16/2.0.17 fixes merged into it, then adds the commits made on RC_2_1 since.
Security and hardening:
- The IP filter now applies to WebRTC peers, and websocket streams close correctly.
- Stricter validation of metadata against the info-hashes:
set_metadata()with a buffer that matches the info-hash but is not valid metadata now puts the torrent in an error state and pauses it. - Better DHT write tokens.
0.0.0.0and::count as local host in the tracker and web seed SSRF checks.- A piece picker fix for when a partially downloaded piece is lost.
- Hardened HTTP redirects and web seeds.
- New limits on peer-supplied data: the allowed-fast set and the extension-handshake listen port.
- Hardened i2p, tracker, symlink and torrent-creation code.
Races and memory safety:
- A use-after-free in the pread disk I/O, when a cached piece was evicted while another thread flushed it.
- A race between removing a torrent and a hash job parked in the disk cache.
Behavior:
- Hybrid torrent file order is fixed.
- Filenames go to the OS as UTF-8 on POSIX, whatever the locale.
ip_filterlookups are faster.- New
info_hash_t.contains(), the only public API change in the native layer. - libdatachannel (WebTorrent) is now 0.24.8, and the default peer fingerprint is
-LT2130-.
The full list is in changelog.txt.
Fixes in the Java wrapper
SessionManager.dhtGetItem()returnsnullwhen nothing is found (#352). Both overloads used to return an uninitialized entry that bencoded to0:and threwinvalid type requested from entryfromstring(). They now returnnull, the same answer as a timeout. Callers that already null-check a timeout need no change.Entry.fromList()/fromMap()encode numbers as numbers (#345). OnlyIntegerwas written as a bencode integer.Long,ShortandBytecame out as strings of their decimal value. They are integers now, andBooleanbecomes the integer1or0, since bencode has no boolean. Behavior change: code that stored aLongin a map and read it back as a string must read an integer now, and a peer that expects the old string form will see an integer. Usenew Entry(long)orEntry.bdecode()if you want to be explicit.BDecodeNode.hasString()(#343),hasInt()andgetInt()(#344) look at the key.hasString()was true for every key of a dictionary.hasInt()andgetInt()looked at the dictionary node itself, sohasInt()was always false andgetInt()always returned 0. A stored0no longer counts as absent.TorrentBuilder(#349).creationDate()threwNullPointerExceptionunless the setter had been called, andgenerate()never passed the value on. The date now defaults to the time of construction andgenerate()applies it.alignment()is deprecated, because libtorrent 2.1 has no such parameter.Ed25519.keyExchange()is static (#348). It was a public instance method of a class with a private constructor, so nobody could call it without reflection.AlertType.fromSwig()(#347) andCloseReason.fromSwig()(#346). Unknown values answerUNKNOWNinstead of throwing or returningnull.CloseReason‘s lookup table is built in a static initializer, so other threads can no longer see it half filled.IntSeries.last()(#350). It returned 0 whenever the newest value sat at index 0, and threw on an empty series.Logger(#354).warn(),error()anddebug()logged at INFO. They now log at WARNING, SEVERE and FINE. Debug messages from the native library loader no longer print unless FINE is enabled.LibTorrent.revision()(#351). It reported libtorrent 2.0.x’s revision. A test now fails if the constant drifts from the libtorrent version in the changelog.
Tests
The hand-written Java code now has 95.8% line coverage, with the SWIG glue excluded. The new tests use a loopback session harness and a hand-written BitTorrent peer for the alert tests. A JaCoCo report is part of the build.
Get jlibtorrent 2.1.3.0
The jars for core, sources and javadoc, the Android AAR, and one native jar each for macOS (arm64, x86_64), Linux (x86_64, arm64), Windows and Android (arm, arm64, x86, x86_64) are attached to the GitHub release with SHA256SUMS.txt. They are also on dl.frostwire.com/maven.
If you build BitTorrent clients, media streaming tools or decentralized data pipelines in Java, this is the build you want. jlibtorrent is free and open source, and it is the same engine that powers FrostWire on desktop and Android.
