From 16931c3d0c336b1c08f49b6edd554c601112d1ec Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Sun, 28 Mar 2021 18:19:53 +0800 Subject: [PATCH 01/31] Update to the latest dydns register url. --- src/base/net/dnsupdater.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base/net/dnsupdater.cpp b/src/base/net/dnsupdater.cpp index 00737c8bcc4..e7dfb44958b 100644 --- a/src/base/net/dnsupdater.cpp +++ b/src/base/net/dnsupdater.cpp @@ -300,7 +300,7 @@ QUrl DNSUpdater::getRegistrationUrl(const int service) switch (service) { case DNS::DYNDNS: - return {"https://www.dyndns.com/account/services/hosts/add.html"}; + return {"https://account.dyn.com/entrance/"}; case DNS::NOIP: return {"https://www.noip.com/remote-access"}; default: From 8d34f5b119c493ef79be2f7af120c892209ff335 Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Sun, 28 Mar 2021 18:24:02 +0800 Subject: [PATCH 02/31] Beautify coding style. --- src/base/bittorrent/session.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 77b76dd9fbd..17bb9d8a8d6 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -1009,9 +1009,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() From 724a385b90458a6f658f3e131073f6e11a82e7da Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Sun, 28 Mar 2021 18:57:01 +0800 Subject: [PATCH 03/31] - Related to [issue #14545](https://github.com/qbittorrent/qBittorrent/issues/14545) - Add a timer in BitTorrent::Session to send a public ip address request to http://api64.ipify.org every 30 mins. - Once public ip address change is detected, force announce to all trackers. - This new feature is optional, can be toggled during running time, default is false. --- src/base/bittorrent/session.cpp | 88 +++++++++++++++++++++++++++++++++ src/base/bittorrent/session.h | 15 ++++++ 2 files changed, 103 insertions(+) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 17bb9d8a8d6..16f383166bc 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -426,6 +426,7 @@ Session::Session(QObject *parent) , m_peerTurnover(BITTORRENT_SESSION_KEY("PeerTurnover"), 4) , m_peerTurnoverCutoff(BITTORRENT_SESSION_KEY("PeerTurnoverCutOff"), 90) , m_peerTurnoverInterval(BITTORRENT_SESSION_KEY("PeerTurnoverInterval"), 300) + , m_isCheckPublicIPEnabled(false) , m_bannedIPs("State/BannedIPs" , QStringList() , [](const QStringList &value) @@ -441,6 +442,7 @@ Session::Session(QObject *parent) , m_resumeFolderLock {new QFile {this}} , m_seedingLimitTimer {new QTimer {this}} , m_resumeDataTimer {new QTimer {this}} + , m_publicIPCheckTimer {new QTimer {this}} , m_statistics {new Statistics {this}} , m_ioThread {new QThread {this}} , m_recentErroredTorrentsTimer {new QTimer {this}} @@ -511,6 +513,15 @@ Session::Session(QObject *parent) new PortForwarderImpl {m_nativeSession}; initMetrics(); + + m_publicIPCheckTimer->setInterval(PUBLIC_IP_CHECK_INTERVAL); + connect(m_publicIPCheckTimer, &QTimer::timeout, this, &Session::checkPublicIP); + if (isCheckPublicIPEnabled()) + { + m_lastPublicIP = QHostAddress(); + m_lastPublicIPCheckTime = QDateTime::currentDateTime(); + m_publicIPCheckTimer->start(); + } } bool Session::isDHTEnabled() const @@ -4804,3 +4815,80 @@ void Session::handleSocks5Alert(const lt::socks5_alert *p) const , Log::WARNING); } } + +bool Session::isCheckPublicIPEnabled() const +{ + return m_isCheckPublicIPEnabled; +} + +void Session::setCheckPublicIPEnabled(bool enabled) +{ + if (enabled == m_isCheckPublicIPEnabled) + { + return; + } + + m_isCheckPublicIPEnabled = enabled; + + if (m_isCheckPublicIPEnabled == true) + { + m_lastPublicIP = QHostAddress(); + m_lastPublicIPCheckTime = QDateTime::currentDateTime(); + m_publicIPCheckTimer->start(); + } + else + { + m_publicIPCheckTimer->stop(); + } + + configureDeferred(); +} + +void Session::checkPublicIP() +{ + Net::DownloadManager::instance()->download( + Net::DownloadRequest("http://api64.ipify.org").userAgent("qBittorrent/" QBT_VERSION_2) + , this, &Session::publicIPRequestFinished); + + m_lastPublicIPCheckTime = QDateTime::currentDateTime(); +} + +void Session::publicIPRequestFinished(const Net::DownloadResult& result) +{ + if (result.status != Net::DownloadStatus::Success) + { + qWarning() << "Public IP request failed:" << result.errorString; + return; + } + + // Parse response + QString ipStr = QString::fromUtf8(result.data); + qDebug() << Q_FUNC_INFO << "The following public IP was captured:" << ipStr; + QHostAddress newIP(ipStr); + if (!newIP.isNull()) + { + if (m_lastPublicIP != newIP) + { + qDebug() << Q_FUNC_INFO << "The public IP address changed, announce to all trackers..."; + qDebug() << m_lastPublicIP.toString() << "->" << newIP.toString(); + m_lastPublicIP = newIP; + forceAnnounceToAllTrackers(); + } + } + else + { + qWarning() << Q_FUNC_INFO << "Failed to construct a QHostAddress from the IP string"; + } +} + +void Session::forceAnnounceToAllTrackers() +{ + lt::settings_pack settingsPack = m_nativeSession->get_settings(); + forceAnnounceToAllTrackers(settingsPack); + m_nativeSession->apply_settings(settingsPack); +} + +void Session::forceAnnounceToAllTrackers(lt::settings_pack& settingsPack) const +{ + settingsPack.set_int(lt::settings_pack::announce_to_all_trackers, true); +} diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index e6a2bb0b2cc..d5b111c1a52 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -46,6 +46,7 @@ #include "base/settingvalue.h" #include "base/types.h" +#include "base/net/dnsupdater.h" #include "addtorrentparams.h" #include "cachestatus.h" #include "sessionstatus.h" @@ -493,6 +494,9 @@ namespace BitTorrent void findIncompleteFiles(const TorrentInfo &torrentInfo, const QString &savePath) const; + bool isCheckPublicIPEnabled() const; + void setCheckPublicIPEnabled(bool enabled); + signals: void allTorrentsFinished(); void categoryAdded(const QString &categoryName); @@ -546,6 +550,9 @@ namespace BitTorrent void networkOnlineStateChanged(bool online); void networkConfigurationChange(const QNetworkConfiguration &); + void checkPublicIP(); + void publicIPRequestFinished(const Net::DownloadResult& result); + private: struct MoveStorageJob { @@ -788,6 +795,14 @@ namespace BitTorrent QList m_moveStorageQueue; + bool m_isCheckPublicIPEnabled = false; + QTimer *m_publicIPCheckTimer = nullptr; + static const int PUBLIC_IP_CHECK_INTERVAL = 1800000; // 30 min + QHostAddress m_lastPublicIP; + QDateTime m_lastPublicIPCheckTime; + void forceAnnounceToAllTrackers(); + void forceAnnounceToAllTrackers(lt::settings_pack& settingsPack) const; + static Session *m_instance; }; } From 276179ae04576227795fb5b9f06fd2604e424cfd Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Mon, 29 Mar 2021 09:38:11 +0800 Subject: [PATCH 04/31] Use explicit include file. --- src/base/bittorrent/session.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index d5b111c1a52..bf95da60f00 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -43,10 +43,11 @@ #include #include #include +#include +#include #include "base/settingvalue.h" #include "base/types.h" -#include "base/net/dnsupdater.h" #include "addtorrentparams.h" #include "cachestatus.h" #include "sessionstatus.h" From d892f0c61e96f2679df9e41ebe7455919bb7f43d Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Mon, 29 Mar 2021 10:08:10 +0800 Subject: [PATCH 05/31] Rename force reannounce function to be explicit. --- src/base/bittorrent/session.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index bf95da60f00..3af9bf0df41 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -801,8 +801,7 @@ namespace BitTorrent static const int PUBLIC_IP_CHECK_INTERVAL = 1800000; // 30 min QHostAddress m_lastPublicIP; QDateTime m_lastPublicIPCheckTime; - void forceAnnounceToAllTrackers(); - void forceAnnounceToAllTrackers(lt::settings_pack& settingsPack) const; + void forceReannounceToAllTrackers(); static Session *m_instance; }; From d8c9972f5968fffad2e5e4599ef14018efb76b1b Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Mon, 29 Mar 2021 10:10:37 +0800 Subject: [PATCH 06/31] Reimplement logic of force-reannounce by using TorrentImpl::forceReannounce. --- src/base/bittorrent/session.cpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 16f383166bc..e3b3683caa0 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -4857,38 +4857,37 @@ void Session::publicIPRequestFinished(const Net::DownloadResult& result) { if (result.status != Net::DownloadStatus::Success) { - qWarning() << "Public IP request failed:" << result.errorString; + LogMsg(tr("Public IP request failed: %1").arg(result.errorString), Log::WARNING); return; } // Parse response QString ipStr = QString::fromUtf8(result.data); - qDebug() << Q_FUNC_INFO << "The following public IP was captured:" << ipStr; + LogMsg(tr("The following public IP was captured: %1").arg(ipStr)); QHostAddress newIP(ipStr); if (!newIP.isNull()) { if (m_lastPublicIP != newIP) { - qDebug() << Q_FUNC_INFO << "The public IP address changed, announce to all trackers..."; - qDebug() << m_lastPublicIP.toString() << "->" << newIP.toString(); + LogMsg("The public IP address changed, force reannounce to all trackers..."); + LogMsg(tr("%1 -> %2").arg(m_lastPublicIP.toString(), newIP.toString())); m_lastPublicIP = newIP; - forceAnnounceToAllTrackers(); + forceReannounceToAllTrackers(); } } else { - qWarning() << Q_FUNC_INFO << "Failed to construct a QHostAddress from the IP string"; + LogMsg("Failed to construct a QHostAddress from the IP string", Log::WARNING); } } -void Session::forceAnnounceToAllTrackers() +void Session::forceReannounceToAllTrackers() { - lt::settings_pack settingsPack = m_nativeSession->get_settings(); - forceAnnounceToAllTrackers(settingsPack); - m_nativeSession->apply_settings(settingsPack); -} - -void Session::forceAnnounceToAllTrackers(lt::settings_pack& settingsPack) const -{ - settingsPack.set_int(lt::settings_pack::announce_to_all_trackers, true); + for (TorrentImpl* const torrent : asConst(m_torrents)) + { + if (!torrent->isPrivate() && torrent->isActive()) + { + torrent->forceReannounce(); + } + } } From 62ca0beaa5b957bb9aef23cbfccc72e80050780c Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Sat, 3 Apr 2021 20:10:46 +0800 Subject: [PATCH 07/31] Revert "Reimplement logic of force-reannounce by using TorrentImpl::forceReannounce." This reverts commit d8c9972f5968fffad2e5e4599ef14018efb76b1b. --- src/base/bittorrent/session.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index e3b3683caa0..16f383166bc 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -4857,37 +4857,38 @@ void Session::publicIPRequestFinished(const Net::DownloadResult& result) { if (result.status != Net::DownloadStatus::Success) { - LogMsg(tr("Public IP request failed: %1").arg(result.errorString), Log::WARNING); + qWarning() << "Public IP request failed:" << result.errorString; return; } // Parse response QString ipStr = QString::fromUtf8(result.data); - LogMsg(tr("The following public IP was captured: %1").arg(ipStr)); + qDebug() << Q_FUNC_INFO << "The following public IP was captured:" << ipStr; QHostAddress newIP(ipStr); if (!newIP.isNull()) { if (m_lastPublicIP != newIP) { - LogMsg("The public IP address changed, force reannounce to all trackers..."); - LogMsg(tr("%1 -> %2").arg(m_lastPublicIP.toString(), newIP.toString())); + qDebug() << Q_FUNC_INFO << "The public IP address changed, announce to all trackers..."; + qDebug() << m_lastPublicIP.toString() << "->" << newIP.toString(); m_lastPublicIP = newIP; - forceReannounceToAllTrackers(); + forceAnnounceToAllTrackers(); } } else { - LogMsg("Failed to construct a QHostAddress from the IP string", Log::WARNING); + qWarning() << Q_FUNC_INFO << "Failed to construct a QHostAddress from the IP string"; } } -void Session::forceReannounceToAllTrackers() +void Session::forceAnnounceToAllTrackers() { - for (TorrentImpl* const torrent : asConst(m_torrents)) - { - if (!torrent->isPrivate() && torrent->isActive()) - { - torrent->forceReannounce(); - } - } + lt::settings_pack settingsPack = m_nativeSession->get_settings(); + forceAnnounceToAllTrackers(settingsPack); + m_nativeSession->apply_settings(settingsPack); +} + +void Session::forceAnnounceToAllTrackers(lt::settings_pack& settingsPack) const +{ + settingsPack.set_int(lt::settings_pack::announce_to_all_trackers, true); } From 9a487702a9997102dfde3a18ce305dca8fdd484c Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Sat, 3 Apr 2021 20:11:05 +0800 Subject: [PATCH 08/31] Revert "Rename force reannounce function to be explicit." This reverts commit d892f0c61e96f2679df9e41ebe7455919bb7f43d. --- src/base/bittorrent/session.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 3af9bf0df41..bf95da60f00 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -801,7 +801,8 @@ namespace BitTorrent static const int PUBLIC_IP_CHECK_INTERVAL = 1800000; // 30 min QHostAddress m_lastPublicIP; QDateTime m_lastPublicIPCheckTime; - void forceReannounceToAllTrackers(); + void forceAnnounceToAllTrackers(); + void forceAnnounceToAllTrackers(lt::settings_pack& settingsPack) const; static Session *m_instance; }; From f024777f833c218b9371f4ca16b2efa3da0ba8b9 Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Sat, 3 Apr 2021 20:11:14 +0800 Subject: [PATCH 09/31] Revert "Use explicit include file." This reverts commit 276179ae04576227795fb5b9f06fd2604e424cfd. --- src/base/bittorrent/session.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index bf95da60f00..d5b111c1a52 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -43,11 +43,10 @@ #include #include #include -#include -#include #include "base/settingvalue.h" #include "base/types.h" +#include "base/net/dnsupdater.h" #include "addtorrentparams.h" #include "cachestatus.h" #include "sessionstatus.h" From a09865160daa610a42e52ea87380c8bdef8e18d8 Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Sat, 3 Apr 2021 20:11:36 +0800 Subject: [PATCH 10/31] Revert "- Related to [issue #14545](https://github.com/qbittorrent/qBittorrent/issues/14545)" This reverts commit 724a385b90458a6f658f3e131073f6e11a82e7da. --- src/base/bittorrent/session.cpp | 88 --------------------------------- src/base/bittorrent/session.h | 15 ------ 2 files changed, 103 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 16f383166bc..17bb9d8a8d6 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -426,7 +426,6 @@ Session::Session(QObject *parent) , m_peerTurnover(BITTORRENT_SESSION_KEY("PeerTurnover"), 4) , m_peerTurnoverCutoff(BITTORRENT_SESSION_KEY("PeerTurnoverCutOff"), 90) , m_peerTurnoverInterval(BITTORRENT_SESSION_KEY("PeerTurnoverInterval"), 300) - , m_isCheckPublicIPEnabled(false) , m_bannedIPs("State/BannedIPs" , QStringList() , [](const QStringList &value) @@ -442,7 +441,6 @@ Session::Session(QObject *parent) , m_resumeFolderLock {new QFile {this}} , m_seedingLimitTimer {new QTimer {this}} , m_resumeDataTimer {new QTimer {this}} - , m_publicIPCheckTimer {new QTimer {this}} , m_statistics {new Statistics {this}} , m_ioThread {new QThread {this}} , m_recentErroredTorrentsTimer {new QTimer {this}} @@ -513,15 +511,6 @@ Session::Session(QObject *parent) new PortForwarderImpl {m_nativeSession}; initMetrics(); - - m_publicIPCheckTimer->setInterval(PUBLIC_IP_CHECK_INTERVAL); - connect(m_publicIPCheckTimer, &QTimer::timeout, this, &Session::checkPublicIP); - if (isCheckPublicIPEnabled()) - { - m_lastPublicIP = QHostAddress(); - m_lastPublicIPCheckTime = QDateTime::currentDateTime(); - m_publicIPCheckTimer->start(); - } } bool Session::isDHTEnabled() const @@ -4815,80 +4804,3 @@ void Session::handleSocks5Alert(const lt::socks5_alert *p) const , Log::WARNING); } } - -bool Session::isCheckPublicIPEnabled() const -{ - return m_isCheckPublicIPEnabled; -} - -void Session::setCheckPublicIPEnabled(bool enabled) -{ - if (enabled == m_isCheckPublicIPEnabled) - { - return; - } - - m_isCheckPublicIPEnabled = enabled; - - if (m_isCheckPublicIPEnabled == true) - { - m_lastPublicIP = QHostAddress(); - m_lastPublicIPCheckTime = QDateTime::currentDateTime(); - m_publicIPCheckTimer->start(); - } - else - { - m_publicIPCheckTimer->stop(); - } - - configureDeferred(); -} - -void Session::checkPublicIP() -{ - Net::DownloadManager::instance()->download( - Net::DownloadRequest("http://api64.ipify.org").userAgent("qBittorrent/" QBT_VERSION_2) - , this, &Session::publicIPRequestFinished); - - m_lastPublicIPCheckTime = QDateTime::currentDateTime(); -} - -void Session::publicIPRequestFinished(const Net::DownloadResult& result) -{ - if (result.status != Net::DownloadStatus::Success) - { - qWarning() << "Public IP request failed:" << result.errorString; - return; - } - - // Parse response - QString ipStr = QString::fromUtf8(result.data); - qDebug() << Q_FUNC_INFO << "The following public IP was captured:" << ipStr; - QHostAddress newIP(ipStr); - if (!newIP.isNull()) - { - if (m_lastPublicIP != newIP) - { - qDebug() << Q_FUNC_INFO << "The public IP address changed, announce to all trackers..."; - qDebug() << m_lastPublicIP.toString() << "->" << newIP.toString(); - m_lastPublicIP = newIP; - forceAnnounceToAllTrackers(); - } - } - else - { - qWarning() << Q_FUNC_INFO << "Failed to construct a QHostAddress from the IP string"; - } -} - -void Session::forceAnnounceToAllTrackers() -{ - lt::settings_pack settingsPack = m_nativeSession->get_settings(); - forceAnnounceToAllTrackers(settingsPack); - m_nativeSession->apply_settings(settingsPack); -} - -void Session::forceAnnounceToAllTrackers(lt::settings_pack& settingsPack) const -{ - settingsPack.set_int(lt::settings_pack::announce_to_all_trackers, true); -} diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index d5b111c1a52..e6a2bb0b2cc 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -46,7 +46,6 @@ #include "base/settingvalue.h" #include "base/types.h" -#include "base/net/dnsupdater.h" #include "addtorrentparams.h" #include "cachestatus.h" #include "sessionstatus.h" @@ -494,9 +493,6 @@ namespace BitTorrent void findIncompleteFiles(const TorrentInfo &torrentInfo, const QString &savePath) const; - bool isCheckPublicIPEnabled() const; - void setCheckPublicIPEnabled(bool enabled); - signals: void allTorrentsFinished(); void categoryAdded(const QString &categoryName); @@ -550,9 +546,6 @@ namespace BitTorrent void networkOnlineStateChanged(bool online); void networkConfigurationChange(const QNetworkConfiguration &); - void checkPublicIP(); - void publicIPRequestFinished(const Net::DownloadResult& result); - private: struct MoveStorageJob { @@ -795,14 +788,6 @@ namespace BitTorrent QList m_moveStorageQueue; - bool m_isCheckPublicIPEnabled = false; - QTimer *m_publicIPCheckTimer = nullptr; - static const int PUBLIC_IP_CHECK_INTERVAL = 1800000; // 30 min - QHostAddress m_lastPublicIP; - QDateTime m_lastPublicIPCheckTime; - void forceAnnounceToAllTrackers(); - void forceAnnounceToAllTrackers(lt::settings_pack& settingsPack) const; - static Session *m_instance; }; } From 06462306b5a7886bfa83dc18889a271c684b6558 Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Sat, 3 Apr 2021 20:18:41 +0800 Subject: [PATCH 11/31] Use force_reannounce with ignore_min_interval flag when external ip/port changed --- src/base/bittorrent/session.cpp | 12 +++++++++++- src/base/bittorrent/session.h | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 17bb9d8a8d6..f6857403b8f 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -438,6 +438,7 @@ Session::Session(QObject *parent) #if defined(Q_OS_WIN) , m_OSMemoryPriority(BITTORRENT_KEY("OSMemoryPriority"), OSMemoryPriority::BelowNormal) #endif + , m_lastExternalIP() , m_resumeFolderLock {new QFile {this}} , m_seedingLimitTimer {new QTimer {this}} , m_resumeDataTimer {new QTimer {this}} @@ -2736,6 +2737,8 @@ void Session::setPort(const int port) { m_port = port; configureListeningInterface(); + for (const lt::torrent_handle &torrent : m_nativeSession->get_torrents()) + torrent.force_reannounce(lt::torrent_handle::ignore_min_interval); } } @@ -4635,8 +4638,15 @@ void Session::handleListenFailedAlert(const lt::listen_failed_alert *p) void Session::handleExternalIPAlert(const lt::external_ip_alert *p) { + const QHostAddress 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.toString()), Log::INFO); + if (!m_lastExternalIP.isNull() && m_lastExternalIP != externalIP) + { + for (const lt::torrent_handle &torrent : m_nativeSession->get_torrents()) + torrent.force_reannounce(lt::torrent_handle::ignore_min_interval); + } + m_lastExternalIP = externalIP; } void Session::handleSessionStatsAlert(const lt::session_stats_alert *p) diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index e6a2bb0b2cc..50c1062c478 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -43,6 +43,7 @@ #include #include #include +#include #include "base/settingvalue.h" #include "base/types.h" @@ -788,6 +789,8 @@ namespace BitTorrent QList m_moveStorageQueue; + QHostAddress m_lastExternalIP; + static Session *m_instance; }; } From e543a5c464820c2797eb1c19c4c465496c777d3c Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Sat, 3 Apr 2021 21:11:38 +0800 Subject: [PATCH 12/31] Complete force_reannounce argument list --- src/base/bittorrent/session.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 3c0b7e8d80b..cc377117015 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -2741,7 +2741,7 @@ void Session::setPort(const int port) m_port = port; configureListeningInterface(); for (const lt::torrent_handle &torrent : m_nativeSession->get_torrents()) - torrent.force_reannounce(lt::torrent_handle::ignore_min_interval); + torrent.force_reannounce(0, -1, lt::torrent_handle::ignore_min_interval); } } @@ -4604,7 +4604,7 @@ void Session::handleExternalIPAlert(const lt::external_ip_alert *p) if (!m_lastExternalIP.isNull() && m_lastExternalIP != externalIP) { for (const lt::torrent_handle &torrent : m_nativeSession->get_torrents()) - torrent.force_reannounce(lt::torrent_handle::ignore_min_interval); + torrent.force_reannounce(0, -1, lt::torrent_handle::ignore_min_interval); } m_lastExternalIP = externalIP; } From 8fda6e10c23e99196d8432a70b0b591d15d52a94 Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Thu, 15 Apr 2021 21:31:08 +0800 Subject: [PATCH 13/31] Enable toggling this feature --- src/base/bittorrent/session.cpp | 26 +++++++++++++++++++++++--- src/base/bittorrent/session.h | 4 ++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index cc377117015..469e78f9621 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -439,6 +439,7 @@ Session::Session(QObject *parent) #if defined(Q_OS_WIN) , m_OSMemoryPriority(BITTORRENT_KEY("OSMemoryPriority"), OSMemoryPriority::BelowNormal) #endif + , m_isForceReannounceEnabled(false) , m_lastExternalIP() , m_seedingLimitTimer {new QTimer {this}} , m_resumeDataTimer {new QTimer {this}} @@ -2740,8 +2741,12 @@ void Session::setPort(const int port) { m_port = port; configureListeningInterface(); - for (const lt::torrent_handle &torrent : m_nativeSession->get_torrents()) - torrent.force_reannounce(0, -1, lt::torrent_handle::ignore_min_interval); + + if (isForceReannounceEnabled()) + { + for (const lt::torrent_handle& torrent : m_nativeSession->get_torrents()) + torrent.force_reannounce(0, -1, lt::torrent_handle::ignore_min_interval); + } } } @@ -4601,7 +4606,7 @@ void Session::handleExternalIPAlert(const lt::external_ip_alert *p) const QHostAddress externalIP {toString(p->external_address)}; LogMsg(tr("Detected external IP: %1", "e.g. Detected external IP: 1.1.1.1") .arg(externalIP.toString()), Log::INFO); - if (!m_lastExternalIP.isNull() && m_lastExternalIP != externalIP) + if (isForceReannounceEnabled() && !m_lastExternalIP.isNull() && m_lastExternalIP != externalIP) { for (const lt::torrent_handle &torrent : m_nativeSession->get_torrents()) torrent.force_reannounce(0, -1, lt::torrent_handle::ignore_min_interval); @@ -4774,3 +4779,18 @@ void Session::handleSocks5Alert(const lt::socks5_alert *p) const , Log::WARNING); } } + +bool Session::isForceReannounceEnabled() const +{ + return m_isForceReannounceEnabled; +} + +void Session::setForceReannounceEnabled(bool enabled) +{ + if (enabled == m_isForceReannounceEnabled) + { + return; + } + + m_isForceReannounceEnabled = enabled; +} diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index a08c5bf38e0..659dc123e24 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -495,6 +495,9 @@ namespace BitTorrent void findIncompleteFiles(const TorrentInfo &torrentInfo, const QString &savePath) const; + bool isForceReannounceEnabled() const; + void setForceReannounceEnabled(bool enabled); + signals: void allTorrentsFinished(); void categoryAdded(const QString &categoryName); @@ -792,6 +795,7 @@ namespace BitTorrent QList m_moveStorageQueue; QHostAddress m_lastExternalIP; + bool m_isForceReannounceEnabled = false; static Session *m_instance; }; From bc507686b806db682d02297b8354ee8315700525 Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Thu, 15 Apr 2021 21:32:00 +0800 Subject: [PATCH 14/31] Revert dyndns register url change --- src/base/net/dnsupdater.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base/net/dnsupdater.cpp b/src/base/net/dnsupdater.cpp index e7dfb44958b..00737c8bcc4 100644 --- a/src/base/net/dnsupdater.cpp +++ b/src/base/net/dnsupdater.cpp @@ -300,7 +300,7 @@ QUrl DNSUpdater::getRegistrationUrl(const int service) switch (service) { case DNS::DYNDNS: - return {"https://account.dyn.com/entrance/"}; + return {"https://www.dyndns.com/account/services/hosts/add.html"}; case DNS::NOIP: return {"https://www.noip.com/remote-access"}; default: From a9242ed9985f73f5efbf5c42c2cd08b6311f25b2 Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Sun, 25 Apr 2021 20:15:33 +0800 Subject: [PATCH 15/31] Rename vars to *ReannounceWhenAddressChanged* --- src/base/bittorrent/session.cpp | 16 ++++++++-------- src/base/bittorrent/session.h | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 469e78f9621..131e7ca32d9 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -439,7 +439,7 @@ Session::Session(QObject *parent) #if defined(Q_OS_WIN) , m_OSMemoryPriority(BITTORRENT_KEY("OSMemoryPriority"), OSMemoryPriority::BelowNormal) #endif - , m_isForceReannounceEnabled(false) + , m_isReannounceWhenAddressChanged(false) , m_lastExternalIP() , m_seedingLimitTimer {new QTimer {this}} , m_resumeDataTimer {new QTimer {this}} @@ -2742,7 +2742,7 @@ void Session::setPort(const int port) m_port = port; configureListeningInterface(); - if (isForceReannounceEnabled()) + if (isReannounceWhenAddressChanged()) { for (const lt::torrent_handle& torrent : m_nativeSession->get_torrents()) torrent.force_reannounce(0, -1, lt::torrent_handle::ignore_min_interval); @@ -4606,7 +4606,7 @@ void Session::handleExternalIPAlert(const lt::external_ip_alert *p) const QHostAddress externalIP {toString(p->external_address)}; LogMsg(tr("Detected external IP: %1", "e.g. Detected external IP: 1.1.1.1") .arg(externalIP.toString()), Log::INFO); - if (isForceReannounceEnabled() && !m_lastExternalIP.isNull() && m_lastExternalIP != externalIP) + if (isReannounceWhenAddressChanged() && !m_lastExternalIP.isNull() && m_lastExternalIP != externalIP) { for (const lt::torrent_handle &torrent : m_nativeSession->get_torrents()) torrent.force_reannounce(0, -1, lt::torrent_handle::ignore_min_interval); @@ -4780,17 +4780,17 @@ void Session::handleSocks5Alert(const lt::socks5_alert *p) const } } -bool Session::isForceReannounceEnabled() const +bool Session::isReannounceWhenAddressChanged() const { - return m_isForceReannounceEnabled; + return m_isReannounceWhenAddressChanged; } -void Session::setForceReannounceEnabled(bool enabled) +void Session::setReannounceWhenAddressChanged(bool enabled) { - if (enabled == m_isForceReannounceEnabled) + if (enabled == m_isReannounceWhenAddressChanged) { return; } - m_isForceReannounceEnabled = enabled; + m_isReannounceWhenAddressChanged = enabled; } diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 659dc123e24..b493aef09f6 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -495,8 +495,8 @@ namespace BitTorrent void findIncompleteFiles(const TorrentInfo &torrentInfo, const QString &savePath) const; - bool isForceReannounceEnabled() const; - void setForceReannounceEnabled(bool enabled); + bool isReannounceWhenAddressChanged() const; + void setReannounceWhenAddressChanged(bool enabled); signals: void allTorrentsFinished(); @@ -795,7 +795,7 @@ namespace BitTorrent QList m_moveStorageQueue; QHostAddress m_lastExternalIP; - bool m_isForceReannounceEnabled = false; + bool m_isReannounceWhenAddressChanged = false; static Session *m_instance; }; From 4ff5c6e322223ed4a59deec07e6d8dd7c23c9d73 Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Sun, 25 Apr 2021 20:31:57 +0800 Subject: [PATCH 16/31] Use cached setting value --- src/base/bittorrent/session.cpp | 2 +- src/base/bittorrent/session.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 131e7ca32d9..19396bb17d0 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -439,7 +439,7 @@ Session::Session(QObject *parent) #if defined(Q_OS_WIN) , m_OSMemoryPriority(BITTORRENT_KEY("OSMemoryPriority"), OSMemoryPriority::BelowNormal) #endif - , m_isReannounceWhenAddressChanged(false) + , m_isReannounceWhenAddressChanged(BITTORRENT_SESSION_KEY("Reannounce/AddressChanged"), false) , m_lastExternalIP() , m_seedingLimitTimer {new QTimer {this}} , m_resumeDataTimer {new QTimer {this}} diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index b493aef09f6..2e5bf5ace15 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -742,6 +742,7 @@ namespace BitTorrent CachedSettingValue m_peerTurnoverCutoff; CachedSettingValue m_peerTurnoverInterval; CachedSettingValue m_bannedIPs; + CachedSettingValue m_isReannounceWhenAddressChanged; #if defined(Q_OS_WIN) CachedSettingValue m_OSMemoryPriority; #endif @@ -795,7 +796,6 @@ namespace BitTorrent QList m_moveStorageQueue; QHostAddress m_lastExternalIP; - bool m_isReannounceWhenAddressChanged = false; static Session *m_instance; }; From 048c051642869b605b12946a1e386a4db6c629b2 Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Sun, 25 Apr 2021 22:03:19 +0800 Subject: [PATCH 17/31] Add desktop and web gui control checkbox --- src/gui/advancedsettings.cpp | 10 ++++++++++ src/gui/advancedsettings.h | 2 +- src/webui/api/appcontroller.cpp | 5 +++++ src/webui/www/private/views/preferences.html | 10 ++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index c975a1b024e..7f991b66d06 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -133,6 +133,7 @@ namespace PEER_TURNOVER, PEER_TURNOVER_CUTOFF, PEER_TURNOVER_INTERVAL, + REANNOUNCE_WHEN_ADDRESS_CHANGED, ROW_COUNT }; @@ -296,6 +297,9 @@ void AdvancedSettings::saveAdvancedSettings() session->setAnnounceToAllTrackers(m_checkBoxAnnounceAllTrackers.isChecked()); session->setAnnounceToAllTiers(m_checkBoxAnnounceAllTiers.isChecked()); + // Reannounce to all trackers when ip/port changed + session->setReannounceWhenAddressChanged(m_checkBoxReannounceWhenAddressChanged.isChecked()); + session->setPeerTurnover(m_spinBoxPeerTurnover.value()); session->setPeerTurnoverCutoff(m_spinBoxPeerTurnoverCutoff.value()); session->setPeerTurnoverInterval(m_spinBoxPeerTurnoverInterval.value()); @@ -694,6 +698,12 @@ void AdvancedSettings::loadAdvancedSettings() + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#announce_to_all_tiers", "(?)")) , &m_checkBoxAnnounceAllTiers); + // Reannounce to all trackers when ip/port changed + m_checkBoxReannounceWhenAddressChanged.setChecked(session->isReannounceWhenAddressChanged()); + addRow(REANNOUNCE_WHEN_ADDRESS_CHANGED, (tr("Reannounce to all trackers when IP or port changed") + + ' ' + makeLink("https://libtorrent.org/reference-Torrent_Handle.html#force-reannounce-force-dht-announce-force-lsd-announce", "(?)")) + , &m_checkBoxReannounceWhenAddressChanged); + m_spinBoxPeerTurnover.setMinimum(0); m_spinBoxPeerTurnover.setMaximum(100); m_spinBoxPeerTurnover.setValue(session->peerTurnover()); diff --git a/src/gui/advancedsettings.h b/src/gui/advancedsettings.h index 428b264df69..8bf15af3cfc 100644 --- a/src/gui/advancedsettings.h +++ b/src/gui/advancedsettings.h @@ -69,7 +69,7 @@ private slots: m_checkBoxProgramNotifications, m_checkBoxTorrentAddedNotifications, 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; + m_checkBoxSuggestMode, m_checkBoxSpeedWidgetEnabled, m_checkBoxIDNSupport, m_checkBoxReannounceWhenAddressChanged; QComboBox m_comboBoxInterface, m_comboBoxInterfaceAddress, m_comboBoxUtpMixedMode, m_comboBoxChokingAlgorithm, m_comboBoxSeedChokingAlgorithm; QLineEdit m_lineEditAnnounceIP; diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index 3a3c01b0473..bc313f07fef 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -334,6 +334,8 @@ void AppController::preferencesAction() data["announce_ip"] = session->announceIP(); data["max_concurrent_http_announces"] = session->maxConcurrentHTTPAnnounces(); data["stop_tracker_timeout"] = session->stopTrackerTimeout(); + // Reannounce to all trackers when ip/port changed + data["reannounce_when_address_changed"] = session->isReannounceWhenAddressChanged(); // Peer Turnover data["peer_turnover"] = session->peerTurnover(); data["peer_turnover_cutoff"] = session->peerTurnoverCutoff(); @@ -808,6 +810,9 @@ void AppController::setPreferencesAction() session->setMaxConcurrentHTTPAnnounces(it.value().toInt()); if (hasKey("stop_tracker_timeout")) session->setStopTrackerTimeout(it.value().toInt()); + // Reannounce to all trackers when ip/port changed + if (hasKey("reannounce_when_address_changed")) + session->setReannounceWhenAddressChanged(it.value().toBool()); // Peer Turnover if (hasKey("peer_turnover")) session->setPeerTurnover(it.value().toInt()); diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index d8e845baa7e..d6b6f0f062a 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -1193,6 +1193,14 @@ + + + + + + + + @@ -1915,6 +1923,7 @@ $('announceIP').setProperty('value', pref.announce_ip); $('maxConcurrentHTTPAnnounces').setProperty('value', pref.max_concurrent_http_announces); $('stopTrackerTimeout').setProperty('value', pref.stop_tracker_timeout); + $('reannounceWhenAddressChanged').setProperty('checked', pref.reannounce_when_address_changed); $('peerTurnover').setProperty('value', pref.peer_turnover); $('peerTurnoverCutoff').setProperty('value', pref.peer_turnover_cutoff); $('peerTurnoverInterval').setProperty('value', pref.peer_turnover_interval); @@ -2304,6 +2313,7 @@ settings.set('announce_ip', $('announceIP').getProperty('value')); settings.set('max_concurrent_http_announces', $('maxConcurrentHTTPAnnounces').getProperty('value')); settings.set('stop_tracker_timeout', $('stopTrackerTimeout').getProperty('value')); + settings.set('reannounce_when_address_changed', $('reannounceWhenAddressChanged').getProperty('checked')); settings.set('peer_turnover', $('peerTurnover').getProperty('value')); settings.set('peer_turnover_cutoff', $('peerTurnoverCutoff').getProperty('value')); settings.set('peer_turnover_interval', $('peerTurnoverInterval').getProperty('value')); From c1dc44ab090283bab6aa25f3a3d28ae66de12797 Mon Sep 17 00:00:00 2001 From: zhuangzi926 <30551102+zhuangzi926@users.noreply.github.com> Date: Mon, 26 Apr 2021 00:20:33 +0800 Subject: [PATCH 18/31] Fix variable name in session.h --- src/base/bittorrent/session.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 2e5bf5ace15..44b9b5bb040 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -742,7 +742,7 @@ namespace BitTorrent CachedSettingValue m_peerTurnoverCutoff; CachedSettingValue m_peerTurnoverInterval; CachedSettingValue m_bannedIPs; - CachedSettingValue m_isReannounceWhenAddressChanged; + CachedSettingValue m_reannounceWhenAddressChanged; #if defined(Q_OS_WIN) CachedSettingValue m_OSMemoryPriority; #endif From 9d5d19ae7a1228877fd3426a7bf69e45ae61a003 Mon Sep 17 00:00:00 2001 From: zhuangzi926 <30551102+zhuangzi926@users.noreply.github.com> Date: Mon, 26 Apr 2021 00:22:10 +0800 Subject: [PATCH 19/31] Fix variable name in session.cpp --- src/base/bittorrent/session.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 19396bb17d0..200c8ff2961 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -4782,15 +4782,15 @@ void Session::handleSocks5Alert(const lt::socks5_alert *p) const bool Session::isReannounceWhenAddressChanged() const { - return m_isReannounceWhenAddressChanged; + return m_reannounceWhenAddressChanged; } void Session::setReannounceWhenAddressChanged(bool enabled) { - if (enabled == m_isReannounceWhenAddressChanged) + if (enabled == m_reannounceWhenAddressChanged) { return; } - m_isReannounceWhenAddressChanged = enabled; + m_reannounceWhenAddressChanged = enabled; } From 9d52f5aa6bdc277f2a43da4dd0fc65f740e586c1 Mon Sep 17 00:00:00 2001 From: zhuangzi926 <30551102+zhuangzi926@users.noreply.github.com> Date: Mon, 26 Apr 2021 00:23:28 +0800 Subject: [PATCH 20/31] Fix variable name in session constructior --- src/base/bittorrent/session.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 200c8ff2961..0326e98dd46 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -439,7 +439,7 @@ Session::Session(QObject *parent) #if defined(Q_OS_WIN) , m_OSMemoryPriority(BITTORRENT_KEY("OSMemoryPriority"), OSMemoryPriority::BelowNormal) #endif - , m_isReannounceWhenAddressChanged(BITTORRENT_SESSION_KEY("Reannounce/AddressChanged"), false) + , m_reannounceWhenAddressChanged(BITTORRENT_SESSION_KEY("Reannounce/AddressChanged"), false) , m_lastExternalIP() , m_seedingLimitTimer {new QTimer {this}} , m_resumeDataTimer {new QTimer {this}} From e911a5260220fbdac51061346907e526fa755b08 Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Tue, 18 May 2021 16:14:19 +0800 Subject: [PATCH 21/31] Remove url from libtorrent --- src/gui/advancedsettings.cpp | 9 +++------ src/webui/www/private/views/preferences.html | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index 7f991b66d06..1240dff5d5a 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -644,6 +644,9 @@ void AdvancedSettings::loadAdvancedSettings() // Torrent added notifications m_checkBoxTorrentAddedNotifications.setChecked(mainWindow->isTorrentAddedNotificationsEnabled()); addRow(TORRENT_ADDED_NOTIFICATIONS, tr("Display notifications for added torrents"), &m_checkBoxTorrentAddedNotifications); + // Reannounce to all trackers when ip/port changed + m_checkBoxReannounceWhenAddressChanged.setChecked(session->isReannounceWhenAddressChanged()); + 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); @@ -698,12 +701,6 @@ void AdvancedSettings::loadAdvancedSettings() + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#announce_to_all_tiers", "(?)")) , &m_checkBoxAnnounceAllTiers); - // Reannounce to all trackers when ip/port changed - m_checkBoxReannounceWhenAddressChanged.setChecked(session->isReannounceWhenAddressChanged()); - addRow(REANNOUNCE_WHEN_ADDRESS_CHANGED, (tr("Reannounce to all trackers when IP or port changed") - + ' ' + makeLink("https://libtorrent.org/reference-Torrent_Handle.html#force-reannounce-force-dht-announce-force-lsd-announce", "(?)")) - , &m_checkBoxReannounceWhenAddressChanged); - m_spinBoxPeerTurnover.setMinimum(0); m_spinBoxPeerTurnover.setMaximum(100); m_spinBoxPeerTurnover.setValue(session->peerTurnover()); diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index d6b6f0f062a..8ed1e3e7171 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -1195,7 +1195,7 @@ - + From 08682eabdfb619411de19cd18ee0462695378f30 Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Tue, 18 May 2021 16:38:04 +0800 Subject: [PATCH 22/31] Relocate option from libtorrent section to qbt section --- src/gui/advancedsettings.cpp | 7 +++---- src/gui/advancedsettings.h | 4 ++-- src/webui/www/private/views/preferences.html | 20 ++++++++++---------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index 1240dff5d5a..99bfb93f9c8 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -79,6 +79,7 @@ namespace PROGRAM_NOTIFICATIONS, TORRENT_ADDED_NOTIFICATIONS, CONFIRM_REMOVE_ALL_TAGS, + REANNOUNCE_WHEN_ADDRESS_CHANGED, DOWNLOAD_TRACKER_FAVICON, SAVE_PATH_HISTORY_LENGTH, ENABLE_SPEED_WIDGET, @@ -133,7 +134,6 @@ namespace PEER_TURNOVER, PEER_TURNOVER_CUTOFF, PEER_TURNOVER_INTERVAL, - REANNOUNCE_WHEN_ADDRESS_CHANGED, ROW_COUNT }; @@ -274,6 +274,8 @@ void AdvancedSettings::saveAdvancedSettings() MainWindow *const mainWindow = static_cast(QCoreApplication::instance())->mainWindow(); mainWindow->setNotificationsEnabled(m_checkBoxProgramNotifications.isChecked()); mainWindow->setTorrentAddedNotificationsEnabled(m_checkBoxTorrentAddedNotifications.isChecked()); + // Reannounce to all trackers when ip/port changed + session->setReannounceWhenAddressChanged(m_checkBoxReannounceWhenAddressChanged.isChecked()); // Misc GUI properties mainWindow->setDownloadTrackerFavicon(m_checkBoxTrackerFavicon.isChecked()); AddNewTorrentDialog::setSavePathHistoryLength(m_spinBoxSavePathHistoryLength.value()); @@ -297,9 +299,6 @@ void AdvancedSettings::saveAdvancedSettings() session->setAnnounceToAllTrackers(m_checkBoxAnnounceAllTrackers.isChecked()); session->setAnnounceToAllTiers(m_checkBoxAnnounceAllTiers.isChecked()); - // Reannounce to all trackers when ip/port changed - session->setReannounceWhenAddressChanged(m_checkBoxReannounceWhenAddressChanged.isChecked()); - session->setPeerTurnover(m_spinBoxPeerTurnover.value()); session->setPeerTurnoverCutoff(m_spinBoxPeerTurnoverCutoff.value()); session->setPeerTurnoverInterval(m_spinBoxPeerTurnoverInterval.value()); diff --git a/src/gui/advancedsettings.h b/src/gui/advancedsettings.h index 8bf15af3cfc..0b061450af3 100644 --- a/src/gui/advancedsettings.h +++ b/src/gui/advancedsettings.h @@ -66,10 +66,10 @@ 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, m_checkBoxReannounceWhenAddressChanged; + m_checkBoxSuggestMode, m_checkBoxSpeedWidgetEnabled, m_checkBoxIDNSupport; QComboBox m_comboBoxInterface, m_comboBoxInterfaceAddress, m_comboBoxUtpMixedMode, m_comboBoxChokingAlgorithm, m_comboBoxSeedChokingAlgorithm; QLineEdit m_lineEditAnnounceIP; diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index 8ed1e3e7171..6a3397d99d4 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -922,6 +922,14 @@ + + + + + + + + @@ -1193,14 +1201,6 @@ - - - - - - - - @@ -1890,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); @@ -1923,7 +1924,6 @@ $('announceIP').setProperty('value', pref.announce_ip); $('maxConcurrentHTTPAnnounces').setProperty('value', pref.max_concurrent_http_announces); $('stopTrackerTimeout').setProperty('value', pref.stop_tracker_timeout); - $('reannounceWhenAddressChanged').setProperty('checked', pref.reannounce_when_address_changed); $('peerTurnover').setProperty('value', pref.peer_turnover); $('peerTurnoverCutoff').setProperty('value', pref.peer_turnover_cutoff); $('peerTurnoverInterval').setProperty('value', pref.peer_turnover_interval); @@ -2279,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')); @@ -2313,7 +2314,6 @@ settings.set('announce_ip', $('announceIP').getProperty('value')); settings.set('max_concurrent_http_announces', $('maxConcurrentHTTPAnnounces').getProperty('value')); settings.set('stop_tracker_timeout', $('stopTrackerTimeout').getProperty('value')); - settings.set('reannounce_when_address_changed', $('reannounceWhenAddressChanged').getProperty('checked')); settings.set('peer_turnover', $('peerTurnover').getProperty('value')); settings.set('peer_turnover_cutoff', $('peerTurnoverCutoff').getProperty('value')); settings.set('peer_turnover_interval', $('peerTurnoverInterval').getProperty('value')); From 473425c2a953e774ce13805c7b8da970f3850d62 Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Tue, 18 May 2021 16:39:41 +0800 Subject: [PATCH 23/31] Change BITTORRENT_SESSION_KEY into ReannounceWhenAddressChanged --- src/base/bittorrent/session.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 19396bb17d0..f08e84ea568 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -439,7 +439,7 @@ Session::Session(QObject *parent) #if defined(Q_OS_WIN) , m_OSMemoryPriority(BITTORRENT_KEY("OSMemoryPriority"), OSMemoryPriority::BelowNormal) #endif - , m_isReannounceWhenAddressChanged(BITTORRENT_SESSION_KEY("Reannounce/AddressChanged"), false) + , m_isReannounceWhenAddressChanged(BITTORRENT_SESSION_KEY("ReannounceWhenAddressChanged"), false) , m_lastExternalIP() , m_seedingLimitTimer {new QTimer {this}} , m_resumeDataTimer {new QTimer {this}} From 2c29dc70ef1e31bee81f417ded62ca8374fd426d Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Tue, 18 May 2021 16:54:24 +0800 Subject: [PATCH 24/31] Extract duplicated loops into a single class method reannounceToAllTrackers --- src/base/bittorrent/session.cpp | 12 ++++++++---- src/base/bittorrent/session.h | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index f08e84ea568..83e38041bf4 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -2744,8 +2744,7 @@ void Session::setPort(const int port) if (isReannounceWhenAddressChanged()) { - for (const lt::torrent_handle& torrent : m_nativeSession->get_torrents()) - torrent.force_reannounce(0, -1, lt::torrent_handle::ignore_min_interval); + reannounceToAllTrackers(); } } } @@ -4608,8 +4607,7 @@ void Session::handleExternalIPAlert(const lt::external_ip_alert *p) .arg(externalIP.toString()), Log::INFO); if (isReannounceWhenAddressChanged() && !m_lastExternalIP.isNull() && m_lastExternalIP != externalIP) { - for (const lt::torrent_handle &torrent : m_nativeSession->get_torrents()) - torrent.force_reannounce(0, -1, lt::torrent_handle::ignore_min_interval); + reannounceToAllTrackers(); } m_lastExternalIP = externalIP; } @@ -4794,3 +4792,9 @@ void Session::setReannounceWhenAddressChanged(bool enabled) m_isReannounceWhenAddressChanged = enabled; } + +void Session::reannounceToAllTrackers() +{ + for (const lt::torrent_handle& torrent : m_nativeSession->get_torrents()) + torrent.force_reannounce(0, -1, lt::torrent_handle::ignore_min_interval); +} diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 2e5bf5ace15..5c8d47e73a5 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -497,6 +497,7 @@ namespace BitTorrent bool isReannounceWhenAddressChanged() const; void setReannounceWhenAddressChanged(bool enabled); + void reannounceToAllTrackers(); signals: void allTorrentsFinished(); From 2a30ed605ba7730aafe9232a9b44bdf83397393f Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Tue, 18 May 2021 16:56:22 +0800 Subject: [PATCH 25/31] Formalize setReannounceWhenAddressChanged method --- src/base/bittorrent/session.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 83e38041bf4..f17229a5357 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -4783,12 +4783,10 @@ bool Session::isReannounceWhenAddressChanged() const return m_isReannounceWhenAddressChanged; } -void Session::setReannounceWhenAddressChanged(bool enabled) +void Session::setReannounceWhenAddressChanged(const bool enabled) { if (enabled == m_isReannounceWhenAddressChanged) - { return; - } m_isReannounceWhenAddressChanged = enabled; } From 1fafef52f1c05310aee7c73f0368fe3b03db4ee8 Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Tue, 18 May 2021 17:00:17 +0800 Subject: [PATCH 26/31] Relocate *reannounce* methods in session.h and session.cpp --- src/base/bittorrent/session.cpp | 38 ++++++++++++++++----------------- src/base/bittorrent/session.h | 7 +++--- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index f17229a5357..0ac0c402118 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -3582,6 +3582,25 @@ void Session::setMaxConcurrentHTTPAnnounces(const int value) configureDeferred(); } +bool Session::isReannounceWhenAddressChanged() const +{ + return m_isReannounceWhenAddressChanged; +} + +void Session::setReannounceWhenAddressChanged(const bool enabled) +{ + if (enabled == m_isReannounceWhenAddressChanged) + return; + + m_isReannounceWhenAddressChanged = enabled; +} + +void Session::reannounceToAllTrackers() +{ + 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; @@ -4777,22 +4796,3 @@ void Session::handleSocks5Alert(const lt::socks5_alert *p) const , Log::WARNING); } } - -bool Session::isReannounceWhenAddressChanged() const -{ - return m_isReannounceWhenAddressChanged; -} - -void Session::setReannounceWhenAddressChanged(const bool enabled) -{ - if (enabled == m_isReannounceWhenAddressChanged) - return; - - m_isReannounceWhenAddressChanged = enabled; -} - -void Session::reannounceToAllTrackers() -{ - for (const lt::torrent_handle& torrent : m_nativeSession->get_torrents()) - torrent.force_reannounce(0, -1, lt::torrent_handle::ignore_min_interval); -} diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 5c8d47e73a5..027884af59d 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -396,6 +396,9 @@ namespace BitTorrent void setAnnounceIP(const QString &ip); int maxConcurrentHTTPAnnounces() const; void setMaxConcurrentHTTPAnnounces(int value); + bool isReannounceWhenAddressChanged() const; + void setReannounceWhenAddressChanged(bool enabled); + void reannounceToAllTrackers(); int stopTrackerTimeout() const; void setStopTrackerTimeout(int value); int maxConnections() const; @@ -495,10 +498,6 @@ namespace BitTorrent void findIncompleteFiles(const TorrentInfo &torrentInfo, const QString &savePath) const; - bool isReannounceWhenAddressChanged() const; - void setReannounceWhenAddressChanged(bool enabled); - void reannounceToAllTrackers(); - signals: void allTorrentsFinished(); void categoryAdded(const QString &categoryName); From 9601129b3da069fd745f28a3a45690a2dbea12aa Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Tue, 18 May 2021 17:02:39 +0800 Subject: [PATCH 27/31] Relocate m_isReannounceWhenAddressChanged in session.h --- src/base/bittorrent/session.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 027884af59d..9845c5b17ed 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -687,6 +687,7 @@ namespace BitTorrent CachedSettingValue m_includeOverheadInLimits; CachedSettingValue m_announceIP; CachedSettingValue m_maxConcurrentHTTPAnnounces; + CachedSettingValue m_isReannounceWhenAddressChanged; CachedSettingValue m_stopTrackerTimeout; CachedSettingValue m_maxConnections; CachedSettingValue m_maxUploads; @@ -742,7 +743,6 @@ namespace BitTorrent CachedSettingValue m_peerTurnoverCutoff; CachedSettingValue m_peerTurnoverInterval; CachedSettingValue m_bannedIPs; - CachedSettingValue m_isReannounceWhenAddressChanged; #if defined(Q_OS_WIN) CachedSettingValue m_OSMemoryPriority; #endif From 7fe472dd8a180a1806c1b6976dc1495853e33a44 Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Tue, 18 May 2021 17:10:36 +0800 Subject: [PATCH 28/31] Change m_lastExternalIP from QHostname to QString --- src/base/bittorrent/session.cpp | 6 +++--- src/base/bittorrent/session.h | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 0ac0c402118..60d12b5ed07 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -4621,10 +4621,10 @@ void Session::handleListenFailedAlert(const lt::listen_failed_alert *p) void Session::handleExternalIPAlert(const lt::external_ip_alert *p) { - const QHostAddress externalIP {toString(p->external_address)}; + const QString externalIP {toString(p->external_address)}; LogMsg(tr("Detected external IP: %1", "e.g. Detected external IP: 1.1.1.1") - .arg(externalIP.toString()), Log::INFO); - if (isReannounceWhenAddressChanged() && !m_lastExternalIP.isNull() && m_lastExternalIP != externalIP) + .arg(externalIP), Log::INFO); + if (isReannounceWhenAddressChanged() && !m_lastExternalIP.isEmpty() && m_lastExternalIP != externalIP) { reannounceToAllTrackers(); } diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 9845c5b17ed..0d2622bd606 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -43,7 +43,6 @@ #include #include #include -#include #include "base/settingvalue.h" #include "base/types.h" @@ -795,7 +794,7 @@ namespace BitTorrent QList m_moveStorageQueue; - QHostAddress m_lastExternalIP; + QString m_lastExternalIP; static Session *m_instance; }; From 25779a38fbb60c08f761d7596c74be90937204f6 Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Tue, 18 May 2021 19:09:58 +0800 Subject: [PATCH 29/31] Relocate reannounce-related statements --- src/webui/api/appcontroller.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index bc313f07fef..3d1bbf9e62e 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -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->isReannounceWhenAddressChanged(); // libtorrent preferences // Async IO threads @@ -334,8 +336,6 @@ void AppController::preferencesAction() data["announce_ip"] = session->announceIP(); data["max_concurrent_http_announces"] = session->maxConcurrentHTTPAnnounces(); data["stop_tracker_timeout"] = session->stopTrackerTimeout(); - // Reannounce to all trackers when ip/port changed - data["reannounce_when_address_changed"] = session->isReannounceWhenAddressChanged(); // Peer Turnover data["peer_turnover"] = session->peerTurnover(); data["peer_turnover_cutoff"] = session->peerTurnoverCutoff(); @@ -718,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->setReannounceWhenAddressChanged(it.value().toBool()); // libtorrent preferences // Async IO threads @@ -810,9 +813,6 @@ void AppController::setPreferencesAction() session->setMaxConcurrentHTTPAnnounces(it.value().toInt()); if (hasKey("stop_tracker_timeout")) session->setStopTrackerTimeout(it.value().toInt()); - // Reannounce to all trackers when ip/port changed - if (hasKey("reannounce_when_address_changed")) - session->setReannounceWhenAddressChanged(it.value().toBool()); // Peer Turnover if (hasKey("peer_turnover")) session->setPeerTurnover(it.value().toInt()); From 2deab3968bc730f00c2dd70508b9c2456d2729ae Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Sat, 22 May 2021 12:08:59 +0800 Subject: [PATCH 30/31] Remove redundant codes, fix coding style and rename vars to is*Enabled and set*Enabled style --- src/base/bittorrent/session.cpp | 31 ++++++++++++------------------- src/base/bittorrent/session.h | 8 ++++---- src/gui/advancedsettings.cpp | 10 +++++----- src/webui/api/appcontroller.cpp | 4 ++-- 4 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 1775f956d6e..6f7af7c4938 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -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)) @@ -441,8 +442,6 @@ Session::Session(QObject *parent) #if defined(Q_OS_WIN) , m_OSMemoryPriority(BITTORRENT_KEY("OSMemoryPriority"), OSMemoryPriority::BelowNormal) #endif - , m_isReannounceWhenAddressChanged(BITTORRENT_SESSION_KEY("ReannounceWhenAddressChanged"), false) - , m_lastExternalIP() , m_seedingLimitTimer {new QTimer {this}} , m_resumeDataTimer {new QTimer {this}} , m_statistics {new Statistics {this}} @@ -2742,10 +2741,8 @@ void Session::setPort(const int port) m_port = port; configureListeningInterface(); - if (isReannounceWhenAddressChanged()) - { + if (isReannounceWhenAddressChangedEnabled()) reannounceToAllTrackers(); - } } } @@ -3036,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); @@ -3061,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); @@ -3592,22 +3587,22 @@ void Session::setMaxConcurrentHTTPAnnounces(const int value) configureDeferred(); } -bool Session::isReannounceWhenAddressChanged() const +bool Session::isReannounceWhenAddressChangedEnabled() const { - return m_isReannounceWhenAddressChanged; + return m_isReannounceWhenAddressChangedEnabled; } -void Session::setReannounceWhenAddressChanged(const bool enabled) +void Session::setReannounceWhenAddressChangedEnabled(const bool enabled) { - if (enabled == m_isReannounceWhenAddressChanged) + if (enabled == m_isReannounceWhenAddressChangedEnabled) return; - m_isReannounceWhenAddressChanged = enabled; + m_isReannounceWhenAddressChangedEnabled = enabled; } -void Session::reannounceToAllTrackers() +void Session::reannounceToAllTrackers() const { - for (const lt::torrent_handle& torrent : m_nativeSession->get_torrents()) + for (const lt::torrent_handle &torrent : m_nativeSession->get_torrents()) torrent.force_reannounce(0, -1, lt::torrent_handle::ignore_min_interval); } @@ -4658,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) @@ -4676,10 +4670,9 @@ 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(externalIP), Log::INFO); - if (isReannounceWhenAddressChanged() && !m_lastExternalIP.isEmpty() && m_lastExternalIP != externalIP) - { + + if (isReannounceWhenAddressChangedEnabled() && !m_lastExternalIP.isEmpty() && m_lastExternalIP != externalIP) reannounceToAllTrackers(); - } m_lastExternalIP = externalIP; } diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index c593b516461..7c2bbfba948 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -402,9 +402,9 @@ namespace BitTorrent void setAnnounceIP(const QString &ip); int maxConcurrentHTTPAnnounces() const; void setMaxConcurrentHTTPAnnounces(int value); - bool isReannounceWhenAddressChanged() const; - void setReannounceWhenAddressChanged(bool enabled); - void reannounceToAllTrackers(); + bool isReannounceWhenAddressChangedEnabled() const; + void setReannounceWhenAddressChangedEnabled(bool enabled); + void reannounceToAllTrackers() const; int stopTrackerTimeout() const; void setStopTrackerTimeout(int value); int maxConnections() const; @@ -693,7 +693,7 @@ namespace BitTorrent CachedSettingValue m_includeOverheadInLimits; CachedSettingValue m_announceIP; CachedSettingValue m_maxConcurrentHTTPAnnounces; - CachedSettingValue m_isReannounceWhenAddressChanged; + CachedSettingValue m_isReannounceWhenAddressChangedEnabled; CachedSettingValue m_stopTrackerTimeout; CachedSettingValue m_maxConnections; CachedSettingValue m_maxUploads; diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index a1c00ffddcb..af0e91cb90f 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -282,11 +282,11 @@ void AdvancedSettings::saveAdvancedSettings() MainWindow *const mainWindow = static_cast(QCoreApplication::instance())->mainWindow(); mainWindow->setNotificationsEnabled(m_checkBoxProgramNotifications.isChecked()); mainWindow->setTorrentAddedNotificationsEnabled(m_checkBoxTorrentAddedNotifications.isChecked()); - // Reannounce to all trackers when ip/port changed - session->setReannounceWhenAddressChanged(m_checkBoxReannounceWhenAddressChanged.isChecked()); #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()); @@ -658,9 +658,6 @@ void AdvancedSettings::loadAdvancedSettings() // Torrent added notifications m_checkBoxTorrentAddedNotifications.setChecked(mainWindow->isTorrentAddedNotificationsEnabled()); addRow(TORRENT_ADDED_NOTIFICATIONS, tr("Display notifications for added torrents"), &m_checkBoxTorrentAddedNotifications); - // Reannounce to all trackers when ip/port changed - m_checkBoxReannounceWhenAddressChanged.setChecked(session->isReannounceWhenAddressChanged()); - addRow(REANNOUNCE_WHEN_ADDRESS_CHANGED, tr("Reannounce to all trackers when IP or port changed"), &m_checkBoxReannounceWhenAddressChanged); #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB) // Notification timeout m_spinBoxNotificationTimeout.setMinimum(-1); @@ -670,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); diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index 3d1bbf9e62e..4dcf2d84d62 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -278,7 +278,7 @@ void AppController::preferencesAction() // Resolve peer countries data["resolve_peer_countries"] = pref->resolvePeerCountries(); // Reannounce to all trackers when ip/port changed - data["reannounce_when_address_changed"] = session->isReannounceWhenAddressChanged(); + data["reannounce_when_address_changed"] = session->isReannounceWhenAddressChangedEnabled(); // libtorrent preferences // Async IO threads @@ -720,7 +720,7 @@ void AppController::setPreferencesAction() pref->resolvePeerCountries(it.value().toBool()); // Reannounce to all trackers when ip/port changed if (hasKey("reannounce_when_address_changed")) - session->setReannounceWhenAddressChanged(it.value().toBool()); + session->setReannounceWhenAddressChangedEnabled(it.value().toBool()); // libtorrent preferences // Async IO threads From 23b8e2f2c19fe4dc3fdbf94d51a71380781b038a Mon Sep 17 00:00:00 2001 From: zhuangzi926 Date: Sat, 22 May 2021 22:04:53 +0800 Subject: [PATCH 31/31] Fix coding style --- src/base/bittorrent/session.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 6f7af7c4938..63382143bf4 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -4671,9 +4671,12 @@ void Session::handleExternalIPAlert(const lt::external_ip_alert *p) LogMsg(tr("Detected external IP: %1", "e.g. Detected external IP: 1.1.1.1") .arg(externalIP), Log::INFO); - if (isReannounceWhenAddressChangedEnabled() && !m_lastExternalIP.isEmpty() && m_lastExternalIP != externalIP) - reannounceToAllTrackers(); - m_lastExternalIP = externalIP; + if (m_lastExternalIP != externalIP) + { + if (isReannounceWhenAddressChangedEnabled() && !m_lastExternalIP.isEmpty()) + reannounceToAllTrackers(); + m_lastExternalIP = externalIP; + } } void Session::handleSessionStatsAlert(const lt::session_stats_alert *p)