mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-04 06:32:29 -06:00
Merge pull request #18528 from glassez/proxy
Allow to use proxy per subsystem
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -42,7 +42,10 @@
|
||||
#include <iphlpapi.h>
|
||||
#endif
|
||||
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
|
||||
#include <libtorrent/add_torrent_params.hpp>
|
||||
#include <libtorrent/address.hpp>
|
||||
#include <libtorrent/alert_types.hpp>
|
||||
#include <libtorrent/error_code.hpp>
|
||||
#include <libtorrent/extensions/smart_ban.hpp>
|
||||
@@ -495,7 +498,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
|
||||
@@ -1629,44 +1631,47 @@ lt::settings_pack SessionImpl::loadLTSettings() const
|
||||
settingsPack.set_int(lt::settings_pack::active_checking, maxActiveCheckingTorrents());
|
||||
|
||||
// proxy
|
||||
const auto proxyManager = Net::ProxyConfigurationManager::instance();
|
||||
const Net::ProxyConfiguration proxyConfig = proxyManager->proxyConfiguration();
|
||||
|
||||
switch (proxyConfig.type)
|
||||
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::none);
|
||||
if (Preferences::instance()->useProxyForBT())
|
||||
{
|
||||
case Net::ProxyType::HTTP:
|
||||
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::http);
|
||||
break;
|
||||
case Net::ProxyType::HTTP_PW:
|
||||
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::http_pw);
|
||||
break;
|
||||
case Net::ProxyType::SOCKS4:
|
||||
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::socks4);
|
||||
break;
|
||||
case Net::ProxyType::SOCKS5:
|
||||
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::socks5);
|
||||
break;
|
||||
case Net::ProxyType::SOCKS5_PW:
|
||||
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::socks5_pw);
|
||||
break;
|
||||
case Net::ProxyType::None:
|
||||
default:
|
||||
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::none);
|
||||
}
|
||||
const auto proxyManager = Net::ProxyConfigurationManager::instance();
|
||||
const Net::ProxyConfiguration proxyConfig = proxyManager->proxyConfiguration();
|
||||
|
||||
switch (proxyConfig.type)
|
||||
{
|
||||
case Net::ProxyType::SOCKS4:
|
||||
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::socks4);
|
||||
break;
|
||||
|
||||
case Net::ProxyType::HTTP:
|
||||
if (proxyConfig.authEnabled)
|
||||
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::http_pw);
|
||||
else
|
||||
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::http);
|
||||
break;
|
||||
|
||||
case Net::ProxyType::SOCKS5:
|
||||
if (proxyConfig.authEnabled)
|
||||
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::socks5_pw);
|
||||
else
|
||||
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::socks5);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (proxyConfig.type != Net::ProxyType::None)
|
||||
{
|
||||
settingsPack.set_str(lt::settings_pack::proxy_hostname, proxyConfig.ip.toStdString());
|
||||
settingsPack.set_int(lt::settings_pack::proxy_port, proxyConfig.port);
|
||||
|
||||
if (proxyManager->isAuthenticationRequired())
|
||||
if (proxyConfig.authEnabled)
|
||||
{
|
||||
settingsPack.set_str(lt::settings_pack::proxy_username, proxyConfig.username.toStdString());
|
||||
settingsPack.set_str(lt::settings_pack::proxy_password, proxyConfig.password.toStdString());
|
||||
}
|
||||
|
||||
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());
|
||||
@@ -2493,7 +2498,7 @@ bool SessionImpl::addTorrent(const QString &source, const AddTorrentParams ¶
|
||||
LogMsg(tr("Downloading torrent, please wait... Source: \"%1\"").arg(source));
|
||||
// Launch downloader
|
||||
Net::DownloadManager::instance()->download(Net::DownloadRequest(source).limit(MAX_TORRENT_SIZE)
|
||||
, this, &SessionImpl::handleDownloadFinished);
|
||||
, Preferences::instance()->useProxyForGeneralPurposes(), this, &SessionImpl::handleDownloadFinished);
|
||||
m_downloadedTorrents[source] = params;
|
||||
return true;
|
||||
}
|
||||
@@ -3542,20 +3547,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;
|
||||
@@ -5791,8 +5782,12 @@ void SessionImpl::handleSocks5Alert(const lt::socks5_alert *p) const
|
||||
{
|
||||
if (p->error)
|
||||
{
|
||||
LogMsg(tr("SOCKS5 proxy error. Message: \"%1\"").arg(QString::fromStdString(p->message()))
|
||||
, Log::WARNING);
|
||||
const auto addr = p->ip.address();
|
||||
const QString endpoint = (addr.is_v6() ? u"[%1]:%2"_qs : u"%1:%2"_qs)
|
||||
.arg(QString::fromStdString(addr.to_string()), QString::number(p->ip.port()));
|
||||
LogMsg(tr("SOCKS5 proxy error. Address: %1. Message: \"%2\".")
|
||||
.arg(endpoint, QString::fromLocal8Bit(p->error.message().c_str()))
|
||||
, Log::WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<int> m_encryption;
|
||||
CachedSettingValue<int> m_maxActiveCheckingTorrents;
|
||||
CachedSettingValue<bool> m_isProxyPeerConnectionsEnabled;
|
||||
CachedSettingValue<bool> m_isProxyHostnameLookupEnabled;
|
||||
CachedSettingValue<ChokingAlgorithm> m_chokingAlgorithm;
|
||||
CachedSettingValue<SeedChokingAlgorithm> m_seedChokingAlgorithm;
|
||||
CachedSettingValue<QStringList> m_storedTags;
|
||||
|
||||
Reference in New Issue
Block a user