diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 7e1b9dc6c551..75be5b362970 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -386,6 +386,8 @@ namespace BitTorrent virtual void setIncludeOverheadInLimits(bool include) = 0; virtual QString announceIP() const = 0; virtual void setAnnounceIP(const QString &ip) = 0; + virtual int announcePort() const = 0; + virtual void setAnnouncePort(int port) = 0; virtual int maxConcurrentHTTPAnnounces() const = 0; virtual void setMaxConcurrentHTTPAnnounces(int value) = 0; virtual bool isReannounceWhenAddressChangedEnabled() const = 0; diff --git a/src/base/bittorrent/sessionimpl.cpp b/src/base/bittorrent/sessionimpl.cpp index 496308fef53a..518be9ebbae6 100644 --- a/src/base/bittorrent/sessionimpl.cpp +++ b/src/base/bittorrent/sessionimpl.cpp @@ -440,6 +440,7 @@ SessionImpl::SessionImpl(QObject *parent) , m_ignoreLimitsOnLAN(BITTORRENT_SESSION_KEY(u"IgnoreLimitsOnLAN"_s), false) , m_includeOverheadInLimits(BITTORRENT_SESSION_KEY(u"IncludeOverheadInLimits"_s), false) , m_announceIP(BITTORRENT_SESSION_KEY(u"AnnounceIP"_s)) + , m_announcePort(BITTORRENT_SESSION_KEY(u"AnnouncePort"_s), 0) , m_maxConcurrentHTTPAnnounces(BITTORRENT_SESSION_KEY(u"MaxConcurrentHTTPAnnounces"_s), 50) , m_isReannounceWhenAddressChangedEnabled(BITTORRENT_SESSION_KEY(u"ReannounceWhenAddressChanged"_s), false) , m_stopTrackerTimeout(BITTORRENT_SESSION_KEY(u"StopTrackerTimeout"_s), 2) @@ -1982,6 +1983,8 @@ lt::settings_pack SessionImpl::loadLTSettings() const settingsPack.set_bool(lt::settings_pack::rate_limit_ip_overhead, includeOverheadInLimits()); // IP address to announce to trackers settingsPack.set_str(lt::settings_pack::announce_ip, announceIP().toStdString()); + // Port to announce to trackers + settingsPack.set_int(lt::settings_pack::announce_port, announcePort()); // Max concurrent HTTP announces settingsPack.set_int(lt::settings_pack::max_concurrent_http_announces, maxConcurrentHTTPAnnounces()); // Stop tracker timeout @@ -4746,6 +4749,20 @@ void SessionImpl::setAnnounceIP(const QString &ip) } } +int SessionImpl::announcePort() const +{ + return m_announcePort; +} + +void SessionImpl::setAnnouncePort(int port) +{ + if (port != m_announcePort) + { + m_announcePort = port; + configureDeferred(); + } +} + int SessionImpl::maxConcurrentHTTPAnnounces() const { return m_maxConcurrentHTTPAnnounces; diff --git a/src/base/bittorrent/sessionimpl.h b/src/base/bittorrent/sessionimpl.h index 6899fedfc629..c948feead527 100644 --- a/src/base/bittorrent/sessionimpl.h +++ b/src/base/bittorrent/sessionimpl.h @@ -361,6 +361,8 @@ namespace BitTorrent void setIncludeOverheadInLimits(bool include) override; QString announceIP() const override; void setAnnounceIP(const QString &ip) override; + int announcePort() const override; + void setAnnouncePort(int port) override; int maxConcurrentHTTPAnnounces() const override; void setMaxConcurrentHTTPAnnounces(int value) override; bool isReannounceWhenAddressChangedEnabled() const override; @@ -657,6 +659,7 @@ namespace BitTorrent CachedSettingValue m_ignoreLimitsOnLAN; CachedSettingValue m_includeOverheadInLimits; CachedSettingValue m_announceIP; + CachedSettingValue m_announcePort; CachedSettingValue m_maxConcurrentHTTPAnnounces; CachedSettingValue m_isReannounceWhenAddressChangedEnabled; CachedSettingValue m_stopTrackerTimeout; diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index a698bbcb40a4..e632d3f5366f 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -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 @@ -796,11 +799,17 @@ void AdvancedSettings::loadAdvancedSettings() // Network interface address updateInterfaceAddressCombo(); addRow(NETWORK_IFACE_ADDRESS, tr("Optional IP address to bind to"), &m_comboBoxInterfaceAddress); - // Announce IP + // Announce IP & port m_lineEditAnnounceIP.setText(session->announceIP()); 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); + 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::max()); m_spinBoxMaxConcurrentHTTPAnnounces.setValue(session->maxConcurrentHTTPAnnounces()); diff --git a/src/gui/advancedsettings.h b/src/gui/advancedsettings.h index 5c81745bede7..81a308af3757 100644 --- a/src/gui/advancedsettings.h +++ b/src/gui/advancedsettings.h @@ -74,7 +74,8 @@ private slots: m_spinBoxListRefresh, m_spinBoxTrackerPort, m_spinBoxSendBufferWatermark, m_spinBoxSendBufferLowWatermark, m_spinBoxSendBufferWatermarkFactor, m_spinBoxConnectionSpeed, m_spinBoxSocketSendBufferSize, m_spinBoxSocketReceiveBufferSize, m_spinBoxSocketBacklogSize, m_spinBoxMaxConcurrentHTTPAnnounces, m_spinBoxStopTrackerTimeout, m_spinBoxSessionShutdownTimeout, - m_spinBoxSavePathHistoryLength, m_spinBoxPeerTurnover, m_spinBoxPeerTurnoverCutoff, m_spinBoxPeerTurnoverInterval, m_spinBoxRequestQueueSize; + m_spinBoxSavePathHistoryLength, m_spinBoxPeerTurnover, m_spinBoxPeerTurnoverCutoff, m_spinBoxPeerTurnoverInterval, m_spinBoxRequestQueueSize, + m_spinBoxAnnouncePort; QCheckBox m_checkBoxOsCache, m_checkBoxRecheckCompleted, m_checkBoxResolveCountries, m_checkBoxResolveHosts, m_checkBoxProgramNotifications, m_checkBoxTorrentAddedNotifications, m_checkBoxReannounceWhenAddressChanged, m_checkBoxTrackerFavicon, m_checkBoxTrackerStatus, m_checkBoxTrackerPortForwarding, m_checkBoxIgnoreSSLErrors, m_checkBoxConfirmTorrentRecheck, m_checkBoxConfirmRemoveAllTags, m_checkBoxAnnounceAllTrackers, diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index 14517be7d030..83f1a012d612 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -469,6 +469,7 @@ void AppController::preferencesAction() data[u"announce_to_all_trackers"_s] = session->announceToAllTrackers(); data[u"announce_to_all_tiers"_s] = session->announceToAllTiers(); data[u"announce_ip"_s] = session->announceIP(); + data[u"announce_port"_s] = session->announcePort(); data[u"max_concurrent_http_announces"_s] = session->maxConcurrentHTTPAnnounces(); data[u"stop_tracker_timeout"_s] = session->stopTrackerTimeout(); // Peer Turnover @@ -1134,6 +1135,8 @@ void AppController::setPreferencesAction() const QHostAddress announceAddr {it.value().toString().trimmed()}; session->setAnnounceIP(announceAddr.isNull() ? QString {} : announceAddr.toString()); } + if (hasKey(u"announce_port"_s)) + session->setAnnouncePort(it.value().toInt()); if (hasKey(u"max_concurrent_http_announces"_s)) session->setMaxConcurrentHTTPAnnounces(it.value().toInt()); if (hasKey(u"stop_tracker_timeout"_s)) diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index 361dd9c5e26f..795bbe9611ab 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -1589,6 +1589,14 @@ + + + + + + + + @@ -2531,6 +2539,7 @@ $("announceAllTrackers").checked = pref.announce_to_all_trackers; $("announceAllTiers").checked = pref.announce_to_all_tiers; $("announceIP").value = pref.announce_ip; + $("announcePort").value = pref.announce_port; $("maxConcurrentHTTPAnnounces").value = pref.max_concurrent_http_announces; $("stopTrackerTimeout").value = pref.stop_tracker_timeout; $("peerTurnover").value = pref.peer_turnover; @@ -2990,6 +2999,12 @@ settings["announce_to_all_trackers"] = $("announceAllTrackers").checked; settings["announce_to_all_tiers"] = $("announceAllTiers").checked; settings["announce_ip"] = $("announceIP").value; + const announce_port = $("announce_port").value.toInt(); + if (isNaN(announce_port) || (announce_port < 0) || (announce_port > 65535)) { + alert("QBT_TR(The announced port must be between 0 and 65535.)QBT_TR[CONTEXT=OptionsDialog]"); + return; + } + settings["announce_port"] = announce_port; settings["max_concurrent_http_announces"] = Number($("maxConcurrentHTTPAnnounces").value); settings["stop_tracker_timeout"] = Number($("stopTrackerTimeout").value); settings["peer_turnover"] = Number($("peerTurnover").value);