From 801cfdbc24942a88d53fae185395c860ca48f272 Mon Sep 17 00:00:00 2001 From: An0n <79678786+an0n666@users.noreply.github.com> Date: Sun, 27 Feb 2022 20:08:10 +0600 Subject: [PATCH 1/2] Allow setting the number of maximum active checking torrents This is to allow re-checking of multiple torrents simultaneously. This will benefit users who have multiple disks or SSD. Closes #15296. Co-authored-by: Chocobo1 --- src/base/bittorrent/session.cpp | 17 +++++++++ src/base/bittorrent/session.h | 3 ++ src/gui/optionsdialog.cpp | 3 ++ src/gui/optionsdialog.ui | 37 ++++++++++++++++++++ src/webui/api/appcontroller.cpp | 5 +++ src/webui/webapplication.h | 2 +- src/webui/www/private/views/preferences.html | 9 +++++ 7 files changed, 75 insertions(+), 1 deletion(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index ab1059e73..485045f90 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -450,6 +450,7 @@ Session::Session(QObject *parent) , m_networkInterfaceName(BITTORRENT_SESSION_KEY("InterfaceName")) , m_networkInterfaceAddress(BITTORRENT_SESSION_KEY("InterfaceAddress")) , m_encryption(BITTORRENT_SESSION_KEY("Encryption"), 0) + , m_maxActiveCheckingTorrents(BITTORRENT_SESSION_KEY("MaxActiveCheckingTorrents"), 1) , m_isProxyPeerConnectionsEnabled(BITTORRENT_SESSION_KEY("ProxyPeerConnections"), false) , m_chokingAlgorithm(BITTORRENT_SESSION_KEY("ChokingAlgorithm"), ChokingAlgorithm::FixedSlots , clampValue(ChokingAlgorithm::FixedSlots, ChokingAlgorithm::RateBased)) @@ -1287,6 +1288,8 @@ void Session::loadLTSettings(lt::settings_pack &settingsPack) settingsPack.set_int(lt::settings_pack::in_enc_policy, lt::settings_pack::pe_disabled); } + settingsPack.set_int(lt::settings_pack::active_checking, maxActiveCheckingTorrents()); + // proxy const auto proxyManager = Net::ProxyConfigurationManager::instance(); const Net::ProxyConfiguration proxyConfig = proxyManager->proxyConfiguration(); @@ -2985,6 +2988,20 @@ void Session::setEncryption(const int state) } } +int Session::maxActiveCheckingTorrents() const +{ + return m_maxActiveCheckingTorrents; +} + +void Session::setMaxActiveCheckingTorrents(const int val) +{ + if (val == m_maxActiveCheckingTorrents) + return; + + m_maxActiveCheckingTorrents = val; + configureDeferred(); +} + bool Session::isProxyPeerConnectionsEnabled() const { return m_isProxyPeerConnectionsEnabled; diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 7447451ac..c3f071a20 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -326,6 +326,8 @@ namespace BitTorrent void setNetworkInterfaceAddress(const QString &address); int encryption() const; void setEncryption(int state); + int maxActiveCheckingTorrents() const; + void setMaxActiveCheckingTorrents(int val); bool isProxyPeerConnectionsEnabled() const; void setProxyPeerConnectionsEnabled(bool enabled); ChokingAlgorithm chokingAlgorithm() const; @@ -750,6 +752,7 @@ namespace BitTorrent CachedSettingValue m_networkInterfaceName; CachedSettingValue m_networkInterfaceAddress; CachedSettingValue m_encryption; + CachedSettingValue m_maxActiveCheckingTorrents; CachedSettingValue m_isProxyPeerConnectionsEnabled; CachedSettingValue m_chokingAlgorithm; CachedSettingValue m_seedChokingAlgorithm; diff --git a/src/gui/optionsdialog.cpp b/src/gui/optionsdialog.cpp index 6224718a0..7fb413dc8 100644 --- a/src/gui/optionsdialog.cpp +++ b/src/gui/optionsdialog.cpp @@ -434,6 +434,7 @@ OptionsDialog::OptionsDialog(QWidget *parent) connect(m_ui->spinMaxUploadsPerTorrent, qSpinBoxValueChanged, this, &ThisType::enableApplyButton); connect(m_ui->checkDHT, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); connect(m_ui->checkAnonymousMode, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); + connect(m_ui->spinBoxMaxActiveCheckingTorrents, qSpinBoxValueChanged, this, &ThisType::enableApplyButton); connect(m_ui->checkPeX, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); connect(m_ui->checkLSD, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); connect(m_ui->comboEncryption, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton); @@ -816,6 +817,7 @@ void OptionsDialog::saveOptions() session->setLSDEnabled(isLSDEnabled()); session->setEncryption(getEncryptionSetting()); session->setAnonymousModeEnabled(m_ui->checkAnonymousMode->isChecked()); + session->setMaxActiveCheckingTorrents(m_ui->spinBoxMaxActiveCheckingTorrents->value()); session->setAddTrackersEnabled(m_ui->checkEnableAddTrackers->isChecked()); session->setAdditionalTrackers(m_ui->textTrackers->toPlainText()); session->setGlobalMaxRatio(getMaxRatio()); @@ -1208,6 +1210,7 @@ void OptionsDialog::loadOptions() m_ui->checkLSD->setChecked(session->isLSDEnabled()); m_ui->comboEncryption->setCurrentIndex(session->encryption()); m_ui->checkAnonymousMode->setChecked(session->isAnonymousModeEnabled()); + m_ui->spinBoxMaxActiveCheckingTorrents->setValue(session->maxActiveCheckingTorrents()); m_ui->checkEnableAddTrackers->setChecked(session->isAddTrackersEnabled()); m_ui->textTrackers->setPlainText(session->additionalTrackers()); diff --git a/src/gui/optionsdialog.ui b/src/gui/optionsdialog.ui index a3013df59..c0eb5193a 100644 --- a/src/gui/optionsdialog.ui +++ b/src/gui/optionsdialog.ui @@ -2377,6 +2377,43 @@ Disable encryption: Only connect to peers without protocol encryption + + + + + + Maximum active checking torrents: + + + + + + + + + + -1 + + + 2147483647 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index 8443b1c8c..258b5bd93 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -210,6 +210,8 @@ void AppController::preferencesAction() data["lsd"] = session->isLSDEnabled(); data["encryption"] = session->encryption(); data["anonymous_mode"] = session->isAnonymousModeEnabled(); + // Max active checking torrents + data["max_active_checking_torrents"] = session->maxActiveCheckingTorrents(); // Torrent Queueing data["queueing_enabled"] = session->isQueueingSystemEnabled(); data["max_active_downloads"] = session->maxActiveDownloads(); @@ -584,6 +586,9 @@ void AppController::setPreferencesAction() session->setEncryption(it.value().toInt()); if (hasKey("anonymous_mode")) session->setAnonymousModeEnabled(it.value().toBool()); + // Max active checking torrents + if (hasKey("max_active_checking_torrents")) + session->setMaxActiveCheckingTorrents(it.value().toInt()); // Torrent Queueing if (hasKey("queueing_enabled")) session->setQueueingSystemEnabled(it.value().toBool()); diff --git a/src/webui/webapplication.h b/src/webui/webapplication.h index 1fd3e1e41..88e0aee65 100644 --- a/src/webui/webapplication.h +++ b/src/webui/webapplication.h @@ -44,7 +44,7 @@ #include "base/utils/net.h" #include "base/utils/version.h" -inline const Utils::Version API_VERSION {2, 8, 8}; +inline const Utils::Version API_VERSION {2, 8, 9}; class APIController; class WebApplication; diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index 4b174797d..db06eafa9 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -472,6 +472,11 @@ +
+ + +
+
@@ -1835,6 +1840,8 @@ $('encryption_select').getChildren('option')[encryption].setAttribute('selected', ''); $('anonymous_mode_checkbox').setProperty('checked', pref.anonymous_mode); + $('maxActiveCheckingTorrents').setProperty('value', pref.max_active_checking_torrents); + // Torrent Queueing $('queueing_checkbox').setProperty('checked', pref.queueing_enabled); $('max_active_dl_value').setProperty('value', pref.max_active_downloads.toInt()); @@ -2184,6 +2191,8 @@ settings.set('encryption', $('encryption_select').getSelected()[0].getProperty('value')); settings.set('anonymous_mode', $('anonymous_mode_checkbox').getProperty('checked')); + settings.set('max_active_checking_torrents', $('maxActiveCheckingTorrents').getProperty('value')); + // Torrent Queueing settings.set('queueing_enabled', $('queueing_checkbox').getProperty('checked')); if ($('queueing_checkbox').getProperty('checked')) { From 9f32e6e50d1aee84258a81b068f3388c454ba72b Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 8 Mar 2022 13:58:02 +0800 Subject: [PATCH 2/2] Fix wrong parentheses Fix up 294ea172222382905e4d8f97c8ebf928bfefbef3. --- src/base/bittorrent/torrentimpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index e69b9c5ca..535a82a79 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -1925,7 +1925,7 @@ void TorrentImpl::handleMetadataReceivedAlert(const lt::metadata_received_alert void TorrentImpl::handlePerformanceAlert(const lt::performance_alert *p) const { - LogMsg((tr("Performance alert: %1. More info: %2").arg(QString::fromStdString(p->message())), u"https://libtorrent.org/reference-Alerts.html#enum-performance-warning-t"_qs) + LogMsg((tr("Performance alert: %1. More info: %2").arg(QString::fromStdString(p->message()), u"https://libtorrent.org/reference-Alerts.html#enum-performance-warning-t"_qs)) , Log::INFO); }