Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add announce_port support #21692

Merged
merged 1 commit into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/base/bittorrent/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,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;
Expand Down
19 changes: 19 additions & 0 deletions src/base/bittorrent/sessionimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,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)
Expand Down Expand Up @@ -2004,6 +2005,10 @@ 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());
#if LIBTORRENT_VERSION_NUM >= 20011
// Port to announce to trackers
settingsPack.set_int(lt::settings_pack::announce_port, announcePort());
#endif
// Max concurrent HTTP announces
settingsPack.set_int(lt::settings_pack::max_concurrent_http_announces, maxConcurrentHTTPAnnounces());
// Stop tracker timeout
Expand Down Expand Up @@ -4879,6 +4884,20 @@ void SessionImpl::setAnnounceIP(const QString &ip)
}
}

int SessionImpl::announcePort() const
{
return m_announcePort;
}

void SessionImpl::setAnnouncePort(const int port)
{
if (port != m_announcePort)
{
m_announcePort = port;
configureDeferred();
}
}

int SessionImpl::maxConcurrentHTTPAnnounces() const
{
return m_maxConcurrentHTTPAnnounces;
Expand Down
3 changes: 3 additions & 0 deletions src/base/bittorrent/sessionimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -670,6 +672,7 @@ namespace BitTorrent
CachedSettingValue<bool> m_ignoreLimitsOnLAN;
CachedSettingValue<bool> m_includeOverheadInLimits;
CachedSettingValue<QString> m_announceIP;
CachedSettingValue<int> m_announcePort;
CachedSettingValue<int> m_maxConcurrentHTTPAnnounces;
CachedSettingValue<bool> m_isReannounceWhenAddressChangedEnabled;
CachedSettingValue<int> m_stopTrackerTimeout;
Expand Down
10 changes: 10 additions & 0 deletions src/gui/advancedsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ namespace
ANNOUNCE_ALL_TRACKERS,
ANNOUNCE_ALL_TIERS,
ANNOUNCE_IP,
ANNOUNCE_PORT,
MAX_CONCURRENT_HTTP_ANNOUNCES,
STOP_TRACKER_TIMEOUT,
PEER_TURNOVER,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/gui/advancedsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private slots:
m_spinBoxOutgoingPortsMin, m_spinBoxOutgoingPortsMax, m_spinBoxUPnPLeaseDuration, m_spinBoxPeerToS,
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_spinBoxAnnouncePort, m_spinBoxMaxConcurrentHTTPAnnounces, m_spinBoxStopTrackerTimeout, m_spinBoxSessionShutdownTimeout,
m_spinBoxSavePathHistoryLength, m_spinBoxPeerTurnover, m_spinBoxPeerTurnoverCutoff, m_spinBoxPeerTurnoverInterval, m_spinBoxRequestQueueSize;
QCheckBox m_checkBoxOsCache, m_checkBoxRecheckCompleted, m_checkBoxResolveCountries, m_checkBoxResolveHosts,
m_checkBoxProgramNotifications, m_checkBoxTorrentAddedNotifications, m_checkBoxReannounceWhenAddressChanged, m_checkBoxTrackerFavicon, m_checkBoxTrackerStatus,
Expand Down
3 changes: 3 additions & 0 deletions src/webui/api/appcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,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
Expand Down Expand Up @@ -1144,6 +1145,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))
Expand Down
15 changes: 15 additions & 0 deletions src/webui/www/private/views/preferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,14 @@
<input type="text" id="announceIP" style="width: 15em;">
</td>
</tr>
<tr>
<td>
<label for="announcePort">QBT_TR(Port reported to trackers (requires restart) [0: listening port]:)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://www.libtorrent.org/reference-Settings.html#announce_port" target="_blank">(?)</a></label>
</td>
<td>
<input type="text" id="announcePort" style="width: 15em;">
</td>
</tr>
<tr>
<td>
<label for="maxConcurrentHTTPAnnounces">QBT_TR(Max concurrent HTTP announces:)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://www.libtorrent.org/reference-Settings.html#max_concurrent_http_announces" target="_blank">(?)</a></label>
Expand Down Expand Up @@ -2593,6 +2601,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;
Expand Down Expand Up @@ -3061,6 +3070,12 @@
settings["announce_to_all_trackers"] = $("announceAllTrackers").checked;
settings["announce_to_all_tiers"] = $("announceAllTiers").checked;
settings["announce_ip"] = $("announceIP").value;
const announcePort = Number($("announcePort").value);
if (Number.isNaN(announcePort) || (announcePort < 0) || (announcePort > 65535)) {
alert("QBT_TR(The announce port must be between 0 and 65535.)QBT_TR[CONTEXT=OptionsDialog]");
return;
}
settings["announce_port"] = announcePort;
settings["max_concurrent_http_announces"] = Number($("maxConcurrentHTTPAnnounces").value);
settings["stop_tracker_timeout"] = Number($("stopTrackerTimeout").value);
settings["peer_turnover"] = Number($("peerTurnover").value);
Expand Down
Loading