Skip to content

Enable WebTorrent: wss:// trackers + WebRTC browser peers (#18) - #22

Merged
jpcottin merged 7 commits into
masterfrom
webtorrent
Aug 3, 2026
Merged

Enable WebTorrent: wss:// trackers + WebRTC browser peers (#18)#22
jpcottin merged 7 commits into
masterfrom
webtorrent

Conversation

@jpcottin

@jpcottin jpcottin commented Aug 3, 2026

Copy link
Copy Markdown
Owner

Stage 2 of WebTorrent support (#18) — stacked on #21 (libtorrent 2.1 bump). Verified working end-to-end; leaving #18 open until it's confirmed on master.

What's enabled

  • webtorrent=ON + encryption=ON in the native build: the app announces to wss:// WebSocket trackers and connects to WebTorrent (browser) peers over WebRTC data channels (libdatachannel + libjuice + usrsctp, statically linked).
  • Static OpenSSL 3.5.7 for Android built by scripts/build-openssl-android.sh (arm64-v8a + x86_64; output gitignored; CI builds it with an actions/cache keyed on version in the four native-build jobs).
  • Android trust store bridge: OpenSSL knows nothing about Android's CA layout, so the JNI exports the system trust store (conscrypt APEX on 14+, else /system/etc/security/cacerts) as one PEM bundle at session init and points SSL_CERT_FILE at it.
  • Submodule moves to fork branch RC_2_1-simpletorrent = RC_2_1 + one upstreamable patch: load the SSL_CERT_FILE bundle explicitly (asio's set_default_verify_paths() leaves the store empty with a static OpenSSL on Android → certificate verify failed on every wss handshake).
  • Debug builds log libtorrent session/torrent alerts to logcat (tag libtorrent) — this is how the CA issue was found.
  • New SampleTorrentsTest (4 tests): magnet well-formedness, wss-only trackers on the WebTorrent sample, shared infohash with plain Sintel, distinct hashes elsewhere.
  • README: WebTorrent feature entry + OpenSSL build step.

Verification

  • Announce succeeds against wss://tracker.webtorrent.dev and wss://tracker.openwebtorrent.com.
  • Browser peers' WebRTC answers arrive and RTC data channels open within seconds of announce.
  • WebTorrent peers download from the app over WebRTC; manually confirmed against webtorrent.io in a real browser.
  • Unit tests 33/33 green.

Known quirk

The first wss announce right after session start is sometimes canceled by libtorrent's initial external-IP discovery; the retry ~120 s later succeeds. Tracked for a possible follow-up (force re-announce once the external address settles).

Switch libs/libtorrent from RC_2_0 (2.0.13) to RC_2_1 (v2.1.0 + 122
bugfix commits). Groundwork for WebTorrent support (#18): 2.1 ships the
WebRTC/WebSocket-tracker code, kept disabled for now (webtorrent=OFF)
until the libdatachannel + TLS toolchain work lands.

No JNI changes needed; RC_2_1 adds deps/libdatachannel and
deps/asio-gnutls submodules (only built when webtorrent=ON).
New Sample Torrents row pointing at the same Sintel torrent through the
modern WebTorrent trackers (tracker.webtorrent.dev, openwebtorrent.com,
btorrent.xyz) plus the webtorrent.io web seed. Groundwork for #18: once
the engine is built with webtorrent=ON this row demonstrates sharing
with browser peers; until then it still downloads via DHT.
Browser-peer sharing isn't live until the engine builds with
webtorrent=ON; don't claim it in the UI yet.
Flip webtorrent=ON and encryption=ON in the native build, backed by a
static OpenSSL 3.5.7 built for Android by scripts/build-openssl-android.sh
(arm64-v8a + x86_64, gitignored output, cached in CI).

- Submodule moves to fork branch RC_2_1-simpletorrent: RC_2_1 plus one
  patch that loads the CA bundle named by SSL_CERT_FILE explicitly —
  asio's set_default_verify_paths() leaves the store empty with a static
  OpenSSL on Android, so wss:// certificate validation failed.
- JNI exports the Android system trust store (conscrypt APEX or
  /system/etc/security/cacerts) as a single PEM bundle at session init
  and points SSL_CERT_FILE at it.
- Debug builds now log libtorrent session/torrent log alerts to logcat
  (tag "libtorrent"), which is how the CA failure was diagnosed.
- CI builds OpenSSL (actions/cache keyed on version) in the four jobs
  that compile native code.
- New SampleTorrentsTest covers magnet well-formedness and the
  wss://-only WebTorrent sample.

Verified end-to-end on the emulator: announces to wss://tracker.webtorrent.dev
and openwebtorrent.com succeed, browser peers' answers arrive, RTC data
channels open, and a WebRTC-only WebTorrent client (DHT/TCP disabled)
downloaded Sintel from the app at 1.3 MB/s over a webrtc wire
(peer id -LT2100-). Known quirk: the first announce right after session
start can be canceled by the initial external-IP discovery; the retry
120 s later succeeds.
The pull_request branch filter matches the PR base, so stacked PRs
(like webtorrent -> libtorrent-2.1) got no CI at all.
@jpcottin
jpcottin changed the base branch from libtorrent-2.1 to master August 3, 2026 01:45
@jpcottin
jpcottin merged commit 3b1fd23 into master Aug 3, 2026
6 checks passed
@jpcottin jpcottin mentioned this pull request Aug 3, 2026
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