Browse Source

Don't increase limits when prefetching metadata for added magnets

Adjusting limits was made based on the belief that "forced" torrents (internally used for prefetching metadata)
are still under limits, but ignore only the queue. This is not really the case. "Forced" torrents ignore the limits
like "maximum active torrents/downloads", so adjusting limits is not required, and what's more, it really causes the
problem of unexpectedly activated previously queued torrents when adding some magnet using "Add new torrent" dialog.

PR #18503.
Fixes #18490.
adaptive-webui-19844
Vladimir Golovnev 2 years ago committed by GitHub
parent
commit
09e58df03f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 36
      src/base/bittorrent/sessionimpl.cpp
  2. 3
      src/base/bittorrent/sessionimpl.h

36
src/base/bittorrent/sessionimpl.cpp

@ -1086,18 +1086,6 @@ void SessionImpl::setGlobalMaxSeedingMinutes(int minutes)
} }
} }
void SessionImpl::adjustLimits()
{
if (isQueueingSystemEnabled())
{
lt::settings_pack settingsPack;
// Internally increase the queue limits to ensure that the magnet is started
settingsPack.set_int(lt::settings_pack::active_downloads, adjustLimit(maxActiveDownloads()));
settingsPack.set_int(lt::settings_pack::active_limit, adjustLimit(maxActiveTorrents()));
m_nativeSession->apply_settings(std::move(settingsPack));
}
}
void SessionImpl::applyBandwidthLimits() void SessionImpl::applyBandwidthLimits()
{ {
lt::settings_pack settingsPack; lt::settings_pack settingsPack;
@ -1540,16 +1528,6 @@ void SessionImpl::processBannedIPs(lt::ip_filter &filter)
} }
} }
int SessionImpl::adjustLimit(const int limit) const
{
if (limit <= -1)
return limit;
// check for overflow: (limit + m_extraLimit) < std::numeric_limits<int>::max()
return (m_extraLimit < (std::numeric_limits<int>::max() - limit))
? (limit + m_extraLimit)
: std::numeric_limits<int>::max();
}
void SessionImpl::initMetrics() void SessionImpl::initMetrics()
{ {
const auto findMetricIndex = [](const char *name) -> int const auto findMetricIndex = [](const char *name) -> int
@ -1751,10 +1729,8 @@ lt::settings_pack SessionImpl::loadLTSettings() const
// Queueing System // Queueing System
if (isQueueingSystemEnabled()) if (isQueueingSystemEnabled())
{ {
// Internally increase the queue limits to ensure that the magnet is started settingsPack.set_int(lt::settings_pack::active_downloads, maxActiveDownloads());
settingsPack.set_int(lt::settings_pack::active_downloads, adjustLimit(maxActiveDownloads())); settingsPack.set_int(lt::settings_pack::active_limit, maxActiveTorrents());
settingsPack.set_int(lt::settings_pack::active_limit, adjustLimit(maxActiveTorrents()));
settingsPack.set_int(lt::settings_pack::active_seeds, maxActiveUploads()); settingsPack.set_int(lt::settings_pack::active_seeds, maxActiveUploads());
settingsPack.set_bool(lt::settings_pack::dont_count_slow_torrents, ignoreSlowTorrentsForQueueing()); settingsPack.set_bool(lt::settings_pack::dont_count_slow_torrents, ignoreSlowTorrentsForQueueing());
settingsPack.set_int(lt::settings_pack::inactive_down_rate, downloadRateForSlowTorrents() * 1024); // KiB to Bytes settingsPack.set_int(lt::settings_pack::inactive_down_rate, downloadRateForSlowTorrents() * 1024); // KiB to Bytes
@ -2333,8 +2309,6 @@ bool SessionImpl::cancelDownloadMetadata(const TorrentID &id)
} }
#endif #endif
m_downloadedMetadata.erase(downloadedMetadataIter); m_downloadedMetadata.erase(downloadedMetadataIter);
--m_extraLimit;
adjustLimits();
m_nativeSession->remove_torrent(nativeHandle, lt::session::delete_files); m_nativeSession->remove_torrent(nativeHandle, lt::session::delete_files);
return true; return true;
} }
@ -5212,9 +5186,6 @@ void SessionImpl::handleAddTorrentAlerts(const std::vector<lt::alert *> &alerts)
else if (const auto downloadedMetadataIter = m_downloadedMetadata.find(torrentID) else if (const auto downloadedMetadataIter = m_downloadedMetadata.find(torrentID)
; downloadedMetadataIter != m_downloadedMetadata.end()) ; downloadedMetadataIter != m_downloadedMetadata.end())
{ {
++m_extraLimit;
adjustLimits();
downloadedMetadataIter.value() = alert->handle; downloadedMetadataIter.value() = alert->handle;
if (infoHash.isHybrid()) if (infoHash.isHybrid())
{ {
@ -5493,9 +5464,6 @@ void SessionImpl::handleMetadataReceivedAlert(const lt::metadata_received_alert
if (found) if (found)
{ {
const TorrentInfo metadata {*p->handle.torrent_file()}; const TorrentInfo metadata {*p->handle.torrent_file()};
--m_extraLimit;
adjustLimits();
m_nativeSession->remove_torrent(p->handle, lt::session::delete_files); m_nativeSession->remove_torrent(p->handle, lt::session::delete_files);
emit metadataDownloaded(metadata); emit metadataDownloaded(metadata);

3
src/base/bittorrent/sessionimpl.h

@ -492,9 +492,7 @@ namespace BitTorrent
lt::settings_pack loadLTSettings() const; lt::settings_pack loadLTSettings() const;
void applyNetworkInterfacesSettings(lt::settings_pack &settingsPack) const; void applyNetworkInterfacesSettings(lt::settings_pack &settingsPack) const;
void configurePeerClasses(); void configurePeerClasses();
int adjustLimit(int limit) const;
void initMetrics(); void initMetrics();
void adjustLimits();
void applyBandwidthLimits(); void applyBandwidthLimits();
void processBannedIPs(lt::ip_filter &filter); void processBannedIPs(lt::ip_filter &filter);
QStringList getListeningIPs() const; QStringList getListeningIPs() const;
@ -686,7 +684,6 @@ namespace BitTorrent
const bool m_wasPexEnabled = m_isPeXEnabled; const bool m_wasPexEnabled = m_isPeXEnabled;
int m_numResumeData = 0; int m_numResumeData = 0;
int m_extraLimit = 0;
QVector<TrackerEntry> m_additionalTrackerList; QVector<TrackerEntry> m_additionalTrackerList;
QVector<QRegularExpression> m_excludedFileNamesRegExpList; QVector<QRegularExpression> m_excludedFileNamesRegExpList;

Loading…
Cancel
Save