From 09e58df03f39d7a2be387b19aeb2bc28766e3fc2 Mon Sep 17 00:00:00 2001 From: Vladimir Golovnev Date: Thu, 2 Feb 2023 06:16:32 +0300 Subject: [PATCH] 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. --- src/base/bittorrent/sessionimpl.cpp | 36 ++--------------------------- src/base/bittorrent/sessionimpl.h | 3 --- 2 files changed, 2 insertions(+), 37 deletions(-) diff --git a/src/base/bittorrent/sessionimpl.cpp b/src/base/bittorrent/sessionimpl.cpp index 5fa4cb699..0c2a6cbb7 100644 --- a/src/base/bittorrent/sessionimpl.cpp +++ b/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() { 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::max() - return (m_extraLimit < (std::numeric_limits::max() - limit)) - ? (limit + m_extraLimit) - : std::numeric_limits::max(); -} - void SessionImpl::initMetrics() { const auto findMetricIndex = [](const char *name) -> int @@ -1751,10 +1729,8 @@ lt::settings_pack SessionImpl::loadLTSettings() const // Queueing System if (isQueueingSystemEnabled()) { - // 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())); - + settingsPack.set_int(lt::settings_pack::active_downloads, maxActiveDownloads()); + settingsPack.set_int(lt::settings_pack::active_limit, maxActiveTorrents()); settingsPack.set_int(lt::settings_pack::active_seeds, maxActiveUploads()); 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 @@ -2333,8 +2309,6 @@ bool SessionImpl::cancelDownloadMetadata(const TorrentID &id) } #endif m_downloadedMetadata.erase(downloadedMetadataIter); - --m_extraLimit; - adjustLimits(); m_nativeSession->remove_torrent(nativeHandle, lt::session::delete_files); return true; } @@ -5212,9 +5186,6 @@ void SessionImpl::handleAddTorrentAlerts(const std::vector &alerts) else if (const auto downloadedMetadataIter = m_downloadedMetadata.find(torrentID) ; downloadedMetadataIter != m_downloadedMetadata.end()) { - ++m_extraLimit; - adjustLimits(); - downloadedMetadataIter.value() = alert->handle; if (infoHash.isHybrid()) { @@ -5493,9 +5464,6 @@ void SessionImpl::handleMetadataReceivedAlert(const lt::metadata_received_alert if (found) { const TorrentInfo metadata {*p->handle.torrent_file()}; - - --m_extraLimit; - adjustLimits(); m_nativeSession->remove_torrent(p->handle, lt::session::delete_files); emit metadataDownloaded(metadata); diff --git a/src/base/bittorrent/sessionimpl.h b/src/base/bittorrent/sessionimpl.h index e1df5ce81..a6de23091 100644 --- a/src/base/bittorrent/sessionimpl.h +++ b/src/base/bittorrent/sessionimpl.h @@ -492,9 +492,7 @@ namespace BitTorrent lt::settings_pack loadLTSettings() const; void applyNetworkInterfacesSettings(lt::settings_pack &settingsPack) const; void configurePeerClasses(); - int adjustLimit(int limit) const; void initMetrics(); - void adjustLimits(); void applyBandwidthLimits(); void processBannedIPs(lt::ip_filter &filter); QStringList getListeningIPs() const; @@ -686,7 +684,6 @@ namespace BitTorrent const bool m_wasPexEnabled = m_isPeXEnabled; int m_numResumeData = 0; - int m_extraLimit = 0; QVector m_additionalTrackerList; QVector m_excludedFileNamesRegExpList;