feat: add built-in CGNAT STUN port discovery#24687
Conversation
|
Does this work for any 100.64.0.0/10 prefix? I have CGNAT here. |
|
Personally (as I am not a Project Maintainer so I don't speak for the Project), I have huge privacy concerns around this. |
|
UPnP/NAT-PMP cannot work with CGNAT. So this is the same option. |
- Independent CGNATEnabled toggle (default off, decoupled from UPnP) - UDP STUN discovers external port for uTP - Standalone TCP proxy maintains NAT mapping + forwards inbound connections - Fix STUN XOR-MAPPED-ADDRESS byte-order bug - WebUI settings: enable toggle, STUN server, probe interval - Default STUN server empty (user-configured) Verified: 364MB upload through CGNAT proxy port on pure IPv4 Full Cone NAT.
4c5ae0e to
51b9a7e
Compare
|
Thank you for reviewing — you were absolutely right. Hardcoding a I've made these changes:
Please take another look when you have time. Happy to address any |
|
In theory it should work. STUN is designed for NAT traversal, and On my end (China Mobile Full Cone CGNAT) it works — external peers That said, different ISPs may handle CGNAT differently. I also found |
Summary
Add built-in CGNAT STUN port discovery to qBittorrent, eliminating the need for UPnP/NAT-PMP on carrier-grade NAT (CGNAT) connections.
Problem
When qBittorrent runs behind CGNAT (common with Chinese ISPs like China Mobile, and increasingly common worldwide with IPv4 exhaustion), the listen port is translated to a random external port by the carrier's NAT. qBittorrent announces its listen port to trackers, but peers receive the wrong port and cannot connect — resulting in zero upload.
Solution
CGNATManager — a lightweight, built-in STUN client that:
setAnnouncePort(), which updates libtorrent's announce portThe feature is toggled via the existing "Use UPnP / NAT-PMP port forwarding" setting — no new UI checkbox needed.
Architecture
Configuration
Files Changed
src/base/bittorrent/cgnatmanager.h(74 lines) — STUN client headersrc/base/bittorrent/cgnatmanager.cpp(219 lines) — RFC 5389 implementationsrc/base/CMakeLists.txt— +2 lines for new filessrc/base/bittorrent/sessionimpl.h— +5 lines (include, members)src/base/bittorrent/sessionimpl.cpp— +22 lines (init, signal, enable/disable)Testing
Tested on Debian 13 with qBittorrent-nox behind China Mobile CGNAT:
announce_portauto-updated to correct external port