From 1757973f88f6f467b45e70ebf5ec185c9bc75ee9 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Sun, 30 Oct 2016 00:11:52 +0300 Subject: [PATCH] Misc fixes. --- src/base/bittorrent/session.cpp | 24 +++++++++++----------- src/base/net/portforwarder.cpp | 4 +++- src/base/net/proxyconfigurationmanager.cpp | 7 +++++-- src/base/settingsstorage.cpp | 2 +- src/gui/advancedsettings.cpp | 2 +- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 683e95fa4..40b8cd28d 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -90,9 +90,9 @@ #include "tracker.h" #include "trackerentry.h" -const char PEER_ID[] = "qB"; -const char RESUME_FOLDER[] = "BT_backup"; -const char USER_AGENT[] = "qBittorrent " VERSION; +static const char PEER_ID[] = "qB"; +static const char RESUME_FOLDER[] = "BT_backup"; +static const char USER_AGENT[] = "qBittorrent " VERSION; namespace libt = libtorrent; using namespace BitTorrent; @@ -416,7 +416,6 @@ Session::Session(QObject *parent) .arg(encryption() == 0 ? tr("ON") : encryption() == 1 ? tr("FORCED") : tr("OFF")) , Log::INFO); - m_nativeSession->set_ip_filter({}); if (isIPFilteringEnabled()) enableIPFilter(); // Add the banned IPs @@ -901,7 +900,7 @@ void Session::adjustLimits() adjustLimits(sessionSettings); m_nativeSession->set_settings(sessionSettings); #else - libt::settings_pack settingsPack; + libt::settings_pack settingsPack = m_nativeSession->get_settings(); adjustLimits(settingsPack); m_nativeSession->apply_settings(settingsPack); #endif @@ -917,7 +916,7 @@ void Session::configure() configure(sessionSettings); m_nativeSession->set_settings(sessionSettings); #else - libt::settings_pack settingsPack; + libt::settings_pack settingsPack = m_nativeSession->get_settings(); configure(settingsPack); m_nativeSession->apply_settings(settingsPack); #endif @@ -942,7 +941,8 @@ void Session::processBannedIPs() boost::system::error_code ec; libt::address addr = libt::address::from_string(ip.toLatin1().constData(), ec); Q_ASSERT(!ec); - filter.add_rule(addr, addr, libt::ip_filter::blocked); + if (!ec) + filter.add_rule(addr, addr, libt::ip_filter::blocked); } m_nativeSession->set_ip_filter(filter); @@ -1206,7 +1206,7 @@ void Session::configure(libtorrent::session_settings &sessionSettings) sessionSettings.announce_to_all_trackers = announceToAll; sessionSettings.announce_to_all_tiers = announceToAll; int cacheSize = diskCacheSize(); - sessionSettings.cache_size = cacheSize ? cacheSize * 64 : -1; + sessionSettings.cache_size = (cacheSize > 0) ? cacheSize * 64 : -1; sessionSettings.cache_expiry = diskCacheTTL(); qDebug() << "Using a disk cache size of" << cacheSize << "MiB"; libt::session_settings::io_buffer_mode_t mode = useOSCache() ? libt::session_settings::enable_os_cache @@ -1254,10 +1254,9 @@ void Session::configure(libtorrent::session_settings &sessionSettings) sessionSettings.enable_outgoing_utp = isUTPEnabled(); // uTP rate limiting sessionSettings.rate_limit_utp = isUTPRateLimited(); - if (sessionSettings.rate_limit_utp) - sessionSettings.mixed_mode_algorithm = libt::session_settings::prefer_tcp; - else - sessionSettings.mixed_mode_algorithm = libt::session_settings::peer_proportional; + sessionSettings.mixed_mode_algorithm = isUTPRateLimited() + ? libt::session_settings::prefer_tcp + : libt::session_settings::peer_proportional; sessionSettings.apply_ip_filter_to_trackers = isTrackerFilteringEnabled(); @@ -1402,6 +1401,7 @@ void Session::banIP(const QString &ip) boost::system::error_code ec; libt::address addr = libt::address::from_string(ip.toLatin1().constData(), ec); Q_ASSERT(!ec); + if (ec) return; filter.add_rule(addr, addr, libt::ip_filter::blocked); m_nativeSession->set_ip_filter(filter); diff --git a/src/base/net/portforwarder.cpp b/src/base/net/portforwarder.cpp index 5dfc757a4..3b7dd5ebc 100644 --- a/src/base/net/portforwarder.cpp +++ b/src/base/net/portforwarder.cpp @@ -36,7 +36,7 @@ #include "base/logger.h" #include "base/settingsstorage.h" -const QString KEY_ENABLED = QLatin1String("Network/PortForwardingEnabled"); +static const QString KEY_ENABLED = QLatin1String("Network/PortForwardingEnabled"); namespace libt = libtorrent; using namespace Net; @@ -86,6 +86,8 @@ void PortForwarder::setEnabled(bool enabled) start(); else stop(); + + SettingsStorage::instance()->storeValue(KEY_ENABLED, enabled); } } diff --git a/src/base/net/proxyconfigurationmanager.cpp b/src/base/net/proxyconfigurationmanager.cpp index 0dba21fe2..c750b11cf 100644 --- a/src/base/net/proxyconfigurationmanager.cpp +++ b/src/base/net/proxyconfigurationmanager.cpp @@ -34,7 +34,6 @@ const QString KEY_DISABLED = SETTINGS_KEY("Disabled"); const QString KEY_TYPE = SETTINGS_KEY("Type"); const QString KEY_IP = SETTINGS_KEY("IP"); const QString KEY_PORT = SETTINGS_KEY("Port"); -const QString KEY_AUTHENTICATION = SETTINGS_KEY("Authentication"); const QString KEY_USERNAME = SETTINGS_KEY("Username"); const QString KEY_PASSWORD = SETTINGS_KEY("Password"); @@ -68,6 +67,7 @@ ProxyConfigurationManager::ProxyConfigurationManager(QObject *parent) m_config.port = static_cast(settings()->loadValue(KEY_PORT, 8080).toUInt()); m_config.username = settings()->loadValue(KEY_USERNAME).toString(); m_config.password = settings()->loadValue(KEY_PASSWORD).toString(); + configureProxy(); } void ProxyConfigurationManager::initInstance() @@ -78,7 +78,10 @@ void ProxyConfigurationManager::initInstance() void ProxyConfigurationManager::freeInstance() { - delete m_instance; + if (m_instance) { + delete m_instance; + m_instance = 0; + } } ProxyConfigurationManager *ProxyConfigurationManager::instance() diff --git a/src/base/settingsstorage.cpp b/src/base/settingsstorage.cpp index 8f8a6afeb..d927fc66e 100644 --- a/src/base/settingsstorage.cpp +++ b/src/base/settingsstorage.cpp @@ -155,7 +155,7 @@ namespace {"BitTorrent/Session/MaxHalfOpenConnections", "Preferences/Connection/MaxHalfOpenConnec"}, {"BitTorrent/Session/uTPEnabled", "Preferences/Bittorrent/uTP"}, {"BitTorrent/Session/uTPRateLimited", "Preferences/Bittorrent/uTP_rate_limited"}, - {"BitTorrent/TrackerEnabled", "Preferences/TrackerEnabled"}, + {"BitTorrent/TrackerEnabled", "Preferences/Advanced/trackerEnabled"}, {"Network/Proxy/Disabled", "Preferences/Connection/ProxyOnlyForTorrents"}, {"Network/Proxy/Type", "Preferences/Connection/ProxyType"}, {"Network/Proxy/Authentication", "Preferences/Connection/Proxy/Authentication"}, diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index 05cb5cb5a..c0a359b06 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -236,7 +236,7 @@ void AdvancedSettings::updateInterfaceAddressCombo() void AdvancedSettings::loadAdvancedSettings() { const Preferences* const pref = Preferences::instance(); - BitTorrent::Session *const session = BitTorrent::Session::instance(); + const BitTorrent::Session *const session = BitTorrent::Session::instance(); // add section headers QFont boldFont;