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

Announce to all trackers if IP changed #15001

Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
16931c3
Update to the latest dydns register url.
zhuangzi926 Mar 28, 2021
8d34f5b
Beautify coding style.
zhuangzi926 Mar 28, 2021
724a385
- Related to [issue #14545](https://github.com/qbittorrent/qBittorren…
zhuangzi926 Mar 28, 2021
276179a
Use explicit include file.
zhuangzi926 Mar 29, 2021
d892f0c
Rename force reannounce function to be explicit.
zhuangzi926 Mar 29, 2021
d8c9972
Reimplement logic of force-reannounce by using TorrentImpl::forceRean…
zhuangzi926 Mar 29, 2021
62ca0be
Revert "Reimplement logic of force-reannounce by using TorrentImpl::f…
zhuangzi926 Apr 3, 2021
9a48770
Revert "Rename force reannounce function to be explicit."
zhuangzi926 Apr 3, 2021
f024777
Revert "Use explicit include file."
zhuangzi926 Apr 3, 2021
a098651
Revert "- Related to [issue #14545](https://github.com/qbittorrent/qB…
zhuangzi926 Apr 3, 2021
0646230
Use force_reannounce with ignore_min_interval flag when external ip/p…
zhuangzi926 Apr 3, 2021
e1f96c6
Merge branch 'master' into pr-announce-to-all-trackers-if-public-ip-c…
zhuangzi926 Apr 3, 2021
e543a5c
Complete force_reannounce argument list
zhuangzi926 Apr 3, 2021
8fda6e1
Enable toggling this feature
zhuangzi926 Apr 15, 2021
bc50768
Revert dyndns register url change
zhuangzi926 Apr 15, 2021
a9242ed
Rename vars to *ReannounceWhenAddressChanged*
zhuangzi926 Apr 25, 2021
4ff5c6e
Use cached setting value
zhuangzi926 Apr 25, 2021
048c051
Add desktop and web gui control checkbox
zhuangzi926 Apr 25, 2021
c1dc44a
Fix variable name in session.h
zhuangzi926 Apr 25, 2021
9d5d19a
Fix variable name in session.cpp
zhuangzi926 Apr 25, 2021
9d52f5a
Fix variable name in session constructior
zhuangzi926 Apr 25, 2021
897372a
Merge branch 'master' into pr-announce-to-all-trackers-if-public-ip-c…
zhuangzi926 May 4, 2021
e911a52
Remove url from libtorrent
zhuangzi926 May 18, 2021
08682ea
Relocate option from libtorrent section to qbt section
zhuangzi926 May 18, 2021
473425c
Change BITTORRENT_SESSION_KEY into ReannounceWhenAddressChanged
zhuangzi926 May 18, 2021
2c29dc7
Extract duplicated loops into a single class method reannounceToAllTr…
zhuangzi926 May 18, 2021
2a30ed6
Formalize setReannounceWhenAddressChanged method
zhuangzi926 May 18, 2021
1fafef5
Relocate *reannounce* methods in session.h and session.cpp
zhuangzi926 May 18, 2021
9601129
Relocate m_isReannounceWhenAddressChanged in session.h
zhuangzi926 May 18, 2021
7fe472d
Change m_lastExternalIP from QHostname to QString
zhuangzi926 May 18, 2021
1164b6b
Merge remote-tracking branch 'origin/pr-announce-to-all-trackers-if-p…
zhuangzi926 May 18, 2021
25779a3
Relocate reannounce-related statements
zhuangzi926 May 18, 2021
2deab39
Remove redundant codes, fix coding style and rename vars to is*Enable…
zhuangzi926 May 22, 2021
23b8e2f
Fix coding style
zhuangzi926 May 22, 2021
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
41 changes: 33 additions & 8 deletions src/base/bittorrent/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ Session::Session(QObject *parent)
, m_includeOverheadInLimits(BITTORRENT_SESSION_KEY("IncludeOverheadInLimits"), false)
, m_announceIP(BITTORRENT_SESSION_KEY("AnnounceIP"))
, m_maxConcurrentHTTPAnnounces(BITTORRENT_SESSION_KEY("MaxConcurrentHTTPAnnounces"), 50)
, m_isReannounceWhenAddressChangedEnabled(BITTORRENT_SESSION_KEY("ReannounceWhenAddressChanged"), false)
, m_stopTrackerTimeout(BITTORRENT_SESSION_KEY("StopTrackerTimeout"), 5)
, m_maxConnections(BITTORRENT_SESSION_KEY("MaxConnections"), 500, lowerLimited(0, -1))
, m_maxUploads(BITTORRENT_SESSION_KEY("MaxUploads"), 20, lowerLimited(0, -1))
Expand Down Expand Up @@ -1010,9 +1011,9 @@ void Session::adjustLimits()

void Session::applyBandwidthLimits()
{
lt::settings_pack settingsPack = m_nativeSession->get_settings();
applyBandwidthLimits(settingsPack);
m_nativeSession->apply_settings(settingsPack);
lt::settings_pack settingsPack = m_nativeSession->get_settings();
applyBandwidthLimits(settingsPack);
m_nativeSession->apply_settings(settingsPack);
}

void Session::configure()
Expand Down Expand Up @@ -2739,6 +2740,9 @@ void Session::setPort(const int port)
{
m_port = port;
configureListeningInterface();

if (isReannounceWhenAddressChangedEnabled())
reannounceToAllTrackers();
}
}

Expand Down Expand Up @@ -3029,7 +3033,6 @@ void Session::setMaxConnectionsPerTorrent(int max)
// Apply this to all session torrents
for (const lt::torrent_handle &handle : m_nativeSession->get_torrents())
{
if (!handle.is_valid()) continue;
try
{
handle.set_max_connections(max);
Expand All @@ -3054,7 +3057,6 @@ void Session::setMaxUploadsPerTorrent(int max)
// Apply this to all session torrents
for (const lt::torrent_handle &handle : m_nativeSession->get_torrents())
{
if (!handle.is_valid()) continue;
try
{
handle.set_max_uploads(max);
Expand Down Expand Up @@ -3585,6 +3587,25 @@ void Session::setMaxConcurrentHTTPAnnounces(const int value)
configureDeferred();
}

bool Session::isReannounceWhenAddressChangedEnabled() const
{
return m_isReannounceWhenAddressChangedEnabled;
}

void Session::setReannounceWhenAddressChangedEnabled(const bool enabled)
{
if (enabled == m_isReannounceWhenAddressChangedEnabled)
return;

m_isReannounceWhenAddressChangedEnabled = enabled;
}

void Session::reannounceToAllTrackers() const
{
for (const lt::torrent_handle &torrent : m_nativeSession->get_torrents())
torrent.force_reannounce(0, -1, lt::torrent_handle::ignore_min_interval);
}

int Session::stopTrackerTimeout() const
{
return m_stopTrackerTimeout;
Expand Down Expand Up @@ -4632,8 +4653,7 @@ void Session::handleListenSucceededAlert(const lt::listen_succeeded_alert *p)
.arg(toString(p->address), proto, QString::number(p->port)), Log::INFO);

// Force reannounce on all torrents because some trackers blacklist some ports
for (const lt::torrent_handle &torrent : m_nativeSession->get_torrents())
torrent.force_reannounce();
reannounceToAllTrackers();
}

void Session::handleListenFailedAlert(const lt::listen_failed_alert *p)
Expand All @@ -4647,8 +4667,13 @@ void Session::handleListenFailedAlert(const lt::listen_failed_alert *p)

void Session::handleExternalIPAlert(const lt::external_ip_alert *p)
{
const QString externalIP {toString(p->external_address)};
LogMsg(tr("Detected external IP: %1", "e.g. Detected external IP: 1.1.1.1")
.arg(toString(p->external_address)), Log::INFO);
.arg(externalIP), Log::INFO);

if (isReannounceWhenAddressChangedEnabled() && !m_lastExternalIP.isEmpty() && m_lastExternalIP != externalIP)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rewrite it as the following :

if (m_lastExternalIP != externalIP)
{
    if (!m_lastExternalIP.isEmpty() && isReannounceWhenAddressChangedEnabled())
        reannounceToAllTrackers();
    m_lastExternalIP = externalIP;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

reannounceToAllTrackers();
m_lastExternalIP = externalIP;
}

void Session::handleSessionStatsAlert(const lt::session_stats_alert *p)
Expand Down
6 changes: 6 additions & 0 deletions src/base/bittorrent/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ namespace BitTorrent
void setAnnounceIP(const QString &ip);
int maxConcurrentHTTPAnnounces() const;
void setMaxConcurrentHTTPAnnounces(int value);
bool isReannounceWhenAddressChangedEnabled() const;
void setReannounceWhenAddressChangedEnabled(bool enabled);
void reannounceToAllTrackers() const;
int stopTrackerTimeout() const;
void setStopTrackerTimeout(int value);
int maxConnections() const;
Expand Down Expand Up @@ -690,6 +693,7 @@ namespace BitTorrent
CachedSettingValue<bool> m_includeOverheadInLimits;
CachedSettingValue<QString> m_announceIP;
CachedSettingValue<int> m_maxConcurrentHTTPAnnounces;
CachedSettingValue<bool> m_isReannounceWhenAddressChangedEnabled;
CachedSettingValue<int> m_stopTrackerTimeout;
CachedSettingValue<int> m_maxConnections;
CachedSettingValue<int> m_maxUploads;
Expand Down Expand Up @@ -798,6 +802,8 @@ namespace BitTorrent

QList<MoveStorageJob> m_moveStorageQueue;

QString m_lastExternalIP;

static Session *m_instance;
};
}
6 changes: 6 additions & 0 deletions src/gui/advancedsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ namespace
NOTIFICATION_TIMEOUT,
#endif
CONFIRM_REMOVE_ALL_TAGS,
REANNOUNCE_WHEN_ADDRESS_CHANGED,
DOWNLOAD_TRACKER_FAVICON,
SAVE_PATH_HISTORY_LENGTH,
ENABLE_SPEED_WIDGET,
Expand Down Expand Up @@ -284,6 +285,8 @@ void AdvancedSettings::saveAdvancedSettings()
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB)
mainWindow->setNotificationTimeout(m_spinBoxNotificationTimeout.value());
#endif
// Reannounce to all trackers when ip/port changed
session->setReannounceWhenAddressChangedEnabled(m_checkBoxReannounceWhenAddressChanged.isChecked());
// Misc GUI properties
mainWindow->setDownloadTrackerFavicon(m_checkBoxTrackerFavicon.isChecked());
AddNewTorrentDialog::setSavePathHistoryLength(m_spinBoxSavePathHistoryLength.value());
Expand Down Expand Up @@ -664,6 +667,9 @@ void AdvancedSettings::loadAdvancedSettings()
m_spinBoxNotificationTimeout.setSuffix(tr(" ms", " milliseconds"));
addRow(NOTIFICATION_TIMEOUT, tr("Notification timeout [0: infinite]"), &m_spinBoxNotificationTimeout);
#endif
// Reannounce to all trackers when ip/port changed
m_checkBoxReannounceWhenAddressChanged.setChecked(session->isReannounceWhenAddressChangedEnabled());
addRow(REANNOUNCE_WHEN_ADDRESS_CHANGED, tr("Reannounce to all trackers when IP or port changed"), &m_checkBoxReannounceWhenAddressChanged);
// Download tracker's favicon
m_checkBoxTrackerFavicon.setChecked(mainWindow->isDownloadTrackerFavicon());
addRow(DOWNLOAD_TRACKER_FAVICON, tr("Download tracker's favicon"), &m_checkBoxTrackerFavicon);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/advancedsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private slots:
m_spinBoxSendBufferWatermarkFactor, m_spinBoxSocketBacklogSize, m_spinBoxMaxConcurrentHTTPAnnounces, m_spinBoxStopTrackerTimeout,
m_spinBoxSavePathHistoryLength, m_spinBoxPeerTurnover, m_spinBoxPeerTurnoverCutoff, m_spinBoxPeerTurnoverInterval;
QCheckBox m_checkBoxOsCache, m_checkBoxRecheckCompleted, m_checkBoxResolveCountries, m_checkBoxResolveHosts,
m_checkBoxProgramNotifications, m_checkBoxTorrentAddedNotifications, m_checkBoxTrackerFavicon, m_checkBoxTrackerStatus,
m_checkBoxProgramNotifications, m_checkBoxTorrentAddedNotifications, m_checkBoxReannounceWhenAddressChanged, m_checkBoxTrackerFavicon, m_checkBoxTrackerStatus,
m_checkBoxConfirmTorrentRecheck, m_checkBoxConfirmRemoveAllTags, m_checkBoxAnnounceAllTrackers, m_checkBoxAnnounceAllTiers,
m_checkBoxMultiConnectionsPerIp, m_checkBoxValidateHTTPSTrackerCertificate, m_checkBoxBlockPeersOnPrivilegedPorts, m_checkBoxPieceExtentAffinity,
m_checkBoxSuggestMode, m_checkBoxSpeedWidgetEnabled, m_checkBoxIDNSupport;
Expand Down
5 changes: 5 additions & 0 deletions src/webui/api/appcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ void AppController::preferencesAction()
data["recheck_completed_torrents"] = pref->recheckTorrentsOnCompletion();
// Resolve peer countries
data["resolve_peer_countries"] = pref->resolvePeerCountries();
// Reannounce to all trackers when ip/port changed
data["reannounce_when_address_changed"] = session->isReannounceWhenAddressChangedEnabled();

// libtorrent preferences
// Async IO threads
Expand Down Expand Up @@ -716,6 +718,9 @@ void AppController::setPreferencesAction()
// Resolve peer countries
if (hasKey("resolve_peer_countries"))
pref->resolvePeerCountries(it.value().toBool());
// Reannounce to all trackers when ip/port changed
if (hasKey("reannounce_when_address_changed"))
session->setReannounceWhenAddressChangedEnabled(it.value().toBool());

// libtorrent preferences
// Async IO threads
Expand Down
10 changes: 10 additions & 0 deletions src/webui/www/private/views/preferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,14 @@
<input type="checkbox" id="resolvePeerCountries">
</td>
</tr>
<tr>
<td>
<label for="reannounceWhenAddressChanged">QBT_TR(Reannounce to all trackers when IP or port changed:)QBT_TR[CONTEXT=OptionsDialog]</label>
</td>
<td>
<input type="checkbox" id="reannounceWhenAddressChanged" />
</td>
</tr>
<tr>
<td>
<label for="enableEmbeddedTracker">QBT_TR(Enable embedded tracker:)QBT_TR[CONTEXT=OptionsDialog]</label>
Expand Down Expand Up @@ -1882,6 +1890,7 @@
$('saveResumeDataInterval').setProperty('value', pref.save_resume_data_interval);
$('recheckTorrentsOnCompletion').setProperty('checked', pref.recheck_completed_torrents);
$('resolvePeerCountries').setProperty('checked', pref.resolve_peer_countries);
$('reannounceWhenAddressChanged').setProperty('checked', pref.reannounce_when_address_changed);
// libtorrent section
$('asyncIOThreads').setProperty('value', pref.async_io_threads);
$('hashingThreads').setProperty('value', pref.hashing_threads);
Expand Down Expand Up @@ -2270,6 +2279,7 @@
settings.set('save_resume_data_interval', $('saveResumeDataInterval').getProperty('value'));
settings.set('recheck_completed_torrents', $('recheckTorrentsOnCompletion').getProperty('checked'));
settings.set('resolve_peer_countries', $('resolvePeerCountries').getProperty('checked'));
settings.set('reannounce_when_address_changed', $('reannounceWhenAddressChanged').getProperty('checked'));

// libtorrent section
settings.set('async_io_threads', $('asyncIOThreads').getProperty('value'));
Expand Down