Add announce_port support

The `announce_port` setting permits to overwrite the port passed along to trackers as the `&port=` parameter. If left as the default, the listening port is used. This setting is only meant for very special cases where a seed's listening port differs from the effectively exposed port (e.g., through external NAT-PMP). See https://github.com/arvidn/libtorrent/pull/7771 for an example use-case.

This PR adds the relevant setting alongside the existing `announce_ip` setting.

PR #21692.
This commit is contained in:
Maxime Thiebaut 2025-02-08 09:12:50 +01:00 committed by GitHub
parent 9c2e698514
commit 4406a3f173
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 53 additions and 1 deletions

View file

@ -163,6 +163,7 @@ namespace
ANNOUNCE_ALL_TRACKERS,
ANNOUNCE_ALL_TIERS,
ANNOUNCE_IP,
ANNOUNCE_PORT,
MAX_CONCURRENT_HTTP_ANNOUNCES,
STOP_TRACKER_TIMEOUT,
PEER_TURNOVER,
@ -309,6 +310,8 @@ void AdvancedSettings::saveAdvancedSettings() const
// Construct a QHostAddress to filter malformed strings
const QHostAddress addr(m_lineEditAnnounceIP.text().trimmed());
session->setAnnounceIP(addr.toString());
// Announce Port
session->setAnnouncePort(m_spinBoxAnnouncePort.value());
// Max concurrent HTTP announces
session->setMaxConcurrentHTTPAnnounces(m_spinBoxMaxConcurrentHTTPAnnounces.value());
// Stop tracker timeout
@ -801,6 +804,13 @@ void AdvancedSettings::loadAdvancedSettings()
addRow(ANNOUNCE_IP, (tr("IP address reported to trackers (requires restart)")
+ u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#announce_ip", u"(?)"))
, &m_lineEditAnnounceIP);
// Announce port
m_spinBoxAnnouncePort.setMinimum(0);
m_spinBoxAnnouncePort.setMaximum(65535);
m_spinBoxAnnouncePort.setValue(session->announcePort());
addRow(ANNOUNCE_PORT, (tr("Port reported to trackers (requires restart) [0: listening port]")
+ u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#announce_port", u"(?)"))
, &m_spinBoxAnnouncePort);
// Max concurrent HTTP announces
m_spinBoxMaxConcurrentHTTPAnnounces.setMaximum(std::numeric_limits<int>::max());
m_spinBoxMaxConcurrentHTTPAnnounces.setValue(session->maxConcurrentHTTPAnnounces());