|
|
@ -72,6 +72,7 @@ |
|
|
|
#include <QRegularExpression> |
|
|
|
#include <QRegularExpression> |
|
|
|
#include <QString> |
|
|
|
#include <QString> |
|
|
|
#include <QThread> |
|
|
|
#include <QThread> |
|
|
|
|
|
|
|
#include <QThreadPool> |
|
|
|
#include <QTimer> |
|
|
|
#include <QTimer> |
|
|
|
#include <QUuid> |
|
|
|
#include <QUuid> |
|
|
|
|
|
|
|
|
|
|
@ -509,14 +510,18 @@ SessionImpl::SessionImpl(QObject *parent) |
|
|
|
} |
|
|
|
} |
|
|
|
) |
|
|
|
) |
|
|
|
, m_resumeDataStorageType(BITTORRENT_SESSION_KEY(u"ResumeDataStorageType"_qs), ResumeDataStorageType::Legacy) |
|
|
|
, m_resumeDataStorageType(BITTORRENT_SESSION_KEY(u"ResumeDataStorageType"_qs), ResumeDataStorageType::Legacy) |
|
|
|
, m_seedingLimitTimer {new QTimer {this}} |
|
|
|
, m_seedingLimitTimer {new QTimer(this)} |
|
|
|
, m_resumeDataTimer {new QTimer {this}} |
|
|
|
, m_resumeDataTimer {new QTimer(this)} |
|
|
|
, m_ioThread {new QThread {this}} |
|
|
|
, m_ioThread {new QThread(this)} |
|
|
|
, m_recentErroredTorrentsTimer {new QTimer {this}} |
|
|
|
, m_asyncWorker {new QThreadPool(this)} |
|
|
|
|
|
|
|
, m_recentErroredTorrentsTimer {new QTimer(this)} |
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) |
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) |
|
|
|
, m_networkManager {new QNetworkConfigurationManager {this}} |
|
|
|
, m_networkManager {new QNetworkConfigurationManager(this)} |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
// It is required to perform async access to libtorrent sequentially
|
|
|
|
|
|
|
|
m_asyncWorker->setMaxThreadCount(1); |
|
|
|
|
|
|
|
|
|
|
|
if (port() < 0) |
|
|
|
if (port() < 0) |
|
|
|
m_port = Utils::Random::rand(1024, 65535); |
|
|
|
m_port = Utils::Random::rand(1024, 65535); |
|
|
|
|
|
|
|
|
|
|
@ -597,6 +602,9 @@ SessionImpl::~SessionImpl() |
|
|
|
|
|
|
|
|
|
|
|
saveStatistics(); |
|
|
|
saveStatistics(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_asyncWorker->clear(); |
|
|
|
|
|
|
|
m_asyncWorker->waitForDone(); |
|
|
|
|
|
|
|
|
|
|
|
// We must delete FilterParserThread
|
|
|
|
// We must delete FilterParserThread
|
|
|
|
// before we delete lt::session
|
|
|
|
// before we delete lt::session
|
|
|
|
delete m_filterParser; |
|
|
|
delete m_filterParser; |
|
|
@ -2230,21 +2238,26 @@ bool SessionImpl::hasRunningSeed() const |
|
|
|
|
|
|
|
|
|
|
|
void SessionImpl::banIP(const QString &ip) |
|
|
|
void SessionImpl::banIP(const QString &ip) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QStringList bannedIPs = m_bannedIPs; |
|
|
|
if (m_bannedIPs.get().contains(ip)) |
|
|
|
if (!bannedIPs.contains(ip)) |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lt::error_code ec; |
|
|
|
|
|
|
|
const lt::address addr = lt::make_address(ip.toLatin1().constData(), ec); |
|
|
|
|
|
|
|
Q_ASSERT(!ec); |
|
|
|
|
|
|
|
if (ec) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
invokeAsync([session = m_nativeSession, addr] |
|
|
|
{ |
|
|
|
{ |
|
|
|
lt::ip_filter filter = m_nativeSession->get_ip_filter(); |
|
|
|
lt::ip_filter filter = session->get_ip_filter(); |
|
|
|
lt::error_code ec; |
|
|
|
|
|
|
|
const lt::address addr = lt::make_address(ip.toLatin1().constData(), ec); |
|
|
|
|
|
|
|
Q_ASSERT(!ec); |
|
|
|
|
|
|
|
if (ec) return; |
|
|
|
|
|
|
|
filter.add_rule(addr, addr, lt::ip_filter::blocked); |
|
|
|
filter.add_rule(addr, addr, lt::ip_filter::blocked); |
|
|
|
m_nativeSession->set_ip_filter(filter); |
|
|
|
session->set_ip_filter(std::move(filter)); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
bannedIPs << ip; |
|
|
|
QStringList bannedIPs = m_bannedIPs; |
|
|
|
bannedIPs.sort(); |
|
|
|
bannedIPs.append(ip); |
|
|
|
m_bannedIPs = bannedIPs; |
|
|
|
bannedIPs.sort(); |
|
|
|
} |
|
|
|
m_bannedIPs = bannedIPs; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Delete a torrent from the session, given its hash
|
|
|
|
// Delete a torrent from the session, given its hash
|
|
|
@ -2809,6 +2822,11 @@ void SessionImpl::findIncompleteFiles(const TorrentInfo &torrentInfo, const Path |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SessionImpl::invokeAsync(std::function<void ()> func) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_asyncWorker->start(std::move(func)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Add a torrent to libtorrent session in hidden mode
|
|
|
|
// Add a torrent to libtorrent session in hidden mode
|
|
|
|
// and force it to download its metadata
|
|
|
|
// and force it to download its metadata
|
|
|
|
bool SessionImpl::downloadMetadata(const MagnetUri &magnetUri) |
|
|
|
bool SessionImpl::downloadMetadata(const MagnetUri &magnetUri) |
|
|
|