Split Session class into interface/implementation parts

PR #17579.
This commit is contained in:
Vladimir Golovnev 2022-08-27 08:01:24 +03:00 committed by GitHub
parent e5491645e4
commit 525692759d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 1421 additions and 1079 deletions

View file

@ -30,6 +30,7 @@ add_library(qbt_base STATIC
bittorrent/portforwarderimpl.h
bittorrent/resumedatastorage.h
bittorrent/session.h
bittorrent/sessionimpl.h
bittorrent/sessionstatus.h
bittorrent/speedmonitor.h
bittorrent/statistics.h
@ -125,7 +126,7 @@ add_library(qbt_base STATIC
bittorrent/peerinfo.cpp
bittorrent/portforwarderimpl.cpp
bittorrent/resumedatastorage.cpp
bittorrent/session.cpp
bittorrent/sessionimpl.cpp
bittorrent/speedmonitor.cpp
bittorrent/statistics.cpp
bittorrent/torrent.cpp

View file

@ -29,6 +29,7 @@ HEADERS += \
$$PWD/bittorrent/portforwarderimpl.h \
$$PWD/bittorrent/resumedatastorage.h \
$$PWD/bittorrent/session.h \
$$PWD/bittorrent/sessionimpl.h \
$$PWD/bittorrent/sessionstatus.h \
$$PWD/bittorrent/speedmonitor.h \
$$PWD/bittorrent/statistics.h \
@ -125,7 +126,7 @@ SOURCES += \
$$PWD/bittorrent/peerinfo.cpp \
$$PWD/bittorrent/portforwarderimpl.cpp \
$$PWD/bittorrent/resumedatastorage.cpp \
$$PWD/bittorrent/session.cpp \
$$PWD/bittorrent/sessionimpl.cpp \
$$PWD/bittorrent/speedmonitor.cpp \
$$PWD/bittorrent/statistics.cpp \
$$PWD/bittorrent/torrent.cpp \

View file

@ -35,7 +35,7 @@
namespace
{
void handleAddTorrentAlert(const lt::add_torrent_alert *alert)
void handleAddTorrentAlert([[maybe_unused]] const lt::add_torrent_alert *alert)
{
#ifndef QBT_USES_LIBTORRENT2
if (alert->error)

View file

@ -1,6 +1,6 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2015-2022 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
*
* This program is free software; you can redistribute it and/or
@ -29,22 +29,10 @@
#pragma once
#include <variant>
#include <vector>
#include <libtorrent/add_torrent_params.hpp>
#include <libtorrent/fwd.hpp>
#include <libtorrent/torrent_handle.hpp>
#include <QHash>
#include <QPointer>
#include <QSet>
#include <QtContainerFwd>
#include <QVector>
#include <QObject>
#include "base/path.h"
#include "base/settingvalue.h"
#include "base/types.h"
#include "base/pathfwd.h"
#include "addtorrentparams.h"
#include "cachestatus.h"
#include "categoryoptions.h"
@ -52,28 +40,10 @@
#include "torrentinfo.h"
#include "trackerentry.h"
#ifdef QBT_USES_LIBTORRENT2
// TODO: Remove the following forward declaration once v2.0.8 is released
namespace libtorrent
{
struct torrent_conflict_alert;
}
#endif
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
class QNetworkConfiguration;
class QNetworkConfigurationManager;
#endif
class QString;
class QThread;
class QTimer;
class QUrl;
class BandwidthScheduler;
class FileSearcher;
class FilterParserThread;
class Statistics;
// These values should remain unchanged when adding new items
// so as not to break the existing user settings.
enum MaxRatioAction
@ -100,6 +70,7 @@ namespace BitTorrent
class InfoHash;
class MagnetUri;
class ResumeDataStorage;
class SessionImpl;
class Torrent;
class TorrentImpl;
class Tracker;
@ -177,53 +148,7 @@ namespace BitTorrent
Q_ENUM_NS(ResumeDataStorageType)
}
struct SessionMetricIndices
{
struct
{
int hasIncomingConnections = -1;
int sentPayloadBytes = -1;
int recvPayloadBytes = -1;
int sentBytes = -1;
int recvBytes = -1;
int sentIPOverheadBytes = -1;
int recvIPOverheadBytes = -1;
int sentTrackerBytes = -1;
int recvTrackerBytes = -1;
int recvRedundantBytes = -1;
int recvFailedBytes = -1;
} net;
struct
{
int numPeersConnected = -1;
int numPeersUpDisk = -1;
int numPeersDownDisk = -1;
} peer;
struct
{
int dhtBytesIn = -1;
int dhtBytesOut = -1;
int dhtNodes = -1;
} dht;
struct
{
int diskBlocksInUse = -1;
int numBlocksRead = -1;
#ifndef QBT_USES_LIBTORRENT2
int numBlocksCacheHits = -1;
#endif
int writeJobs = -1;
int readJobs = -1;
int hashJobs = -1;
int queuedDiskJobs = -1;
int diskJobTime = -1;
} disk;
};
class Session final : public QObject
class Session : public QObject
{
Q_OBJECT
Q_DISABLE_COPY_MOVE(Session)
@ -233,34 +158,36 @@ namespace BitTorrent
static void freeInstance();
static Session *instance();
Path savePath() const;
void setSavePath(const Path &path);
Path downloadPath() const;
void setDownloadPath(const Path &path);
bool isDownloadPathEnabled() const;
void setDownloadPathEnabled(bool enabled);
using QObject::QObject;
virtual Path savePath() const = 0;
virtual void setSavePath(const Path &path) = 0;
virtual Path downloadPath() const = 0;
virtual void setDownloadPath(const Path &path) = 0;
virtual bool isDownloadPathEnabled() const = 0;
virtual void setDownloadPathEnabled(bool enabled) = 0;
static bool isValidCategoryName(const QString &name);
// returns category itself and all top level categories
static QStringList expandCategory(const QString &category);
QStringList categories() const;
CategoryOptions categoryOptions(const QString &categoryName) const;
Path categorySavePath(const QString &categoryName) const;
Path categoryDownloadPath(const QString &categoryName) const;
bool addCategory(const QString &name, const CategoryOptions &options = {});
bool editCategory(const QString &name, const CategoryOptions &options);
bool removeCategory(const QString &name);
bool isSubcategoriesEnabled() const;
void setSubcategoriesEnabled(bool value);
bool useCategoryPathsInManualMode() const;
void setUseCategoryPathsInManualMode(bool value);
virtual QStringList categories() const = 0;
virtual CategoryOptions categoryOptions(const QString &categoryName) const = 0;
virtual Path categorySavePath(const QString &categoryName) const = 0;
virtual Path categoryDownloadPath(const QString &categoryName) const = 0;
virtual bool addCategory(const QString &name, const CategoryOptions &options = {}) = 0;
virtual bool editCategory(const QString &name, const CategoryOptions &options) = 0;
virtual bool removeCategory(const QString &name) = 0;
virtual bool isSubcategoriesEnabled() const = 0;
virtual void setSubcategoriesEnabled(bool value) = 0;
virtual bool useCategoryPathsInManualMode() const = 0;
virtual void setUseCategoryPathsInManualMode(bool value) = 0;
static bool isValidTag(const QString &tag);
QSet<QString> tags() const;
bool hasTag(const QString &tag) const;
bool addTag(const QString &tag);
bool removeTag(const QString &tag);
virtual QSet<QString> tags() const = 0;
virtual bool hasTag(const QString &tag) const = 0;
virtual bool addTag(const QString &tag) = 0;
virtual bool removeTag(const QString &tag) = 0;
// Torrent Management Mode subsystem (TMM)
//
@ -273,273 +200,245 @@ namespace BitTorrent
// 2. Torrent category save path changed
// 3. Torrent category changed
// (unless otherwise is specified)
bool isAutoTMMDisabledByDefault() const;
void setAutoTMMDisabledByDefault(bool value);
bool isDisableAutoTMMWhenCategoryChanged() const;
void setDisableAutoTMMWhenCategoryChanged(bool value);
bool isDisableAutoTMMWhenDefaultSavePathChanged() const;
void setDisableAutoTMMWhenDefaultSavePathChanged(bool value);
bool isDisableAutoTMMWhenCategorySavePathChanged() const;
void setDisableAutoTMMWhenCategorySavePathChanged(bool value);
virtual bool isAutoTMMDisabledByDefault() const = 0;
virtual void setAutoTMMDisabledByDefault(bool value) = 0;
virtual bool isDisableAutoTMMWhenCategoryChanged() const = 0;
virtual void setDisableAutoTMMWhenCategoryChanged(bool value) = 0;
virtual bool isDisableAutoTMMWhenDefaultSavePathChanged() const = 0;
virtual void setDisableAutoTMMWhenDefaultSavePathChanged(bool value) = 0;
virtual bool isDisableAutoTMMWhenCategorySavePathChanged() const = 0;
virtual void setDisableAutoTMMWhenCategorySavePathChanged(bool value) = 0;
qreal globalMaxRatio() const;
void setGlobalMaxRatio(qreal ratio);
int globalMaxSeedingMinutes() const;
void setGlobalMaxSeedingMinutes(int minutes);
bool isDHTEnabled() const;
void setDHTEnabled(bool enabled);
bool isLSDEnabled() const;
void setLSDEnabled(bool enabled);
bool isPeXEnabled() const;
void setPeXEnabled(bool enabled);
bool isAddTorrentPaused() const;
void setAddTorrentPaused(bool value);
TorrentContentLayout torrentContentLayout() const;
void setTorrentContentLayout(TorrentContentLayout value);
bool isTrackerEnabled() const;
void setTrackerEnabled(bool enabled);
bool isAppendExtensionEnabled() const;
void setAppendExtensionEnabled(bool enabled);
int refreshInterval() const;
void setRefreshInterval(int value);
bool isPreallocationEnabled() const;
void setPreallocationEnabled(bool enabled);
Path torrentExportDirectory() const;
void setTorrentExportDirectory(const Path &path);
Path finishedTorrentExportDirectory() const;
void setFinishedTorrentExportDirectory(const Path &path);
virtual qreal globalMaxRatio() const = 0;
virtual void setGlobalMaxRatio(qreal ratio) = 0;
virtual int globalMaxSeedingMinutes() const = 0;
virtual void setGlobalMaxSeedingMinutes(int minutes) = 0;
virtual bool isDHTEnabled() const = 0;
virtual void setDHTEnabled(bool enabled) = 0;
virtual bool isLSDEnabled() const = 0;
virtual void setLSDEnabled(bool enabled) = 0;
virtual bool isPeXEnabled() const = 0;
virtual void setPeXEnabled(bool enabled) = 0;
virtual bool isAddTorrentPaused() const = 0;
virtual void setAddTorrentPaused(bool value) = 0;
virtual TorrentContentLayout torrentContentLayout() const = 0;
virtual void setTorrentContentLayout(TorrentContentLayout value) = 0;
virtual bool isTrackerEnabled() const = 0;
virtual void setTrackerEnabled(bool enabled) = 0;
virtual bool isAppendExtensionEnabled() const = 0;
virtual void setAppendExtensionEnabled(bool enabled) = 0;
virtual int refreshInterval() const = 0;
virtual void setRefreshInterval(int value) = 0;
virtual bool isPreallocationEnabled() const = 0;
virtual void setPreallocationEnabled(bool enabled) = 0;
virtual Path torrentExportDirectory() const = 0;
virtual void setTorrentExportDirectory(const Path &path) = 0;
virtual Path finishedTorrentExportDirectory() const = 0;
virtual void setFinishedTorrentExportDirectory(const Path &path) = 0;
int globalDownloadSpeedLimit() const;
void setGlobalDownloadSpeedLimit(int limit);
int globalUploadSpeedLimit() const;
void setGlobalUploadSpeedLimit(int limit);
int altGlobalDownloadSpeedLimit() const;
void setAltGlobalDownloadSpeedLimit(int limit);
int altGlobalUploadSpeedLimit() const;
void setAltGlobalUploadSpeedLimit(int limit);
int downloadSpeedLimit() const;
void setDownloadSpeedLimit(int limit);
int uploadSpeedLimit() const;
void setUploadSpeedLimit(int limit);
bool isAltGlobalSpeedLimitEnabled() const;
void setAltGlobalSpeedLimitEnabled(bool enabled);
bool isBandwidthSchedulerEnabled() const;
void setBandwidthSchedulerEnabled(bool enabled);
virtual int globalDownloadSpeedLimit() const = 0;
virtual void setGlobalDownloadSpeedLimit(int limit) = 0;
virtual int globalUploadSpeedLimit() const = 0;
virtual void setGlobalUploadSpeedLimit(int limit) = 0;
virtual int altGlobalDownloadSpeedLimit() const = 0;
virtual void setAltGlobalDownloadSpeedLimit(int limit) = 0;
virtual int altGlobalUploadSpeedLimit() const = 0;
virtual void setAltGlobalUploadSpeedLimit(int limit) = 0;
virtual int downloadSpeedLimit() const = 0;
virtual void setDownloadSpeedLimit(int limit) = 0;
virtual int uploadSpeedLimit() const = 0;
virtual void setUploadSpeedLimit(int limit) = 0;
virtual bool isAltGlobalSpeedLimitEnabled() const = 0;
virtual void setAltGlobalSpeedLimitEnabled(bool enabled) = 0;
virtual bool isBandwidthSchedulerEnabled() const = 0;
virtual void setBandwidthSchedulerEnabled(bool enabled) = 0;
bool isPerformanceWarningEnabled() const;
void setPerformanceWarningEnabled(bool enable);
int saveResumeDataInterval() const;
void setSaveResumeDataInterval(int value);
int port() const;
void setPort(int port);
QString networkInterface() const;
void setNetworkInterface(const QString &iface);
QString networkInterfaceName() const;
void setNetworkInterfaceName(const QString &name);
QString networkInterfaceAddress() const;
void setNetworkInterfaceAddress(const QString &address);
int encryption() const;
void setEncryption(int state);
int maxActiveCheckingTorrents() const;
void setMaxActiveCheckingTorrents(int val);
bool isProxyPeerConnectionsEnabled() const;
void setProxyPeerConnectionsEnabled(bool enabled);
ChokingAlgorithm chokingAlgorithm() const;
void setChokingAlgorithm(ChokingAlgorithm mode);
SeedChokingAlgorithm seedChokingAlgorithm() const;
void setSeedChokingAlgorithm(SeedChokingAlgorithm mode);
bool isAddTrackersEnabled() const;
void setAddTrackersEnabled(bool enabled);
QString additionalTrackers() const;
void setAdditionalTrackers(const QString &trackers);
bool isIPFilteringEnabled() const;
void setIPFilteringEnabled(bool enabled);
Path IPFilterFile() const;
void setIPFilterFile(const Path &path);
bool announceToAllTrackers() const;
void setAnnounceToAllTrackers(bool val);
bool announceToAllTiers() const;
void setAnnounceToAllTiers(bool val);
int peerTurnover() const;
void setPeerTurnover(int val);
int peerTurnoverCutoff() const;
void setPeerTurnoverCutoff(int val);
int peerTurnoverInterval() const;
void setPeerTurnoverInterval(int val);
int requestQueueSize() const;
void setRequestQueueSize(int val);
int asyncIOThreads() const;
void setAsyncIOThreads(int num);
int hashingThreads() const;
void setHashingThreads(int num);
int filePoolSize() const;
void setFilePoolSize(int size);
int checkingMemUsage() const;
void setCheckingMemUsage(int size);
int diskCacheSize() const;
void setDiskCacheSize(int size);
int diskCacheTTL() const;
void setDiskCacheTTL(int ttl);
qint64 diskQueueSize() const;
void setDiskQueueSize(qint64 size);
DiskIOType diskIOType() const;
void setDiskIOType(DiskIOType type);
DiskIOReadMode diskIOReadMode() const;
void setDiskIOReadMode(DiskIOReadMode mode);
DiskIOWriteMode diskIOWriteMode() const;
void setDiskIOWriteMode(DiskIOWriteMode mode);
bool isCoalesceReadWriteEnabled() const;
void setCoalesceReadWriteEnabled(bool enabled);
bool usePieceExtentAffinity() const;
void setPieceExtentAffinity(bool enabled);
bool isSuggestModeEnabled() const;
void setSuggestMode(bool mode);
int sendBufferWatermark() const;
void setSendBufferWatermark(int value);
int sendBufferLowWatermark() const;
void setSendBufferLowWatermark(int value);
int sendBufferWatermarkFactor() const;
void setSendBufferWatermarkFactor(int value);
int connectionSpeed() const;
void setConnectionSpeed(int value);
int socketBacklogSize() const;
void setSocketBacklogSize(int value);
bool isAnonymousModeEnabled() const;
void setAnonymousModeEnabled(bool enabled);
bool isQueueingSystemEnabled() const;
void setQueueingSystemEnabled(bool enabled);
bool ignoreSlowTorrentsForQueueing() const;
void setIgnoreSlowTorrentsForQueueing(bool ignore);
int downloadRateForSlowTorrents() const;
void setDownloadRateForSlowTorrents(int rateInKibiBytes);
int uploadRateForSlowTorrents() const;
void setUploadRateForSlowTorrents(int rateInKibiBytes);
int slowTorrentsInactivityTimer() const;
void setSlowTorrentsInactivityTimer(int timeInSeconds);
int outgoingPortsMin() const;
void setOutgoingPortsMin(int min);
int outgoingPortsMax() const;
void setOutgoingPortsMax(int max);
int UPnPLeaseDuration() const;
void setUPnPLeaseDuration(int duration);
int peerToS() const;
void setPeerToS(int value);
bool ignoreLimitsOnLAN() const;
void setIgnoreLimitsOnLAN(bool ignore);
bool includeOverheadInLimits() const;
void setIncludeOverheadInLimits(bool include);
QString announceIP() const;
void setAnnounceIP(const QString &ip);
int maxConcurrentHTTPAnnounces() const;
void setMaxConcurrentHTTPAnnounces(int value);
bool isReannounceWhenAddressChangedEnabled() const;
void setReannounceWhenAddressChangedEnabled(bool enabled);
void reannounceToAllTrackers() const;
int stopTrackerTimeout() const;
void setStopTrackerTimeout(int value);
int maxConnections() const;
void setMaxConnections(int max);
int maxConnectionsPerTorrent() const;
void setMaxConnectionsPerTorrent(int max);
int maxUploads() const;
void setMaxUploads(int max);
int maxUploadsPerTorrent() const;
void setMaxUploadsPerTorrent(int max);
int maxActiveDownloads() const;
void setMaxActiveDownloads(int max);
int maxActiveUploads() const;
void setMaxActiveUploads(int max);
int maxActiveTorrents() const;
void setMaxActiveTorrents(int max);
BTProtocol btProtocol() const;
void setBTProtocol(BTProtocol protocol);
bool isUTPRateLimited() const;
void setUTPRateLimited(bool limited);
MixedModeAlgorithm utpMixedMode() const;
void setUtpMixedMode(MixedModeAlgorithm mode);
bool isIDNSupportEnabled() const;
void setIDNSupportEnabled(bool enabled);
bool multiConnectionsPerIpEnabled() const;
void setMultiConnectionsPerIpEnabled(bool enabled);
bool validateHTTPSTrackerCertificate() const;
void setValidateHTTPSTrackerCertificate(bool enabled);
bool isSSRFMitigationEnabled() const;
void setSSRFMitigationEnabled(bool enabled);
bool blockPeersOnPrivilegedPorts() const;
void setBlockPeersOnPrivilegedPorts(bool enabled);
bool isTrackerFilteringEnabled() const;
void setTrackerFilteringEnabled(bool enabled);
bool isExcludedFileNamesEnabled() const;
void setExcludedFileNamesEnabled(const bool enabled);
QStringList excludedFileNames() const;
void setExcludedFileNames(const QStringList &newList);
bool isFilenameExcluded(const QString &fileName) const;
QStringList bannedIPs() const;
void setBannedIPs(const QStringList &newList);
ResumeDataStorageType resumeDataStorageType() const;
void setResumeDataStorageType(ResumeDataStorageType type);
virtual bool isPerformanceWarningEnabled() const = 0;
virtual void setPerformanceWarningEnabled(bool enable) = 0;
virtual int saveResumeDataInterval() const = 0;
virtual void setSaveResumeDataInterval(int value) = 0;
virtual int port() const = 0;
virtual void setPort(int port) = 0;
virtual QString networkInterface() const = 0;
virtual void setNetworkInterface(const QString &iface) = 0;
virtual QString networkInterfaceName() const = 0;
virtual void setNetworkInterfaceName(const QString &name) = 0;
virtual QString networkInterfaceAddress() const = 0;
virtual void setNetworkInterfaceAddress(const QString &address) = 0;
virtual int encryption() const = 0;
virtual void setEncryption(int state) = 0;
virtual int maxActiveCheckingTorrents() const = 0;
virtual void setMaxActiveCheckingTorrents(int val) = 0;
virtual bool isProxyPeerConnectionsEnabled() const = 0;
virtual void setProxyPeerConnectionsEnabled(bool enabled) = 0;
virtual ChokingAlgorithm chokingAlgorithm() const = 0;
virtual void setChokingAlgorithm(ChokingAlgorithm mode) = 0;
virtual SeedChokingAlgorithm seedChokingAlgorithm() const = 0;
virtual void setSeedChokingAlgorithm(SeedChokingAlgorithm mode) = 0;
virtual bool isAddTrackersEnabled() const = 0;
virtual void setAddTrackersEnabled(bool enabled) = 0;
virtual QString additionalTrackers() const = 0;
virtual void setAdditionalTrackers(const QString &trackers) = 0;
virtual bool isIPFilteringEnabled() const = 0;
virtual void setIPFilteringEnabled(bool enabled) = 0;
virtual Path IPFilterFile() const = 0;
virtual void setIPFilterFile(const Path &path) = 0;
virtual bool announceToAllTrackers() const = 0;
virtual void setAnnounceToAllTrackers(bool val) = 0;
virtual bool announceToAllTiers() const = 0;
virtual void setAnnounceToAllTiers(bool val) = 0;
virtual int peerTurnover() const = 0;
virtual void setPeerTurnover(int val) = 0;
virtual int peerTurnoverCutoff() const = 0;
virtual void setPeerTurnoverCutoff(int val) = 0;
virtual int peerTurnoverInterval() const = 0;
virtual void setPeerTurnoverInterval(int val) = 0;
virtual int requestQueueSize() const = 0;
virtual void setRequestQueueSize(int val) = 0;
virtual int asyncIOThreads() const = 0;
virtual void setAsyncIOThreads(int num) = 0;
virtual int hashingThreads() const = 0;
virtual void setHashingThreads(int num) = 0;
virtual int filePoolSize() const = 0;
virtual void setFilePoolSize(int size) = 0;
virtual int checkingMemUsage() const = 0;
virtual void setCheckingMemUsage(int size) = 0;
virtual int diskCacheSize() const = 0;
virtual void setDiskCacheSize(int size) = 0;
virtual int diskCacheTTL() const = 0;
virtual void setDiskCacheTTL(int ttl) = 0;
virtual qint64 diskQueueSize() const = 0;
virtual void setDiskQueueSize(qint64 size) = 0;
virtual DiskIOType diskIOType() const = 0;
virtual void setDiskIOType(DiskIOType type) = 0;
virtual DiskIOReadMode diskIOReadMode() const = 0;
virtual void setDiskIOReadMode(DiskIOReadMode mode) = 0;
virtual DiskIOWriteMode diskIOWriteMode() const = 0;
virtual void setDiskIOWriteMode(DiskIOWriteMode mode) = 0;
virtual bool isCoalesceReadWriteEnabled() const = 0;
virtual void setCoalesceReadWriteEnabled(bool enabled) = 0;
virtual bool usePieceExtentAffinity() const = 0;
virtual void setPieceExtentAffinity(bool enabled) = 0;
virtual bool isSuggestModeEnabled() const = 0;
virtual void setSuggestMode(bool mode) = 0;
virtual int sendBufferWatermark() const = 0;
virtual void setSendBufferWatermark(int value) = 0;
virtual int sendBufferLowWatermark() const = 0;
virtual void setSendBufferLowWatermark(int value) = 0;
virtual int sendBufferWatermarkFactor() const = 0;
virtual void setSendBufferWatermarkFactor(int value) = 0;
virtual int connectionSpeed() const = 0;
virtual void setConnectionSpeed(int value) = 0;
virtual int socketBacklogSize() const = 0;
virtual void setSocketBacklogSize(int value) = 0;
virtual bool isAnonymousModeEnabled() const = 0;
virtual void setAnonymousModeEnabled(bool enabled) = 0;
virtual bool isQueueingSystemEnabled() const = 0;
virtual void setQueueingSystemEnabled(bool enabled) = 0;
virtual bool ignoreSlowTorrentsForQueueing() const = 0;
virtual void setIgnoreSlowTorrentsForQueueing(bool ignore) = 0;
virtual int downloadRateForSlowTorrents() const = 0;
virtual void setDownloadRateForSlowTorrents(int rateInKibiBytes) = 0;
virtual int uploadRateForSlowTorrents() const = 0;
virtual void setUploadRateForSlowTorrents(int rateInKibiBytes) = 0;
virtual int slowTorrentsInactivityTimer() const = 0;
virtual void setSlowTorrentsInactivityTimer(int timeInSeconds) = 0;
virtual int outgoingPortsMin() const = 0;
virtual void setOutgoingPortsMin(int min) = 0;
virtual int outgoingPortsMax() const = 0;
virtual void setOutgoingPortsMax(int max) = 0;
virtual int UPnPLeaseDuration() const = 0;
virtual void setUPnPLeaseDuration(int duration) = 0;
virtual int peerToS() const = 0;
virtual void setPeerToS(int value) = 0;
virtual bool ignoreLimitsOnLAN() const = 0;
virtual void setIgnoreLimitsOnLAN(bool ignore) = 0;
virtual bool includeOverheadInLimits() const = 0;
virtual void setIncludeOverheadInLimits(bool include) = 0;
virtual QString announceIP() const = 0;
virtual void setAnnounceIP(const QString &ip) = 0;
virtual int maxConcurrentHTTPAnnounces() const = 0;
virtual void setMaxConcurrentHTTPAnnounces(int value) = 0;
virtual bool isReannounceWhenAddressChangedEnabled() const = 0;
virtual void setReannounceWhenAddressChangedEnabled(bool enabled) = 0;
virtual void reannounceToAllTrackers() const = 0;
virtual int stopTrackerTimeout() const = 0;
virtual void setStopTrackerTimeout(int value) = 0;
virtual int maxConnections() const = 0;
virtual void setMaxConnections(int max) = 0;
virtual int maxConnectionsPerTorrent() const = 0;
virtual void setMaxConnectionsPerTorrent(int max) = 0;
virtual int maxUploads() const = 0;
virtual void setMaxUploads(int max) = 0;
virtual int maxUploadsPerTorrent() const = 0;
virtual void setMaxUploadsPerTorrent(int max) = 0;
virtual int maxActiveDownloads() const = 0;
virtual void setMaxActiveDownloads(int max) = 0;
virtual int maxActiveUploads() const = 0;
virtual void setMaxActiveUploads(int max) = 0;
virtual int maxActiveTorrents() const = 0;
virtual void setMaxActiveTorrents(int max) = 0;
virtual BTProtocol btProtocol() const = 0;
virtual void setBTProtocol(BTProtocol protocol) = 0;
virtual bool isUTPRateLimited() const = 0;
virtual void setUTPRateLimited(bool limited) = 0;
virtual MixedModeAlgorithm utpMixedMode() const = 0;
virtual void setUtpMixedMode(MixedModeAlgorithm mode) = 0;
virtual bool isIDNSupportEnabled() const = 0;
virtual void setIDNSupportEnabled(bool enabled) = 0;
virtual bool multiConnectionsPerIpEnabled() const = 0;
virtual void setMultiConnectionsPerIpEnabled(bool enabled) = 0;
virtual bool validateHTTPSTrackerCertificate() const = 0;
virtual void setValidateHTTPSTrackerCertificate(bool enabled) = 0;
virtual bool isSSRFMitigationEnabled() const = 0;
virtual void setSSRFMitigationEnabled(bool enabled) = 0;
virtual bool blockPeersOnPrivilegedPorts() const = 0;
virtual void setBlockPeersOnPrivilegedPorts(bool enabled) = 0;
virtual bool isTrackerFilteringEnabled() const = 0;
virtual void setTrackerFilteringEnabled(bool enabled) = 0;
virtual bool isExcludedFileNamesEnabled() const = 0;
virtual void setExcludedFileNamesEnabled(const bool enabled) = 0;
virtual QStringList excludedFileNames() const = 0;
virtual void setExcludedFileNames(const QStringList &newList) = 0;
virtual bool isFilenameExcluded(const QString &fileName) const = 0;
virtual QStringList bannedIPs() const = 0;
virtual void setBannedIPs(const QStringList &newList) = 0;
virtual ResumeDataStorageType resumeDataStorageType() const = 0;
virtual void setResumeDataStorageType(ResumeDataStorageType type) = 0;
bool isRestored() const;
virtual bool isRestored() const = 0;
Torrent *getTorrent(const TorrentID &id) const;
Torrent *findTorrent(const InfoHash &infoHash) const;
QVector<Torrent *> torrents() const;
qsizetype torrentsCount() const;
bool hasActiveTorrents() const;
bool hasUnfinishedTorrents() const;
bool hasRunningSeed() const;
const SessionStatus &status() const;
const CacheStatus &cacheStatus() const;
qint64 getAlltimeDL() const;
qint64 getAlltimeUL() const;
bool isListening() const;
virtual Torrent *getTorrent(const TorrentID &id) const = 0;
virtual Torrent *findTorrent(const InfoHash &infoHash) const = 0;
virtual QVector<Torrent *> torrents() const = 0;
virtual qsizetype torrentsCount() const = 0;
virtual bool hasActiveTorrents() const = 0;
virtual bool hasUnfinishedTorrents() const = 0;
virtual bool hasRunningSeed() const = 0;
virtual const SessionStatus &status() const = 0;
virtual const CacheStatus &cacheStatus() const = 0;
virtual qint64 getAlltimeDL() const = 0;
virtual qint64 getAlltimeUL() const = 0;
virtual bool isListening() const = 0;
MaxRatioAction maxRatioAction() const;
void setMaxRatioAction(MaxRatioAction act);
virtual MaxRatioAction maxRatioAction() const = 0;
virtual void setMaxRatioAction(MaxRatioAction act) = 0;
void banIP(const QString &ip);
virtual void banIP(const QString &ip) = 0;
bool isKnownTorrent(const InfoHash &infoHash) const;
bool addTorrent(const QString &source, const AddTorrentParams &params = AddTorrentParams());
bool addTorrent(const MagnetUri &magnetUri, const AddTorrentParams &params = AddTorrentParams());
bool addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams &params = AddTorrentParams());
bool deleteTorrent(const TorrentID &id, DeleteOption deleteOption = DeleteTorrent);
bool downloadMetadata(const MagnetUri &magnetUri);
bool cancelDownloadMetadata(const TorrentID &id);
virtual bool isKnownTorrent(const InfoHash &infoHash) const = 0;
virtual bool addTorrent(const QString &source, const AddTorrentParams &params = AddTorrentParams()) = 0;
virtual bool addTorrent(const MagnetUri &magnetUri, const AddTorrentParams &params = AddTorrentParams()) = 0;
virtual bool addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams &params = AddTorrentParams()) = 0;
virtual bool deleteTorrent(const TorrentID &id, DeleteOption deleteOption = DeleteOption::DeleteTorrent) = 0;
virtual bool downloadMetadata(const MagnetUri &magnetUri) = 0;
virtual bool cancelDownloadMetadata(const TorrentID &id) = 0;
void recursiveTorrentDownload(const TorrentID &id);
void increaseTorrentsQueuePos(const QVector<TorrentID> &ids);
void decreaseTorrentsQueuePos(const QVector<TorrentID> &ids);
void topTorrentsQueuePos(const QVector<TorrentID> &ids);
void bottomTorrentsQueuePos(const QVector<TorrentID> &ids);
// Torrent interface
void handleTorrentNeedSaveResumeData(const TorrentImpl *torrent);
void handleTorrentSaveResumeDataRequested(const TorrentImpl *torrent);
void handleTorrentShareLimitChanged(TorrentImpl *const torrent);
void handleTorrentNameChanged(TorrentImpl *const torrent);
void handleTorrentSavePathChanged(TorrentImpl *const torrent);
void handleTorrentCategoryChanged(TorrentImpl *const torrent, const QString &oldCategory);
void handleTorrentTagAdded(TorrentImpl *const torrent, const QString &tag);
void handleTorrentTagRemoved(TorrentImpl *const torrent, const QString &tag);
void handleTorrentSavingModeChanged(TorrentImpl *const torrent);
void handleTorrentMetadataReceived(TorrentImpl *const torrent);
void handleTorrentPaused(TorrentImpl *const torrent);
void handleTorrentResumed(TorrentImpl *const torrent);
void handleTorrentChecked(TorrentImpl *const torrent);
void handleTorrentFinished(TorrentImpl *const torrent);
void handleTorrentTrackersAdded(TorrentImpl *const torrent, const QVector<TrackerEntry> &newTrackers);
void handleTorrentTrackersRemoved(TorrentImpl *const torrent, const QStringList &deletedTrackers);
void handleTorrentTrackersChanged(TorrentImpl *const torrent);
void handleTorrentUrlSeedsAdded(TorrentImpl *const torrent, const QVector<QUrl> &newUrlSeeds);
void handleTorrentUrlSeedsRemoved(TorrentImpl *const torrent, const QVector<QUrl> &urlSeeds);
void handleTorrentResumeDataReady(TorrentImpl *const torrent, const LoadTorrentParams &data);
void handleTorrentIDChanged(const TorrentImpl *torrent, const TorrentID &prevID);
bool addMoveTorrentStorageJob(TorrentImpl *torrent, const Path &newPath, MoveStorageMode mode);
void findIncompleteFiles(const TorrentInfo &torrentInfo, const Path &savePath
, const Path &downloadPath, const PathList &filePaths = {}) const;
virtual void recursiveTorrentDownload(const TorrentID &id) = 0;
virtual void increaseTorrentsQueuePos(const QVector<TorrentID> &ids) = 0;
virtual void decreaseTorrentsQueuePos(const QVector<TorrentID> &ids) = 0;
virtual void topTorrentsQueuePos(const QVector<TorrentID> &ids) = 0;
virtual void bottomTorrentsQueuePos(const QVector<TorrentID> &ids) = 0;
signals:
void startupProgressUpdated(int progress);
@ -581,293 +480,5 @@ namespace BitTorrent
void trackerSuccess(Torrent *torrent, const QString &tracker);
void trackerWarning(Torrent *torrent, const QString &tracker);
void trackerEntriesUpdated(const QHash<Torrent *, QSet<QString>> &updateInfos);
private slots:
void configureDeferred();
void readAlerts();
void enqueueRefresh();
void processShareLimits();
void generateResumeData();
void handleIPFilterParsed(int ruleCount);
void handleIPFilterError();
void handleDownloadFinished(const Net::DownloadResult &result);
void fileSearchFinished(const TorrentID &id, const Path &savePath, const PathList &fileNames);
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
// Session reconfiguration triggers
void networkOnlineStateChanged(bool online);
void networkConfigurationChange(const QNetworkConfiguration &);
#endif
private:
struct ResumeSessionContext;
struct MoveStorageJob
{
lt::torrent_handle torrentHandle;
Path path;
MoveStorageMode mode;
};
struct RemovingTorrentData
{
QString name;
Path pathToRemove;
DeleteOption deleteOption;
};
explicit Session(QObject *parent = nullptr);
~Session();
bool hasPerTorrentRatioLimit() const;
bool hasPerTorrentSeedingTimeLimit() const;
// Session configuration
Q_INVOKABLE void configure();
void configureComponents();
void initializeNativeSession();
void loadLTSettings(lt::settings_pack &settingsPack);
void configureNetworkInterfaces(lt::settings_pack &settingsPack);
void configurePeerClasses();
void adjustLimits(lt::settings_pack &settingsPack) const;
void applyBandwidthLimits(lt::settings_pack &settingsPack) const;
void initMetrics();
void adjustLimits();
void applyBandwidthLimits();
void processBannedIPs(lt::ip_filter &filter);
QStringList getListeningIPs() const;
void configureListeningInterface();
void enableTracker(bool enable);
void enableBandwidthScheduler();
void populateAdditionalTrackers();
void enableIPFilter();
void disableIPFilter();
void processTrackerStatuses();
void populateExcludedFileNamesRegExpList();
void prepareStartup();
void handleLoadedResumeData(ResumeSessionContext *context);
void processNextResumeData(ResumeSessionContext *context);
void endStartup(ResumeSessionContext *context);
LoadTorrentParams initLoadTorrentParams(const AddTorrentParams &addTorrentParams);
bool addTorrent_impl(const std::variant<MagnetUri, TorrentInfo> &source, const AddTorrentParams &addTorrentParams);
void updateSeedingLimitTimer();
void exportTorrentFile(const Torrent *torrent, const Path &folderPath);
void handleAlert(const lt::alert *a);
void handleAddTorrentAlerts(const std::vector<lt::alert *> &alerts);
void dispatchTorrentAlert(const lt::torrent_alert *a);
void handleStateUpdateAlert(const lt::state_update_alert *p);
void handleMetadataReceivedAlert(const lt::metadata_received_alert *p);
void handleFileErrorAlert(const lt::file_error_alert *p);
void handleTorrentRemovedAlert(const lt::torrent_removed_alert *p);
void handleTorrentDeletedAlert(const lt::torrent_deleted_alert *p);
void handleTorrentDeleteFailedAlert(const lt::torrent_delete_failed_alert *p);
void handlePortmapWarningAlert(const lt::portmap_error_alert *p);
void handlePortmapAlert(const lt::portmap_alert *p);
void handlePeerBlockedAlert(const lt::peer_blocked_alert *p);
void handlePeerBanAlert(const lt::peer_ban_alert *p);
void handleUrlSeedAlert(const lt::url_seed_alert *p);
void handleListenSucceededAlert(const lt::listen_succeeded_alert *p);
void handleListenFailedAlert(const lt::listen_failed_alert *p);
void handleExternalIPAlert(const lt::external_ip_alert *p);
void handleSessionStatsAlert(const lt::session_stats_alert *p);
void handleAlertsDroppedAlert(const lt::alerts_dropped_alert *p) const;
void handleStorageMovedAlert(const lt::storage_moved_alert *p);
void handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert *p);
void handleSocks5Alert(const lt::socks5_alert *p) const;
void handleTrackerAlert(const lt::tracker_alert *a);
#ifdef QBT_USES_LIBTORRENT2
void handleTorrentConflictAlert(const lt::torrent_conflict_alert *a);
#endif
TorrentImpl *createTorrent(const lt::torrent_handle &nativeHandle, const LoadTorrentParams &params);
void saveResumeData();
void saveTorrentsQueue() const;
void removeTorrentsQueue() const;
std::vector<lt::alert *> getPendingAlerts(lt::time_duration time = lt::time_duration::zero()) const;
void moveTorrentStorage(const MoveStorageJob &job) const;
void handleMoveTorrentStorageJobFinished(const Path &newPath);
void loadCategories();
void storeCategories() const;
void upgradeCategories();
// BitTorrent
lt::session *m_nativeSession = nullptr;
bool m_deferredConfigureScheduled = false;
bool m_IPFilteringConfigured = false;
bool m_listenInterfaceConfigured = false;
CachedSettingValue<bool> m_isDHTEnabled;
CachedSettingValue<bool> m_isLSDEnabled;
CachedSettingValue<bool> m_isPeXEnabled;
CachedSettingValue<bool> m_isIPFilteringEnabled;
CachedSettingValue<bool> m_isTrackerFilteringEnabled;
CachedSettingValue<Path> m_IPFilterFile;
CachedSettingValue<bool> m_announceToAllTrackers;
CachedSettingValue<bool> m_announceToAllTiers;
CachedSettingValue<int> m_asyncIOThreads;
CachedSettingValue<int> m_hashingThreads;
CachedSettingValue<int> m_filePoolSize;
CachedSettingValue<int> m_checkingMemUsage;
CachedSettingValue<int> m_diskCacheSize;
CachedSettingValue<int> m_diskCacheTTL;
CachedSettingValue<qint64> m_diskQueueSize;
CachedSettingValue<DiskIOType> m_diskIOType;
CachedSettingValue<DiskIOReadMode> m_diskIOReadMode;
CachedSettingValue<DiskIOWriteMode> m_diskIOWriteMode;
CachedSettingValue<bool> m_coalesceReadWriteEnabled;
CachedSettingValue<bool> m_usePieceExtentAffinity;
CachedSettingValue<bool> m_isSuggestMode;
CachedSettingValue<int> m_sendBufferWatermark;
CachedSettingValue<int> m_sendBufferLowWatermark;
CachedSettingValue<int> m_sendBufferWatermarkFactor;
CachedSettingValue<int> m_connectionSpeed;
CachedSettingValue<int> m_socketBacklogSize;
CachedSettingValue<bool> m_isAnonymousModeEnabled;
CachedSettingValue<bool> m_isQueueingEnabled;
CachedSettingValue<int> m_maxActiveDownloads;
CachedSettingValue<int> m_maxActiveUploads;
CachedSettingValue<int> m_maxActiveTorrents;
CachedSettingValue<bool> m_ignoreSlowTorrentsForQueueing;
CachedSettingValue<int> m_downloadRateForSlowTorrents;
CachedSettingValue<int> m_uploadRateForSlowTorrents;
CachedSettingValue<int> m_slowTorrentsInactivityTimer;
CachedSettingValue<int> m_outgoingPortsMin;
CachedSettingValue<int> m_outgoingPortsMax;
CachedSettingValue<int> m_UPnPLeaseDuration;
CachedSettingValue<int> m_peerToS;
CachedSettingValue<bool> m_ignoreLimitsOnLAN;
CachedSettingValue<bool> m_includeOverheadInLimits;
CachedSettingValue<QString> m_announceIP;
CachedSettingValue<int> m_maxConcurrentHTTPAnnounces;
CachedSettingValue<bool> m_isReannounceWhenAddressChangedEnabled;
CachedSettingValue<int> m_stopTrackerTimeout;
CachedSettingValue<int> m_maxConnections;
CachedSettingValue<int> m_maxUploads;
CachedSettingValue<int> m_maxConnectionsPerTorrent;
CachedSettingValue<int> m_maxUploadsPerTorrent;
CachedSettingValue<BTProtocol> m_btProtocol;
CachedSettingValue<bool> m_isUTPRateLimited;
CachedSettingValue<MixedModeAlgorithm> m_utpMixedMode;
CachedSettingValue<bool> m_IDNSupportEnabled;
CachedSettingValue<bool> m_multiConnectionsPerIpEnabled;
CachedSettingValue<bool> m_validateHTTPSTrackerCertificate;
CachedSettingValue<bool> m_SSRFMitigationEnabled;
CachedSettingValue<bool> m_blockPeersOnPrivilegedPorts;
CachedSettingValue<bool> m_isAddTrackersEnabled;
CachedSettingValue<QString> m_additionalTrackers;
CachedSettingValue<qreal> m_globalMaxRatio;
CachedSettingValue<int> m_globalMaxSeedingMinutes;
CachedSettingValue<bool> m_isAddTorrentPaused;
CachedSettingValue<TorrentContentLayout> m_torrentContentLayout;
CachedSettingValue<bool> m_isAppendExtensionEnabled;
CachedSettingValue<int> m_refreshInterval;
CachedSettingValue<bool> m_isPreallocationEnabled;
CachedSettingValue<Path> m_torrentExportDirectory;
CachedSettingValue<Path> m_finishedTorrentExportDirectory;
CachedSettingValue<int> m_globalDownloadSpeedLimit;
CachedSettingValue<int> m_globalUploadSpeedLimit;
CachedSettingValue<int> m_altGlobalDownloadSpeedLimit;
CachedSettingValue<int> m_altGlobalUploadSpeedLimit;
CachedSettingValue<bool> m_isAltGlobalSpeedLimitEnabled;
CachedSettingValue<bool> m_isBandwidthSchedulerEnabled;
CachedSettingValue<bool> m_isPerformanceWarningEnabled;
CachedSettingValue<int> m_saveResumeDataInterval;
CachedSettingValue<int> m_port;
CachedSettingValue<QString> m_networkInterface;
CachedSettingValue<QString> m_networkInterfaceName;
CachedSettingValue<QString> m_networkInterfaceAddress;
CachedSettingValue<int> m_encryption;
CachedSettingValue<int> m_maxActiveCheckingTorrents;
CachedSettingValue<bool> m_isProxyPeerConnectionsEnabled;
CachedSettingValue<ChokingAlgorithm> m_chokingAlgorithm;
CachedSettingValue<SeedChokingAlgorithm> m_seedChokingAlgorithm;
CachedSettingValue<QStringList> m_storedTags;
CachedSettingValue<int> m_maxRatioAction;
CachedSettingValue<Path> m_savePath;
CachedSettingValue<Path> m_downloadPath;
CachedSettingValue<bool> m_isDownloadPathEnabled;
CachedSettingValue<bool> m_isSubcategoriesEnabled;
CachedSettingValue<bool> m_useCategoryPathsInManualMode;
CachedSettingValue<bool> m_isAutoTMMDisabledByDefault;
CachedSettingValue<bool> m_isDisableAutoTMMWhenCategoryChanged;
CachedSettingValue<bool> m_isDisableAutoTMMWhenDefaultSavePathChanged;
CachedSettingValue<bool> m_isDisableAutoTMMWhenCategorySavePathChanged;
CachedSettingValue<bool> m_isTrackerEnabled;
CachedSettingValue<int> m_peerTurnover;
CachedSettingValue<int> m_peerTurnoverCutoff;
CachedSettingValue<int> m_peerTurnoverInterval;
CachedSettingValue<int> m_requestQueueSize;
CachedSettingValue<bool> m_isExcludedFileNamesEnabled;
CachedSettingValue<QStringList> m_excludedFileNames;
CachedSettingValue<QStringList> m_bannedIPs;
CachedSettingValue<ResumeDataStorageType> m_resumeDataStorageType;
bool m_isRestored = false;
// Order is important. This needs to be declared after its CachedSettingsValue
// counterpart, because it uses it for initialization in the constructor
// initialization list.
const bool m_wasPexEnabled = m_isPeXEnabled;
int m_numResumeData = 0;
int m_extraLimit = 0;
QVector<TrackerEntry> m_additionalTrackerList;
QVector<QRegularExpression> m_excludedFileNamesRegExpList;
bool m_refreshEnqueued = false;
QTimer *m_seedingLimitTimer = nullptr;
QTimer *m_resumeDataTimer = nullptr;
Statistics *m_statistics = nullptr;
// IP filtering
QPointer<FilterParserThread> m_filterParser;
QPointer<BandwidthScheduler> m_bwScheduler;
// Tracker
QPointer<Tracker> m_tracker;
QThread *m_ioThread = nullptr;
ResumeDataStorage *m_resumeDataStorage = nullptr;
FileSearcher *m_fileSearcher = nullptr;
QSet<TorrentID> m_downloadedMetadata;
QHash<TorrentID, TorrentImpl *> m_torrents;
QHash<TorrentID, LoadTorrentParams> m_loadingTorrents;
QHash<QString, AddTorrentParams> m_downloadedTorrents;
QHash<TorrentID, RemovingTorrentData> m_removingTorrents;
QSet<TorrentID> m_needSaveResumeDataTorrents;
QHash<TorrentID, TorrentID> m_changedTorrentIDs;
QMap<QString, CategoryOptions> m_categories;
QSet<QString> m_tags;
QHash<Torrent *, QSet<QString>> m_updatedTrackerEntries;
// I/O errored torrents
QSet<TorrentID> m_recentErroredTorrents;
QTimer *m_recentErroredTorrentsTimer = nullptr;
SessionMetricIndices m_metricIndices;
lt::time_point m_statsLastTimestamp = lt::clock_type::now();
SessionStatus m_status;
CacheStatus m_cacheStatus;
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QNetworkConfigurationManager *m_networkManager = nullptr;
#endif
QList<MoveStorageJob> m_moveStorageQueue;
QString m_lastExternalIP;
bool m_needUpgradeDownloadPath = false;
static Session *m_instance;
};
}

View file

@ -0,0 +1,730 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2015-2022 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*/
#pragma once
#include <variant>
#include <vector>
#include <libtorrent/add_torrent_params.hpp>
#include <libtorrent/fwd.hpp>
#include <libtorrent/torrent_handle.hpp>
#include <QHash>
#include <QPointer>
#include <QSet>
#include <QtContainerFwd>
#include <QVector>
#include "base/path.h"
#include "base/settingvalue.h"
#include "base/types.h"
#include "addtorrentparams.h"
#include "cachestatus.h"
#include "categoryoptions.h"
#include "session.h"
#include "sessionstatus.h"
#include "torrentinfo.h"
#include "trackerentry.h"
#ifdef QBT_USES_LIBTORRENT2
// TODO: Remove the following forward declaration once v2.0.8 is released
namespace libtorrent
{
struct torrent_conflict_alert;
}
#endif
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
class QNetworkConfiguration;
class QNetworkConfigurationManager;
#endif
class QString;
class QThread;
class QTimer;
class QUrl;
class BandwidthScheduler;
class FileSearcher;
class FilterParserThread;
class Statistics;
namespace Net
{
struct DownloadResult;
}
namespace BitTorrent
{
class InfoHash;
class MagnetUri;
class ResumeDataStorage;
class Torrent;
class TorrentImpl;
class Tracker;
struct LoadTorrentParams;
enum class MoveStorageMode;
struct SessionMetricIndices
{
struct
{
int hasIncomingConnections = -1;
int sentPayloadBytes = -1;
int recvPayloadBytes = -1;
int sentBytes = -1;
int recvBytes = -1;
int sentIPOverheadBytes = -1;
int recvIPOverheadBytes = -1;
int sentTrackerBytes = -1;
int recvTrackerBytes = -1;
int recvRedundantBytes = -1;
int recvFailedBytes = -1;
} net;
struct
{
int numPeersConnected = -1;
int numPeersUpDisk = -1;
int numPeersDownDisk = -1;
} peer;
struct
{
int dhtBytesIn = -1;
int dhtBytesOut = -1;
int dhtNodes = -1;
} dht;
struct
{
int diskBlocksInUse = -1;
int numBlocksRead = -1;
#ifndef QBT_USES_LIBTORRENT2
int numBlocksCacheHits = -1;
#endif
int writeJobs = -1;
int readJobs = -1;
int hashJobs = -1;
int queuedDiskJobs = -1;
int diskJobTime = -1;
} disk;
};
class SessionImpl final : public Session
{
Q_OBJECT
Q_DISABLE_COPY_MOVE(SessionImpl)
public:
Path savePath() const override;
void setSavePath(const Path &path) override;
Path downloadPath() const override;
void setDownloadPath(const Path &path) override;
bool isDownloadPathEnabled() const override;
void setDownloadPathEnabled(bool enabled) override;
QStringList categories() const override;
CategoryOptions categoryOptions(const QString &categoryName) const override;
Path categorySavePath(const QString &categoryName) const override;
Path categoryDownloadPath(const QString &categoryName) const override;
bool addCategory(const QString &name, const CategoryOptions &options = {}) override;
bool editCategory(const QString &name, const CategoryOptions &options) override;
bool removeCategory(const QString &name) override;
bool isSubcategoriesEnabled() const override;
void setSubcategoriesEnabled(bool value) override;
bool useCategoryPathsInManualMode() const override;
void setUseCategoryPathsInManualMode(bool value) override;
QSet<QString> tags() const override;
bool hasTag(const QString &tag) const override;
bool addTag(const QString &tag) override;
bool removeTag(const QString &tag) override;
bool isAutoTMMDisabledByDefault() const override;
void setAutoTMMDisabledByDefault(bool value) override;
bool isDisableAutoTMMWhenCategoryChanged() const override;
void setDisableAutoTMMWhenCategoryChanged(bool value) override;
bool isDisableAutoTMMWhenDefaultSavePathChanged() const override;
void setDisableAutoTMMWhenDefaultSavePathChanged(bool value) override;
bool isDisableAutoTMMWhenCategorySavePathChanged() const override;
void setDisableAutoTMMWhenCategorySavePathChanged(bool value) override;
qreal globalMaxRatio() const override;
void setGlobalMaxRatio(qreal ratio) override;
int globalMaxSeedingMinutes() const override;
void setGlobalMaxSeedingMinutes(int minutes) override;
bool isDHTEnabled() const override;
void setDHTEnabled(bool enabled) override;
bool isLSDEnabled() const override;
void setLSDEnabled(bool enabled) override;
bool isPeXEnabled() const override;
void setPeXEnabled(bool enabled) override;
bool isAddTorrentPaused() const override;
void setAddTorrentPaused(bool value) override;
TorrentContentLayout torrentContentLayout() const override;
void setTorrentContentLayout(TorrentContentLayout value) override;
bool isTrackerEnabled() const override;
void setTrackerEnabled(bool enabled) override;
bool isAppendExtensionEnabled() const override;
void setAppendExtensionEnabled(bool enabled) override;
int refreshInterval() const override;
void setRefreshInterval(int value) override;
bool isPreallocationEnabled() const override;
void setPreallocationEnabled(bool enabled) override;
Path torrentExportDirectory() const override;
void setTorrentExportDirectory(const Path &path) override;
Path finishedTorrentExportDirectory() const override;
void setFinishedTorrentExportDirectory(const Path &path) override;
int globalDownloadSpeedLimit() const override;
void setGlobalDownloadSpeedLimit(int limit) override;
int globalUploadSpeedLimit() const override;
void setGlobalUploadSpeedLimit(int limit) override;
int altGlobalDownloadSpeedLimit() const override;
void setAltGlobalDownloadSpeedLimit(int limit) override;
int altGlobalUploadSpeedLimit() const override;
void setAltGlobalUploadSpeedLimit(int limit) override;
int downloadSpeedLimit() const override;
void setDownloadSpeedLimit(int limit) override;
int uploadSpeedLimit() const override;
void setUploadSpeedLimit(int limit) override;
bool isAltGlobalSpeedLimitEnabled() const override;
void setAltGlobalSpeedLimitEnabled(bool enabled) override;
bool isBandwidthSchedulerEnabled() const override;
void setBandwidthSchedulerEnabled(bool enabled) override;
bool isPerformanceWarningEnabled() const override;
void setPerformanceWarningEnabled(bool enable) override;
int saveResumeDataInterval() const override;
void setSaveResumeDataInterval(int value) override;
int port() const override;
void setPort(int port) override;
QString networkInterface() const override;
void setNetworkInterface(const QString &iface) override;
QString networkInterfaceName() const override;
void setNetworkInterfaceName(const QString &name) override;
QString networkInterfaceAddress() const override;
void setNetworkInterfaceAddress(const QString &address) override;
int encryption() const override;
void setEncryption(int state) override;
int maxActiveCheckingTorrents() const override;
void setMaxActiveCheckingTorrents(int val) override;
bool isProxyPeerConnectionsEnabled() const override;
void setProxyPeerConnectionsEnabled(bool enabled) override;
ChokingAlgorithm chokingAlgorithm() const override;
void setChokingAlgorithm(ChokingAlgorithm mode) override;
SeedChokingAlgorithm seedChokingAlgorithm() const override;
void setSeedChokingAlgorithm(SeedChokingAlgorithm mode) override;
bool isAddTrackersEnabled() const override;
void setAddTrackersEnabled(bool enabled) override;
QString additionalTrackers() const override;
void setAdditionalTrackers(const QString &trackers) override;
bool isIPFilteringEnabled() const override;
void setIPFilteringEnabled(bool enabled) override;
Path IPFilterFile() const override;
void setIPFilterFile(const Path &path) override;
bool announceToAllTrackers() const override;
void setAnnounceToAllTrackers(bool val) override;
bool announceToAllTiers() const override;
void setAnnounceToAllTiers(bool val) override;
int peerTurnover() const override;
void setPeerTurnover(int val) override;
int peerTurnoverCutoff() const override;
void setPeerTurnoverCutoff(int val) override;
int peerTurnoverInterval() const override;
void setPeerTurnoverInterval(int val) override;
int requestQueueSize() const override;
void setRequestQueueSize(int val) override;
int asyncIOThreads() const override;
void setAsyncIOThreads(int num) override;
int hashingThreads() const override;
void setHashingThreads(int num) override;
int filePoolSize() const override;
void setFilePoolSize(int size) override;
int checkingMemUsage() const override;
void setCheckingMemUsage(int size) override;
int diskCacheSize() const override;
void setDiskCacheSize(int size) override;
int diskCacheTTL() const override;
void setDiskCacheTTL(int ttl) override;
qint64 diskQueueSize() const override;
void setDiskQueueSize(qint64 size) override;
DiskIOType diskIOType() const override;
void setDiskIOType(DiskIOType type) override;
DiskIOReadMode diskIOReadMode() const override;
void setDiskIOReadMode(DiskIOReadMode mode) override;
DiskIOWriteMode diskIOWriteMode() const override;
void setDiskIOWriteMode(DiskIOWriteMode mode) override;
bool isCoalesceReadWriteEnabled() const override;
void setCoalesceReadWriteEnabled(bool enabled) override;
bool usePieceExtentAffinity() const override;
void setPieceExtentAffinity(bool enabled) override;
bool isSuggestModeEnabled() const override;
void setSuggestMode(bool mode) override;
int sendBufferWatermark() const override;
void setSendBufferWatermark(int value) override;
int sendBufferLowWatermark() const override;
void setSendBufferLowWatermark(int value) override;
int sendBufferWatermarkFactor() const override;
void setSendBufferWatermarkFactor(int value) override;
int connectionSpeed() const override;
void setConnectionSpeed(int value) override;
int socketBacklogSize() const override;
void setSocketBacklogSize(int value) override;
bool isAnonymousModeEnabled() const override;
void setAnonymousModeEnabled(bool enabled) override;
bool isQueueingSystemEnabled() const override;
void setQueueingSystemEnabled(bool enabled) override;
bool ignoreSlowTorrentsForQueueing() const override;
void setIgnoreSlowTorrentsForQueueing(bool ignore) override;
int downloadRateForSlowTorrents() const override;
void setDownloadRateForSlowTorrents(int rateInKibiBytes) override;
int uploadRateForSlowTorrents() const override;
void setUploadRateForSlowTorrents(int rateInKibiBytes) override;
int slowTorrentsInactivityTimer() const override;
void setSlowTorrentsInactivityTimer(int timeInSeconds) override;
int outgoingPortsMin() const override;
void setOutgoingPortsMin(int min) override;
int outgoingPortsMax() const override;
void setOutgoingPortsMax(int max) override;
int UPnPLeaseDuration() const override;
void setUPnPLeaseDuration(int duration) override;
int peerToS() const override;
void setPeerToS(int value) override;
bool ignoreLimitsOnLAN() const override;
void setIgnoreLimitsOnLAN(bool ignore) override;
bool includeOverheadInLimits() const override;
void setIncludeOverheadInLimits(bool include) override;
QString announceIP() const override;
void setAnnounceIP(const QString &ip) override;
int maxConcurrentHTTPAnnounces() const override;
void setMaxConcurrentHTTPAnnounces(int value) override;
bool isReannounceWhenAddressChangedEnabled() const override;
void setReannounceWhenAddressChangedEnabled(bool enabled) override;
void reannounceToAllTrackers() const override;
int stopTrackerTimeout() const override;
void setStopTrackerTimeout(int value) override;
int maxConnections() const override;
void setMaxConnections(int max) override;
int maxConnectionsPerTorrent() const override;
void setMaxConnectionsPerTorrent(int max) override;
int maxUploads() const override;
void setMaxUploads(int max) override;
int maxUploadsPerTorrent() const override;
void setMaxUploadsPerTorrent(int max) override;
int maxActiveDownloads() const override;
void setMaxActiveDownloads(int max) override;
int maxActiveUploads() const override;
void setMaxActiveUploads(int max) override;
int maxActiveTorrents() const override;
void setMaxActiveTorrents(int max) override;
BTProtocol btProtocol() const override;
void setBTProtocol(BTProtocol protocol) override;
bool isUTPRateLimited() const override;
void setUTPRateLimited(bool limited) override;
MixedModeAlgorithm utpMixedMode() const override;
void setUtpMixedMode(MixedModeAlgorithm mode) override;
bool isIDNSupportEnabled() const override;
void setIDNSupportEnabled(bool enabled) override;
bool multiConnectionsPerIpEnabled() const override;
void setMultiConnectionsPerIpEnabled(bool enabled) override;
bool validateHTTPSTrackerCertificate() const override;
void setValidateHTTPSTrackerCertificate(bool enabled) override;
bool isSSRFMitigationEnabled() const override;
void setSSRFMitigationEnabled(bool enabled) override;
bool blockPeersOnPrivilegedPorts() const override;
void setBlockPeersOnPrivilegedPorts(bool enabled) override;
bool isTrackerFilteringEnabled() const override;
void setTrackerFilteringEnabled(bool enabled) override;
bool isExcludedFileNamesEnabled() const override;
void setExcludedFileNamesEnabled(const bool enabled) override;
QStringList excludedFileNames() const override;
void setExcludedFileNames(const QStringList &newList) override;
bool isFilenameExcluded(const QString &fileName) const override;
QStringList bannedIPs() const override;
void setBannedIPs(const QStringList &newList) override;
ResumeDataStorageType resumeDataStorageType() const override;
void setResumeDataStorageType(ResumeDataStorageType type) override;
bool isRestored() const override;
Torrent *getTorrent(const TorrentID &id) const override;
Torrent *findTorrent(const InfoHash &infoHash) const override;
QVector<Torrent *> torrents() const override;
qsizetype torrentsCount() const override;
bool hasActiveTorrents() const override;
bool hasUnfinishedTorrents() const override;
bool hasRunningSeed() const override;
const SessionStatus &status() const override;
const CacheStatus &cacheStatus() const override;
qint64 getAlltimeDL() const override;
qint64 getAlltimeUL() const override;
bool isListening() const override;
MaxRatioAction maxRatioAction() const override;
void setMaxRatioAction(MaxRatioAction act) override;
void banIP(const QString &ip) override;
bool isKnownTorrent(const InfoHash &infoHash) const override;
bool addTorrent(const QString &source, const AddTorrentParams &params = AddTorrentParams()) override;
bool addTorrent(const MagnetUri &magnetUri, const AddTorrentParams &params = AddTorrentParams()) override;
bool addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams &params = AddTorrentParams()) override;
bool deleteTorrent(const TorrentID &id, DeleteOption deleteOption = DeleteTorrent) override;
bool downloadMetadata(const MagnetUri &magnetUri) override;
bool cancelDownloadMetadata(const TorrentID &id) override;
void recursiveTorrentDownload(const TorrentID &id) override;
void increaseTorrentsQueuePos(const QVector<TorrentID> &ids) override;
void decreaseTorrentsQueuePos(const QVector<TorrentID> &ids) override;
void topTorrentsQueuePos(const QVector<TorrentID> &ids) override;
void bottomTorrentsQueuePos(const QVector<TorrentID> &ids) override;
// Torrent interface
void handleTorrentNeedSaveResumeData(const TorrentImpl *torrent);
void handleTorrentSaveResumeDataRequested(const TorrentImpl *torrent);
void handleTorrentShareLimitChanged(TorrentImpl *const torrent);
void handleTorrentNameChanged(TorrentImpl *const torrent);
void handleTorrentSavePathChanged(TorrentImpl *const torrent);
void handleTorrentCategoryChanged(TorrentImpl *const torrent, const QString &oldCategory);
void handleTorrentTagAdded(TorrentImpl *const torrent, const QString &tag);
void handleTorrentTagRemoved(TorrentImpl *const torrent, const QString &tag);
void handleTorrentSavingModeChanged(TorrentImpl *const torrent);
void handleTorrentMetadataReceived(TorrentImpl *const torrent);
void handleTorrentPaused(TorrentImpl *const torrent);
void handleTorrentResumed(TorrentImpl *const torrent);
void handleTorrentChecked(TorrentImpl *const torrent);
void handleTorrentFinished(TorrentImpl *const torrent);
void handleTorrentTrackersAdded(TorrentImpl *const torrent, const QVector<TrackerEntry> &newTrackers);
void handleTorrentTrackersRemoved(TorrentImpl *const torrent, const QStringList &deletedTrackers);
void handleTorrentTrackersChanged(TorrentImpl *const torrent);
void handleTorrentUrlSeedsAdded(TorrentImpl *const torrent, const QVector<QUrl> &newUrlSeeds);
void handleTorrentUrlSeedsRemoved(TorrentImpl *const torrent, const QVector<QUrl> &urlSeeds);
void handleTorrentResumeDataReady(TorrentImpl *const torrent, const LoadTorrentParams &data);
void handleTorrentIDChanged(const TorrentImpl *torrent, const TorrentID &prevID);
bool addMoveTorrentStorageJob(TorrentImpl *torrent, const Path &newPath, MoveStorageMode mode);
void findIncompleteFiles(const TorrentInfo &torrentInfo, const Path &savePath
, const Path &downloadPath, const PathList &filePaths = {}) const;
private slots:
void configureDeferred();
void readAlerts();
void enqueueRefresh();
void processShareLimits();
void generateResumeData();
void handleIPFilterParsed(int ruleCount);
void handleIPFilterError();
void handleDownloadFinished(const Net::DownloadResult &result);
void fileSearchFinished(const TorrentID &id, const Path &savePath, const PathList &fileNames);
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
// Session reconfiguration triggers
void networkOnlineStateChanged(bool online);
void networkConfigurationChange(const QNetworkConfiguration &);
#endif
private:
struct ResumeSessionContext;
struct MoveStorageJob
{
lt::torrent_handle torrentHandle;
Path path;
MoveStorageMode mode;
};
struct RemovingTorrentData
{
QString name;
Path pathToRemove;
DeleteOption deleteOption;
};
explicit SessionImpl(QObject *parent = nullptr);
~SessionImpl();
bool hasPerTorrentRatioLimit() const;
bool hasPerTorrentSeedingTimeLimit() const;
// Session configuration
Q_INVOKABLE void configure();
void configureComponents();
void initializeNativeSession();
void loadLTSettings(lt::settings_pack &settingsPack);
void configureNetworkInterfaces(lt::settings_pack &settingsPack);
void configurePeerClasses();
void adjustLimits(lt::settings_pack &settingsPack) const;
void applyBandwidthLimits(lt::settings_pack &settingsPack) const;
void initMetrics();
void adjustLimits();
void applyBandwidthLimits();
void processBannedIPs(lt::ip_filter &filter);
QStringList getListeningIPs() const;
void configureListeningInterface();
void enableTracker(bool enable);
void enableBandwidthScheduler();
void populateAdditionalTrackers();
void enableIPFilter();
void disableIPFilter();
void processTrackerStatuses();
void populateExcludedFileNamesRegExpList();
void prepareStartup();
void handleLoadedResumeData(ResumeSessionContext *context);
void processNextResumeData(ResumeSessionContext *context);
void endStartup(ResumeSessionContext *context);
LoadTorrentParams initLoadTorrentParams(const AddTorrentParams &addTorrentParams);
bool addTorrent_impl(const std::variant<MagnetUri, TorrentInfo> &source, const AddTorrentParams &addTorrentParams);
void updateSeedingLimitTimer();
void exportTorrentFile(const Torrent *torrent, const Path &folderPath);
void handleAlert(const lt::alert *a);
void handleAddTorrentAlerts(const std::vector<lt::alert *> &alerts);
void dispatchTorrentAlert(const lt::torrent_alert *a);
void handleStateUpdateAlert(const lt::state_update_alert *p);
void handleMetadataReceivedAlert(const lt::metadata_received_alert *p);
void handleFileErrorAlert(const lt::file_error_alert *p);
void handleTorrentRemovedAlert(const lt::torrent_removed_alert *p);
void handleTorrentDeletedAlert(const lt::torrent_deleted_alert *p);
void handleTorrentDeleteFailedAlert(const lt::torrent_delete_failed_alert *p);
void handlePortmapWarningAlert(const lt::portmap_error_alert *p);
void handlePortmapAlert(const lt::portmap_alert *p);
void handlePeerBlockedAlert(const lt::peer_blocked_alert *p);
void handlePeerBanAlert(const lt::peer_ban_alert *p);
void handleUrlSeedAlert(const lt::url_seed_alert *p);
void handleListenSucceededAlert(const lt::listen_succeeded_alert *p);
void handleListenFailedAlert(const lt::listen_failed_alert *p);
void handleExternalIPAlert(const lt::external_ip_alert *p);
void handleSessionStatsAlert(const lt::session_stats_alert *p);
void handleAlertsDroppedAlert(const lt::alerts_dropped_alert *p) const;
void handleStorageMovedAlert(const lt::storage_moved_alert *p);
void handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert *p);
void handleSocks5Alert(const lt::socks5_alert *p) const;
void handleTrackerAlert(const lt::tracker_alert *a);
#ifdef QBT_USES_LIBTORRENT2
void handleTorrentConflictAlert(const lt::torrent_conflict_alert *a);
#endif
TorrentImpl *createTorrent(const lt::torrent_handle &nativeHandle, const LoadTorrentParams &params);
void saveResumeData();
void saveTorrentsQueue() const;
void removeTorrentsQueue() const;
std::vector<lt::alert *> getPendingAlerts(lt::time_duration time = lt::time_duration::zero()) const;
void moveTorrentStorage(const MoveStorageJob &job) const;
void handleMoveTorrentStorageJobFinished(const Path &newPath);
void loadCategories();
void storeCategories() const;
void upgradeCategories();
// BitTorrent
lt::session *m_nativeSession = nullptr;
bool m_deferredConfigureScheduled = false;
bool m_IPFilteringConfigured = false;
bool m_listenInterfaceConfigured = false;
CachedSettingValue<bool> m_isDHTEnabled;
CachedSettingValue<bool> m_isLSDEnabled;
CachedSettingValue<bool> m_isPeXEnabled;
CachedSettingValue<bool> m_isIPFilteringEnabled;
CachedSettingValue<bool> m_isTrackerFilteringEnabled;
CachedSettingValue<Path> m_IPFilterFile;
CachedSettingValue<bool> m_announceToAllTrackers;
CachedSettingValue<bool> m_announceToAllTiers;
CachedSettingValue<int> m_asyncIOThreads;
CachedSettingValue<int> m_hashingThreads;
CachedSettingValue<int> m_filePoolSize;
CachedSettingValue<int> m_checkingMemUsage;
CachedSettingValue<int> m_diskCacheSize;
CachedSettingValue<int> m_diskCacheTTL;
CachedSettingValue<qint64> m_diskQueueSize;
CachedSettingValue<DiskIOType> m_diskIOType;
CachedSettingValue<DiskIOReadMode> m_diskIOReadMode;
CachedSettingValue<DiskIOWriteMode> m_diskIOWriteMode;
CachedSettingValue<bool> m_coalesceReadWriteEnabled;
CachedSettingValue<bool> m_usePieceExtentAffinity;
CachedSettingValue<bool> m_isSuggestMode;
CachedSettingValue<int> m_sendBufferWatermark;
CachedSettingValue<int> m_sendBufferLowWatermark;
CachedSettingValue<int> m_sendBufferWatermarkFactor;
CachedSettingValue<int> m_connectionSpeed;
CachedSettingValue<int> m_socketBacklogSize;
CachedSettingValue<bool> m_isAnonymousModeEnabled;
CachedSettingValue<bool> m_isQueueingEnabled;
CachedSettingValue<int> m_maxActiveDownloads;
CachedSettingValue<int> m_maxActiveUploads;
CachedSettingValue<int> m_maxActiveTorrents;
CachedSettingValue<bool> m_ignoreSlowTorrentsForQueueing;
CachedSettingValue<int> m_downloadRateForSlowTorrents;
CachedSettingValue<int> m_uploadRateForSlowTorrents;
CachedSettingValue<int> m_slowTorrentsInactivityTimer;
CachedSettingValue<int> m_outgoingPortsMin;
CachedSettingValue<int> m_outgoingPortsMax;
CachedSettingValue<int> m_UPnPLeaseDuration;
CachedSettingValue<int> m_peerToS;
CachedSettingValue<bool> m_ignoreLimitsOnLAN;
CachedSettingValue<bool> m_includeOverheadInLimits;
CachedSettingValue<QString> m_announceIP;
CachedSettingValue<int> m_maxConcurrentHTTPAnnounces;
CachedSettingValue<bool> m_isReannounceWhenAddressChangedEnabled;
CachedSettingValue<int> m_stopTrackerTimeout;
CachedSettingValue<int> m_maxConnections;
CachedSettingValue<int> m_maxUploads;
CachedSettingValue<int> m_maxConnectionsPerTorrent;
CachedSettingValue<int> m_maxUploadsPerTorrent;
CachedSettingValue<BTProtocol> m_btProtocol;
CachedSettingValue<bool> m_isUTPRateLimited;
CachedSettingValue<MixedModeAlgorithm> m_utpMixedMode;
CachedSettingValue<bool> m_IDNSupportEnabled;
CachedSettingValue<bool> m_multiConnectionsPerIpEnabled;
CachedSettingValue<bool> m_validateHTTPSTrackerCertificate;
CachedSettingValue<bool> m_SSRFMitigationEnabled;
CachedSettingValue<bool> m_blockPeersOnPrivilegedPorts;
CachedSettingValue<bool> m_isAddTrackersEnabled;
CachedSettingValue<QString> m_additionalTrackers;
CachedSettingValue<qreal> m_globalMaxRatio;
CachedSettingValue<int> m_globalMaxSeedingMinutes;
CachedSettingValue<bool> m_isAddTorrentPaused;
CachedSettingValue<TorrentContentLayout> m_torrentContentLayout;
CachedSettingValue<bool> m_isAppendExtensionEnabled;
CachedSettingValue<int> m_refreshInterval;
CachedSettingValue<bool> m_isPreallocationEnabled;
CachedSettingValue<Path> m_torrentExportDirectory;
CachedSettingValue<Path> m_finishedTorrentExportDirectory;
CachedSettingValue<int> m_globalDownloadSpeedLimit;
CachedSettingValue<int> m_globalUploadSpeedLimit;
CachedSettingValue<int> m_altGlobalDownloadSpeedLimit;
CachedSettingValue<int> m_altGlobalUploadSpeedLimit;
CachedSettingValue<bool> m_isAltGlobalSpeedLimitEnabled;
CachedSettingValue<bool> m_isBandwidthSchedulerEnabled;
CachedSettingValue<bool> m_isPerformanceWarningEnabled;
CachedSettingValue<int> m_saveResumeDataInterval;
CachedSettingValue<int> m_port;
CachedSettingValue<QString> m_networkInterface;
CachedSettingValue<QString> m_networkInterfaceName;
CachedSettingValue<QString> m_networkInterfaceAddress;
CachedSettingValue<int> m_encryption;
CachedSettingValue<int> m_maxActiveCheckingTorrents;
CachedSettingValue<bool> m_isProxyPeerConnectionsEnabled;
CachedSettingValue<ChokingAlgorithm> m_chokingAlgorithm;
CachedSettingValue<SeedChokingAlgorithm> m_seedChokingAlgorithm;
CachedSettingValue<QStringList> m_storedTags;
CachedSettingValue<int> m_maxRatioAction;
CachedSettingValue<Path> m_savePath;
CachedSettingValue<Path> m_downloadPath;
CachedSettingValue<bool> m_isDownloadPathEnabled;
CachedSettingValue<bool> m_isSubcategoriesEnabled;
CachedSettingValue<bool> m_useCategoryPathsInManualMode;
CachedSettingValue<bool> m_isAutoTMMDisabledByDefault;
CachedSettingValue<bool> m_isDisableAutoTMMWhenCategoryChanged;
CachedSettingValue<bool> m_isDisableAutoTMMWhenDefaultSavePathChanged;
CachedSettingValue<bool> m_isDisableAutoTMMWhenCategorySavePathChanged;
CachedSettingValue<bool> m_isTrackerEnabled;
CachedSettingValue<int> m_peerTurnover;
CachedSettingValue<int> m_peerTurnoverCutoff;
CachedSettingValue<int> m_peerTurnoverInterval;
CachedSettingValue<int> m_requestQueueSize;
CachedSettingValue<bool> m_isExcludedFileNamesEnabled;
CachedSettingValue<QStringList> m_excludedFileNames;
CachedSettingValue<QStringList> m_bannedIPs;
CachedSettingValue<ResumeDataStorageType> m_resumeDataStorageType;
bool m_isRestored = false;
// Order is important. This needs to be declared after its CachedSettingsValue
// counterpart, because it uses it for initialization in the constructor
// initialization list.
const bool m_wasPexEnabled = m_isPeXEnabled;
int m_numResumeData = 0;
int m_extraLimit = 0;
QVector<TrackerEntry> m_additionalTrackerList;
QVector<QRegularExpression> m_excludedFileNamesRegExpList;
bool m_refreshEnqueued = false;
QTimer *m_seedingLimitTimer = nullptr;
QTimer *m_resumeDataTimer = nullptr;
Statistics *m_statistics = nullptr;
// IP filtering
QPointer<FilterParserThread> m_filterParser;
QPointer<BandwidthScheduler> m_bwScheduler;
// Tracker
QPointer<Tracker> m_tracker;
QThread *m_ioThread = nullptr;
ResumeDataStorage *m_resumeDataStorage = nullptr;
FileSearcher *m_fileSearcher = nullptr;
QSet<TorrentID> m_downloadedMetadata;
QHash<TorrentID, TorrentImpl *> m_torrents;
QHash<TorrentID, LoadTorrentParams> m_loadingTorrents;
QHash<QString, AddTorrentParams> m_downloadedTorrents;
QHash<TorrentID, RemovingTorrentData> m_removingTorrents;
QSet<TorrentID> m_needSaveResumeDataTorrents;
QHash<TorrentID, TorrentID> m_changedTorrentIDs;
QMap<QString, CategoryOptions> m_categories;
QSet<QString> m_tags;
QHash<Torrent *, QSet<QString>> m_updatedTrackerEntries;
// I/O errored torrents
QSet<TorrentID> m_recentErroredTorrents;
QTimer *m_recentErroredTorrentsTimer = nullptr;
SessionMetricIndices m_metricIndices;
lt::time_point m_statsLastTimestamp = lt::clock_type::now();
SessionStatus m_status;
CacheStatus m_cacheStatus;
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QNetworkConfigurationManager *m_networkManager = nullptr;
#endif
QList<MoveStorageJob> m_moveStorageQueue;
QString m_lastExternalIP;
bool m_needUpgradeDownloadPath = false;
friend void Session::initInstance();
friend void Session::freeInstance();
friend Session *Session::instance();
static Session *m_instance;
};
}

View file

@ -33,7 +33,7 @@
#include <QTimer>
#include "base/global.h"
#include "base/bittorrent/session.h"
#include "base/bittorrent/sessionimpl.h"
#include "base/bittorrent/sessionstatus.h"
#include "base/profile.h"
@ -42,7 +42,7 @@ using namespace BitTorrent;
const int SAVE_INTERVAL = std::chrono::milliseconds(15min).count();
Statistics::Statistics(Session *session)
Statistics::Statistics(BitTorrent::SessionImpl *session)
: QObject(session)
, m_session(session)
{

View file

@ -33,7 +33,7 @@
namespace BitTorrent
{
class Session;
class SessionImpl;
}
class Statistics : public QObject
@ -42,7 +42,7 @@ class Statistics : public QObject
Q_DISABLE_COPY_MOVE(Statistics)
public:
explicit Statistics(BitTorrent::Session *session);
explicit Statistics(BitTorrent::SessionImpl *session);
~Statistics();
qint64 getAlltimeDL() const;
@ -55,7 +55,7 @@ private:
void save() const;
void load();
BitTorrent::Session *m_session = nullptr;
BitTorrent::SessionImpl *m_session = nullptr;
mutable QElapsedTimer m_lastUpdateTimer;
mutable bool m_dirty = false;

View file

@ -67,7 +67,7 @@
#include "lttypecast.h"
#include "peeraddress.h"
#include "peerinfo.h"
#include "session.h"
#include "sessionimpl.h"
using namespace BitTorrent;
@ -227,7 +227,7 @@ namespace
// TorrentImpl
TorrentImpl::TorrentImpl(Session *session, lt::session *nativeSession
TorrentImpl::TorrentImpl(SessionImpl *session, lt::session *nativeSession
, const lt::torrent_handle &nativeHandle, const LoadTorrentParams &params)
: QObject(session)
, m_session(session)
@ -738,7 +738,7 @@ bool TorrentImpl::hasTag(const QString &tag) const
bool TorrentImpl::addTag(const QString &tag)
{
if (!Session::isValidTag(tag))
if (!m_session->isValidTag(tag))
return false;
if (hasTag(tag))
return false;

View file

@ -58,7 +58,7 @@
namespace BitTorrent
{
class Session;
class SessionImpl;
struct LoadTorrentParams;
enum class MoveStorageMode
@ -85,7 +85,7 @@ namespace BitTorrent
Q_DECLARE_TR_FUNCTIONS(BitTorrent::TorrentImpl)
public:
TorrentImpl(Session *session, lt::session *nativeSession
TorrentImpl(SessionImpl *session, lt::session *nativeSession
, const lt::torrent_handle &nativeHandle, const LoadTorrentParams &params);
~TorrentImpl() override;
@ -287,7 +287,7 @@ namespace BitTorrent
nonstd::expected<lt::entry, QString> exportTorrent() const;
Session *const m_session = nullptr;
SessionImpl *const m_session = nullptr;
lt::session *m_nativeSession = nullptr;
lt::torrent_handle m_nativeHandle;
mutable lt::torrent_status m_nativeStatus;

View file

@ -308,7 +308,7 @@ void CategoryFilterModel::categoryAdded(const QString &categoryName)
if (m_isSubcategoriesEnabled)
{
QStringList expanded = BitTorrent::Session::expandCategory(categoryName);
QStringList expanded = BitTorrent::Session::instance()->expandCategory(categoryName);
if (expanded.count() > 1)
parent = findItem(expanded[expanded.count() - 2]);
}
@ -443,7 +443,7 @@ CategoryModelItem *CategoryFilterModel::findItem(const QString &fullName) const
return m_rootItem->child(fullName);
CategoryModelItem *item = m_rootItem;
for (const QString &subcat : asConst(BitTorrent::Session::expandCategory(fullName)))
for (const QString &subcat : asConst(BitTorrent::Session::instance()->expandCategory(fullName)))
{
const QString subcatName = shortName(subcat);
if (!item->hasChild(subcatName)) return nullptr;

View file

@ -46,6 +46,7 @@
#include "base/bittorrent/torrent.h"
#include "base/path.h"
#include "base/preferences.h"
#include "base/types.h"
#include "base/unicodestrings.h"
#include "base/utils/fs.h"
#include "base/utils/misc.h"

View file

@ -38,6 +38,7 @@
#include "base/bittorrent/torrent.h"
#include "base/global.h"
#include "base/preferences.h"
#include "base/types.h"
#include "base/unicodestrings.h"
#include "base/utils/fs.h"
#include "base/utils/misc.h"

View file

@ -35,6 +35,7 @@
#include "base/bittorrent/peerinfo.h"
#include "base/bittorrent/session.h"
#include "base/global.h"
#include "base/utils/string.h"
#include "apierror.h"
const QString KEY_TRANSFER_DLSPEED = u"dl_info_speed"_qs;