From 96da685e5d72061cab7caf4d68a9e2c8dea86de7 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Mon, 13 Feb 2023 11:23:52 +0300 Subject: [PATCH] Expand the scope of "Proxy hostname lookup" option --- src/app/upgrade.cpp | 4 ++ src/base/bittorrent/session.h | 2 - src/base/bittorrent/sessionimpl.cpp | 17 +------- src/base/bittorrent/sessionimpl.h | 3 -- src/base/net/downloadmanager.cpp | 5 +++ src/base/net/proxyconfigurationmanager.cpp | 6 ++- src/base/net/proxyconfigurationmanager.h | 2 + src/gui/optionsdialog.cpp | 6 +-- src/gui/optionsdialog.ui | 44 ++++++++++---------- src/webui/api/appcontroller.cpp | 6 +-- src/webui/www/private/views/preferences.html | 21 +++++----- 11 files changed, 56 insertions(+), 60 deletions(-) diff --git a/src/app/upgrade.cpp b/src/app/upgrade.cpp index 0aa568d75..2cdb52260 100644 --- a/src/app/upgrade.cpp +++ b/src/app/upgrade.cpp @@ -403,6 +403,10 @@ namespace } settingsStorage->removeValue(u"Network/Proxy/OnlyForTorrents"_qs); + + const auto proxyHostnameLookup = settingsStorage->loadValue(u"BitTorrent/Session/ProxyHostnameLookup"_qs); + settingsStorage->storeValue(u"Network/Proxy/HostnameLookupEnabled"_qs, proxyHostnameLookup); + settingsStorage->removeValue(u"BitTorrent/Session/ProxyHostnameLookup"_qs); } #ifdef Q_OS_WIN diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 777eaae15..e4c9bdb8a 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -262,8 +262,6 @@ namespace BitTorrent virtual void setMaxActiveCheckingTorrents(int val) = 0; virtual bool isProxyPeerConnectionsEnabled() const = 0; virtual void setProxyPeerConnectionsEnabled(bool enabled) = 0; - virtual bool isProxyHostnameLookupEnabled() const = 0; - virtual void setProxyHostnameLookupEnabled(bool enabled) = 0; virtual ChokingAlgorithm chokingAlgorithm() const = 0; virtual void setChokingAlgorithm(ChokingAlgorithm mode) = 0; virtual SeedChokingAlgorithm seedChokingAlgorithm() const = 0; diff --git a/src/base/bittorrent/sessionimpl.cpp b/src/base/bittorrent/sessionimpl.cpp index ac8af8f43..c862a6197 100644 --- a/src/base/bittorrent/sessionimpl.cpp +++ b/src/base/bittorrent/sessionimpl.cpp @@ -495,7 +495,6 @@ SessionImpl::SessionImpl(QObject *parent) , m_encryption(BITTORRENT_SESSION_KEY(u"Encryption"_qs), 0) , m_maxActiveCheckingTorrents(BITTORRENT_SESSION_KEY(u"MaxActiveCheckingTorrents"_qs), 1) , m_isProxyPeerConnectionsEnabled(BITTORRENT_SESSION_KEY(u"ProxyPeerConnections"_qs), false) - , m_isProxyHostnameLookupEnabled(BITTORRENT_SESSION_KEY(u"ProxyHostnameLookup"_qs), true) , m_chokingAlgorithm(BITTORRENT_SESSION_KEY(u"ChokingAlgorithm"_qs), ChokingAlgorithm::FixedSlots , clampValue(ChokingAlgorithm::FixedSlots, ChokingAlgorithm::RateBased)) , m_seedChokingAlgorithm(BITTORRENT_SESSION_KEY(u"SeedChokingAlgorithm"_qs), SeedChokingAlgorithm::FastestUpload @@ -1669,7 +1668,7 @@ lt::settings_pack SessionImpl::loadLTSettings() const } settingsPack.set_bool(lt::settings_pack::proxy_peer_connections, isProxyPeerConnectionsEnabled()); - settingsPack.set_bool(lt::settings_pack::proxy_hostnames, isProxyHostnameLookupEnabled()); + settingsPack.set_bool(lt::settings_pack::proxy_hostnames, proxyConfig.hostnameLookupEnabled); } settingsPack.set_bool(lt::settings_pack::announce_to_all_trackers, announceToAllTrackers()); @@ -3545,20 +3544,6 @@ void SessionImpl::setProxyPeerConnectionsEnabled(const bool enabled) } } -bool SessionImpl::isProxyHostnameLookupEnabled() const -{ - return m_isProxyHostnameLookupEnabled; -} - -void SessionImpl::setProxyHostnameLookupEnabled(const bool enabled) -{ - if (enabled != isProxyHostnameLookupEnabled()) - { - m_isProxyHostnameLookupEnabled = enabled; - configureDeferred(); - } -} - ChokingAlgorithm SessionImpl::chokingAlgorithm() const { return m_chokingAlgorithm; diff --git a/src/base/bittorrent/sessionimpl.h b/src/base/bittorrent/sessionimpl.h index a7d378a3e..2b7e2ca7d 100644 --- a/src/base/bittorrent/sessionimpl.h +++ b/src/base/bittorrent/sessionimpl.h @@ -239,8 +239,6 @@ namespace BitTorrent void setMaxActiveCheckingTorrents(int val) override; bool isProxyPeerConnectionsEnabled() const override; void setProxyPeerConnectionsEnabled(bool enabled) override; - bool isProxyHostnameLookupEnabled() const override; - void setProxyHostnameLookupEnabled(bool enabled) override; ChokingAlgorithm chokingAlgorithm() const override; void setChokingAlgorithm(ChokingAlgorithm mode) override; SeedChokingAlgorithm seedChokingAlgorithm() const override; @@ -655,7 +653,6 @@ namespace BitTorrent CachedSettingValue m_encryption; CachedSettingValue m_maxActiveCheckingTorrents; CachedSettingValue m_isProxyPeerConnectionsEnabled; - CachedSettingValue m_isProxyHostnameLookupEnabled; CachedSettingValue m_chokingAlgorithm; CachedSettingValue m_seedChokingAlgorithm; CachedSettingValue m_storedTags; diff --git a/src/base/net/downloadmanager.cpp b/src/base/net/downloadmanager.cpp index 96f206bc1..ffadffedc 100644 --- a/src/base/net/downloadmanager.cpp +++ b/src/base/net/downloadmanager.cpp @@ -250,6 +250,11 @@ void Net::DownloadManager::applyProxySettings() m_proxy.setUser(proxyConfig.username); m_proxy.setPassword(proxyConfig.password); } + + if (proxyConfig.hostnameLookupEnabled) + m_proxy.setCapabilities(m_proxy.capabilities() | QNetworkProxy::HostNameLookupCapability); + else + m_proxy.setCapabilities(m_proxy.capabilities() & ~QNetworkProxy::HostNameLookupCapability); } } diff --git a/src/base/net/proxyconfigurationmanager.cpp b/src/base/net/proxyconfigurationmanager.cpp index 589d651e3..46d4cc006 100644 --- a/src/base/net/proxyconfigurationmanager.cpp +++ b/src/base/net/proxyconfigurationmanager.cpp @@ -37,7 +37,8 @@ bool Net::operator==(const ProxyConfiguration &left, const ProxyConfiguration &r && (left.port == right.port) && (left.authEnabled == right.authEnabled) && (left.username == right.username) - && (left.password == right.password); + && (left.password == right.password) + && (left.hostnameLookupEnabled == right.hostnameLookupEnabled); } bool Net::operator!=(const ProxyConfiguration &left, const ProxyConfiguration &right) @@ -57,6 +58,7 @@ ProxyConfigurationManager::ProxyConfigurationManager(QObject *parent) , m_storeProxyAuthEnabled {SETTINGS_KEY(u"AuthEnabled"_qs)} , m_storeProxyUsername {SETTINGS_KEY(u"Username"_qs)} , m_storeProxyPassword {SETTINGS_KEY(u"Password"_qs)} + , m_storeProxyHostnameLookupEnabled {SETTINGS_KEY(u"HostnameLookupEnabled"_qs)} { m_config.type = m_storeProxyType.get(ProxyType::HTTP); if ((m_config.type < ProxyType::HTTP) || (m_config.type > ProxyType::SOCKS4)) @@ -66,6 +68,7 @@ ProxyConfigurationManager::ProxyConfigurationManager(QObject *parent) m_config.authEnabled = m_storeProxyAuthEnabled; m_config.username = m_storeProxyUsername; m_config.password = m_storeProxyPassword; + m_config.hostnameLookupEnabled = m_storeProxyHostnameLookupEnabled.get(true); } void ProxyConfigurationManager::initInstance() @@ -101,6 +104,7 @@ void ProxyConfigurationManager::setProxyConfiguration(const ProxyConfiguration & m_storeProxyAuthEnabled = config.authEnabled; m_storeProxyUsername = config.username; m_storeProxyPassword = config.password; + m_storeProxyHostnameLookupEnabled = config.hostnameLookupEnabled; emit proxyConfigurationChanged(); } diff --git a/src/base/net/proxyconfigurationmanager.h b/src/base/net/proxyconfigurationmanager.h index 3b998eda1..830d1ba5b 100644 --- a/src/base/net/proxyconfigurationmanager.h +++ b/src/base/net/proxyconfigurationmanager.h @@ -53,6 +53,7 @@ namespace Net bool authEnabled = false; QString username; QString password; + bool hostnameLookupEnabled = true; }; bool operator==(const ProxyConfiguration &left, const ProxyConfiguration &right); bool operator!=(const ProxyConfiguration &left, const ProxyConfiguration &right); @@ -85,5 +86,6 @@ namespace Net SettingValue m_storeProxyAuthEnabled; SettingValue m_storeProxyUsername; SettingValue m_storeProxyPassword; + SettingValue m_storeProxyHostnameLookupEnabled; }; } diff --git a/src/gui/optionsdialog.cpp b/src/gui/optionsdialog.cpp index 2dfaf344f..96b0817d8 100644 --- a/src/gui/optionsdialog.cpp +++ b/src/gui/optionsdialog.cpp @@ -782,10 +782,10 @@ void OptionsDialog::loadConnectionTabOptions() m_ui->checkProxyAuth->setChecked(proxyConf.authEnabled); m_ui->textProxyUsername->setText(proxyConf.username); m_ui->textProxyPassword->setText(proxyConf.password); + m_ui->checkProxyHostnameLookup->setChecked(proxyConf.hostnameLookupEnabled); m_ui->checkProxyBitTorrent->setChecked(Preferences::instance()->useProxyForBT()); m_ui->checkProxyPeerConnections->setChecked(session->isProxyPeerConnectionsEnabled()); - m_ui->checkProxyHostnameLookup->setChecked(session->isProxyHostnameLookupEnabled()); m_ui->checkProxyRSS->setChecked(Preferences::instance()->useProxyForRSS()); m_ui->checkProxyMisc->setChecked(Preferences::instance()->useProxyForGeneralPurposes()); @@ -856,6 +856,7 @@ void OptionsDialog::saveConnectionTabOptions() const proxyConf.authEnabled = m_ui->checkProxyAuth->isChecked(); proxyConf.username = getProxyUsername(); proxyConf.password = getProxyPassword(); + proxyConf.hostnameLookupEnabled = m_ui->checkProxyHostnameLookup->isChecked(); proxyConfigManager->setProxyConfiguration(proxyConf); Preferences::instance()->setUseProxyForBT(m_ui->checkProxyBitTorrent->isChecked()); @@ -863,7 +864,6 @@ void OptionsDialog::saveConnectionTabOptions() const Preferences::instance()->setUseProxyForGeneralPurposes(m_ui->checkProxyMisc->isChecked()); session->setProxyPeerConnectionsEnabled(m_ui->checkProxyPeerConnections->isChecked()); - session->setProxyHostnameLookupEnabled(m_ui->checkProxyHostnameLookup->isChecked()); // IPFilter session->setIPFilteringEnabled(isIPFilteringEnabled()); @@ -1507,7 +1507,7 @@ void OptionsDialog::adjustProxyOptions() // SOCKS5 or HTTP m_ui->labelProxyTypeIncompatible->setVisible(false); - m_ui->checkProxyHostnameLookup->setEnabled(m_ui->checkProxyBitTorrent->isChecked()); + m_ui->checkProxyHostnameLookup->setEnabled(true); m_ui->checkProxyRSS->setEnabled(true); m_ui->checkProxyMisc->setEnabled(true); } diff --git a/src/gui/optionsdialog.ui b/src/gui/optionsdialog.ui index 62625686d..9260af724 100644 --- a/src/gui/optionsdialog.ui +++ b/src/gui/optionsdialog.ui @@ -1835,17 +1835,27 @@ readme[0-9].txt: filter 'readme1.txt', 'readme2.txt' but not 'readme10.txt'. - - - - true - - - - Some options are incompatible with the chosen proxy type! - - - + + + + true + + + + Some options are incompatible with the chosen proxy type! + + + + + + + If checked, hostname lookups are done via the proxy + + + Use proxy for hostname lookups + + + @@ -1921,16 +1931,6 @@ readme[0-9].txt: filter 'readme1.txt', 'readme2.txt' but not 'readme10.txt'. - - - - If checked, hostname lookups are done via the proxy - - - Use proxy for hostname lookups - - - @@ -3716,12 +3716,12 @@ Use ';' to split multiple entries. Can use wildcard '*'. comboProxyType textProxyIP spinProxyPort + checkProxyHostnameLookup checkProxyAuth textProxyUsername textProxyPassword checkProxyBitTorrent checkProxyPeerConnections - checkProxyHostnameLookup checkProxyRSS checkProxyMisc checkIPFilter diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index 0fdfff096..889689876 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -200,10 +200,10 @@ void AppController::preferencesAction() data[u"proxy_auth_enabled"_qs] = proxyConf.authEnabled; data[u"proxy_username"_qs] = proxyConf.username; data[u"proxy_password"_qs] = proxyConf.password; + data[u"proxy_hostname_lookup"_qs] = proxyConf.hostnameLookupEnabled; data[u"proxy_bittorrent"_qs] = pref->useProxyForBT(); data[u"proxy_peer_connections"_qs] = session->isProxyPeerConnectionsEnabled(); - data[u"proxy_hostname_lookup"_qs] = session->isProxyHostnameLookupEnabled(); data[u"proxy_rss"_qs] = pref->useProxyForRSS(); data[u"proxy_misc"_qs] = pref->useProxyForGeneralPurposes(); @@ -623,14 +623,14 @@ void AppController::setPreferencesAction() proxyConf.username = it.value().toString(); if (hasKey(u"proxy_password"_qs)) proxyConf.password = it.value().toString(); + if (hasKey(u"proxy_hostname_lookup"_qs)) + proxyConf.hostnameLookupEnabled = it.value().toBool(); proxyManager->setProxyConfiguration(proxyConf); if (hasKey(u"proxy_bittorrent"_qs)) pref->setUseProxyForBT(it.value().toBool()); if (hasKey(u"proxy_peer_connections"_qs)) session->setProxyPeerConnectionsEnabled(it.value().toBool()); - if (hasKey(u"proxy_hostname_lookup"_qs)) - session->setProxyHostnameLookupEnabled(it.value().toBool()); if (hasKey(u"proxy_rss"_qs)) pref->setUseProxyForRSS(it.value().toBool()); if (hasKey(u"proxy_misc"_qs)) diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index 5bf0ec1c2..cc9648e63 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -370,6 +370,11 @@ +
+ + +
+
@@ -407,10 +412,6 @@ -
- - -
@@ -1591,7 +1592,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD $('peer_proxy_auth_checkbox').setProperty('disabled', isProxySocks4); $('use_peer_proxy_checkbox').setProperty('disabled', !$('proxy_bittorrent_checkbox').getProperty('checked')); - $('proxyHostnameLookupCheckbox').setProperty('disabled', isProxySocks4 || !$('proxy_bittorrent_checkbox').getProperty('checked')); + $('proxyHostnameLookupCheckbox').setProperty('disabled', isProxySocks4); $('proxy_rss_checkbox').setProperty('disabled', isProxySocks4); $('proxy_misc_checkbox').setProperty('disabled', isProxySocks4); @@ -1952,14 +1953,14 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD $('peer_proxy_type_select').setProperty('value', pref.proxy_type); $('peer_proxy_host_text').setProperty('value', pref.proxy_ip); $('peer_proxy_port_value').setProperty('value', pref.proxy_port); - $('use_peer_proxy_checkbox').setProperty('checked', pref.proxy_peer_connections); + $('peer_proxy_auth_checkbox').setProperty('checked', pref.proxy_auth_enabled); + $('peer_proxy_username_text').setProperty('value', pref.proxy_username); + $('peer_proxy_password_text').setProperty('value', pref.proxy_password); $('proxyHostnameLookupCheckbox').setProperty('checked', pref.proxy_hostname_lookup); $('proxy_bittorrent_checkbox').setProperty('checked', pref.proxy_bittorrent); + $('use_peer_proxy_checkbox').setProperty('checked', pref.proxy_peer_connections); $('proxy_rss_checkbox').setProperty('checked', pref.proxy_rss); $('proxy_misc_checkbox').setProperty('checked', pref.proxy_misc); - $('peer_proxy_auth_checkbox').setProperty('checked', pref.proxy_auth_enabled); - $('peer_proxy_username_text').setProperty('value', pref.proxy_username); - $('peer_proxy_password_text').setProperty('value', pref.proxy_password); updatePeerProxySettings(); // IP Filtering @@ -2283,9 +2284,9 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD settings.set('proxy_auth_enabled', $('peer_proxy_auth_checkbox').getProperty('checked')); settings.set('proxy_username', $('peer_proxy_username_text').getProperty('value')); settings.set('proxy_password', $('peer_proxy_password_text').getProperty('value')); + settings.set('proxy_hostname_lookup', $('proxyHostnameLookupCheckbox').getProperty('checked')); settings.set('proxy_bittorrent', $('proxy_bittorrent_checkbox').getProperty('checked')); settings.set('proxy_peer_connections', $('use_peer_proxy_checkbox').getProperty('checked')); - settings.set('proxy_hostname_lookup', $('proxyHostnameLookupCheckbox').getProperty('checked')); settings.set('proxy_rss', $('proxy_rss_checkbox').getProperty('checked')); settings.set('proxy_misc', $('proxy_misc_checkbox').getProperty('checked'));