Browse Source

Split Session class into interface/implementation parts

PR #17579.
adaptive-webui-19844
Vladimir Golovnev 2 years ago committed by GitHub
parent
commit
525692759d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/base/CMakeLists.txt
  2. 3
      src/base/base.pri
  3. 2
      src/base/bittorrent/nativesessionextension.cpp
  4. 923
      src/base/bittorrent/session.h
  5. 828
      src/base/bittorrent/sessionimpl.cpp
  6. 730
      src/base/bittorrent/sessionimpl.h
  7. 4
      src/base/bittorrent/statistics.cpp
  8. 6
      src/base/bittorrent/statistics.h
  9. 6
      src/base/bittorrent/torrentimpl.cpp
  10. 6
      src/base/bittorrent/torrentimpl.h
  11. 4
      src/gui/categoryfiltermodel.cpp
  12. 1
      src/gui/properties/propertieswidget.cpp
  13. 1
      src/gui/transferlistmodel.cpp
  14. 1
      src/webui/api/transfercontroller.cpp

3
src/base/CMakeLists.txt

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

3
src/base/base.pri

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

2
src/base/bittorrent/nativesessionextension.cpp

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

923
src/base/bittorrent/session.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * 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> * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -29,22 +29,10 @@
#pragma once #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 <QtContainerFwd>
#include <QVector> #include <QObject>
#include "base/path.h" #include "base/pathfwd.h"
#include "base/settingvalue.h"
#include "base/types.h"
#include "addtorrentparams.h" #include "addtorrentparams.h"
#include "cachestatus.h" #include "cachestatus.h"
#include "categoryoptions.h" #include "categoryoptions.h"
@ -52,28 +40,10 @@
#include "torrentinfo.h" #include "torrentinfo.h"
#include "trackerentry.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 QString;
class QThread;
class QTimer; class QTimer;
class QUrl; class QUrl;
class BandwidthScheduler;
class FileSearcher;
class FilterParserThread;
class Statistics;
// These values should remain unchanged when adding new items // These values should remain unchanged when adding new items
// so as not to break the existing user settings. // so as not to break the existing user settings.
enum MaxRatioAction enum MaxRatioAction
@ -100,6 +70,7 @@ namespace BitTorrent
class InfoHash; class InfoHash;
class MagnetUri; class MagnetUri;
class ResumeDataStorage; class ResumeDataStorage;
class SessionImpl;
class Torrent; class Torrent;
class TorrentImpl; class TorrentImpl;
class Tracker; class Tracker;
@ -177,53 +148,7 @@ namespace BitTorrent
Q_ENUM_NS(ResumeDataStorageType) Q_ENUM_NS(ResumeDataStorageType)
} }
struct SessionMetricIndices class Session : public QObject
{
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
{ {
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY_MOVE(Session) Q_DISABLE_COPY_MOVE(Session)
@ -233,34 +158,36 @@ namespace BitTorrent
static void freeInstance(); static void freeInstance();
static Session *instance(); static Session *instance();
Path savePath() const; using QObject::QObject;
void setSavePath(const Path &path);
Path downloadPath() const; virtual Path savePath() const = 0;
void setDownloadPath(const Path &path); virtual void setSavePath(const Path &path) = 0;
bool isDownloadPathEnabled() const; virtual Path downloadPath() const = 0;
void setDownloadPathEnabled(bool enabled); virtual void setDownloadPath(const Path &path) = 0;
virtual bool isDownloadPathEnabled() const = 0;
virtual void setDownloadPathEnabled(bool enabled) = 0;
static bool isValidCategoryName(const QString &name); static bool isValidCategoryName(const QString &name);
// returns category itself and all top level categories // returns category itself and all top level categories
static QStringList expandCategory(const QString &category); static QStringList expandCategory(const QString &category);
QStringList categories() const; virtual QStringList categories() const = 0;
CategoryOptions categoryOptions(const QString &categoryName) const; virtual CategoryOptions categoryOptions(const QString &categoryName) const = 0;
Path categorySavePath(const QString &categoryName) const; virtual Path categorySavePath(const QString &categoryName) const = 0;
Path categoryDownloadPath(const QString &categoryName) const; virtual Path categoryDownloadPath(const QString &categoryName) const = 0;
bool addCategory(const QString &name, const CategoryOptions &options = {}); virtual bool addCategory(const QString &name, const CategoryOptions &options = {}) = 0;
bool editCategory(const QString &name, const CategoryOptions &options); virtual bool editCategory(const QString &name, const CategoryOptions &options) = 0;
bool removeCategory(const QString &name); virtual bool removeCategory(const QString &name) = 0;
bool isSubcategoriesEnabled() const; virtual bool isSubcategoriesEnabled() const = 0;
void setSubcategoriesEnabled(bool value); virtual void setSubcategoriesEnabled(bool value) = 0;
bool useCategoryPathsInManualMode() const; virtual bool useCategoryPathsInManualMode() const = 0;
void setUseCategoryPathsInManualMode(bool value); virtual void setUseCategoryPathsInManualMode(bool value) = 0;
static bool isValidTag(const QString &tag); static bool isValidTag(const QString &tag);
QSet<QString> tags() const; virtual QSet<QString> tags() const = 0;
bool hasTag(const QString &tag) const; virtual bool hasTag(const QString &tag) const = 0;
bool addTag(const QString &tag); virtual bool addTag(const QString &tag) = 0;
bool removeTag(const QString &tag); virtual bool removeTag(const QString &tag) = 0;
// Torrent Management Mode subsystem (TMM) // Torrent Management Mode subsystem (TMM)
// //
@ -273,273 +200,245 @@ namespace BitTorrent
// 2. Torrent category save path changed // 2. Torrent category save path changed
// 3. Torrent category changed // 3. Torrent category changed
// (unless otherwise is specified) // (unless otherwise is specified)
bool isAutoTMMDisabledByDefault() const; virtual bool isAutoTMMDisabledByDefault() const = 0;
void setAutoTMMDisabledByDefault(bool value); virtual void setAutoTMMDisabledByDefault(bool value) = 0;
bool isDisableAutoTMMWhenCategoryChanged() const; virtual bool isDisableAutoTMMWhenCategoryChanged() const = 0;
void setDisableAutoTMMWhenCategoryChanged(bool value); virtual void setDisableAutoTMMWhenCategoryChanged(bool value) = 0;
bool isDisableAutoTMMWhenDefaultSavePathChanged() const; virtual bool isDisableAutoTMMWhenDefaultSavePathChanged() const = 0;
void setDisableAutoTMMWhenDefaultSavePathChanged(bool value); virtual void setDisableAutoTMMWhenDefaultSavePathChanged(bool value) = 0;
bool isDisableAutoTMMWhenCategorySavePathChanged() const; virtual bool isDisableAutoTMMWhenCategorySavePathChanged() const = 0;
void setDisableAutoTMMWhenCategorySavePathChanged(bool value); virtual void setDisableAutoTMMWhenCategorySavePathChanged(bool value) = 0;
qreal globalMaxRatio() const; virtual qreal globalMaxRatio() const = 0;
void setGlobalMaxRatio(qreal ratio); virtual void setGlobalMaxRatio(qreal ratio) = 0;
int globalMaxSeedingMinutes() const; virtual int globalMaxSeedingMinutes() const = 0;
void setGlobalMaxSeedingMinutes(int minutes); virtual void setGlobalMaxSeedingMinutes(int minutes) = 0;
bool isDHTEnabled() const; virtual bool isDHTEnabled() const = 0;
void setDHTEnabled(bool enabled); virtual void setDHTEnabled(bool enabled) = 0;
bool isLSDEnabled() const; virtual bool isLSDEnabled() const = 0;
void setLSDEnabled(bool enabled); virtual void setLSDEnabled(bool enabled) = 0;
bool isPeXEnabled() const; virtual bool isPeXEnabled() const = 0;
void setPeXEnabled(bool enabled); virtual void setPeXEnabled(bool enabled) = 0;
bool isAddTorrentPaused() const; virtual bool isAddTorrentPaused() const = 0;
void setAddTorrentPaused(bool value); virtual void setAddTorrentPaused(bool value) = 0;
TorrentContentLayout torrentContentLayout() const; virtual TorrentContentLayout torrentContentLayout() const = 0;
void setTorrentContentLayout(TorrentContentLayout value); virtual void setTorrentContentLayout(TorrentContentLayout value) = 0;
bool isTrackerEnabled() const; virtual bool isTrackerEnabled() const = 0;
void setTrackerEnabled(bool enabled); virtual void setTrackerEnabled(bool enabled) = 0;
bool isAppendExtensionEnabled() const; virtual bool isAppendExtensionEnabled() const = 0;
void setAppendExtensionEnabled(bool enabled); virtual void setAppendExtensionEnabled(bool enabled) = 0;
int refreshInterval() const; virtual int refreshInterval() const = 0;
void setRefreshInterval(int value); virtual void setRefreshInterval(int value) = 0;
bool isPreallocationEnabled() const; virtual bool isPreallocationEnabled() const = 0;
void setPreallocationEnabled(bool enabled); virtual void setPreallocationEnabled(bool enabled) = 0;
Path torrentExportDirectory() const; virtual Path torrentExportDirectory() const = 0;
void setTorrentExportDirectory(const Path &path); virtual void setTorrentExportDirectory(const Path &path) = 0;
Path finishedTorrentExportDirectory() const; virtual Path finishedTorrentExportDirectory() const = 0;
void setFinishedTorrentExportDirectory(const Path &path); virtual void setFinishedTorrentExportDirectory(const Path &path) = 0;
int globalDownloadSpeedLimit() const; virtual int globalDownloadSpeedLimit() const = 0;
void setGlobalDownloadSpeedLimit(int limit); virtual void setGlobalDownloadSpeedLimit(int limit) = 0;
int globalUploadSpeedLimit() const; virtual int globalUploadSpeedLimit() const = 0;
void setGlobalUploadSpeedLimit(int limit); virtual void setGlobalUploadSpeedLimit(int limit) = 0;
int altGlobalDownloadSpeedLimit() const; virtual int altGlobalDownloadSpeedLimit() const = 0;
void setAltGlobalDownloadSpeedLimit(int limit); virtual void setAltGlobalDownloadSpeedLimit(int limit) = 0;
int altGlobalUploadSpeedLimit() const; virtual int altGlobalUploadSpeedLimit() const = 0;
void setAltGlobalUploadSpeedLimit(int limit); virtual void setAltGlobalUploadSpeedLimit(int limit) = 0;
int downloadSpeedLimit() const; virtual int downloadSpeedLimit() const = 0;
void setDownloadSpeedLimit(int limit); virtual void setDownloadSpeedLimit(int limit) = 0;
int uploadSpeedLimit() const; virtual int uploadSpeedLimit() const = 0;
void setUploadSpeedLimit(int limit); virtual void setUploadSpeedLimit(int limit) = 0;
bool isAltGlobalSpeedLimitEnabled() const; virtual bool isAltGlobalSpeedLimitEnabled() const = 0;
void setAltGlobalSpeedLimitEnabled(bool enabled); virtual void setAltGlobalSpeedLimitEnabled(bool enabled) = 0;
bool isBandwidthSchedulerEnabled() const; virtual bool isBandwidthSchedulerEnabled() const = 0;
void setBandwidthSchedulerEnabled(bool enabled); virtual void setBandwidthSchedulerEnabled(bool enabled) = 0;
bool isPerformanceWarningEnabled() const; virtual bool isPerformanceWarningEnabled() const = 0;
void setPerformanceWarningEnabled(bool enable); virtual void setPerformanceWarningEnabled(bool enable) = 0;
int saveResumeDataInterval() const; virtual int saveResumeDataInterval() const = 0;
void setSaveResumeDataInterval(int value); virtual void setSaveResumeDataInterval(int value) = 0;
int port() const; virtual int port() const = 0;
void setPort(int port); virtual void setPort(int port) = 0;
QString networkInterface() const; virtual QString networkInterface() const = 0;
void setNetworkInterface(const QString &iface); virtual void setNetworkInterface(const QString &iface) = 0;
QString networkInterfaceName() const; virtual QString networkInterfaceName() const = 0;
void setNetworkInterfaceName(const QString &name); virtual void setNetworkInterfaceName(const QString &name) = 0;
QString networkInterfaceAddress() const; virtual QString networkInterfaceAddress() const = 0;
void setNetworkInterfaceAddress(const QString &address); virtual void setNetworkInterfaceAddress(const QString &address) = 0;
int encryption() const; virtual int encryption() const = 0;
void setEncryption(int state); virtual void setEncryption(int state) = 0;
int maxActiveCheckingTorrents() const; virtual int maxActiveCheckingTorrents() const = 0;
void setMaxActiveCheckingTorrents(int val); virtual void setMaxActiveCheckingTorrents(int val) = 0;
bool isProxyPeerConnectionsEnabled() const; virtual bool isProxyPeerConnectionsEnabled() const = 0;
void setProxyPeerConnectionsEnabled(bool enabled); virtual void setProxyPeerConnectionsEnabled(bool enabled) = 0;
ChokingAlgorithm chokingAlgorithm() const; virtual ChokingAlgorithm chokingAlgorithm() const = 0;
void setChokingAlgorithm(ChokingAlgorithm mode); virtual void setChokingAlgorithm(ChokingAlgorithm mode) = 0;
SeedChokingAlgorithm seedChokingAlgorithm() const; virtual SeedChokingAlgorithm seedChokingAlgorithm() const = 0;
void setSeedChokingAlgorithm(SeedChokingAlgorithm mode); virtual void setSeedChokingAlgorithm(SeedChokingAlgorithm mode) = 0;
bool isAddTrackersEnabled() const; virtual bool isAddTrackersEnabled() const = 0;
void setAddTrackersEnabled(bool enabled); virtual void setAddTrackersEnabled(bool enabled) = 0;
QString additionalTrackers() const; virtual QString additionalTrackers() const = 0;
void setAdditionalTrackers(const QString &trackers); virtual void setAdditionalTrackers(const QString &trackers) = 0;
bool isIPFilteringEnabled() const; virtual bool isIPFilteringEnabled() const = 0;
void setIPFilteringEnabled(bool enabled); virtual void setIPFilteringEnabled(bool enabled) = 0;
Path IPFilterFile() const; virtual Path IPFilterFile() const = 0;
void setIPFilterFile(const Path &path); virtual void setIPFilterFile(const Path &path) = 0;
bool announceToAllTrackers() const; virtual bool announceToAllTrackers() const = 0;
void setAnnounceToAllTrackers(bool val); virtual void setAnnounceToAllTrackers(bool val) = 0;
bool announceToAllTiers() const; virtual bool announceToAllTiers() const = 0;
void setAnnounceToAllTiers(bool val); virtual void setAnnounceToAllTiers(bool val) = 0;
int peerTurnover() const; virtual int peerTurnover() const = 0;
void setPeerTurnover(int val); virtual void setPeerTurnover(int val) = 0;
int peerTurnoverCutoff() const; virtual int peerTurnoverCutoff() const = 0;
void setPeerTurnoverCutoff(int val); virtual void setPeerTurnoverCutoff(int val) = 0;
int peerTurnoverInterval() const; virtual int peerTurnoverInterval() const = 0;
void setPeerTurnoverInterval(int val); virtual void setPeerTurnoverInterval(int val) = 0;
int requestQueueSize() const; virtual int requestQueueSize() const = 0;
void setRequestQueueSize(int val); virtual void setRequestQueueSize(int val) = 0;
int asyncIOThreads() const; virtual int asyncIOThreads() const = 0;
void setAsyncIOThreads(int num); virtual void setAsyncIOThreads(int num) = 0;
int hashingThreads() const; virtual int hashingThreads() const = 0;
void setHashingThreads(int num); virtual void setHashingThreads(int num) = 0;
int filePoolSize() const; virtual int filePoolSize() const = 0;
void setFilePoolSize(int size); virtual void setFilePoolSize(int size) = 0;
int checkingMemUsage() const; virtual int checkingMemUsage() const = 0;
void setCheckingMemUsage(int size); virtual void setCheckingMemUsage(int size) = 0;
int diskCacheSize() const; virtual int diskCacheSize() const = 0;
void setDiskCacheSize(int size); virtual void setDiskCacheSize(int size) = 0;
int diskCacheTTL() const; virtual int diskCacheTTL() const = 0;
void setDiskCacheTTL(int ttl); virtual void setDiskCacheTTL(int ttl) = 0;
qint64 diskQueueSize() const; virtual qint64 diskQueueSize() const = 0;
void setDiskQueueSize(qint64 size); virtual void setDiskQueueSize(qint64 size) = 0;
DiskIOType diskIOType() const; virtual DiskIOType diskIOType() const = 0;
void setDiskIOType(DiskIOType type); virtual void setDiskIOType(DiskIOType type) = 0;
DiskIOReadMode diskIOReadMode() const; virtual DiskIOReadMode diskIOReadMode() const = 0;
void setDiskIOReadMode(DiskIOReadMode mode); virtual void setDiskIOReadMode(DiskIOReadMode mode) = 0;
DiskIOWriteMode diskIOWriteMode() const; virtual DiskIOWriteMode diskIOWriteMode() const = 0;
void setDiskIOWriteMode(DiskIOWriteMode mode); virtual void setDiskIOWriteMode(DiskIOWriteMode mode) = 0;
bool isCoalesceReadWriteEnabled() const; virtual bool isCoalesceReadWriteEnabled() const = 0;
void setCoalesceReadWriteEnabled(bool enabled); virtual void setCoalesceReadWriteEnabled(bool enabled) = 0;
bool usePieceExtentAffinity() const; virtual bool usePieceExtentAffinity() const = 0;
void setPieceExtentAffinity(bool enabled); virtual void setPieceExtentAffinity(bool enabled) = 0;
bool isSuggestModeEnabled() const; virtual bool isSuggestModeEnabled() const = 0;
void setSuggestMode(bool mode); virtual void setSuggestMode(bool mode) = 0;
int sendBufferWatermark() const; virtual int sendBufferWatermark() const = 0;
void setSendBufferWatermark(int value); virtual void setSendBufferWatermark(int value) = 0;
int sendBufferLowWatermark() const; virtual int sendBufferLowWatermark() const = 0;
void setSendBufferLowWatermark(int value); virtual void setSendBufferLowWatermark(int value) = 0;
int sendBufferWatermarkFactor() const; virtual int sendBufferWatermarkFactor() const = 0;
void setSendBufferWatermarkFactor(int value); virtual void setSendBufferWatermarkFactor(int value) = 0;
int connectionSpeed() const; virtual int connectionSpeed() const = 0;
void setConnectionSpeed(int value); virtual void setConnectionSpeed(int value) = 0;
int socketBacklogSize() const; virtual int socketBacklogSize() const = 0;
void setSocketBacklogSize(int value); virtual void setSocketBacklogSize(int value) = 0;
bool isAnonymousModeEnabled() const; virtual bool isAnonymousModeEnabled() const = 0;
void setAnonymousModeEnabled(bool enabled); virtual void setAnonymousModeEnabled(bool enabled) = 0;
bool isQueueingSystemEnabled() const; virtual bool isQueueingSystemEnabled() const = 0;
void setQueueingSystemEnabled(bool enabled); virtual void setQueueingSystemEnabled(bool enabled) = 0;
bool ignoreSlowTorrentsForQueueing() const; virtual bool ignoreSlowTorrentsForQueueing() const = 0;
void setIgnoreSlowTorrentsForQueueing(bool ignore); virtual void setIgnoreSlowTorrentsForQueueing(bool ignore) = 0;
int downloadRateForSlowTorrents() const; virtual int downloadRateForSlowTorrents() const = 0;
void setDownloadRateForSlowTorrents(int rateInKibiBytes); virtual void setDownloadRateForSlowTorrents(int rateInKibiBytes) = 0;
int uploadRateForSlowTorrents() const; virtual int uploadRateForSlowTorrents() const = 0;
void setUploadRateForSlowTorrents(int rateInKibiBytes); virtual void setUploadRateForSlowTorrents(int rateInKibiBytes) = 0;
int slowTorrentsInactivityTimer() const; virtual int slowTorrentsInactivityTimer() const = 0;
void setSlowTorrentsInactivityTimer(int timeInSeconds); virtual void setSlowTorrentsInactivityTimer(int timeInSeconds) = 0;
int outgoingPortsMin() const; virtual int outgoingPortsMin() const = 0;
void setOutgoingPortsMin(int min); virtual void setOutgoingPortsMin(int min) = 0;
int outgoingPortsMax() const; virtual int outgoingPortsMax() const = 0;
void setOutgoingPortsMax(int max); virtual void setOutgoingPortsMax(int max) = 0;
int UPnPLeaseDuration() const; virtual int UPnPLeaseDuration() const = 0;
void setUPnPLeaseDuration(int duration); virtual void setUPnPLeaseDuration(int duration) = 0;
int peerToS() const; virtual int peerToS() const = 0;
void setPeerToS(int value); virtual void setPeerToS(int value) = 0;
bool ignoreLimitsOnLAN() const; virtual bool ignoreLimitsOnLAN() const = 0;
void setIgnoreLimitsOnLAN(bool ignore); virtual void setIgnoreLimitsOnLAN(bool ignore) = 0;
bool includeOverheadInLimits() const; virtual bool includeOverheadInLimits() const = 0;
void setIncludeOverheadInLimits(bool include); virtual void setIncludeOverheadInLimits(bool include) = 0;
QString announceIP() const; virtual QString announceIP() const = 0;
void setAnnounceIP(const QString &ip); virtual void setAnnounceIP(const QString &ip) = 0;
int maxConcurrentHTTPAnnounces() const; virtual int maxConcurrentHTTPAnnounces() const = 0;
void setMaxConcurrentHTTPAnnounces(int value); virtual void setMaxConcurrentHTTPAnnounces(int value) = 0;
bool isReannounceWhenAddressChangedEnabled() const; virtual bool isReannounceWhenAddressChangedEnabled() const = 0;
void setReannounceWhenAddressChangedEnabled(bool enabled); virtual void setReannounceWhenAddressChangedEnabled(bool enabled) = 0;
void reannounceToAllTrackers() const; virtual void reannounceToAllTrackers() const = 0;
int stopTrackerTimeout() const; virtual int stopTrackerTimeout() const = 0;
void setStopTrackerTimeout(int value); virtual void setStopTrackerTimeout(int value) = 0;
int maxConnections() const; virtual int maxConnections() const = 0;
void setMaxConnections(int max); virtual void setMaxConnections(int max) = 0;
int maxConnectionsPerTorrent() const; virtual int maxConnectionsPerTorrent() const = 0;
void setMaxConnectionsPerTorrent(int max); virtual void setMaxConnectionsPerTorrent(int max) = 0;
int maxUploads() const; virtual int maxUploads() const = 0;
void setMaxUploads(int max); virtual void setMaxUploads(int max) = 0;
int maxUploadsPerTorrent() const; virtual int maxUploadsPerTorrent() const = 0;
void setMaxUploadsPerTorrent(int max); virtual void setMaxUploadsPerTorrent(int max) = 0;
int maxActiveDownloads() const; virtual int maxActiveDownloads() const = 0;
void setMaxActiveDownloads(int max); virtual void setMaxActiveDownloads(int max) = 0;
int maxActiveUploads() const; virtual int maxActiveUploads() const = 0;
void setMaxActiveUploads(int max); virtual void setMaxActiveUploads(int max) = 0;
int maxActiveTorrents() const; virtual int maxActiveTorrents() const = 0;
void setMaxActiveTorrents(int max); virtual void setMaxActiveTorrents(int max) = 0;
BTProtocol btProtocol() const; virtual BTProtocol btProtocol() const = 0;
void setBTProtocol(BTProtocol protocol); virtual void setBTProtocol(BTProtocol protocol) = 0;
bool isUTPRateLimited() const; virtual bool isUTPRateLimited() const = 0;
void setUTPRateLimited(bool limited); virtual void setUTPRateLimited(bool limited) = 0;
MixedModeAlgorithm utpMixedMode() const; virtual MixedModeAlgorithm utpMixedMode() const = 0;
void setUtpMixedMode(MixedModeAlgorithm mode); virtual void setUtpMixedMode(MixedModeAlgorithm mode) = 0;
bool isIDNSupportEnabled() const; virtual bool isIDNSupportEnabled() const = 0;
void setIDNSupportEnabled(bool enabled); virtual void setIDNSupportEnabled(bool enabled) = 0;
bool multiConnectionsPerIpEnabled() const; virtual bool multiConnectionsPerIpEnabled() const = 0;
void setMultiConnectionsPerIpEnabled(bool enabled); virtual void setMultiConnectionsPerIpEnabled(bool enabled) = 0;
bool validateHTTPSTrackerCertificate() const; virtual bool validateHTTPSTrackerCertificate() const = 0;
void setValidateHTTPSTrackerCertificate(bool enabled); virtual void setValidateHTTPSTrackerCertificate(bool enabled) = 0;
bool isSSRFMitigationEnabled() const; virtual bool isSSRFMitigationEnabled() const = 0;
void setSSRFMitigationEnabled(bool enabled); virtual void setSSRFMitigationEnabled(bool enabled) = 0;
bool blockPeersOnPrivilegedPorts() const; virtual bool blockPeersOnPrivilegedPorts() const = 0;
void setBlockPeersOnPrivilegedPorts(bool enabled); virtual void setBlockPeersOnPrivilegedPorts(bool enabled) = 0;
bool isTrackerFilteringEnabled() const; virtual bool isTrackerFilteringEnabled() const = 0;
void setTrackerFilteringEnabled(bool enabled); virtual void setTrackerFilteringEnabled(bool enabled) = 0;
bool isExcludedFileNamesEnabled() const; virtual bool isExcludedFileNamesEnabled() const = 0;
void setExcludedFileNamesEnabled(const bool enabled); virtual void setExcludedFileNamesEnabled(const bool enabled) = 0;
QStringList excludedFileNames() const; virtual QStringList excludedFileNames() const = 0;
void setExcludedFileNames(const QStringList &newList); virtual void setExcludedFileNames(const QStringList &newList) = 0;
bool isFilenameExcluded(const QString &fileName) const; virtual bool isFilenameExcluded(const QString &fileName) const = 0;
QStringList bannedIPs() const; virtual QStringList bannedIPs() const = 0;
void setBannedIPs(const QStringList &newList); virtual void setBannedIPs(const QStringList &newList) = 0;
ResumeDataStorageType resumeDataStorageType() const; virtual ResumeDataStorageType resumeDataStorageType() const = 0;
void setResumeDataStorageType(ResumeDataStorageType type); virtual void setResumeDataStorageType(ResumeDataStorageType type) = 0;
bool isRestored() const; virtual bool isRestored() const = 0;
Torrent *getTorrent(const TorrentID &id) const; virtual Torrent *getTorrent(const TorrentID &id) const = 0;
Torrent *findTorrent(const InfoHash &infoHash) const; virtual Torrent *findTorrent(const InfoHash &infoHash) const = 0;
QVector<Torrent *> torrents() const; virtual QVector<Torrent *> torrents() const = 0;
qsizetype torrentsCount() const; virtual qsizetype torrentsCount() const = 0;
bool hasActiveTorrents() const; virtual bool hasActiveTorrents() const = 0;
bool hasUnfinishedTorrents() const; virtual bool hasUnfinishedTorrents() const = 0;
bool hasRunningSeed() const; virtual bool hasRunningSeed() const = 0;
const SessionStatus &status() const; virtual const SessionStatus &status() const = 0;
const CacheStatus &cacheStatus() const; virtual const CacheStatus &cacheStatus() const = 0;
qint64 getAlltimeDL() const; virtual qint64 getAlltimeDL() const = 0;
qint64 getAlltimeUL() const; virtual qint64 getAlltimeUL() const = 0;
bool isListening() const; virtual bool isListening() const = 0;
MaxRatioAction maxRatioAction() const; virtual MaxRatioAction maxRatioAction() const = 0;
void setMaxRatioAction(MaxRatioAction act); virtual void setMaxRatioAction(MaxRatioAction act) = 0;
void banIP(const QString &ip); virtual void banIP(const QString &ip) = 0;
bool isKnownTorrent(const InfoHash &infoHash) const; virtual bool isKnownTorrent(const InfoHash &infoHash) const = 0;
bool addTorrent(const QString &source, const AddTorrentParams &params = AddTorrentParams()); virtual bool addTorrent(const QString &source, const AddTorrentParams &params = AddTorrentParams()) = 0;
bool addTorrent(const MagnetUri &magnetUri, const AddTorrentParams &params = AddTorrentParams()); virtual bool addTorrent(const MagnetUri &magnetUri, const AddTorrentParams &params = AddTorrentParams()) = 0;
bool addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams &params = AddTorrentParams()); virtual bool addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams &params = AddTorrentParams()) = 0;
bool deleteTorrent(const TorrentID &id, DeleteOption deleteOption = DeleteTorrent); virtual bool deleteTorrent(const TorrentID &id, DeleteOption deleteOption = DeleteOption::DeleteTorrent) = 0;
bool downloadMetadata(const MagnetUri &magnetUri); virtual bool downloadMetadata(const MagnetUri &magnetUri) = 0;
bool cancelDownloadMetadata(const TorrentID &id); virtual bool cancelDownloadMetadata(const TorrentID &id) = 0;
void recursiveTorrentDownload(const TorrentID &id); virtual void recursiveTorrentDownload(const TorrentID &id) = 0;
void increaseTorrentsQueuePos(const QVector<TorrentID> &ids); virtual void increaseTorrentsQueuePos(const QVector<TorrentID> &ids) = 0;
void decreaseTorrentsQueuePos(const QVector<TorrentID> &ids); virtual void decreaseTorrentsQueuePos(const QVector<TorrentID> &ids) = 0;
void topTorrentsQueuePos(const QVector<TorrentID> &ids); virtual void topTorrentsQueuePos(const QVector<TorrentID> &ids) = 0;
void bottomTorrentsQueuePos(const QVector<TorrentID> &ids); virtual void bottomTorrentsQueuePos(const QVector<TorrentID> &ids) = 0;
// 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;
signals: signals:
void startupProgressUpdated(int progress); void startupProgressUpdated(int progress);
@ -581,293 +480,5 @@ namespace BitTorrent
void trackerSuccess(Torrent *torrent, const QString &tracker); void trackerSuccess(Torrent *torrent, const QString &tracker);
void trackerWarning(Torrent *torrent, const QString &tracker); void trackerWarning(Torrent *torrent, const QString &tracker);
void trackerEntriesUpdated(const QHash<Torrent *, QSet<QString>> &updateInfos); 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;
}; };
} }

828
src/base/bittorrent/session.cpp → src/base/bittorrent/sessionimpl.cpp

File diff suppressed because it is too large Load Diff

730
src/base/bittorrent/sessionimpl.h

@ -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;
};
}

4
src/base/bittorrent/statistics.cpp

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

6
src/base/bittorrent/statistics.h

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

6
src/base/bittorrent/torrentimpl.cpp

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

6
src/base/bittorrent/torrentimpl.h

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

4
src/gui/categoryfiltermodel.cpp

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

1
src/gui/properties/propertieswidget.cpp

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

1
src/gui/transferlistmodel.cpp

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

1
src/webui/api/transfercontroller.cpp

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

Loading…
Cancel
Save