Skip to content

Commit

Permalink
Add announce_port support
Browse files Browse the repository at this point in the history
  • Loading branch information
0xThiebaut committed Oct 27, 2024
1 parent e8dc6b3 commit 5ae627b
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/base/bittorrent/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions src/base/bittorrent/sessionimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
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 @@ -657,6 +659,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
11 changes: 10 additions & 1 deletion 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 @@ -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<int>::max());
m_spinBoxMaxConcurrentHTTPAnnounces.setValue(session->maxConcurrentHTTPAnnounces());
Expand Down
3 changes: 2 additions & 1 deletion src/gui/advancedsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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 @@ -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
Expand Down Expand Up @@ -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))
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 @@ -1589,6 +1589,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_ip" 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 @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5ae627b

Please sign in to comment.