|
|
|
@ -30,7 +30,6 @@
@@ -30,7 +30,6 @@
|
|
|
|
|
#include "session.h" |
|
|
|
|
|
|
|
|
|
#include <algorithm> |
|
|
|
|
#include <cstdlib> |
|
|
|
|
#include <queue> |
|
|
|
|
#include <string> |
|
|
|
|
#include <utility> |
|
|
|
@ -42,8 +41,10 @@
@@ -42,8 +41,10 @@
|
|
|
|
|
|
|
|
|
|
#include <QDebug> |
|
|
|
|
#include <QDir> |
|
|
|
|
#include <QFile> |
|
|
|
|
#include <QHostAddress> |
|
|
|
|
#include <QNetworkAddressEntry> |
|
|
|
|
#include <QNetworkConfigurationManager> |
|
|
|
|
#include <QNetworkInterface> |
|
|
|
|
#include <QRegularExpression> |
|
|
|
|
#include <QString> |
|
|
|
@ -243,9 +244,6 @@ Session *Session::m_instance = nullptr;
@@ -243,9 +244,6 @@ Session *Session::m_instance = nullptr;
|
|
|
|
|
|
|
|
|
|
Session::Session(QObject *parent) |
|
|
|
|
: QObject(parent) |
|
|
|
|
, m_deferredConfigureScheduled(false) |
|
|
|
|
, m_IPFilteringChanged(false) |
|
|
|
|
, m_listenInterfaceChanged(true) |
|
|
|
|
, m_isDHTEnabled(BITTORRENT_SESSION_KEY("DHTEnabled"), true) |
|
|
|
|
, m_isLSDEnabled(BITTORRENT_SESSION_KEY("LSDEnabled"), true) |
|
|
|
|
, m_isPeXEnabled(BITTORRENT_SESSION_KEY("PeXEnabled"), true) |
|
|
|
@ -346,10 +344,14 @@ Session::Session(QObject *parent)
@@ -346,10 +344,14 @@ Session::Session(QObject *parent)
|
|
|
|
|
return tmp; |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
, m_wasPexEnabled(m_isPeXEnabled) |
|
|
|
|
, m_numResumeData(0) |
|
|
|
|
, m_extraLimit(0) |
|
|
|
|
, m_recentErroredTorrentsTimer(new QTimer(this)) |
|
|
|
|
, m_resumeFolderLock {new QFile {this}} |
|
|
|
|
, m_refreshTimer {new QTimer {this}} |
|
|
|
|
, m_seedingLimitTimer {new QTimer {this}} |
|
|
|
|
, m_resumeDataTimer {new QTimer {this}} |
|
|
|
|
, m_statistics {new Statistics {this}} |
|
|
|
|
, m_ioThread {new QThread {this}} |
|
|
|
|
, m_recentErroredTorrentsTimer {new QTimer {this}} |
|
|
|
|
, m_networkManager {new QNetworkConfigurationManager {this}} |
|
|
|
|
{ |
|
|
|
|
if (port() < 0) |
|
|
|
|
m_port = Utils::Random::rand(1024, 65535); |
|
|
|
@ -358,97 +360,18 @@ Session::Session(QObject *parent)
@@ -358,97 +360,18 @@ Session::Session(QObject *parent)
|
|
|
|
|
|
|
|
|
|
m_recentErroredTorrentsTimer->setSingleShot(true); |
|
|
|
|
m_recentErroredTorrentsTimer->setInterval(1000); |
|
|
|
|
connect(m_recentErroredTorrentsTimer, &QTimer::timeout, this, [this]() { m_recentErroredTorrents.clear(); }); |
|
|
|
|
connect(m_recentErroredTorrentsTimer, &QTimer::timeout |
|
|
|
|
, this, [this]() { m_recentErroredTorrents.clear(); }); |
|
|
|
|
|
|
|
|
|
m_seedingLimitTimer = new QTimer(this); |
|
|
|
|
m_seedingLimitTimer->setInterval(10000); |
|
|
|
|
connect(m_seedingLimitTimer, &QTimer::timeout, this, &Session::processShareLimits); |
|
|
|
|
|
|
|
|
|
// Set severity level of libtorrent session
|
|
|
|
|
const LTAlertCategory alertMask = lt::alert::error_notification |
|
|
|
|
| lt::alert::peer_notification |
|
|
|
|
| lt::alert::port_mapping_notification |
|
|
|
|
| lt::alert::storage_notification |
|
|
|
|
| lt::alert::tracker_notification |
|
|
|
|
| lt::alert::status_notification |
|
|
|
|
| lt::alert::ip_block_notification |
|
|
|
|
| lt::alert::performance_warning |
|
|
|
|
| lt::alert::file_progress_notification; |
|
|
|
|
|
|
|
|
|
const std::string peerId = lt::generate_fingerprint(PEER_ID, QBT_VERSION_MAJOR, QBT_VERSION_MINOR, QBT_VERSION_BUGFIX, QBT_VERSION_BUILD); |
|
|
|
|
lt::settings_pack pack; |
|
|
|
|
pack.set_int(lt::settings_pack::alert_mask, alertMask); |
|
|
|
|
pack.set_str(lt::settings_pack::peer_fingerprint, peerId); |
|
|
|
|
pack.set_bool(lt::settings_pack::listen_system_port_fallback, false); |
|
|
|
|
pack.set_str(lt::settings_pack::user_agent, USER_AGENT); |
|
|
|
|
pack.set_bool(lt::settings_pack::use_dht_as_fallback, false); |
|
|
|
|
// Speed up exit
|
|
|
|
|
pack.set_int(lt::settings_pack::stop_tracker_timeout, 1); |
|
|
|
|
pack.set_int(lt::settings_pack::auto_scrape_interval, 1200); // 20 minutes
|
|
|
|
|
pack.set_int(lt::settings_pack::auto_scrape_min_interval, 900); // 15 minutes
|
|
|
|
|
pack.set_int(lt::settings_pack::connection_speed, 20); // default is 10
|
|
|
|
|
pack.set_bool(lt::settings_pack::no_connect_privileged_ports, false); |
|
|
|
|
// libtorrent 1.1 enables UPnP & NAT-PMP by default
|
|
|
|
|
// turn them off before `lt::session` ctor to avoid split second effects
|
|
|
|
|
pack.set_bool(lt::settings_pack::enable_upnp, false); |
|
|
|
|
pack.set_bool(lt::settings_pack::enable_natpmp, false); |
|
|
|
|
pack.set_bool(lt::settings_pack::upnp_ignore_nonrouters, true); |
|
|
|
|
|
|
|
|
|
#if (LIBTORRENT_VERSION_NUM < 10200) |
|
|
|
|
// Disable support for SSL torrents for now
|
|
|
|
|
pack.set_int(lt::settings_pack::ssl_listen, 0); |
|
|
|
|
// To prevent ISPs from blocking seeding
|
|
|
|
|
pack.set_bool(lt::settings_pack::lazy_bitfields, true); |
|
|
|
|
// Disk cache pool is rarely tested in libtorrent and doesn't free buffers
|
|
|
|
|
// Soon to be deprecated there
|
|
|
|
|
// More info: https://github.com/arvidn/libtorrent/issues/2251
|
|
|
|
|
pack.set_bool(lt::settings_pack::use_disk_cache_pool, false); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
configure(pack); |
|
|
|
|
|
|
|
|
|
m_nativeSession = new lt::session {pack, LTSessionFlags {0}}; |
|
|
|
|
m_nativeSession->set_alert_notify([this]() |
|
|
|
|
{ |
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) |
|
|
|
|
QMetaObject::invokeMethod(this, &Session::readAlerts, Qt::QueuedConnection); |
|
|
|
|
#else |
|
|
|
|
QMetaObject::invokeMethod(this, "readAlerts", Qt::QueuedConnection); |
|
|
|
|
#endif |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
configurePeerClasses(); |
|
|
|
|
|
|
|
|
|
// Enabling plugins
|
|
|
|
|
//m_nativeSession->add_extension(<::create_metadata_plugin);
|
|
|
|
|
m_nativeSession->add_extension(<::create_ut_metadata_plugin); |
|
|
|
|
if (isPeXEnabled()) |
|
|
|
|
m_nativeSession->add_extension(<::create_ut_pex_plugin); |
|
|
|
|
m_nativeSession->add_extension(<::create_smart_ban_plugin); |
|
|
|
|
|
|
|
|
|
LogMsg(tr("Peer ID: ") + QString::fromStdString(peerId)); |
|
|
|
|
LogMsg(tr("HTTP User-Agent is '%1'").arg(USER_AGENT)); |
|
|
|
|
LogMsg(tr("DHT support [%1]").arg(isDHTEnabled() ? tr("ON") : tr("OFF")), Log::INFO); |
|
|
|
|
LogMsg(tr("Local Peer Discovery support [%1]").arg(isLSDEnabled() ? tr("ON") : tr("OFF")), Log::INFO); |
|
|
|
|
LogMsg(tr("PeX support [%1]").arg(isPeXEnabled() ? tr("ON") : tr("OFF")), Log::INFO); |
|
|
|
|
LogMsg(tr("Anonymous mode [%1]").arg(isAnonymousModeEnabled() ? tr("ON") : tr("OFF")), Log::INFO); |
|
|
|
|
LogMsg(tr("Encryption support [%1]").arg((encryption() == 0) ? tr("ON") : |
|
|
|
|
((encryption() == 1) ? tr("FORCED") : tr("OFF"))), Log::INFO); |
|
|
|
|
initializeNativeSession(); |
|
|
|
|
configureComponents(); |
|
|
|
|
|
|
|
|
|
if (isBandwidthSchedulerEnabled()) |
|
|
|
|
enableBandwidthScheduler(); |
|
|
|
|
|
|
|
|
|
if (isIPFilteringEnabled()) { |
|
|
|
|
// Manually banned IPs are handled in that function too(in the slots)
|
|
|
|
|
enableIPFilter(); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
// Add the banned IPs
|
|
|
|
|
lt::ip_filter filter; |
|
|
|
|
processBannedIPs(filter); |
|
|
|
|
m_nativeSession->set_ip_filter(filter); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
m_categories = map_cast(m_storedCategories); |
|
|
|
|
if (isSubcategoriesEnabled()) { |
|
|
|
|
// if subcategories support changed manually
|
|
|
|
@ -458,35 +381,31 @@ Session::Session(QObject *parent)
@@ -458,35 +381,31 @@ Session::Session(QObject *parent)
|
|
|
|
|
|
|
|
|
|
m_tags = QSet<QString>::fromList(m_storedTags.value()); |
|
|
|
|
|
|
|
|
|
m_refreshTimer = new QTimer(this); |
|
|
|
|
m_refreshTimer->setInterval(refreshInterval()); |
|
|
|
|
connect(m_refreshTimer, &QTimer::timeout, this, &Session::refresh); |
|
|
|
|
m_refreshTimer->start(); |
|
|
|
|
|
|
|
|
|
m_statistics = new Statistics(this); |
|
|
|
|
|
|
|
|
|
updateSeedingLimitTimer(); |
|
|
|
|
populateAdditionalTrackers(); |
|
|
|
|
|
|
|
|
|
enableTracker(isTrackerEnabled()); |
|
|
|
|
|
|
|
|
|
connect(Net::ProxyConfigurationManager::instance(), &Net::ProxyConfigurationManager::proxyConfigurationChanged |
|
|
|
|
connect(Net::ProxyConfigurationManager::instance() |
|
|
|
|
, &Net::ProxyConfigurationManager::proxyConfigurationChanged |
|
|
|
|
, this, &Session::configureDeferred); |
|
|
|
|
|
|
|
|
|
// Network configuration monitor
|
|
|
|
|
connect(&m_networkManager, &QNetworkConfigurationManager::onlineStateChanged, this, &Session::networkOnlineStateChanged); |
|
|
|
|
connect(&m_networkManager, &QNetworkConfigurationManager::configurationAdded, this, &Session::networkConfigurationChange); |
|
|
|
|
connect(&m_networkManager, &QNetworkConfigurationManager::configurationRemoved, this, &Session::networkConfigurationChange); |
|
|
|
|
connect(&m_networkManager, &QNetworkConfigurationManager::configurationChanged, this, &Session::networkConfigurationChange); |
|
|
|
|
connect(m_networkManager, &QNetworkConfigurationManager::onlineStateChanged, this, &Session::networkOnlineStateChanged); |
|
|
|
|
connect(m_networkManager, &QNetworkConfigurationManager::configurationAdded, this, &Session::networkConfigurationChange); |
|
|
|
|
connect(m_networkManager, &QNetworkConfigurationManager::configurationRemoved, this, &Session::networkConfigurationChange); |
|
|
|
|
connect(m_networkManager, &QNetworkConfigurationManager::configurationChanged, this, &Session::networkConfigurationChange); |
|
|
|
|
|
|
|
|
|
m_ioThread = new QThread(this); |
|
|
|
|
m_resumeDataSavingManager = new ResumeDataSavingManager {m_resumeFolderPath}; |
|
|
|
|
m_resumeDataSavingManager->moveToThread(m_ioThread); |
|
|
|
|
connect(m_ioThread, &QThread::finished, m_resumeDataSavingManager, &QObject::deleteLater); |
|
|
|
|
m_ioThread->start(); |
|
|
|
|
|
|
|
|
|
// Regular saving of fastresume data
|
|
|
|
|
m_resumeDataTimer = new QTimer(this); |
|
|
|
|
connect(m_resumeDataTimer, &QTimer::timeout, this, [this]() { generateResumeData(); }); |
|
|
|
|
const uint saveInterval = saveResumeDataInterval(); |
|
|
|
|
if (saveInterval > 0) { |
|
|
|
@ -498,8 +417,6 @@ Session::Session(QObject *parent)
@@ -498,8 +417,6 @@ Session::Session(QObject *parent)
|
|
|
|
|
new PortForwarderImpl {m_nativeSession}; |
|
|
|
|
|
|
|
|
|
initMetrics(); |
|
|
|
|
|
|
|
|
|
qDebug("* BitTorrent Session constructed"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool Session::isDHTEnabled() const |
|
|
|
@ -667,7 +584,7 @@ QStringList Session::expandCategory(const QString &category)
@@ -667,7 +584,7 @@ QStringList Session::expandCategory(const QString &category)
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const QStringMap &Session::categories() const |
|
|
|
|
QStringMap Session::categories() const |
|
|
|
|
{ |
|
|
|
|
return m_categories; |
|
|
|
|
} |
|
|
|
@ -948,8 +865,8 @@ Session::~Session()
@@ -948,8 +865,8 @@ Session::~Session()
|
|
|
|
|
m_ioThread->quit(); |
|
|
|
|
m_ioThread->wait(); |
|
|
|
|
|
|
|
|
|
m_resumeFolderLock.close(); |
|
|
|
|
m_resumeFolderLock.remove(); |
|
|
|
|
m_resumeFolderLock->close(); |
|
|
|
|
m_resumeFolderLock->remove(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Session::initInstance() |
|
|
|
@ -987,25 +904,102 @@ void Session::applyBandwidthLimits()
@@ -987,25 +904,102 @@ void Session::applyBandwidthLimits()
|
|
|
|
|
m_nativeSession->apply_settings(settingsPack); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Set BitTorrent session configuration
|
|
|
|
|
void Session::configure() |
|
|
|
|
{ |
|
|
|
|
qDebug("Configuring session"); |
|
|
|
|
lt::settings_pack settingsPack = m_nativeSession->get_settings(); |
|
|
|
|
configure(settingsPack); |
|
|
|
|
loadLTSettings(settingsPack); |
|
|
|
|
m_nativeSession->apply_settings(settingsPack); |
|
|
|
|
|
|
|
|
|
configureComponents(); |
|
|
|
|
|
|
|
|
|
m_deferredConfigureScheduled = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Session::configureComponents() |
|
|
|
|
{ |
|
|
|
|
// This function contains components/actions that:
|
|
|
|
|
// 1. Need to be setup at start up
|
|
|
|
|
// 2. When deferred configure is called
|
|
|
|
|
|
|
|
|
|
configurePeerClasses(); |
|
|
|
|
|
|
|
|
|
if (m_IPFilteringChanged) { |
|
|
|
|
if (!m_IPFilteringConfigured) { |
|
|
|
|
if (isIPFilteringEnabled()) |
|
|
|
|
enableIPFilter(); |
|
|
|
|
else |
|
|
|
|
disableIPFilter(); |
|
|
|
|
m_IPFilteringChanged = false; |
|
|
|
|
m_IPFilteringConfigured = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
m_deferredConfigureScheduled = false; |
|
|
|
|
qDebug("Session configured"); |
|
|
|
|
void Session::initializeNativeSession() |
|
|
|
|
{ |
|
|
|
|
const LTAlertCategory alertMask = lt::alert::error_notification |
|
|
|
|
| lt::alert::file_progress_notification |
|
|
|
|
| lt::alert::ip_block_notification |
|
|
|
|
| lt::alert::peer_notification |
|
|
|
|
| lt::alert::performance_warning |
|
|
|
|
| lt::alert::port_mapping_notification |
|
|
|
|
| lt::alert::status_notification |
|
|
|
|
| lt::alert::storage_notification |
|
|
|
|
| lt::alert::tracker_notification; |
|
|
|
|
const std::string peerId = lt::generate_fingerprint(PEER_ID, QBT_VERSION_MAJOR, QBT_VERSION_MINOR, QBT_VERSION_BUGFIX, QBT_VERSION_BUILD); |
|
|
|
|
|
|
|
|
|
lt::settings_pack pack; |
|
|
|
|
pack.set_int(lt::settings_pack::alert_mask, alertMask); |
|
|
|
|
pack.set_str(lt::settings_pack::peer_fingerprint, peerId); |
|
|
|
|
pack.set_bool(lt::settings_pack::listen_system_port_fallback, false); |
|
|
|
|
pack.set_str(lt::settings_pack::user_agent, USER_AGENT); |
|
|
|
|
pack.set_bool(lt::settings_pack::use_dht_as_fallback, false); |
|
|
|
|
// Speed up exit
|
|
|
|
|
pack.set_int(lt::settings_pack::stop_tracker_timeout, 1); |
|
|
|
|
pack.set_int(lt::settings_pack::auto_scrape_interval, 1200); // 20 minutes
|
|
|
|
|
pack.set_int(lt::settings_pack::auto_scrape_min_interval, 900); // 15 minutes
|
|
|
|
|
pack.set_int(lt::settings_pack::connection_speed, 20); // default is 10
|
|
|
|
|
pack.set_bool(lt::settings_pack::no_connect_privileged_ports, false); |
|
|
|
|
// libtorrent 1.1 enables UPnP & NAT-PMP by default
|
|
|
|
|
// turn them off before `lt::session` ctor to avoid split second effects
|
|
|
|
|
pack.set_bool(lt::settings_pack::enable_upnp, false); |
|
|
|
|
pack.set_bool(lt::settings_pack::enable_natpmp, false); |
|
|
|
|
pack.set_bool(lt::settings_pack::upnp_ignore_nonrouters, true); |
|
|
|
|
|
|
|
|
|
#if (LIBTORRENT_VERSION_NUM < 10200) |
|
|
|
|
// Disable support for SSL torrents for now
|
|
|
|
|
pack.set_int(lt::settings_pack::ssl_listen, 0); |
|
|
|
|
// To prevent ISPs from blocking seeding
|
|
|
|
|
pack.set_bool(lt::settings_pack::lazy_bitfields, true); |
|
|
|
|
// Disk cache pool is rarely tested in libtorrent and doesn't free buffers
|
|
|
|
|
// Soon to be deprecated there
|
|
|
|
|
// More info: https://github.com/arvidn/libtorrent/issues/2251
|
|
|
|
|
pack.set_bool(lt::settings_pack::use_disk_cache_pool, false); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
loadLTSettings(pack); |
|
|
|
|
m_nativeSession = new lt::session {pack, LTSessionFlags {0}}; |
|
|
|
|
|
|
|
|
|
LogMsg(tr("Peer ID: ") + QString::fromStdString(peerId)); |
|
|
|
|
LogMsg(tr("HTTP User-Agent is '%1'").arg(USER_AGENT)); |
|
|
|
|
LogMsg(tr("DHT support [%1]").arg(isDHTEnabled() ? tr("ON") : tr("OFF")), Log::INFO); |
|
|
|
|
LogMsg(tr("Local Peer Discovery support [%1]").arg(isLSDEnabled() ? tr("ON") : tr("OFF")), Log::INFO); |
|
|
|
|
LogMsg(tr("PeX support [%1]").arg(isPeXEnabled() ? tr("ON") : tr("OFF")), Log::INFO); |
|
|
|
|
LogMsg(tr("Anonymous mode [%1]").arg(isAnonymousModeEnabled() ? tr("ON") : tr("OFF")), Log::INFO); |
|
|
|
|
LogMsg(tr("Encryption support [%1]").arg((encryption() == 0) ? tr("ON") : |
|
|
|
|
((encryption() == 1) ? tr("FORCED") : tr("OFF"))), Log::INFO); |
|
|
|
|
|
|
|
|
|
m_nativeSession->set_alert_notify([this]() |
|
|
|
|
{ |
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) |
|
|
|
|
QMetaObject::invokeMethod(this, &Session::readAlerts, Qt::QueuedConnection); |
|
|
|
|
#else |
|
|
|
|
QMetaObject::invokeMethod(this, "readAlerts", Qt::QueuedConnection); |
|
|
|
|
#endif |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// Enabling plugins
|
|
|
|
|
m_nativeSession->add_extension(<::create_smart_ban_plugin); |
|
|
|
|
m_nativeSession->add_extension(<::create_ut_metadata_plugin); |
|
|
|
|
if (isPeXEnabled()) |
|
|
|
|
m_nativeSession->add_extension(<::create_ut_pex_plugin); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Session::processBannedIPs(lt::ip_filter &filter) |
|
|
|
@ -1117,7 +1111,7 @@ void Session::initMetrics()
@@ -1117,7 +1111,7 @@ void Session::initMetrics()
|
|
|
|
|
Q_ASSERT(m_metricIndices.disk.diskJobTime >= 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Session::configure(lt::settings_pack &settingsPack) |
|
|
|
|
void Session::loadLTSettings(lt::settings_pack &settingsPack) |
|
|
|
|
{ |
|
|
|
|
// from libtorrent doc:
|
|
|
|
|
// It will not take affect until the listen_interfaces settings is updated
|
|
|
|
@ -1126,7 +1120,7 @@ void Session::configure(lt::settings_pack &settingsPack)
@@ -1126,7 +1120,7 @@ void Session::configure(lt::settings_pack &settingsPack)
|
|
|
|
|
#ifdef Q_OS_WIN |
|
|
|
|
QString chosenIP; |
|
|
|
|
#endif |
|
|
|
|
if (m_listenInterfaceChanged) { |
|
|
|
|
if (!m_listenInterfaceConfigured) { |
|
|
|
|
const int port = useRandomPort() ? 0 : this->port(); |
|
|
|
|
if (port > 0) // user specified port
|
|
|
|
|
settingsPack.set_int(lt::settings_pack::max_retry_port_bind, 0); |
|
|
|
@ -1182,7 +1176,7 @@ void Session::configure(lt::settings_pack &settingsPack)
@@ -1182,7 +1176,7 @@ void Session::configure(lt::settings_pack &settingsPack)
|
|
|
|
|
settingsPack.set_str(lt::settings_pack::outgoing_interfaces, networkInterface().toStdString()); |
|
|
|
|
#endif // Q_OS_WIN
|
|
|
|
|
|
|
|
|
|
m_listenInterfaceChanged = false; |
|
|
|
|
m_listenInterfaceConfigured = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
applyBandwidthLimits(settingsPack); |
|
|
|
@ -2190,8 +2184,6 @@ void Session::generateResumeData(const bool final)
@@ -2190,8 +2184,6 @@ void Session::generateResumeData(const bool final)
|
|
|
|
|
// Called on exit
|
|
|
|
|
void Session::saveResumeData() |
|
|
|
|
{ |
|
|
|
|
qDebug("Saving resume data..."); |
|
|
|
|
|
|
|
|
|
// Pause session
|
|
|
|
|
m_nativeSession->pause(); |
|
|
|
|
|
|
|
|
@ -2200,14 +2192,14 @@ void Session::saveResumeData()
@@ -2200,14 +2192,14 @@ void Session::saveResumeData()
|
|
|
|
|
generateResumeData(true); |
|
|
|
|
|
|
|
|
|
while (m_numResumeData > 0) { |
|
|
|
|
std::vector<lt::alert *> alerts; |
|
|
|
|
getPendingAlerts(alerts, 30 * 1000); |
|
|
|
|
const std::vector<lt::alert *> alerts = getPendingAlerts(lt::seconds(30)); |
|
|
|
|
if (alerts.empty()) { |
|
|
|
|
fprintf(stderr, " aborting with %d outstanding torrents to save resume data for\n", m_numResumeData); |
|
|
|
|
LogMsg(tr("Error: Aborted saving resume data for %1 outstanding torrents.").arg(QString::number(m_numResumeData)) |
|
|
|
|
, Log::CRITICAL); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (const auto a : alerts) { |
|
|
|
|
for (const lt::alert *a : alerts) { |
|
|
|
|
switch (a->type()) { |
|
|
|
|
case lt::save_resume_data_failed_alert::alert_type: |
|
|
|
|
case lt::save_resume_data_alert::alert_type: |
|
|
|
@ -2377,7 +2369,7 @@ QStringList Session::getListeningIPs() const
@@ -2377,7 +2369,7 @@ QStringList Session::getListeningIPs() const
|
|
|
|
|
// the BitTorrent session will listen to
|
|
|
|
|
void Session::configureListeningInterface() |
|
|
|
|
{ |
|
|
|
|
m_listenInterfaceChanged = true; |
|
|
|
|
m_listenInterfaceConfigured = false; |
|
|
|
|
configureDeferred(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -2703,7 +2695,7 @@ void Session::setIPFilteringEnabled(const bool enabled)
@@ -2703,7 +2695,7 @@ void Session::setIPFilteringEnabled(const bool enabled)
|
|
|
|
|
{ |
|
|
|
|
if (enabled != m_isIPFilteringEnabled) { |
|
|
|
|
m_isIPFilteringEnabled = enabled; |
|
|
|
|
m_IPFilteringChanged = true; |
|
|
|
|
m_IPFilteringConfigured = false; |
|
|
|
|
configureDeferred(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -2718,7 +2710,7 @@ void Session::setIPFilterFile(QString path)
@@ -2718,7 +2710,7 @@ void Session::setIPFilterFile(QString path)
|
|
|
|
|
path = Utils::Fs::toUniformPath(path); |
|
|
|
|
if (path != IPFilterFile()) { |
|
|
|
|
m_IPFilterFile = path; |
|
|
|
|
m_IPFilteringChanged = true; |
|
|
|
|
m_IPFilteringConfigured = false; |
|
|
|
|
configureDeferred(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -2752,7 +2744,7 @@ void Session::setBannedIPs(const QStringList &newList)
@@ -2752,7 +2744,7 @@ void Session::setBannedIPs(const QStringList &newList)
|
|
|
|
|
// also here we have to recreate filter list including 3rd party ban file
|
|
|
|
|
// and install it again into m_session
|
|
|
|
|
m_bannedIPs = filteredList; |
|
|
|
|
m_IPFilteringChanged = true; |
|
|
|
|
m_IPFilteringConfigured = false; |
|
|
|
|
configureDeferred(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -3561,8 +3553,8 @@ void Session::initResumeFolder()
@@ -3561,8 +3553,8 @@ void Session::initResumeFolder()
|
|
|
|
|
m_resumeFolderPath = Utils::Fs::expandPathAbs(specialFolderLocation(SpecialFolder::Data) + RESUME_FOLDER); |
|
|
|
|
const QDir resumeFolderDir(m_resumeFolderPath); |
|
|
|
|
if (resumeFolderDir.exists() || resumeFolderDir.mkpath(resumeFolderDir.absolutePath())) { |
|
|
|
|
m_resumeFolderLock.setFileName(resumeFolderDir.absoluteFilePath("session.lock")); |
|
|
|
|
if (!m_resumeFolderLock.open(QFile::WriteOnly)) { |
|
|
|
|
m_resumeFolderLock->setFileName(resumeFolderDir.absoluteFilePath("session.lock")); |
|
|
|
|
if (!m_resumeFolderLock->open(QFile::WriteOnly)) { |
|
|
|
|
throw RuntimeError {tr("Cannot write to torrent resume folder.")}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -3573,7 +3565,10 @@ void Session::initResumeFolder()
@@ -3573,7 +3565,10 @@ void Session::initResumeFolder()
|
|
|
|
|
|
|
|
|
|
void Session::configureDeferred() |
|
|
|
|
{ |
|
|
|
|
if (!m_deferredConfigureScheduled) { |
|
|
|
|
if (m_deferredConfigureScheduled) |
|
|
|
|
return; |
|
|
|
|
m_deferredConfigureScheduled = true; |
|
|
|
|
|
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) |
|
|
|
|
QMetaObject::invokeMethod(this |
|
|
|
|
, qOverload<>(&Session::configure) |
|
|
|
@ -3581,8 +3576,6 @@ void Session::configureDeferred()
@@ -3581,8 +3576,6 @@ void Session::configureDeferred()
|
|
|
|
|
#else |
|
|
|
|
QMetaObject::invokeMethod(this, "configure", Qt::QueuedConnection); |
|
|
|
|
#endif |
|
|
|
|
m_deferredConfigureScheduled = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Enable IP Filtering
|
|
|
|
@ -3816,13 +3809,14 @@ void Session::handleIPFilterError()
@@ -3816,13 +3809,14 @@ void Session::handleIPFilterError()
|
|
|
|
|
emit IPFilterParsed(true, 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Session::getPendingAlerts(std::vector<lt::alert *> &out, const ulong time) |
|
|
|
|
std::vector<lt::alert *> Session::getPendingAlerts(const lt::time_duration time) const |
|
|
|
|
{ |
|
|
|
|
Q_ASSERT(out.empty()); |
|
|
|
|
if (time > lt::time_duration::zero()) |
|
|
|
|
m_nativeSession->wait_for_alert(time); |
|
|
|
|
|
|
|
|
|
if (time > 0) |
|
|
|
|
m_nativeSession->wait_for_alert(lt::milliseconds(time)); |
|
|
|
|
m_nativeSession->pop_alerts(&out); |
|
|
|
|
std::vector<lt::alert *> alerts; |
|
|
|
|
m_nativeSession->pop_alerts(&alerts); |
|
|
|
|
return alerts; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool Session::isCreateTorrentSubfolder() const |
|
|
|
@ -3838,10 +3832,8 @@ void Session::setCreateTorrentSubfolder(const bool value)
@@ -3838,10 +3832,8 @@ void Session::setCreateTorrentSubfolder(const bool value)
|
|
|
|
|
// Read alerts sent by the BitTorrent session
|
|
|
|
|
void Session::readAlerts() |
|
|
|
|
{ |
|
|
|
|
std::vector<lt::alert *> alerts; |
|
|
|
|
getPendingAlerts(alerts); |
|
|
|
|
|
|
|
|
|
for (const auto a : alerts) |
|
|
|
|
const std::vector<lt::alert *> alerts = getPendingAlerts(); |
|
|
|
|
for (const lt::alert *a : alerts) |
|
|
|
|
handleAlert(a); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|