Browse Source

Announce to all trackers if IP changed (#15001)

Closes #14545.
adaptive-webui-19844
zhuangzi926 4 years ago committed by GitHub
parent
commit
2e8e2b04a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 44
      src/base/bittorrent/session.cpp
  2. 6
      src/base/bittorrent/session.h
  3. 6
      src/gui/advancedsettings.cpp
  4. 2
      src/gui/advancedsettings.h
  5. 5
      src/webui/api/appcontroller.cpp
  6. 10
      src/webui/www/private/views/preferences.html

44
src/base/bittorrent/session.cpp

@ -372,6 +372,7 @@ Session::Session(QObject *parent) @@ -372,6 +372,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))
@ -1012,9 +1013,9 @@ void Session::adjustLimits() @@ -1012,9 +1013,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()
@ -2743,6 +2744,9 @@ void Session::setPort(const int port) @@ -2743,6 +2744,9 @@ void Session::setPort(const int port)
{
m_port = port;
configureListeningInterface();
if (isReannounceWhenAddressChangedEnabled())
reannounceToAllTrackers();
}
}
@ -3033,7 +3037,6 @@ void Session::setMaxConnectionsPerTorrent(int max) @@ -3033,7 +3037,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);
@ -3058,7 +3061,6 @@ void Session::setMaxUploadsPerTorrent(int max) @@ -3058,7 +3061,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);
@ -3589,6 +3591,25 @@ void Session::setMaxConcurrentHTTPAnnounces(const int value) @@ -3589,6 +3591,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;
@ -4636,8 +4657,7 @@ void Session::handleListenSucceededAlert(const lt::listen_succeeded_alert *p) @@ -4636,8 +4657,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)
@ -4651,8 +4671,16 @@ void Session::handleListenFailedAlert(const lt::listen_failed_alert *p) @@ -4651,8 +4671,16 @@ 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 (m_lastExternalIP != externalIP)
{
if (isReannounceWhenAddressChangedEnabled() && !m_lastExternalIP.isEmpty())
reannounceToAllTrackers();
m_lastExternalIP = externalIP;
}
}
void Session::handleSessionStatsAlert(const lt::session_stats_alert *p)

6
src/base/bittorrent/session.h

@ -402,6 +402,9 @@ namespace BitTorrent @@ -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;
@ -690,6 +693,7 @@ namespace BitTorrent @@ -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;
@ -798,6 +802,8 @@ namespace BitTorrent @@ -798,6 +802,8 @@ namespace BitTorrent
QList<MoveStorageJob> m_moveStorageQueue;
QString m_lastExternalIP;
static Session *m_instance;
};
}

6
src/gui/advancedsettings.cpp

@ -83,6 +83,7 @@ namespace @@ -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,
@ -284,6 +285,8 @@ void AdvancedSettings::saveAdvancedSettings() @@ -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());
@ -664,6 +667,9 @@ void AdvancedSettings::loadAdvancedSettings() @@ -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);

2
src/gui/advancedsettings.h

@ -66,7 +66,7 @@ private: @@ -66,7 +66,7 @@ private:
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;

5
src/webui/api/appcontroller.cpp

@ -286,6 +286,8 @@ void AppController::preferencesAction() @@ -286,6 +286,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
@ -733,6 +735,9 @@ void AppController::setPreferencesAction() @@ -733,6 +735,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

10
src/webui/www/private/views/preferences.html

@ -922,6 +922,14 @@ @@ -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>
@ -1882,6 +1890,7 @@ @@ -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);
@ -2270,6 +2279,7 @@ @@ -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'));

Loading…
Cancel
Save