From 525692759de15391eec1760085b95f3042881c35 Mon Sep 17 00:00:00 2001 From: Vladimir Golovnev Date: Sat, 27 Aug 2022 08:01:24 +0300 Subject: [PATCH] Split Session class into interface/implementation parts PR #17579. --- src/base/CMakeLists.txt | 3 +- src/base/base.pri | 3 +- .../bittorrent/nativesessionextension.cpp | 2 +- src/base/bittorrent/session.h | 923 +++++------------- .../{session.cpp => sessionimpl.cpp} | 828 ++++++++-------- src/base/bittorrent/sessionimpl.h | 730 ++++++++++++++ src/base/bittorrent/statistics.cpp | 4 +- src/base/bittorrent/statistics.h | 6 +- src/base/bittorrent/torrentimpl.cpp | 6 +- src/base/bittorrent/torrentimpl.h | 6 +- src/gui/categoryfiltermodel.cpp | 4 +- src/gui/properties/propertieswidget.cpp | 1 + src/gui/transferlistmodel.cpp | 1 + src/webui/api/transfercontroller.cpp | 1 + 14 files changed, 1430 insertions(+), 1088 deletions(-) rename src/base/bittorrent/{session.cpp => sessionimpl.cpp} (88%) create mode 100644 src/base/bittorrent/sessionimpl.h diff --git a/src/base/CMakeLists.txt b/src/base/CMakeLists.txt index d94cc27b1..1e49f2f1b 100644 --- a/src/base/CMakeLists.txt +++ b/src/base/CMakeLists.txt @@ -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 diff --git a/src/base/base.pri b/src/base/base.pri index 79d37b9ec..70bb86855 100644 --- a/src/base/base.pri +++ b/src/base/base.pri @@ -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 \ diff --git a/src/base/bittorrent/nativesessionextension.cpp b/src/base/bittorrent/nativesessionextension.cpp index 243f14bbf..248397cf9 100644 --- a/src/base/bittorrent/nativesessionextension.cpp +++ b/src/base/bittorrent/nativesessionextension.cpp @@ -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) diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index ea369537e..1a4b82103 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -1,6 +1,6 @@ /* * Bittorrent Client using Qt and libtorrent. - * Copyright (C) 2015 Vladimir Golovnev + * Copyright (C) 2015-2022 Vladimir Golovnev * Copyright (C) 2006 Christophe Dumez * * This program is free software; you can redistribute it and/or @@ -29,22 +29,10 @@ #pragma once -#include -#include - -#include -#include -#include - -#include -#include -#include #include -#include +#include -#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 tags() const; - bool hasTag(const QString &tag) const; - bool addTag(const QString &tag); - bool removeTag(const QString &tag); + virtual QSet 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); - - 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); - - 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); - - 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); - - bool isRestored() const; - - Torrent *getTorrent(const TorrentID &id) const; - Torrent *findTorrent(const InfoHash &infoHash) const; - QVector 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; - - MaxRatioAction maxRatioAction() const; - void setMaxRatioAction(MaxRatioAction act); - - void banIP(const QString &ip); - - bool isKnownTorrent(const InfoHash &infoHash) const; - bool addTorrent(const QString &source, const AddTorrentParams ¶ms = AddTorrentParams()); - bool addTorrent(const MagnetUri &magnetUri, const AddTorrentParams ¶ms = AddTorrentParams()); - bool addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams ¶ms = AddTorrentParams()); - bool deleteTorrent(const TorrentID &id, DeleteOption deleteOption = DeleteTorrent); - bool downloadMetadata(const MagnetUri &magnetUri); - bool cancelDownloadMetadata(const TorrentID &id); - - void recursiveTorrentDownload(const TorrentID &id); - void increaseTorrentsQueuePos(const QVector &ids); - void decreaseTorrentsQueuePos(const QVector &ids); - void topTorrentsQueuePos(const QVector &ids); - void bottomTorrentsQueuePos(const QVector &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 &newTrackers); - void handleTorrentTrackersRemoved(TorrentImpl *const torrent, const QStringList &deletedTrackers); - void handleTorrentTrackersChanged(TorrentImpl *const torrent); - void handleTorrentUrlSeedsAdded(TorrentImpl *const torrent, const QVector &newUrlSeeds); - void handleTorrentUrlSeedsRemoved(TorrentImpl *const torrent, const QVector &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 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; + + 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; + + 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; + + 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; + + virtual bool isRestored() const = 0; + + virtual Torrent *getTorrent(const TorrentID &id) const = 0; + virtual Torrent *findTorrent(const InfoHash &infoHash) const = 0; + virtual QVector 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; + + virtual MaxRatioAction maxRatioAction() const = 0; + virtual void setMaxRatioAction(MaxRatioAction act) = 0; + + virtual void banIP(const QString &ip) = 0; + + virtual bool isKnownTorrent(const InfoHash &infoHash) const = 0; + virtual bool addTorrent(const QString &source, const AddTorrentParams ¶ms = AddTorrentParams()) = 0; + virtual bool addTorrent(const MagnetUri &magnetUri, const AddTorrentParams ¶ms = AddTorrentParams()) = 0; + virtual bool addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams ¶ms = 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; + + virtual void recursiveTorrentDownload(const TorrentID &id) = 0; + virtual void increaseTorrentsQueuePos(const QVector &ids) = 0; + virtual void decreaseTorrentsQueuePos(const QVector &ids) = 0; + virtual void topTorrentsQueuePos(const QVector &ids) = 0; + virtual void bottomTorrentsQueuePos(const QVector &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> &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 &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 &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 ¶ms); - - void saveResumeData(); - void saveTorrentsQueue() const; - void removeTorrentsQueue() const; - - std::vector 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 m_isDHTEnabled; - CachedSettingValue m_isLSDEnabled; - CachedSettingValue m_isPeXEnabled; - CachedSettingValue m_isIPFilteringEnabled; - CachedSettingValue m_isTrackerFilteringEnabled; - CachedSettingValue m_IPFilterFile; - CachedSettingValue m_announceToAllTrackers; - CachedSettingValue m_announceToAllTiers; - CachedSettingValue m_asyncIOThreads; - CachedSettingValue m_hashingThreads; - CachedSettingValue m_filePoolSize; - CachedSettingValue m_checkingMemUsage; - CachedSettingValue m_diskCacheSize; - CachedSettingValue m_diskCacheTTL; - CachedSettingValue m_diskQueueSize; - CachedSettingValue m_diskIOType; - CachedSettingValue m_diskIOReadMode; - CachedSettingValue m_diskIOWriteMode; - CachedSettingValue m_coalesceReadWriteEnabled; - CachedSettingValue m_usePieceExtentAffinity; - CachedSettingValue m_isSuggestMode; - CachedSettingValue m_sendBufferWatermark; - CachedSettingValue m_sendBufferLowWatermark; - CachedSettingValue m_sendBufferWatermarkFactor; - CachedSettingValue m_connectionSpeed; - CachedSettingValue m_socketBacklogSize; - CachedSettingValue m_isAnonymousModeEnabled; - CachedSettingValue m_isQueueingEnabled; - CachedSettingValue m_maxActiveDownloads; - CachedSettingValue m_maxActiveUploads; - CachedSettingValue m_maxActiveTorrents; - CachedSettingValue m_ignoreSlowTorrentsForQueueing; - CachedSettingValue m_downloadRateForSlowTorrents; - CachedSettingValue m_uploadRateForSlowTorrents; - CachedSettingValue m_slowTorrentsInactivityTimer; - CachedSettingValue m_outgoingPortsMin; - CachedSettingValue m_outgoingPortsMax; - CachedSettingValue m_UPnPLeaseDuration; - CachedSettingValue m_peerToS; - CachedSettingValue m_ignoreLimitsOnLAN; - CachedSettingValue m_includeOverheadInLimits; - CachedSettingValue m_announceIP; - CachedSettingValue m_maxConcurrentHTTPAnnounces; - CachedSettingValue m_isReannounceWhenAddressChangedEnabled; - CachedSettingValue m_stopTrackerTimeout; - CachedSettingValue m_maxConnections; - CachedSettingValue m_maxUploads; - CachedSettingValue m_maxConnectionsPerTorrent; - CachedSettingValue m_maxUploadsPerTorrent; - CachedSettingValue m_btProtocol; - CachedSettingValue m_isUTPRateLimited; - CachedSettingValue m_utpMixedMode; - CachedSettingValue m_IDNSupportEnabled; - CachedSettingValue m_multiConnectionsPerIpEnabled; - CachedSettingValue m_validateHTTPSTrackerCertificate; - CachedSettingValue m_SSRFMitigationEnabled; - CachedSettingValue m_blockPeersOnPrivilegedPorts; - CachedSettingValue m_isAddTrackersEnabled; - CachedSettingValue m_additionalTrackers; - CachedSettingValue m_globalMaxRatio; - CachedSettingValue m_globalMaxSeedingMinutes; - CachedSettingValue m_isAddTorrentPaused; - CachedSettingValue m_torrentContentLayout; - CachedSettingValue m_isAppendExtensionEnabled; - CachedSettingValue m_refreshInterval; - CachedSettingValue m_isPreallocationEnabled; - CachedSettingValue m_torrentExportDirectory; - CachedSettingValue m_finishedTorrentExportDirectory; - CachedSettingValue m_globalDownloadSpeedLimit; - CachedSettingValue m_globalUploadSpeedLimit; - CachedSettingValue m_altGlobalDownloadSpeedLimit; - CachedSettingValue m_altGlobalUploadSpeedLimit; - CachedSettingValue m_isAltGlobalSpeedLimitEnabled; - CachedSettingValue m_isBandwidthSchedulerEnabled; - CachedSettingValue m_isPerformanceWarningEnabled; - CachedSettingValue m_saveResumeDataInterval; - CachedSettingValue m_port; - CachedSettingValue m_networkInterface; - CachedSettingValue m_networkInterfaceName; - CachedSettingValue m_networkInterfaceAddress; - CachedSettingValue m_encryption; - CachedSettingValue m_maxActiveCheckingTorrents; - CachedSettingValue m_isProxyPeerConnectionsEnabled; - CachedSettingValue m_chokingAlgorithm; - CachedSettingValue m_seedChokingAlgorithm; - CachedSettingValue m_storedTags; - CachedSettingValue m_maxRatioAction; - CachedSettingValue m_savePath; - CachedSettingValue m_downloadPath; - CachedSettingValue m_isDownloadPathEnabled; - CachedSettingValue m_isSubcategoriesEnabled; - CachedSettingValue m_useCategoryPathsInManualMode; - CachedSettingValue m_isAutoTMMDisabledByDefault; - CachedSettingValue m_isDisableAutoTMMWhenCategoryChanged; - CachedSettingValue m_isDisableAutoTMMWhenDefaultSavePathChanged; - CachedSettingValue m_isDisableAutoTMMWhenCategorySavePathChanged; - CachedSettingValue m_isTrackerEnabled; - CachedSettingValue m_peerTurnover; - CachedSettingValue m_peerTurnoverCutoff; - CachedSettingValue m_peerTurnoverInterval; - CachedSettingValue m_requestQueueSize; - CachedSettingValue m_isExcludedFileNamesEnabled; - CachedSettingValue m_excludedFileNames; - CachedSettingValue m_bannedIPs; - CachedSettingValue 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 m_additionalTrackerList; - QVector m_excludedFileNamesRegExpList; - - bool m_refreshEnqueued = false; - QTimer *m_seedingLimitTimer = nullptr; - QTimer *m_resumeDataTimer = nullptr; - Statistics *m_statistics = nullptr; - // IP filtering - QPointer m_filterParser; - QPointer m_bwScheduler; - // Tracker - QPointer m_tracker; - - QThread *m_ioThread = nullptr; - ResumeDataStorage *m_resumeDataStorage = nullptr; - FileSearcher *m_fileSearcher = nullptr; - - QSet m_downloadedMetadata; - - QHash m_torrents; - QHash m_loadingTorrents; - QHash m_downloadedTorrents; - QHash m_removingTorrents; - QSet m_needSaveResumeDataTorrents; - QHash m_changedTorrentIDs; - QMap m_categories; - QSet m_tags; - - QHash> m_updatedTrackerEntries; - - // I/O errored torrents - QSet 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 m_moveStorageQueue; - - QString m_lastExternalIP; - - bool m_needUpgradeDownloadPath = false; - - static Session *m_instance; }; } diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/sessionimpl.cpp similarity index 88% rename from src/base/bittorrent/session.cpp rename to src/base/bittorrent/sessionimpl.cpp index d300648c4..ccab08d88 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/sessionimpl.cpp @@ -27,7 +27,7 @@ * exception statement from your version. */ -#include "session.h" +#include "sessionimpl.h" #include #include @@ -299,7 +299,7 @@ namespace #endif } -struct BitTorrent::Session::ResumeSessionContext final : public QObject +struct BitTorrent::SessionImpl::ResumeSessionContext final : public QObject { using QObject::QObject; @@ -320,15 +320,55 @@ struct BitTorrent::Session::ResumeSessionContext final : public QObject const int addTorrentParamsId = qRegisterMetaType(); -// Session +Session *SessionImpl::m_instance = nullptr; -Session *Session::m_instance = nullptr; +void Session::initInstance() +{ + if (!SessionImpl::m_instance) + SessionImpl::m_instance = new SessionImpl; +} + +void Session::freeInstance() +{ + delete SessionImpl::m_instance; + SessionImpl::m_instance = nullptr; +} + +Session *Session::instance() +{ + return SessionImpl::m_instance; +} + +bool Session::isValidCategoryName(const QString &name) +{ + const QRegularExpression re {uR"(^([^\\\/]|[^\\\/]([^\\\/]|\/(?=[^\/]))*[^\\\/])$)"_qs}; + return (name.isEmpty() || (name.indexOf(re) == 0)); +} + +bool Session::isValidTag(const QString &tag) +{ + return (!tag.trimmed().isEmpty() && !tag.contains(u',')); +} + +QStringList Session::expandCategory(const QString &category) +{ + QStringList result; + int index = 0; + while ((index = category.indexOf(u'/', index)) >= 0) + { + result << category.left(index); + ++index; + } + result << category; + + return result; +} #define BITTORRENT_KEY(name) u"BitTorrent/" name #define BITTORRENT_SESSION_KEY(name) BITTORRENT_KEY(u"Session/") name -Session::Session(QObject *parent) - : QObject(parent) +SessionImpl::SessionImpl(QObject *parent) + : Session(parent) , m_isDHTEnabled(BITTORRENT_SESSION_KEY(u"DHTEnabled"_qs), true) , m_isLSDEnabled(BITTORRENT_SESSION_KEY(u"LSDEnabled"_qs), true) , m_isPeXEnabled(BITTORRENT_SESSION_KEY(u"PeXEnabled"_qs), true) @@ -468,7 +508,7 @@ Session::Session(QObject *parent) , this, [this]() { m_recentErroredTorrents.clear(); }); m_seedingLimitTimer->setInterval(10s); - connect(m_seedingLimitTimer, &QTimer::timeout, this, &Session::processShareLimits); + connect(m_seedingLimitTimer, &QTimer::timeout, this, &SessionImpl::processShareLimits); initializeNativeSession(); configureComponents(); @@ -495,20 +535,20 @@ Session::Session(QObject *parent) connect(Net::ProxyConfigurationManager::instance() , &Net::ProxyConfigurationManager::proxyConfigurationChanged - , this, &Session::configureDeferred); + , this, &SessionImpl::configureDeferred); #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) // Network configuration monitor - connect(m_networkManager, &QNetworkConfigurationManager::onlineStateChanged, this, &Session::networkOnlineStateChanged); - connect(m_networkManager, &QNetworkConfigurationManager::configurationAdded, this, &Session::networkConfigurationChange); - connect(m_networkManager, &QNetworkConfigurationManager::configurationRemoved, this, &Session::networkConfigurationChange); - connect(m_networkManager, &QNetworkConfigurationManager::configurationChanged, this, &Session::networkConfigurationChange); + connect(m_networkManager, &QNetworkConfigurationManager::onlineStateChanged, this, &SessionImpl::networkOnlineStateChanged); + connect(m_networkManager, &QNetworkConfigurationManager::configurationAdded, this, &SessionImpl::networkConfigurationChange); + connect(m_networkManager, &QNetworkConfigurationManager::configurationRemoved, this, &SessionImpl::networkConfigurationChange); + connect(m_networkManager, &QNetworkConfigurationManager::configurationChanged, this, &SessionImpl::networkConfigurationChange); #endif m_fileSearcher = new FileSearcher; m_fileSearcher->moveToThread(m_ioThread); connect(m_ioThread, &QThread::finished, m_fileSearcher, &QObject::deleteLater); - connect(m_fileSearcher, &FileSearcher::searchFinished, this, &Session::fileSearchFinished); + connect(m_fileSearcher, &FileSearcher::searchFinished, this, &SessionImpl::fileSearchFinished); m_ioThread->start(); @@ -520,12 +560,12 @@ Session::Session(QObject *parent) prepareStartup(); } -bool Session::isDHTEnabled() const +bool SessionImpl::isDHTEnabled() const { return m_isDHTEnabled; } -void Session::setDHTEnabled(bool enabled) +void SessionImpl::setDHTEnabled(bool enabled) { if (enabled != m_isDHTEnabled) { @@ -535,12 +575,12 @@ void Session::setDHTEnabled(bool enabled) } } -bool Session::isLSDEnabled() const +bool SessionImpl::isLSDEnabled() const { return m_isLSDEnabled; } -void Session::setLSDEnabled(const bool enabled) +void SessionImpl::setLSDEnabled(const bool enabled) { if (enabled != m_isLSDEnabled) { @@ -551,24 +591,24 @@ void Session::setLSDEnabled(const bool enabled) } } -bool Session::isPeXEnabled() const +bool SessionImpl::isPeXEnabled() const { return m_isPeXEnabled; } -void Session::setPeXEnabled(const bool enabled) +void SessionImpl::setPeXEnabled(const bool enabled) { m_isPeXEnabled = enabled; if (m_wasPexEnabled != enabled) LogMsg(tr("Restart is required to toggle Peer Exchange (PeX) support"), Log::WARNING); } -bool Session::isDownloadPathEnabled() const +bool SessionImpl::isDownloadPathEnabled() const { return m_isDownloadPathEnabled; } -void Session::setDownloadPathEnabled(const bool enabled) +void SessionImpl::setDownloadPathEnabled(const bool enabled) { if (enabled != isDownloadPathEnabled()) { @@ -578,12 +618,12 @@ void Session::setDownloadPathEnabled(const bool enabled) } } -bool Session::isAppendExtensionEnabled() const +bool SessionImpl::isAppendExtensionEnabled() const { return m_isAppendExtensionEnabled; } -void Session::setAppendExtensionEnabled(const bool enabled) +void SessionImpl::setAppendExtensionEnabled(const bool enabled) { if (isAppendExtensionEnabled() != enabled) { @@ -595,12 +635,12 @@ void Session::setAppendExtensionEnabled(const bool enabled) } } -int Session::refreshInterval() const +int SessionImpl::refreshInterval() const { return m_refreshInterval; } -void Session::setRefreshInterval(const int value) +void SessionImpl::setRefreshInterval(const int value) { if (value != refreshInterval()) { @@ -608,79 +648,59 @@ void Session::setRefreshInterval(const int value) } } -bool Session::isPreallocationEnabled() const +bool SessionImpl::isPreallocationEnabled() const { return m_isPreallocationEnabled; } -void Session::setPreallocationEnabled(const bool enabled) +void SessionImpl::setPreallocationEnabled(const bool enabled) { m_isPreallocationEnabled = enabled; } -Path Session::torrentExportDirectory() const +Path SessionImpl::torrentExportDirectory() const { return m_torrentExportDirectory; } -void Session::setTorrentExportDirectory(const Path &path) +void SessionImpl::setTorrentExportDirectory(const Path &path) { if (path != torrentExportDirectory()) m_torrentExportDirectory = path; } -Path Session::finishedTorrentExportDirectory() const +Path SessionImpl::finishedTorrentExportDirectory() const { return m_finishedTorrentExportDirectory; } -void Session::setFinishedTorrentExportDirectory(const Path &path) +void SessionImpl::setFinishedTorrentExportDirectory(const Path &path) { if (path != finishedTorrentExportDirectory()) m_finishedTorrentExportDirectory = path; } -Path Session::savePath() const +Path SessionImpl::savePath() const { return m_savePath; } -Path Session::downloadPath() const +Path SessionImpl::downloadPath() const { return m_downloadPath; } -bool Session::isValidCategoryName(const QString &name) -{ - const QRegularExpression re {uR"(^([^\\\/]|[^\\\/]([^\\\/]|\/(?=[^\/]))*[^\\\/])$)"_qs}; - return (name.isEmpty() || (name.indexOf(re) == 0)); -} - -QStringList Session::expandCategory(const QString &category) -{ - QStringList result; - int index = 0; - while ((index = category.indexOf(u'/', index)) >= 0) - { - result << category.left(index); - ++index; - } - result << category; - - return result; -} - -QStringList Session::categories() const +QStringList SessionImpl::categories() const { return m_categories.keys(); } -CategoryOptions Session::categoryOptions(const QString &categoryName) const +CategoryOptions SessionImpl::categoryOptions(const QString &categoryName) const { return m_categories.value(categoryName); } -Path Session::categorySavePath(const QString &categoryName) const +Path SessionImpl::categorySavePath(const QString &categoryName) const { const Path basePath = savePath(); if (categoryName.isEmpty()) @@ -693,7 +713,7 @@ Path Session::categorySavePath(const QString &categoryName) const return (path.isAbsolute() ? path : (basePath / path)); } -Path Session::categoryDownloadPath(const QString &categoryName) const +Path SessionImpl::categoryDownloadPath(const QString &categoryName) const { const CategoryOptions categoryOptions = m_categories.value(categoryName); const CategoryOptions::DownloadPathOption downloadPathOption = @@ -712,7 +732,7 @@ Path Session::categoryDownloadPath(const QString &categoryName) const return (path.isAbsolute() ? path : (basePath / path)); } -bool Session::addCategory(const QString &name, const CategoryOptions &options) +bool SessionImpl::addCategory(const QString &name, const CategoryOptions &options) { if (name.isEmpty()) return false; @@ -739,7 +759,7 @@ bool Session::addCategory(const QString &name, const CategoryOptions &options) return true; } -bool Session::editCategory(const QString &name, const CategoryOptions &options) +bool SessionImpl::editCategory(const QString &name, const CategoryOptions &options) { const auto it = m_categories.find(name); if (it == m_categories.end()) @@ -771,7 +791,7 @@ bool Session::editCategory(const QString &name, const CategoryOptions &options) return true; } -bool Session::removeCategory(const QString &name) +bool SessionImpl::removeCategory(const QString &name) { for (TorrentImpl *const torrent : asConst(m_torrents)) { @@ -809,12 +829,12 @@ bool Session::removeCategory(const QString &name) return result; } -bool Session::isSubcategoriesEnabled() const +bool SessionImpl::isSubcategoriesEnabled() const { return m_isSubcategoriesEnabled; } -void Session::setSubcategoriesEnabled(const bool value) +void SessionImpl::setSubcategoriesEnabled(const bool value) { if (isSubcategoriesEnabled() == value) return; @@ -835,32 +855,27 @@ void Session::setSubcategoriesEnabled(const bool value) emit subcategoriesSupportChanged(); } -bool Session::useCategoryPathsInManualMode() const +bool SessionImpl::useCategoryPathsInManualMode() const { return m_useCategoryPathsInManualMode; } -void Session::setUseCategoryPathsInManualMode(const bool value) +void SessionImpl::setUseCategoryPathsInManualMode(const bool value) { m_useCategoryPathsInManualMode = value; } -QSet Session::tags() const +QSet SessionImpl::tags() const { return m_tags; } -bool Session::isValidTag(const QString &tag) -{ - return (!tag.trimmed().isEmpty() && !tag.contains(u',')); -} - -bool Session::hasTag(const QString &tag) const +bool SessionImpl::hasTag(const QString &tag) const { return m_tags.contains(tag); } -bool Session::addTag(const QString &tag) +bool SessionImpl::addTag(const QString &tag) { if (!isValidTag(tag) || hasTag(tag)) return false; @@ -871,7 +886,7 @@ bool Session::addTag(const QString &tag) return true; } -bool Session::removeTag(const QString &tag) +bool SessionImpl::removeTag(const QString &tag) { if (m_tags.remove(tag)) { @@ -884,62 +899,62 @@ bool Session::removeTag(const QString &tag) return false; } -bool Session::isAutoTMMDisabledByDefault() const +bool SessionImpl::isAutoTMMDisabledByDefault() const { return m_isAutoTMMDisabledByDefault; } -void Session::setAutoTMMDisabledByDefault(const bool value) +void SessionImpl::setAutoTMMDisabledByDefault(const bool value) { m_isAutoTMMDisabledByDefault = value; } -bool Session::isDisableAutoTMMWhenCategoryChanged() const +bool SessionImpl::isDisableAutoTMMWhenCategoryChanged() const { return m_isDisableAutoTMMWhenCategoryChanged; } -void Session::setDisableAutoTMMWhenCategoryChanged(const bool value) +void SessionImpl::setDisableAutoTMMWhenCategoryChanged(const bool value) { m_isDisableAutoTMMWhenCategoryChanged = value; } -bool Session::isDisableAutoTMMWhenDefaultSavePathChanged() const +bool SessionImpl::isDisableAutoTMMWhenDefaultSavePathChanged() const { return m_isDisableAutoTMMWhenDefaultSavePathChanged; } -void Session::setDisableAutoTMMWhenDefaultSavePathChanged(const bool value) +void SessionImpl::setDisableAutoTMMWhenDefaultSavePathChanged(const bool value) { m_isDisableAutoTMMWhenDefaultSavePathChanged = value; } -bool Session::isDisableAutoTMMWhenCategorySavePathChanged() const +bool SessionImpl::isDisableAutoTMMWhenCategorySavePathChanged() const { return m_isDisableAutoTMMWhenCategorySavePathChanged; } -void Session::setDisableAutoTMMWhenCategorySavePathChanged(const bool value) +void SessionImpl::setDisableAutoTMMWhenCategorySavePathChanged(const bool value) { m_isDisableAutoTMMWhenCategorySavePathChanged = value; } -bool Session::isAddTorrentPaused() const +bool SessionImpl::isAddTorrentPaused() const { return m_isAddTorrentPaused; } -void Session::setAddTorrentPaused(const bool value) +void SessionImpl::setAddTorrentPaused(const bool value) { m_isAddTorrentPaused = value; } -bool Session::isTrackerEnabled() const +bool SessionImpl::isTrackerEnabled() const { return m_isTrackerEnabled; } -void Session::setTrackerEnabled(const bool enabled) +void SessionImpl::setTrackerEnabled(const bool enabled) { if (m_isTrackerEnabled != enabled) m_isTrackerEnabled = enabled; @@ -949,14 +964,14 @@ void Session::setTrackerEnabled(const bool enabled) enableTracker(enabled); } -qreal Session::globalMaxRatio() const +qreal SessionImpl::globalMaxRatio() const { return m_globalMaxRatio; } // Torrents with a ratio superior to the given value will // be automatically deleted -void Session::setGlobalMaxRatio(qreal ratio) +void SessionImpl::setGlobalMaxRatio(qreal ratio) { if (ratio < 0) ratio = -1.; @@ -968,12 +983,12 @@ void Session::setGlobalMaxRatio(qreal ratio) } } -int Session::globalMaxSeedingMinutes() const +int SessionImpl::globalMaxSeedingMinutes() const { return m_globalMaxSeedingMinutes; } -void Session::setGlobalMaxSeedingMinutes(int minutes) +void SessionImpl::setGlobalMaxSeedingMinutes(int minutes) { if (minutes < 0) minutes = -1; @@ -986,7 +1001,7 @@ void Session::setGlobalMaxSeedingMinutes(int minutes) } // Main destructor -Session::~Session() +SessionImpl::~SessionImpl() { // Do some BT related saving saveResumeData(); @@ -1006,24 +1021,7 @@ Session::~Session() m_ioThread->wait(); } -void Session::initInstance() -{ - if (!m_instance) - m_instance = new Session; -} - -void Session::freeInstance() -{ - delete m_instance; - m_instance = nullptr; -} - -Session *Session::instance() -{ - return m_instance; -} - -void Session::adjustLimits() +void SessionImpl::adjustLimits() { if (isQueueingSystemEnabled()) { @@ -1033,14 +1031,14 @@ void Session::adjustLimits() } } -void Session::applyBandwidthLimits() +void SessionImpl::applyBandwidthLimits() { lt::settings_pack settingsPack = m_nativeSession->get_settings(); applyBandwidthLimits(settingsPack); m_nativeSession->apply_settings(settingsPack); } -void Session::configure() +void SessionImpl::configure() { lt::settings_pack settingsPack = m_nativeSession->get_settings(); loadLTSettings(settingsPack); @@ -1051,7 +1049,7 @@ void Session::configure() m_deferredConfigureScheduled = false; } -void Session::configureComponents() +void SessionImpl::configureComponents() { // This function contains components/actions that: // 1. Need to be setup at start up @@ -1069,7 +1067,7 @@ void Session::configureComponents() } } -void Session::prepareStartup() +void SessionImpl::prepareStartup() { qDebug("Initializing torrents resume data storage..."); @@ -1117,7 +1115,7 @@ void Session::prepareStartup() context->isLoadFinished = true; }); - connect(this, &Session::torrentsLoaded, context, [this, context](const QVector &torrents) + connect(this, &SessionImpl::torrentsLoaded, context, [this, context](const QVector &torrents) { context->processingResumeDataCount -= torrents.count(); context->finishedResumeDataCount += torrents.count(); @@ -1139,7 +1137,7 @@ void Session::prepareStartup() context->startupStorage->loadAll(); } -void Session::handleLoadedResumeData(ResumeSessionContext *context) +void SessionImpl::handleLoadedResumeData(ResumeSessionContext *context) { context->isLoadedResumeDataHandlingEnqueued = false; @@ -1174,7 +1172,7 @@ void Session::handleLoadedResumeData(ResumeSessionContext *context) context->finishedResumeDataCount += (count - context->processingResumeDataCount); } -void Session::processNextResumeData(ResumeSessionContext *context) +void SessionImpl::processNextResumeData(ResumeSessionContext *context) { const LoadedResumeData loadedResumeDataItem = context->loadedResumeData.takeFirst(); @@ -1343,7 +1341,7 @@ void Session::processNextResumeData(ResumeSessionContext *context) ++context->processingResumeDataCount; } -void Session::endStartup(ResumeSessionContext *context) +void SessionImpl::endStartup(ResumeSessionContext *context) { if (m_resumeDataStorage != context->startupStorage) { @@ -1366,7 +1364,7 @@ void Session::endStartup(ResumeSessionContext *context) enqueueRefresh(); // Regular saving of fastresume data - connect(m_resumeDataTimer, &QTimer::timeout, this, &Session::generateResumeData); + connect(m_resumeDataTimer, &QTimer::timeout, this, &SessionImpl::generateResumeData); const int saveInterval = saveResumeDataInterval(); if (saveInterval > 0) { @@ -1379,7 +1377,7 @@ void Session::endStartup(ResumeSessionContext *context) emit restored(); } -void Session::initializeNativeSession() +void SessionImpl::initializeNativeSession() { const std::string peerId = lt::generate_fingerprint(PEER_ID, QBT_VERSION_MAJOR, QBT_VERSION_MINOR, QBT_VERSION_BUGFIX, QBT_VERSION_BUILD); @@ -1429,7 +1427,7 @@ void Session::initializeNativeSession() m_nativeSession->set_alert_notify([this]() { - QMetaObject::invokeMethod(this, &Session::readAlerts, Qt::QueuedConnection); + QMetaObject::invokeMethod(this, &SessionImpl::readAlerts, Qt::QueuedConnection); }); // Enabling plugins @@ -1441,7 +1439,7 @@ void Session::initializeNativeSession() m_nativeSession->add_extension(std::make_shared()); } -void Session::processBannedIPs(lt::ip_filter &filter) +void SessionImpl::processBannedIPs(lt::ip_filter &filter) { // First, import current filter for (const QString &ip : asConst(m_bannedIPs.get())) @@ -1454,7 +1452,7 @@ void Session::processBannedIPs(lt::ip_filter &filter) } } -void Session::adjustLimits(lt::settings_pack &settingsPack) const +void SessionImpl::adjustLimits(lt::settings_pack &settingsPack) const { // Internally increase the queue limits to ensure that the magnet is started const auto adjustLimit = [this](const int limit) -> int @@ -1471,14 +1469,14 @@ void Session::adjustLimits(lt::settings_pack &settingsPack) const settingsPack.set_int(lt::settings_pack::active_limit, adjustLimit(maxActiveTorrents())); } -void Session::applyBandwidthLimits(lt::settings_pack &settingsPack) const +void SessionImpl::applyBandwidthLimits(lt::settings_pack &settingsPack) const { const bool altSpeedLimitEnabled = isAltGlobalSpeedLimitEnabled(); settingsPack.set_int(lt::settings_pack::download_rate_limit, altSpeedLimitEnabled ? altGlobalDownloadSpeedLimit() : globalDownloadSpeedLimit()); settingsPack.set_int(lt::settings_pack::upload_rate_limit, altSpeedLimitEnabled ? altGlobalUploadSpeedLimit() : globalUploadSpeedLimit()); } -void Session::initMetrics() +void SessionImpl::initMetrics() { const auto findMetricIndex = [](const char *name) -> int { @@ -1520,7 +1518,7 @@ void Session::initMetrics() m_metricIndices.disk.diskJobTime = findMetricIndex("disk.disk_job_time"); } -void Session::loadLTSettings(lt::settings_pack &settingsPack) +void SessionImpl::loadLTSettings(lt::settings_pack &settingsPack) { const lt::alert_category_t alertMask = lt::alert::error_notification | lt::alert::file_progress_notification @@ -1792,7 +1790,7 @@ void Session::loadLTSettings(lt::settings_pack &settingsPack) } } -void Session::configureNetworkInterfaces(lt::settings_pack &settingsPack) +void SessionImpl::configureNetworkInterfaces(lt::settings_pack &settingsPack) { if (m_listenInterfaceConfigured) return; @@ -1855,7 +1853,7 @@ void Session::configureNetworkInterfaces(lt::settings_pack &settingsPack) m_listenInterfaceConfigured = true; } -void Session::configurePeerClasses() +void SessionImpl::configurePeerClasses() { lt::ip_filter f; // lt::make_address("255.255.255.255") crashes on some people's systems @@ -1933,7 +1931,7 @@ void Session::configurePeerClasses() m_nativeSession->set_peer_class_type_filter(peerClassTypeFilter); } -void Session::enableTracker(const bool enable) +void SessionImpl::enableTracker(const bool enable) { if (enable) { @@ -1948,18 +1946,18 @@ void Session::enableTracker(const bool enable) } } -void Session::enableBandwidthScheduler() +void SessionImpl::enableBandwidthScheduler() { if (!m_bwScheduler) { m_bwScheduler = new BandwidthScheduler(this); connect(m_bwScheduler.data(), &BandwidthScheduler::bandwidthLimitRequested - , this, &Session::setAltGlobalSpeedLimitEnabled); + , this, &SessionImpl::setAltGlobalSpeedLimitEnabled); } m_bwScheduler->start(); } -void Session::populateAdditionalTrackers() +void SessionImpl::populateAdditionalTrackers() { m_additionalTrackerList.clear(); @@ -1972,7 +1970,7 @@ void Session::populateAdditionalTrackers() } } -void Session::processShareLimits() +void SessionImpl::processShareLimits() { qDebug("Processing share limits..."); @@ -2071,7 +2069,7 @@ void Session::processShareLimits() } // Add to BitTorrent session the downloaded torrent file -void Session::handleDownloadFinished(const Net::DownloadResult &result) +void SessionImpl::handleDownloadFinished(const Net::DownloadResult &result) { switch (result.status) { @@ -2091,7 +2089,7 @@ void Session::handleDownloadFinished(const Net::DownloadResult &result) } } -void Session::fileSearchFinished(const TorrentID &id, const Path &savePath, const PathList &fileNames) +void SessionImpl::fileSearchFinished(const TorrentID &id, const Path &savePath, const PathList &fileNames) { TorrentImpl *torrent = m_torrents.value(id); if (torrent) @@ -2116,12 +2114,12 @@ void Session::fileSearchFinished(const TorrentID &id, const Path &savePath, cons } } -Torrent *Session::getTorrent(const TorrentID &id) const +Torrent *SessionImpl::getTorrent(const TorrentID &id) const { return m_torrents.value(id); } -Torrent *Session::findTorrent(const InfoHash &infoHash) const +Torrent *SessionImpl::findTorrent(const InfoHash &infoHash) const { const auto id = TorrentID::fromInfoHash(infoHash); if (Torrent *torrent = m_torrents.value(id); torrent) @@ -2136,7 +2134,7 @@ Torrent *Session::findTorrent(const InfoHash &infoHash) const return m_torrents.value(altID); } -bool Session::hasActiveTorrents() const +bool SessionImpl::hasActiveTorrents() const { return std::any_of(m_torrents.begin(), m_torrents.end(), [](TorrentImpl *torrent) { @@ -2144,7 +2142,7 @@ bool Session::hasActiveTorrents() const }); } -bool Session::hasUnfinishedTorrents() const +bool SessionImpl::hasUnfinishedTorrents() const { return std::any_of(m_torrents.begin(), m_torrents.end(), [](const TorrentImpl *torrent) { @@ -2152,7 +2150,7 @@ bool Session::hasUnfinishedTorrents() const }); } -bool Session::hasRunningSeed() const +bool SessionImpl::hasRunningSeed() const { return std::any_of(m_torrents.begin(), m_torrents.end(), [](const TorrentImpl *torrent) { @@ -2160,7 +2158,7 @@ bool Session::hasRunningSeed() const }); } -void Session::banIP(const QString &ip) +void SessionImpl::banIP(const QString &ip) { QStringList bannedIPs = m_bannedIPs; if (!bannedIPs.contains(ip)) @@ -2181,7 +2179,7 @@ void Session::banIP(const QString &ip) // Delete a torrent from the session, given its hash // and from the disk, if the corresponding deleteOption is chosen -bool Session::deleteTorrent(const TorrentID &id, const DeleteOption deleteOption) +bool SessionImpl::deleteTorrent(const TorrentID &id, const DeleteOption deleteOption) { TorrentImpl *const torrent = m_torrents.take(id); if (!torrent) return false; @@ -2239,7 +2237,7 @@ bool Session::deleteTorrent(const TorrentID &id, const DeleteOption deleteOption return true; } -bool Session::cancelDownloadMetadata(const TorrentID &id) +bool SessionImpl::cancelDownloadMetadata(const TorrentID &id) { const auto downloadedMetadataIter = m_downloadedMetadata.find(id); if (downloadedMetadataIter == m_downloadedMetadata.end()) return false; @@ -2251,7 +2249,7 @@ bool Session::cancelDownloadMetadata(const TorrentID &id) return true; } -void Session::increaseTorrentsQueuePos(const QVector &ids) +void SessionImpl::increaseTorrentsQueuePos(const QVector &ids) { using ElementType = std::pair; std::priority_queue &ids) saveTorrentsQueue(); } -void Session::decreaseTorrentsQueuePos(const QVector &ids) +void SessionImpl::decreaseTorrentsQueuePos(const QVector &ids) { using ElementType = std::pair; std::priority_queue torrentQueue; @@ -2306,7 +2304,7 @@ void Session::decreaseTorrentsQueuePos(const QVector &ids) saveTorrentsQueue(); } -void Session::topTorrentsQueuePos(const QVector &ids) +void SessionImpl::topTorrentsQueuePos(const QVector &ids) { using ElementType = std::pair; std::priority_queue torrentQueue; @@ -2331,7 +2329,7 @@ void Session::topTorrentsQueuePos(const QVector &ids) saveTorrentsQueue(); } -void Session::bottomTorrentsQueuePos(const QVector &ids) +void SessionImpl::bottomTorrentsQueuePos(const QVector &ids) { using ElementType = std::pair; std::priority_queue &ids) saveTorrentsQueue(); } -void Session::handleTorrentNeedSaveResumeData(const TorrentImpl *torrent) +void SessionImpl::handleTorrentNeedSaveResumeData(const TorrentImpl *torrent) { if (m_needSaveResumeDataTorrents.empty()) { @@ -2380,13 +2378,13 @@ void Session::handleTorrentNeedSaveResumeData(const TorrentImpl *torrent) m_needSaveResumeDataTorrents.insert(torrent->id()); } -void Session::handleTorrentSaveResumeDataRequested(const TorrentImpl *torrent) +void SessionImpl::handleTorrentSaveResumeDataRequested(const TorrentImpl *torrent) { qDebug("Saving resume data is requested for torrent '%s'...", qUtf8Printable(torrent->name())); ++m_numResumeData; } -QVector Session::torrents() const +QVector SessionImpl::torrents() const { QVector result; result.reserve(m_torrents.size()); @@ -2396,12 +2394,12 @@ QVector Session::torrents() const return result; } -qsizetype Session::torrentsCount() const +qsizetype SessionImpl::torrentsCount() const { return m_torrents.size(); } -bool Session::addTorrent(const QString &source, const AddTorrentParams ¶ms) +bool SessionImpl::addTorrent(const QString &source, const AddTorrentParams ¶ms) { // `source`: .torrent file path/url or magnet uri @@ -2413,7 +2411,7 @@ bool Session::addTorrent(const QString &source, const AddTorrentParams ¶ms) LogMsg(tr("Downloading torrent, please wait... Source: \"%1\"").arg(source)); // Launch downloader Net::DownloadManager::instance()->download(Net::DownloadRequest(source).limit(MAX_TORRENT_SIZE) - , this, &Session::handleDownloadFinished); + , this, &SessionImpl::handleDownloadFinished); m_downloadedTorrents[source] = params; return true; } @@ -2435,7 +2433,7 @@ bool Session::addTorrent(const QString &source, const AddTorrentParams ¶ms) return addTorrent(loadResult.value(), params); } -bool Session::addTorrent(const MagnetUri &magnetUri, const AddTorrentParams ¶ms) +bool SessionImpl::addTorrent(const MagnetUri &magnetUri, const AddTorrentParams ¶ms) { if (!isRestored()) return false; @@ -2446,7 +2444,7 @@ bool Session::addTorrent(const MagnetUri &magnetUri, const AddTorrentParams &par return addTorrent_impl(magnetUri, params); } -bool Session::addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams ¶ms) +bool SessionImpl::addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams ¶ms) { if (!isRestored()) return false; @@ -2454,7 +2452,7 @@ bool Session::addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams return addTorrent_impl(torrentInfo, params); } -LoadTorrentParams Session::initLoadTorrentParams(const AddTorrentParams &addTorrentParams) +LoadTorrentParams SessionImpl::initLoadTorrentParams(const AddTorrentParams &addTorrentParams) { LoadTorrentParams loadTorrentParams; @@ -2511,7 +2509,7 @@ LoadTorrentParams Session::initLoadTorrentParams(const AddTorrentParams &addTorr } // Add a torrent to the BitTorrent session -bool Session::addTorrent_impl(const std::variant &source, const AddTorrentParams &addTorrentParams) +bool SessionImpl::addTorrent_impl(const std::variant &source, const AddTorrentParams &addTorrentParams) { Q_ASSERT(isRestored()); @@ -2701,7 +2699,7 @@ bool Session::addTorrent_impl(const std::variant &source return true; } -void Session::findIncompleteFiles(const TorrentInfo &torrentInfo, const Path &savePath +void SessionImpl::findIncompleteFiles(const TorrentInfo &torrentInfo, const Path &savePath , const Path &downloadPath, const PathList &filePaths) const { Q_ASSERT(filePaths.isEmpty() || (filePaths.size() == torrentInfo.filesCount())); @@ -2716,7 +2714,7 @@ void Session::findIncompleteFiles(const TorrentInfo &torrentInfo, const Path &sa // Add a torrent to libtorrent session in hidden mode // and force it to download its metadata -bool Session::downloadMetadata(const MagnetUri &magnetUri) +bool SessionImpl::downloadMetadata(const MagnetUri &magnetUri) { if (!magnetUri.isValid()) return false; @@ -2767,7 +2765,7 @@ bool Session::downloadMetadata(const MagnetUri &magnetUri) return true; } -void Session::exportTorrentFile(const Torrent *torrent, const Path &folderPath) +void SessionImpl::exportTorrentFile(const Torrent *torrent, const Path &folderPath) { if (!folderPath.exists() && !Utils::Fs::mkpath(folderPath)) return; @@ -2791,7 +2789,7 @@ void Session::exportTorrentFile(const Torrent *torrent, const Path &folderPath) } } -void Session::generateResumeData() +void SessionImpl::generateResumeData() { for (TorrentImpl *const torrent : asConst(m_torrents)) { @@ -2806,7 +2804,7 @@ void Session::generateResumeData() } // Called on exit -void Session::saveResumeData() +void SessionImpl::saveResumeData() { // Pause session m_nativeSession->pause(); @@ -2838,7 +2836,7 @@ void Session::saveResumeData() } } -void Session::saveTorrentsQueue() const +void SessionImpl::saveTorrentsQueue() const { QVector queue; for (const TorrentImpl *torrent : asConst(m_torrents)) @@ -2856,12 +2854,12 @@ void Session::saveTorrentsQueue() const m_resumeDataStorage->storeQueue(queue); } -void Session::removeTorrentsQueue() const +void SessionImpl::removeTorrentsQueue() const { m_resumeDataStorage->storeQueue({}); } -void Session::setSavePath(const Path &path) +void SessionImpl::setSavePath(const Path &path) { const auto newPath = (path.isAbsolute() ? path : (specialFolderLocation(SpecialFolder::Downloads) / path)); if (newPath == m_savePath) @@ -2890,7 +2888,7 @@ void Session::setSavePath(const Path &path) torrent->handleCategoryOptionsChanged(); } -void Session::setDownloadPath(const Path &path) +void SessionImpl::setDownloadPath(const Path &path) { const Path newPath = (path.isAbsolute() ? path : (savePath() / Path(u"temp"_qs) / path)); if (newPath == m_downloadPath) @@ -2922,12 +2920,12 @@ void Session::setDownloadPath(const Path &path) } #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) -void Session::networkOnlineStateChanged(const bool online) +void SessionImpl::networkOnlineStateChanged(const bool online) { LogMsg(tr("System network status changed to %1", "e.g: System network status changed to ONLINE").arg(online ? tr("ONLINE") : tr("OFFLINE")), Log::INFO); } -void Session::networkConfigurationChange(const QNetworkConfiguration &cfg) +void SessionImpl::networkConfigurationChange(const QNetworkConfiguration &cfg) { const QString configuredInterfaceName = networkInterface(); // Empty means "Any Interface". In this case libtorrent has binded to 0.0.0.0 so any change to any interface will @@ -2944,7 +2942,7 @@ void Session::networkConfigurationChange(const QNetworkConfiguration &cfg) } #endif -QStringList Session::getListeningIPs() const +QStringList SessionImpl::getListeningIPs() const { QStringList IPs; @@ -3041,20 +3039,20 @@ QStringList Session::getListeningIPs() const // Set the ports range in which is chosen the port // the BitTorrent session will listen to -void Session::configureListeningInterface() +void SessionImpl::configureListeningInterface() { m_listenInterfaceConfigured = false; configureDeferred(); } -int Session::globalDownloadSpeedLimit() const +int SessionImpl::globalDownloadSpeedLimit() const { // Unfortunately the value was saved as KiB instead of B. // But it is better to pass it around internally(+ webui) as Bytes. return m_globalDownloadSpeedLimit * 1024; } -void Session::setGlobalDownloadSpeedLimit(const int limit) +void SessionImpl::setGlobalDownloadSpeedLimit(const int limit) { // Unfortunately the value was saved as KiB instead of B. // But it is better to pass it around internally(+ webui) as Bytes. @@ -3072,14 +3070,14 @@ void Session::setGlobalDownloadSpeedLimit(const int limit) configureDeferred(); } -int Session::globalUploadSpeedLimit() const +int SessionImpl::globalUploadSpeedLimit() const { // Unfortunately the value was saved as KiB instead of B. // But it is better to pass it around internally(+ webui) as Bytes. return m_globalUploadSpeedLimit * 1024; } -void Session::setGlobalUploadSpeedLimit(const int limit) +void SessionImpl::setGlobalUploadSpeedLimit(const int limit) { // Unfortunately the value was saved as KiB instead of B. // But it is better to pass it around internally(+ webui) as Bytes. @@ -3097,14 +3095,14 @@ void Session::setGlobalUploadSpeedLimit(const int limit) configureDeferred(); } -int Session::altGlobalDownloadSpeedLimit() const +int SessionImpl::altGlobalDownloadSpeedLimit() const { // Unfortunately the value was saved as KiB instead of B. // But it is better to pass it around internally(+ webui) as Bytes. return m_altGlobalDownloadSpeedLimit * 1024; } -void Session::setAltGlobalDownloadSpeedLimit(const int limit) +void SessionImpl::setAltGlobalDownloadSpeedLimit(const int limit) { // Unfortunately the value was saved as KiB instead of B. // But it is better to pass it around internally(+ webui) as Bytes. @@ -3122,14 +3120,14 @@ void Session::setAltGlobalDownloadSpeedLimit(const int limit) configureDeferred(); } -int Session::altGlobalUploadSpeedLimit() const +int SessionImpl::altGlobalUploadSpeedLimit() const { // Unfortunately the value was saved as KiB instead of B. // But it is better to pass it around internally(+ webui) as Bytes. return m_altGlobalUploadSpeedLimit * 1024; } -void Session::setAltGlobalUploadSpeedLimit(const int limit) +void SessionImpl::setAltGlobalUploadSpeedLimit(const int limit) { // Unfortunately the value was saved as KiB instead of B. // But it is better to pass it around internally(+ webui) as Bytes. @@ -3147,14 +3145,14 @@ void Session::setAltGlobalUploadSpeedLimit(const int limit) configureDeferred(); } -int Session::downloadSpeedLimit() const +int SessionImpl::downloadSpeedLimit() const { return isAltGlobalSpeedLimitEnabled() ? altGlobalDownloadSpeedLimit() : globalDownloadSpeedLimit(); } -void Session::setDownloadSpeedLimit(const int limit) +void SessionImpl::setDownloadSpeedLimit(const int limit) { if (isAltGlobalSpeedLimitEnabled()) setAltGlobalDownloadSpeedLimit(limit); @@ -3162,14 +3160,14 @@ void Session::setDownloadSpeedLimit(const int limit) setGlobalDownloadSpeedLimit(limit); } -int Session::uploadSpeedLimit() const +int SessionImpl::uploadSpeedLimit() const { return isAltGlobalSpeedLimitEnabled() ? altGlobalUploadSpeedLimit() : globalUploadSpeedLimit(); } -void Session::setUploadSpeedLimit(const int limit) +void SessionImpl::setUploadSpeedLimit(const int limit) { if (isAltGlobalSpeedLimitEnabled()) setAltGlobalUploadSpeedLimit(limit); @@ -3177,12 +3175,12 @@ void Session::setUploadSpeedLimit(const int limit) setGlobalUploadSpeedLimit(limit); } -bool Session::isAltGlobalSpeedLimitEnabled() const +bool SessionImpl::isAltGlobalSpeedLimitEnabled() const { return m_isAltGlobalSpeedLimitEnabled; } -void Session::setAltGlobalSpeedLimitEnabled(const bool enabled) +void SessionImpl::setAltGlobalSpeedLimitEnabled(const bool enabled) { if (enabled == isAltGlobalSpeedLimitEnabled()) return; @@ -3193,12 +3191,12 @@ void Session::setAltGlobalSpeedLimitEnabled(const bool enabled) emit speedLimitModeChanged(m_isAltGlobalSpeedLimitEnabled); } -bool Session::isBandwidthSchedulerEnabled() const +bool SessionImpl::isBandwidthSchedulerEnabled() const { return m_isBandwidthSchedulerEnabled; } -void Session::setBandwidthSchedulerEnabled(const bool enabled) +void SessionImpl::setBandwidthSchedulerEnabled(const bool enabled) { if (enabled != isBandwidthSchedulerEnabled()) { @@ -3210,12 +3208,12 @@ void Session::setBandwidthSchedulerEnabled(const bool enabled) } } -bool Session::isPerformanceWarningEnabled() const +bool SessionImpl::isPerformanceWarningEnabled() const { return m_isPerformanceWarningEnabled; } -void Session::setPerformanceWarningEnabled(const bool enable) +void SessionImpl::setPerformanceWarningEnabled(const bool enable) { if (enable == m_isPerformanceWarningEnabled) return; @@ -3224,12 +3222,12 @@ void Session::setPerformanceWarningEnabled(const bool enable) configureDeferred(); } -int Session::saveResumeDataInterval() const +int SessionImpl::saveResumeDataInterval() const { return m_saveResumeDataInterval; } -void Session::setSaveResumeDataInterval(const int value) +void SessionImpl::setSaveResumeDataInterval(const int value) { if (value == m_saveResumeDataInterval) return; @@ -3247,12 +3245,12 @@ void Session::setSaveResumeDataInterval(const int value) } } -int Session::port() const +int SessionImpl::port() const { return m_port; } -void Session::setPort(const int port) +void SessionImpl::setPort(const int port) { if (port != m_port) { @@ -3264,12 +3262,12 @@ void Session::setPort(const int port) } } -QString Session::networkInterface() const +QString SessionImpl::networkInterface() const { return m_networkInterface; } -void Session::setNetworkInterface(const QString &iface) +void SessionImpl::setNetworkInterface(const QString &iface) { if (iface != networkInterface()) { @@ -3278,22 +3276,22 @@ void Session::setNetworkInterface(const QString &iface) } } -QString Session::networkInterfaceName() const +QString SessionImpl::networkInterfaceName() const { return m_networkInterfaceName; } -void Session::setNetworkInterfaceName(const QString &name) +void SessionImpl::setNetworkInterfaceName(const QString &name) { m_networkInterfaceName = name; } -QString Session::networkInterfaceAddress() const +QString SessionImpl::networkInterfaceAddress() const { return m_networkInterfaceAddress; } -void Session::setNetworkInterfaceAddress(const QString &address) +void SessionImpl::setNetworkInterfaceAddress(const QString &address) { if (address != networkInterfaceAddress()) { @@ -3302,12 +3300,12 @@ void Session::setNetworkInterfaceAddress(const QString &address) } } -int Session::encryption() const +int SessionImpl::encryption() const { return m_encryption; } -void Session::setEncryption(const int state) +void SessionImpl::setEncryption(const int state) { if (state != encryption()) { @@ -3319,12 +3317,12 @@ void Session::setEncryption(const int state) } } -int Session::maxActiveCheckingTorrents() const +int SessionImpl::maxActiveCheckingTorrents() const { return m_maxActiveCheckingTorrents; } -void Session::setMaxActiveCheckingTorrents(const int val) +void SessionImpl::setMaxActiveCheckingTorrents(const int val) { if (val == m_maxActiveCheckingTorrents) return; @@ -3333,12 +3331,12 @@ void Session::setMaxActiveCheckingTorrents(const int val) configureDeferred(); } -bool Session::isProxyPeerConnectionsEnabled() const +bool SessionImpl::isProxyPeerConnectionsEnabled() const { return m_isProxyPeerConnectionsEnabled; } -void Session::setProxyPeerConnectionsEnabled(const bool enabled) +void SessionImpl::setProxyPeerConnectionsEnabled(const bool enabled) { if (enabled != isProxyPeerConnectionsEnabled()) { @@ -3347,12 +3345,12 @@ void Session::setProxyPeerConnectionsEnabled(const bool enabled) } } -ChokingAlgorithm Session::chokingAlgorithm() const +ChokingAlgorithm SessionImpl::chokingAlgorithm() const { return m_chokingAlgorithm; } -void Session::setChokingAlgorithm(const ChokingAlgorithm mode) +void SessionImpl::setChokingAlgorithm(const ChokingAlgorithm mode) { if (mode == m_chokingAlgorithm) return; @@ -3360,12 +3358,12 @@ void Session::setChokingAlgorithm(const ChokingAlgorithm mode) configureDeferred(); } -SeedChokingAlgorithm Session::seedChokingAlgorithm() const +SeedChokingAlgorithm SessionImpl::seedChokingAlgorithm() const { return m_seedChokingAlgorithm; } -void Session::setSeedChokingAlgorithm(const SeedChokingAlgorithm mode) +void SessionImpl::setSeedChokingAlgorithm(const SeedChokingAlgorithm mode) { if (mode == m_seedChokingAlgorithm) return; @@ -3373,22 +3371,22 @@ void Session::setSeedChokingAlgorithm(const SeedChokingAlgorithm mode) configureDeferred(); } -bool Session::isAddTrackersEnabled() const +bool SessionImpl::isAddTrackersEnabled() const { return m_isAddTrackersEnabled; } -void Session::setAddTrackersEnabled(const bool enabled) +void SessionImpl::setAddTrackersEnabled(const bool enabled) { m_isAddTrackersEnabled = enabled; } -QString Session::additionalTrackers() const +QString SessionImpl::additionalTrackers() const { return m_additionalTrackers; } -void Session::setAdditionalTrackers(const QString &trackers) +void SessionImpl::setAdditionalTrackers(const QString &trackers) { if (trackers != additionalTrackers()) { @@ -3397,12 +3395,12 @@ void Session::setAdditionalTrackers(const QString &trackers) } } -bool Session::isIPFilteringEnabled() const +bool SessionImpl::isIPFilteringEnabled() const { return m_isIPFilteringEnabled; } -void Session::setIPFilteringEnabled(const bool enabled) +void SessionImpl::setIPFilteringEnabled(const bool enabled) { if (enabled != m_isIPFilteringEnabled) { @@ -3412,12 +3410,12 @@ void Session::setIPFilteringEnabled(const bool enabled) } } -Path Session::IPFilterFile() const +Path SessionImpl::IPFilterFile() const { return m_IPFilterFile; } -void Session::setIPFilterFile(const Path &path) +void SessionImpl::setIPFilterFile(const Path &path) { if (path != IPFilterFile()) { @@ -3427,12 +3425,12 @@ void Session::setIPFilterFile(const Path &path) } } -bool Session::isExcludedFileNamesEnabled() const +bool SessionImpl::isExcludedFileNamesEnabled() const { return m_isExcludedFileNamesEnabled; } -void Session::setExcludedFileNamesEnabled(const bool enabled) +void SessionImpl::setExcludedFileNamesEnabled(const bool enabled) { if (m_isExcludedFileNamesEnabled == enabled) return; @@ -3445,12 +3443,12 @@ void Session::setExcludedFileNamesEnabled(const bool enabled) m_excludedFileNamesRegExpList.clear(); } -QStringList Session::excludedFileNames() const +QStringList SessionImpl::excludedFileNames() const { return m_excludedFileNames; } -void Session::setExcludedFileNames(const QStringList &excludedFileNames) +void SessionImpl::setExcludedFileNames(const QStringList &excludedFileNames) { if (excludedFileNames != m_excludedFileNames) { @@ -3459,7 +3457,7 @@ void Session::setExcludedFileNames(const QStringList &excludedFileNames) } } -void Session::populateExcludedFileNamesRegExpList() +void SessionImpl::populateExcludedFileNamesRegExpList() { const QStringList excludedNames = excludedFileNames(); @@ -3474,7 +3472,7 @@ void Session::populateExcludedFileNamesRegExpList() } } -bool Session::isFilenameExcluded(const QString &fileName) const +bool SessionImpl::isFilenameExcluded(const QString &fileName) const { if (!isExcludedFileNamesEnabled()) return false; @@ -3485,7 +3483,7 @@ bool Session::isFilenameExcluded(const QString &fileName) const }); } -void Session::setBannedIPs(const QStringList &newList) +void SessionImpl::setBannedIPs(const QStringList &newList) { if (newList == m_bannedIPs) return; // do nothing @@ -3521,32 +3519,32 @@ void Session::setBannedIPs(const QStringList &newList) configureDeferred(); } -ResumeDataStorageType Session::resumeDataStorageType() const +ResumeDataStorageType SessionImpl::resumeDataStorageType() const { return m_resumeDataStorageType; } -void Session::setResumeDataStorageType(const ResumeDataStorageType type) +void SessionImpl::setResumeDataStorageType(const ResumeDataStorageType type) { m_resumeDataStorageType = type; } -QStringList Session::bannedIPs() const +QStringList SessionImpl::bannedIPs() const { return m_bannedIPs; } -bool Session::isRestored() const +bool SessionImpl::isRestored() const { return m_isRestored; } -int Session::maxConnectionsPerTorrent() const +int SessionImpl::maxConnectionsPerTorrent() const { return m_maxConnectionsPerTorrent; } -void Session::setMaxConnectionsPerTorrent(int max) +void SessionImpl::setMaxConnectionsPerTorrent(int max) { max = (max > 0) ? max : -1; if (max != maxConnectionsPerTorrent()) @@ -3565,12 +3563,12 @@ void Session::setMaxConnectionsPerTorrent(int max) } } -int Session::maxUploadsPerTorrent() const +int SessionImpl::maxUploadsPerTorrent() const { return m_maxUploadsPerTorrent; } -void Session::setMaxUploadsPerTorrent(int max) +void SessionImpl::setMaxUploadsPerTorrent(int max) { max = (max > 0) ? max : -1; if (max != maxUploadsPerTorrent()) @@ -3589,12 +3587,12 @@ void Session::setMaxUploadsPerTorrent(int max) } } -bool Session::announceToAllTrackers() const +bool SessionImpl::announceToAllTrackers() const { return m_announceToAllTrackers; } -void Session::setAnnounceToAllTrackers(const bool val) +void SessionImpl::setAnnounceToAllTrackers(const bool val) { if (val != m_announceToAllTrackers) { @@ -3603,12 +3601,12 @@ void Session::setAnnounceToAllTrackers(const bool val) } } -bool Session::announceToAllTiers() const +bool SessionImpl::announceToAllTiers() const { return m_announceToAllTiers; } -void Session::setAnnounceToAllTiers(const bool val) +void SessionImpl::setAnnounceToAllTiers(const bool val) { if (val != m_announceToAllTiers) { @@ -3617,12 +3615,12 @@ void Session::setAnnounceToAllTiers(const bool val) } } -int Session::peerTurnover() const +int SessionImpl::peerTurnover() const { return m_peerTurnover; } -void Session::setPeerTurnover(const int val) +void SessionImpl::setPeerTurnover(const int val) { if (val == m_peerTurnover) return; @@ -3631,12 +3629,12 @@ void Session::setPeerTurnover(const int val) configureDeferred(); } -int Session::peerTurnoverCutoff() const +int SessionImpl::peerTurnoverCutoff() const { return m_peerTurnoverCutoff; } -void Session::setPeerTurnoverCutoff(const int val) +void SessionImpl::setPeerTurnoverCutoff(const int val) { if (val == m_peerTurnoverCutoff) return; @@ -3645,12 +3643,12 @@ void Session::setPeerTurnoverCutoff(const int val) configureDeferred(); } -int Session::peerTurnoverInterval() const +int SessionImpl::peerTurnoverInterval() const { return m_peerTurnoverInterval; } -void Session::setPeerTurnoverInterval(const int val) +void SessionImpl::setPeerTurnoverInterval(const int val) { if (val == m_peerTurnoverInterval) return; @@ -3659,12 +3657,12 @@ void Session::setPeerTurnoverInterval(const int val) configureDeferred(); } -DiskIOType Session::diskIOType() const +DiskIOType SessionImpl::diskIOType() const { return m_diskIOType; } -void Session::setDiskIOType(const DiskIOType type) +void SessionImpl::setDiskIOType(const DiskIOType type) { if (type != m_diskIOType) { @@ -3672,12 +3670,12 @@ void Session::setDiskIOType(const DiskIOType type) } } -int Session::requestQueueSize() const +int SessionImpl::requestQueueSize() const { return m_requestQueueSize; } -void Session::setRequestQueueSize(const int val) +void SessionImpl::setRequestQueueSize(const int val) { if (val == m_requestQueueSize) return; @@ -3686,12 +3684,12 @@ void Session::setRequestQueueSize(const int val) configureDeferred(); } -int Session::asyncIOThreads() const +int SessionImpl::asyncIOThreads() const { return std::clamp(m_asyncIOThreads.get(), 1, 1024); } -void Session::setAsyncIOThreads(const int num) +void SessionImpl::setAsyncIOThreads(const int num) { if (num == m_asyncIOThreads) return; @@ -3700,12 +3698,12 @@ void Session::setAsyncIOThreads(const int num) configureDeferred(); } -int Session::hashingThreads() const +int SessionImpl::hashingThreads() const { return std::clamp(m_hashingThreads.get(), 1, 1024); } -void Session::setHashingThreads(const int num) +void SessionImpl::setHashingThreads(const int num) { if (num == m_hashingThreads) return; @@ -3714,12 +3712,12 @@ void Session::setHashingThreads(const int num) configureDeferred(); } -int Session::filePoolSize() const +int SessionImpl::filePoolSize() const { return m_filePoolSize; } -void Session::setFilePoolSize(const int size) +void SessionImpl::setFilePoolSize(const int size) { if (size == m_filePoolSize) return; @@ -3728,12 +3726,12 @@ void Session::setFilePoolSize(const int size) configureDeferred(); } -int Session::checkingMemUsage() const +int SessionImpl::checkingMemUsage() const { return std::max(1, m_checkingMemUsage.get()); } -void Session::setCheckingMemUsage(int size) +void SessionImpl::setCheckingMemUsage(int size) { size = std::max(size, 1); @@ -3744,7 +3742,7 @@ void Session::setCheckingMemUsage(int size) configureDeferred(); } -int Session::diskCacheSize() const +int SessionImpl::diskCacheSize() const { #ifdef QBT_APP_64BIT return std::min(m_diskCacheSize.get(), 33554431); // 32768GiB @@ -3755,7 +3753,7 @@ int Session::diskCacheSize() const #endif } -void Session::setDiskCacheSize(int size) +void SessionImpl::setDiskCacheSize(int size) { #ifdef QBT_APP_64BIT size = std::min(size, 33554431); // 32768GiB @@ -3770,12 +3768,12 @@ void Session::setDiskCacheSize(int size) } } -int Session::diskCacheTTL() const +int SessionImpl::diskCacheTTL() const { return m_diskCacheTTL; } -void Session::setDiskCacheTTL(const int ttl) +void SessionImpl::setDiskCacheTTL(const int ttl) { if (ttl != m_diskCacheTTL) { @@ -3784,12 +3782,12 @@ void Session::setDiskCacheTTL(const int ttl) } } -qint64 Session::diskQueueSize() const +qint64 SessionImpl::diskQueueSize() const { return m_diskQueueSize; } -void Session::setDiskQueueSize(const qint64 size) +void SessionImpl::setDiskQueueSize(const qint64 size) { if (size == m_diskQueueSize) return; @@ -3798,12 +3796,12 @@ void Session::setDiskQueueSize(const qint64 size) configureDeferred(); } -DiskIOReadMode Session::diskIOReadMode() const +DiskIOReadMode SessionImpl::diskIOReadMode() const { return m_diskIOReadMode; } -void Session::setDiskIOReadMode(const DiskIOReadMode mode) +void SessionImpl::setDiskIOReadMode(const DiskIOReadMode mode) { if (mode == m_diskIOReadMode) return; @@ -3812,12 +3810,12 @@ void Session::setDiskIOReadMode(const DiskIOReadMode mode) configureDeferred(); } -DiskIOWriteMode Session::diskIOWriteMode() const +DiskIOWriteMode SessionImpl::diskIOWriteMode() const { return m_diskIOWriteMode; } -void Session::setDiskIOWriteMode(const DiskIOWriteMode mode) +void SessionImpl::setDiskIOWriteMode(const DiskIOWriteMode mode) { if (mode == m_diskIOWriteMode) return; @@ -3826,12 +3824,12 @@ void Session::setDiskIOWriteMode(const DiskIOWriteMode mode) configureDeferred(); } -bool Session::isCoalesceReadWriteEnabled() const +bool SessionImpl::isCoalesceReadWriteEnabled() const { return m_coalesceReadWriteEnabled; } -void Session::setCoalesceReadWriteEnabled(const bool enabled) +void SessionImpl::setCoalesceReadWriteEnabled(const bool enabled) { if (enabled == m_coalesceReadWriteEnabled) return; @@ -3839,17 +3837,17 @@ void Session::setCoalesceReadWriteEnabled(const bool enabled) configureDeferred(); } -bool Session::isSuggestModeEnabled() const +bool SessionImpl::isSuggestModeEnabled() const { return m_isSuggestMode; } -bool Session::usePieceExtentAffinity() const +bool SessionImpl::usePieceExtentAffinity() const { return m_usePieceExtentAffinity; } -void Session::setPieceExtentAffinity(const bool enabled) +void SessionImpl::setPieceExtentAffinity(const bool enabled) { if (enabled == m_usePieceExtentAffinity) return; @@ -3857,7 +3855,7 @@ void Session::setPieceExtentAffinity(const bool enabled) configureDeferred(); } -void Session::setSuggestMode(const bool mode) +void SessionImpl::setSuggestMode(const bool mode) { if (mode == m_isSuggestMode) return; @@ -3865,12 +3863,12 @@ void Session::setSuggestMode(const bool mode) configureDeferred(); } -int Session::sendBufferWatermark() const +int SessionImpl::sendBufferWatermark() const { return m_sendBufferWatermark; } -void Session::setSendBufferWatermark(const int value) +void SessionImpl::setSendBufferWatermark(const int value) { if (value == m_sendBufferWatermark) return; @@ -3878,12 +3876,12 @@ void Session::setSendBufferWatermark(const int value) configureDeferred(); } -int Session::sendBufferLowWatermark() const +int SessionImpl::sendBufferLowWatermark() const { return m_sendBufferLowWatermark; } -void Session::setSendBufferLowWatermark(const int value) +void SessionImpl::setSendBufferLowWatermark(const int value) { if (value == m_sendBufferLowWatermark) return; @@ -3891,12 +3889,12 @@ void Session::setSendBufferLowWatermark(const int value) configureDeferred(); } -int Session::sendBufferWatermarkFactor() const +int SessionImpl::sendBufferWatermarkFactor() const { return m_sendBufferWatermarkFactor; } -void Session::setSendBufferWatermarkFactor(const int value) +void SessionImpl::setSendBufferWatermarkFactor(const int value) { if (value == m_sendBufferWatermarkFactor) return; @@ -3904,12 +3902,12 @@ void Session::setSendBufferWatermarkFactor(const int value) configureDeferred(); } -int Session::connectionSpeed() const +int SessionImpl::connectionSpeed() const { return m_connectionSpeed; } -void Session::setConnectionSpeed(const int value) +void SessionImpl::setConnectionSpeed(const int value) { if (value == m_connectionSpeed) return; @@ -3917,12 +3915,12 @@ void Session::setConnectionSpeed(const int value) configureDeferred(); } -int Session::socketBacklogSize() const +int SessionImpl::socketBacklogSize() const { return m_socketBacklogSize; } -void Session::setSocketBacklogSize(const int value) +void SessionImpl::setSocketBacklogSize(const int value) { if (value == m_socketBacklogSize) return; @@ -3930,12 +3928,12 @@ void Session::setSocketBacklogSize(const int value) configureDeferred(); } -bool Session::isAnonymousModeEnabled() const +bool SessionImpl::isAnonymousModeEnabled() const { return m_isAnonymousModeEnabled; } -void Session::setAnonymousModeEnabled(const bool enabled) +void SessionImpl::setAnonymousModeEnabled(const bool enabled) { if (enabled != m_isAnonymousModeEnabled) { @@ -3946,12 +3944,12 @@ void Session::setAnonymousModeEnabled(const bool enabled) } } -bool Session::isQueueingSystemEnabled() const +bool SessionImpl::isQueueingSystemEnabled() const { return m_isQueueingEnabled; } -void Session::setQueueingSystemEnabled(const bool enabled) +void SessionImpl::setQueueingSystemEnabled(const bool enabled) { if (enabled != m_isQueueingEnabled) { @@ -3965,12 +3963,12 @@ void Session::setQueueingSystemEnabled(const bool enabled) } } -int Session::maxActiveDownloads() const +int SessionImpl::maxActiveDownloads() const { return m_maxActiveDownloads; } -void Session::setMaxActiveDownloads(int max) +void SessionImpl::setMaxActiveDownloads(int max) { max = std::max(max, -1); if (max != m_maxActiveDownloads) @@ -3980,12 +3978,12 @@ void Session::setMaxActiveDownloads(int max) } } -int Session::maxActiveUploads() const +int SessionImpl::maxActiveUploads() const { return m_maxActiveUploads; } -void Session::setMaxActiveUploads(int max) +void SessionImpl::setMaxActiveUploads(int max) { max = std::max(max, -1); if (max != m_maxActiveUploads) @@ -3995,12 +3993,12 @@ void Session::setMaxActiveUploads(int max) } } -int Session::maxActiveTorrents() const +int SessionImpl::maxActiveTorrents() const { return m_maxActiveTorrents; } -void Session::setMaxActiveTorrents(int max) +void SessionImpl::setMaxActiveTorrents(int max) { max = std::max(max, -1); if (max != m_maxActiveTorrents) @@ -4010,12 +4008,12 @@ void Session::setMaxActiveTorrents(int max) } } -bool Session::ignoreSlowTorrentsForQueueing() const +bool SessionImpl::ignoreSlowTorrentsForQueueing() const { return m_ignoreSlowTorrentsForQueueing; } -void Session::setIgnoreSlowTorrentsForQueueing(const bool ignore) +void SessionImpl::setIgnoreSlowTorrentsForQueueing(const bool ignore) { if (ignore != m_ignoreSlowTorrentsForQueueing) { @@ -4024,12 +4022,12 @@ void Session::setIgnoreSlowTorrentsForQueueing(const bool ignore) } } -int Session::downloadRateForSlowTorrents() const +int SessionImpl::downloadRateForSlowTorrents() const { return m_downloadRateForSlowTorrents; } -void Session::setDownloadRateForSlowTorrents(const int rateInKibiBytes) +void SessionImpl::setDownloadRateForSlowTorrents(const int rateInKibiBytes) { if (rateInKibiBytes == m_downloadRateForSlowTorrents) return; @@ -4038,12 +4036,12 @@ void Session::setDownloadRateForSlowTorrents(const int rateInKibiBytes) configureDeferred(); } -int Session::uploadRateForSlowTorrents() const +int SessionImpl::uploadRateForSlowTorrents() const { return m_uploadRateForSlowTorrents; } -void Session::setUploadRateForSlowTorrents(const int rateInKibiBytes) +void SessionImpl::setUploadRateForSlowTorrents(const int rateInKibiBytes) { if (rateInKibiBytes == m_uploadRateForSlowTorrents) return; @@ -4052,12 +4050,12 @@ void Session::setUploadRateForSlowTorrents(const int rateInKibiBytes) configureDeferred(); } -int Session::slowTorrentsInactivityTimer() const +int SessionImpl::slowTorrentsInactivityTimer() const { return m_slowTorrentsInactivityTimer; } -void Session::setSlowTorrentsInactivityTimer(const int timeInSeconds) +void SessionImpl::setSlowTorrentsInactivityTimer(const int timeInSeconds) { if (timeInSeconds == m_slowTorrentsInactivityTimer) return; @@ -4066,12 +4064,12 @@ void Session::setSlowTorrentsInactivityTimer(const int timeInSeconds) configureDeferred(); } -int Session::outgoingPortsMin() const +int SessionImpl::outgoingPortsMin() const { return m_outgoingPortsMin; } -void Session::setOutgoingPortsMin(const int min) +void SessionImpl::setOutgoingPortsMin(const int min) { if (min != m_outgoingPortsMin) { @@ -4080,12 +4078,12 @@ void Session::setOutgoingPortsMin(const int min) } } -int Session::outgoingPortsMax() const +int SessionImpl::outgoingPortsMax() const { return m_outgoingPortsMax; } -void Session::setOutgoingPortsMax(const int max) +void SessionImpl::setOutgoingPortsMax(const int max) { if (max != m_outgoingPortsMax) { @@ -4094,12 +4092,12 @@ void Session::setOutgoingPortsMax(const int max) } } -int Session::UPnPLeaseDuration() const +int SessionImpl::UPnPLeaseDuration() const { return m_UPnPLeaseDuration; } -void Session::setUPnPLeaseDuration(const int duration) +void SessionImpl::setUPnPLeaseDuration(const int duration) { if (duration != m_UPnPLeaseDuration) { @@ -4108,12 +4106,12 @@ void Session::setUPnPLeaseDuration(const int duration) } } -int Session::peerToS() const +int SessionImpl::peerToS() const { return m_peerToS; } -void Session::setPeerToS(const int value) +void SessionImpl::setPeerToS(const int value) { if (value == m_peerToS) return; @@ -4122,12 +4120,12 @@ void Session::setPeerToS(const int value) configureDeferred(); } -bool Session::ignoreLimitsOnLAN() const +bool SessionImpl::ignoreLimitsOnLAN() const { return m_ignoreLimitsOnLAN; } -void Session::setIgnoreLimitsOnLAN(const bool ignore) +void SessionImpl::setIgnoreLimitsOnLAN(const bool ignore) { if (ignore != m_ignoreLimitsOnLAN) { @@ -4136,12 +4134,12 @@ void Session::setIgnoreLimitsOnLAN(const bool ignore) } } -bool Session::includeOverheadInLimits() const +bool SessionImpl::includeOverheadInLimits() const { return m_includeOverheadInLimits; } -void Session::setIncludeOverheadInLimits(const bool include) +void SessionImpl::setIncludeOverheadInLimits(const bool include) { if (include != m_includeOverheadInLimits) { @@ -4150,12 +4148,12 @@ void Session::setIncludeOverheadInLimits(const bool include) } } -QString Session::announceIP() const +QString SessionImpl::announceIP() const { return m_announceIP; } -void Session::setAnnounceIP(const QString &ip) +void SessionImpl::setAnnounceIP(const QString &ip) { if (ip != m_announceIP) { @@ -4164,12 +4162,12 @@ void Session::setAnnounceIP(const QString &ip) } } -int Session::maxConcurrentHTTPAnnounces() const +int SessionImpl::maxConcurrentHTTPAnnounces() const { return m_maxConcurrentHTTPAnnounces; } -void Session::setMaxConcurrentHTTPAnnounces(const int value) +void SessionImpl::setMaxConcurrentHTTPAnnounces(const int value) { if (value == m_maxConcurrentHTTPAnnounces) return; @@ -4178,12 +4176,12 @@ void Session::setMaxConcurrentHTTPAnnounces(const int value) configureDeferred(); } -bool Session::isReannounceWhenAddressChangedEnabled() const +bool SessionImpl::isReannounceWhenAddressChangedEnabled() const { return m_isReannounceWhenAddressChangedEnabled; } -void Session::setReannounceWhenAddressChangedEnabled(const bool enabled) +void SessionImpl::setReannounceWhenAddressChangedEnabled(const bool enabled) { if (enabled == m_isReannounceWhenAddressChangedEnabled) return; @@ -4191,18 +4189,18 @@ void Session::setReannounceWhenAddressChangedEnabled(const bool enabled) m_isReannounceWhenAddressChangedEnabled = enabled; } -void Session::reannounceToAllTrackers() const +void SessionImpl::reannounceToAllTrackers() const { for (const lt::torrent_handle &torrent : m_nativeSession->get_torrents()) torrent.force_reannounce(0, -1, lt::torrent_handle::ignore_min_interval); } -int Session::stopTrackerTimeout() const +int SessionImpl::stopTrackerTimeout() const { return m_stopTrackerTimeout; } -void Session::setStopTrackerTimeout(const int value) +void SessionImpl::setStopTrackerTimeout(const int value) { if (value == m_stopTrackerTimeout) return; @@ -4211,12 +4209,12 @@ void Session::setStopTrackerTimeout(const int value) configureDeferred(); } -int Session::maxConnections() const +int SessionImpl::maxConnections() const { return m_maxConnections; } -void Session::setMaxConnections(int max) +void SessionImpl::setMaxConnections(int max) { max = (max > 0) ? max : -1; if (max != m_maxConnections) @@ -4226,12 +4224,12 @@ void Session::setMaxConnections(int max) } } -int Session::maxUploads() const +int SessionImpl::maxUploads() const { return m_maxUploads; } -void Session::setMaxUploads(int max) +void SessionImpl::setMaxUploads(int max) { max = (max > 0) ? max : -1; if (max != m_maxUploads) @@ -4241,12 +4239,12 @@ void Session::setMaxUploads(int max) } } -BTProtocol Session::btProtocol() const +BTProtocol SessionImpl::btProtocol() const { return m_btProtocol; } -void Session::setBTProtocol(const BTProtocol protocol) +void SessionImpl::setBTProtocol(const BTProtocol protocol) { if ((protocol < BTProtocol::Both) || (BTProtocol::UTP < protocol)) return; @@ -4257,12 +4255,12 @@ void Session::setBTProtocol(const BTProtocol protocol) configureDeferred(); } -bool Session::isUTPRateLimited() const +bool SessionImpl::isUTPRateLimited() const { return m_isUTPRateLimited; } -void Session::setUTPRateLimited(const bool limited) +void SessionImpl::setUTPRateLimited(const bool limited) { if (limited != m_isUTPRateLimited) { @@ -4271,12 +4269,12 @@ void Session::setUTPRateLimited(const bool limited) } } -MixedModeAlgorithm Session::utpMixedMode() const +MixedModeAlgorithm SessionImpl::utpMixedMode() const { return m_utpMixedMode; } -void Session::setUtpMixedMode(const MixedModeAlgorithm mode) +void SessionImpl::setUtpMixedMode(const MixedModeAlgorithm mode) { if (mode == m_utpMixedMode) return; @@ -4284,12 +4282,12 @@ void Session::setUtpMixedMode(const MixedModeAlgorithm mode) configureDeferred(); } -bool Session::isIDNSupportEnabled() const +bool SessionImpl::isIDNSupportEnabled() const { return m_IDNSupportEnabled; } -void Session::setIDNSupportEnabled(const bool enabled) +void SessionImpl::setIDNSupportEnabled(const bool enabled) { if (enabled == m_IDNSupportEnabled) return; @@ -4297,12 +4295,12 @@ void Session::setIDNSupportEnabled(const bool enabled) configureDeferred(); } -bool Session::multiConnectionsPerIpEnabled() const +bool SessionImpl::multiConnectionsPerIpEnabled() const { return m_multiConnectionsPerIpEnabled; } -void Session::setMultiConnectionsPerIpEnabled(const bool enabled) +void SessionImpl::setMultiConnectionsPerIpEnabled(const bool enabled) { if (enabled == m_multiConnectionsPerIpEnabled) return; @@ -4310,12 +4308,12 @@ void Session::setMultiConnectionsPerIpEnabled(const bool enabled) configureDeferred(); } -bool Session::validateHTTPSTrackerCertificate() const +bool SessionImpl::validateHTTPSTrackerCertificate() const { return m_validateHTTPSTrackerCertificate; } -void Session::setValidateHTTPSTrackerCertificate(const bool enabled) +void SessionImpl::setValidateHTTPSTrackerCertificate(const bool enabled) { if (enabled == m_validateHTTPSTrackerCertificate) return; @@ -4323,12 +4321,12 @@ void Session::setValidateHTTPSTrackerCertificate(const bool enabled) configureDeferred(); } -bool Session::isSSRFMitigationEnabled() const +bool SessionImpl::isSSRFMitigationEnabled() const { return m_SSRFMitigationEnabled; } -void Session::setSSRFMitigationEnabled(const bool enabled) +void SessionImpl::setSSRFMitigationEnabled(const bool enabled) { if (enabled == m_SSRFMitigationEnabled) return; @@ -4336,12 +4334,12 @@ void Session::setSSRFMitigationEnabled(const bool enabled) configureDeferred(); } -bool Session::blockPeersOnPrivilegedPorts() const +bool SessionImpl::blockPeersOnPrivilegedPorts() const { return m_blockPeersOnPrivilegedPorts; } -void Session::setBlockPeersOnPrivilegedPorts(const bool enabled) +void SessionImpl::setBlockPeersOnPrivilegedPorts(const bool enabled) { if (enabled == m_blockPeersOnPrivilegedPorts) return; @@ -4349,12 +4347,12 @@ void Session::setBlockPeersOnPrivilegedPorts(const bool enabled) configureDeferred(); } -bool Session::isTrackerFilteringEnabled() const +bool SessionImpl::isTrackerFilteringEnabled() const { return m_isTrackerFilteringEnabled; } -void Session::setTrackerFilteringEnabled(const bool enabled) +void SessionImpl::setTrackerFilteringEnabled(const bool enabled) { if (enabled != m_isTrackerFilteringEnabled) { @@ -4363,24 +4361,22 @@ void Session::setTrackerFilteringEnabled(const bool enabled) } } -bool Session::isListening() const +bool SessionImpl::isListening() const { return m_nativeSession->is_listening(); } -MaxRatioAction Session::maxRatioAction() const +MaxRatioAction SessionImpl::maxRatioAction() const { return static_cast(m_maxRatioAction.get()); } -void Session::setMaxRatioAction(const MaxRatioAction act) +void SessionImpl::setMaxRatioAction(const MaxRatioAction act) { m_maxRatioAction = static_cast(act); } -// If this functions returns true, we cannot add torrent to session, -// but it is still possible to merge trackers in some cases -bool Session::isKnownTorrent(const InfoHash &infoHash) const +bool SessionImpl::isKnownTorrent(const InfoHash &infoHash) const { const bool isHybrid = infoHash.isHybrid(); const auto id = TorrentID::fromInfoHash(infoHash); @@ -4395,7 +4391,7 @@ bool Session::isKnownTorrent(const InfoHash &infoHash) const return findTorrent(infoHash); } -void Session::updateSeedingLimitTimer() +void SessionImpl::updateSeedingLimitTimer() { if ((globalMaxRatio() == Torrent::NO_RATIO_LIMIT) && !hasPerTorrentRatioLimit() && (globalMaxSeedingMinutes() == Torrent::NO_SEEDING_TIME_LIMIT) && !hasPerTorrentSeedingTimeLimit()) @@ -4409,41 +4405,41 @@ void Session::updateSeedingLimitTimer() } } -void Session::handleTorrentShareLimitChanged(TorrentImpl *const) +void SessionImpl::handleTorrentShareLimitChanged(TorrentImpl *const) { updateSeedingLimitTimer(); } -void Session::handleTorrentNameChanged(TorrentImpl *const) +void SessionImpl::handleTorrentNameChanged(TorrentImpl *const) { } -void Session::handleTorrentSavePathChanged(TorrentImpl *const torrent) +void SessionImpl::handleTorrentSavePathChanged(TorrentImpl *const torrent) { emit torrentSavePathChanged(torrent); } -void Session::handleTorrentCategoryChanged(TorrentImpl *const torrent, const QString &oldCategory) +void SessionImpl::handleTorrentCategoryChanged(TorrentImpl *const torrent, const QString &oldCategory) { emit torrentCategoryChanged(torrent, oldCategory); } -void Session::handleTorrentTagAdded(TorrentImpl *const torrent, const QString &tag) +void SessionImpl::handleTorrentTagAdded(TorrentImpl *const torrent, const QString &tag) { emit torrentTagAdded(torrent, tag); } -void Session::handleTorrentTagRemoved(TorrentImpl *const torrent, const QString &tag) +void SessionImpl::handleTorrentTagRemoved(TorrentImpl *const torrent, const QString &tag) { emit torrentTagRemoved(torrent, tag); } -void Session::handleTorrentSavingModeChanged(TorrentImpl *const torrent) +void SessionImpl::handleTorrentSavingModeChanged(TorrentImpl *const torrent) { emit torrentSavingModeChanged(torrent); } -void Session::handleTorrentTrackersAdded(TorrentImpl *const torrent, const QVector &newTrackers) +void SessionImpl::handleTorrentTrackersAdded(TorrentImpl *const torrent, const QVector &newTrackers) { for (const TrackerEntry &newTracker : newTrackers) LogMsg(tr("Added tracker to torrent. Torrent: \"%1\". Tracker: \"%2\"").arg(torrent->name(), newTracker.url)); @@ -4453,7 +4449,7 @@ void Session::handleTorrentTrackersAdded(TorrentImpl *const torrent, const QVect emit trackersChanged(torrent); } -void Session::handleTorrentTrackersRemoved(TorrentImpl *const torrent, const QStringList &deletedTrackers) +void SessionImpl::handleTorrentTrackersRemoved(TorrentImpl *const torrent, const QStringList &deletedTrackers) { for (const QString &deletedTracker : deletedTrackers) LogMsg(tr("Removed tracker from torrent. Torrent: \"%1\". Tracker: \"%2\"").arg(torrent->name(), deletedTracker)); @@ -4463,24 +4459,24 @@ void Session::handleTorrentTrackersRemoved(TorrentImpl *const torrent, const QSt emit trackersChanged(torrent); } -void Session::handleTorrentTrackersChanged(TorrentImpl *const torrent) +void SessionImpl::handleTorrentTrackersChanged(TorrentImpl *const torrent) { emit trackersChanged(torrent); } -void Session::handleTorrentUrlSeedsAdded(TorrentImpl *const torrent, const QVector &newUrlSeeds) +void SessionImpl::handleTorrentUrlSeedsAdded(TorrentImpl *const torrent, const QVector &newUrlSeeds) { for (const QUrl &newUrlSeed : newUrlSeeds) LogMsg(tr("Added URL seed to torrent. Torrent: \"%1\". URL: \"%2\"").arg(torrent->name(), newUrlSeed.toString())); } -void Session::handleTorrentUrlSeedsRemoved(TorrentImpl *const torrent, const QVector &urlSeeds) +void SessionImpl::handleTorrentUrlSeedsRemoved(TorrentImpl *const torrent, const QVector &urlSeeds) { for (const QUrl &urlSeed : urlSeeds) LogMsg(tr("Removed URL seed from torrent. Torrent: \"%1\". URL: \"%2\"").arg(torrent->name(), urlSeed.toString())); } -void Session::handleTorrentMetadataReceived(TorrentImpl *const torrent) +void SessionImpl::handleTorrentMetadataReceived(TorrentImpl *const torrent) { if (!torrentExportDirectory().isEmpty()) exportTorrentFile(torrent, torrentExportDirectory()); @@ -4488,24 +4484,24 @@ void Session::handleTorrentMetadataReceived(TorrentImpl *const torrent) emit torrentMetadataReceived(torrent); } -void Session::handleTorrentPaused(TorrentImpl *const torrent) +void SessionImpl::handleTorrentPaused(TorrentImpl *const torrent) { LogMsg(tr("Torrent paused. Torrent: \"%1\"").arg(torrent->name())); emit torrentPaused(torrent); } -void Session::handleTorrentResumed(TorrentImpl *const torrent) +void SessionImpl::handleTorrentResumed(TorrentImpl *const torrent) { LogMsg(tr("Torrent resumed. Torrent: \"%1\"").arg(torrent->name())); emit torrentResumed(torrent); } -void Session::handleTorrentChecked(TorrentImpl *const torrent) +void SessionImpl::handleTorrentChecked(TorrentImpl *const torrent) { emit torrentFinishedChecking(torrent); } -void Session::handleTorrentFinished(TorrentImpl *const torrent) +void SessionImpl::handleTorrentFinished(TorrentImpl *const torrent) { LogMsg(tr("Torrent download finished. Torrent: \"%1\"").arg(torrent->name())); emit torrentFinished(torrent); @@ -4540,7 +4536,7 @@ void Session::handleTorrentFinished(TorrentImpl *const torrent) emit allTorrentsFinished(); } -void Session::handleTorrentResumeDataReady(TorrentImpl *const torrent, const LoadTorrentParams &data) +void SessionImpl::handleTorrentResumeDataReady(TorrentImpl *const torrent, const LoadTorrentParams &data) { --m_numResumeData; @@ -4553,13 +4549,13 @@ void Session::handleTorrentResumeDataReady(TorrentImpl *const torrent, const Loa } } -void Session::handleTorrentIDChanged(const TorrentImpl *torrent, const TorrentID &prevID) +void SessionImpl::handleTorrentIDChanged(const TorrentImpl *torrent, const TorrentID &prevID) { m_torrents[torrent->id()] = m_torrents.take(prevID); m_changedTorrentIDs[torrent->id()] = prevID; } -bool Session::addMoveTorrentStorageJob(TorrentImpl *torrent, const Path &newPath, const MoveStorageMode mode) +bool SessionImpl::addMoveTorrentStorageJob(TorrentImpl *torrent, const Path &newPath, const MoveStorageMode mode) { Q_ASSERT(torrent); @@ -4621,7 +4617,7 @@ bool Session::addMoveTorrentStorageJob(TorrentImpl *torrent, const Path &newPath return true; } -void Session::moveTorrentStorage(const MoveStorageJob &job) const +void SessionImpl::moveTorrentStorage(const MoveStorageJob &job) const { #ifdef QBT_USES_LIBTORRENT2 const auto id = TorrentID::fromInfoHash(job.torrentHandle.info_hashes()); @@ -4637,7 +4633,7 @@ void Session::moveTorrentStorage(const MoveStorageJob &job) const ? lt::move_flags_t::always_replace_files : lt::move_flags_t::dont_replace)); } -void Session::handleMoveTorrentStorageJobFinished(const Path &newPath) +void SessionImpl::handleMoveTorrentStorageJobFinished(const Path &newPath) { const MoveStorageJob finishedJob = m_moveStorageQueue.takeFirst(); if (!m_moveStorageQueue.isEmpty()) @@ -4666,7 +4662,7 @@ void Session::handleMoveTorrentStorageJobFinished(const Path &newPath) } } -void Session::storeCategories() const +void SessionImpl::storeCategories() const { QJsonObject jsonObj; for (auto it = m_categories.cbegin(); it != m_categories.cend(); ++it) @@ -4686,7 +4682,7 @@ void Session::storeCategories() const } } -void Session::upgradeCategories() +void SessionImpl::upgradeCategories() { const auto legacyCategories = SettingValue(u"BitTorrent/Session/Categories"_qs).get(); for (auto it = legacyCategories.cbegin(); it != legacyCategories.cend(); ++it) @@ -4700,7 +4696,7 @@ void Session::upgradeCategories() storeCategories(); } -void Session::loadCategories() +void SessionImpl::loadCategories() { m_categories.clear(); @@ -4748,7 +4744,7 @@ void Session::loadCategories() } } -bool Session::hasPerTorrentRatioLimit() const +bool SessionImpl::hasPerTorrentRatioLimit() const { return std::any_of(m_torrents.cbegin(), m_torrents.cend(), [](const TorrentImpl *torrent) { @@ -4756,7 +4752,7 @@ bool Session::hasPerTorrentRatioLimit() const }); } -bool Session::hasPerTorrentSeedingTimeLimit() const +bool SessionImpl::hasPerTorrentSeedingTimeLimit() const { return std::any_of(m_torrents.cbegin(), m_torrents.cend(), [](const TorrentImpl *torrent) { @@ -4764,18 +4760,18 @@ bool Session::hasPerTorrentSeedingTimeLimit() const }); } -void Session::configureDeferred() +void SessionImpl::configureDeferred() { if (m_deferredConfigureScheduled) return; m_deferredConfigureScheduled = true; - QMetaObject::invokeMethod(this, qOverload<>(&Session::configure), Qt::QueuedConnection); + QMetaObject::invokeMethod(this, qOverload<>(&SessionImpl::configure), Qt::QueuedConnection); } // Enable IP Filtering // this method creates ban list from scratch combining user ban list and 3rd party ban list file -void Session::enableIPFilter() +void SessionImpl::enableIPFilter() { qDebug("Enabling IPFilter"); // 1. Parse the IP filter @@ -4785,14 +4781,14 @@ void Session::enableIPFilter() if (!m_filterParser) { m_filterParser = new FilterParserThread(this); - connect(m_filterParser.data(), &FilterParserThread::IPFilterParsed, this, &Session::handleIPFilterParsed); - connect(m_filterParser.data(), &FilterParserThread::IPFilterError, this, &Session::handleIPFilterError); + connect(m_filterParser.data(), &FilterParserThread::IPFilterParsed, this, &SessionImpl::handleIPFilterParsed); + connect(m_filterParser.data(), &FilterParserThread::IPFilterError, this, &SessionImpl::handleIPFilterError); } m_filterParser->processFilterFile(IPFilterFile()); } // Disable IP Filtering -void Session::disableIPFilter() +void SessionImpl::disableIPFilter() { qDebug("Disabling IPFilter"); if (m_filterParser) @@ -4809,7 +4805,7 @@ void Session::disableIPFilter() m_nativeSession->set_ip_filter(filter); } -void Session::recursiveTorrentDownload(const TorrentID &id) +void SessionImpl::recursiveTorrentDownload(const TorrentID &id) { TorrentImpl *const torrent = m_torrents.value(id); if (!torrent) return; @@ -4834,27 +4830,27 @@ void Session::recursiveTorrentDownload(const TorrentID &id) } } -const SessionStatus &Session::status() const +const SessionStatus &SessionImpl::status() const { return m_status; } -const CacheStatus &Session::cacheStatus() const +const CacheStatus &SessionImpl::cacheStatus() const { return m_cacheStatus; } -qint64 Session::getAlltimeDL() const +qint64 SessionImpl::getAlltimeDL() const { return m_statistics->getAlltimeDL(); } -qint64 Session::getAlltimeUL() const +qint64 SessionImpl::getAlltimeUL() const { return m_statistics->getAlltimeUL(); } -void Session::enqueueRefresh() +void SessionImpl::enqueueRefresh() { Q_ASSERT(!m_refreshEnqueued); @@ -4867,7 +4863,7 @@ void Session::enqueueRefresh() m_refreshEnqueued = true; } -void Session::handleIPFilterParsed(const int ruleCount) +void SessionImpl::handleIPFilterParsed(const int ruleCount) { if (m_filterParser) { @@ -4879,7 +4875,7 @@ void Session::handleIPFilterParsed(const int ruleCount) emit IPFilterParsed(false, ruleCount); } -void Session::handleIPFilterError() +void SessionImpl::handleIPFilterError() { lt::ip_filter filter; processBannedIPs(filter); @@ -4889,7 +4885,7 @@ void Session::handleIPFilterError() emit IPFilterParsed(true, 0); } -std::vector Session::getPendingAlerts(const lt::time_duration time) const +std::vector SessionImpl::getPendingAlerts(const lt::time_duration time) const { if (time > lt::time_duration::zero()) m_nativeSession->wait_for_alert(time); @@ -4899,18 +4895,18 @@ std::vector Session::getPendingAlerts(const lt::time_duration time) return alerts; } -TorrentContentLayout Session::torrentContentLayout() const +TorrentContentLayout SessionImpl::torrentContentLayout() const { return m_torrentContentLayout; } -void Session::setTorrentContentLayout(const TorrentContentLayout value) +void SessionImpl::setTorrentContentLayout(const TorrentContentLayout value) { m_torrentContentLayout = value; } // Read alerts sent by the BitTorrent session -void Session::readAlerts() +void SessionImpl::readAlerts() { const std::vector alerts = getPendingAlerts(); handleAddTorrentAlerts(alerts); @@ -4920,7 +4916,7 @@ void Session::readAlerts() processTrackerStatuses(); } -void Session::handleAddTorrentAlerts(const std::vector &alerts) +void SessionImpl::handleAddTorrentAlerts(const std::vector &alerts) { QVector loadedTorrents; if (!isRestored()) @@ -4970,7 +4966,7 @@ void Session::handleAddTorrentAlerts(const std::vector &alerts) emit torrentsLoaded(loadedTorrents); } -void Session::handleAlert(const lt::alert *a) +void SessionImpl::handleAlert(const lt::alert *a) { try { @@ -5069,7 +5065,7 @@ void Session::handleAlert(const lt::alert *a) } } -void Session::dispatchTorrentAlert(const lt::torrent_alert *a) +void SessionImpl::dispatchTorrentAlert(const lt::torrent_alert *a) { const TorrentID torrentID {a->handle.info_hash()}; TorrentImpl *torrent = m_torrents.value(torrentID); @@ -5096,7 +5092,7 @@ void Session::dispatchTorrentAlert(const lt::torrent_alert *a) } } -TorrentImpl *Session::createTorrent(const lt::torrent_handle &nativeHandle, const LoadTorrentParams ¶ms) +TorrentImpl *SessionImpl::createTorrent(const lt::torrent_handle &nativeHandle, const LoadTorrentParams ¶ms) { #ifdef QBT_USES_LIBTORRENT2 const auto torrentID = TorrentID::fromInfoHash(nativeHandle.info_hashes()); @@ -5142,7 +5138,7 @@ TorrentImpl *Session::createTorrent(const lt::torrent_handle &nativeHandle, cons return torrent; } -void Session::handleTorrentRemovedAlert(const lt::torrent_removed_alert *p) +void SessionImpl::handleTorrentRemovedAlert(const lt::torrent_removed_alert *p) { #ifdef QBT_USES_LIBTORRENT2 const auto id = TorrentID::fromInfoHash(p->info_hashes); @@ -5161,7 +5157,7 @@ void Session::handleTorrentRemovedAlert(const lt::torrent_removed_alert *p) } } -void Session::handleTorrentDeletedAlert(const lt::torrent_deleted_alert *p) +void SessionImpl::handleTorrentDeletedAlert(const lt::torrent_deleted_alert *p) { #ifdef QBT_USES_LIBTORRENT2 const auto id = TorrentID::fromInfoHash(p->info_hashes); @@ -5179,7 +5175,7 @@ void Session::handleTorrentDeletedAlert(const lt::torrent_deleted_alert *p) m_removingTorrents.erase(removingTorrentDataIter); } -void Session::handleTorrentDeleteFailedAlert(const lt::torrent_delete_failed_alert *p) +void SessionImpl::handleTorrentDeleteFailedAlert(const lt::torrent_delete_failed_alert *p) { #ifdef QBT_USES_LIBTORRENT2 const auto id = TorrentID::fromInfoHash(p->info_hashes); @@ -5209,7 +5205,7 @@ void Session::handleTorrentDeleteFailedAlert(const lt::torrent_delete_failed_ale m_removingTorrents.erase(removingTorrentDataIter); } -void Session::handleMetadataReceivedAlert(const lt::metadata_received_alert *p) +void SessionImpl::handleMetadataReceivedAlert(const lt::metadata_received_alert *p) { #ifdef QBT_USES_LIBTORRENT2 const auto id = TorrentID::fromInfoHash(p->handle.info_hashes()); @@ -5232,7 +5228,7 @@ void Session::handleMetadataReceivedAlert(const lt::metadata_received_alert *p) } } -void Session::handleFileErrorAlert(const lt::file_error_alert *p) +void SessionImpl::handleFileErrorAlert(const lt::file_error_alert *p) { TorrentImpl *const torrent = m_torrents.value(p->handle.info_hash()); if (!torrent) @@ -5255,18 +5251,18 @@ void Session::handleFileErrorAlert(const lt::file_error_alert *p) m_recentErroredTorrentsTimer->start(); } -void Session::handlePortmapWarningAlert(const lt::portmap_error_alert *p) +void SessionImpl::handlePortmapWarningAlert(const lt::portmap_error_alert *p) { LogMsg(tr("UPnP/NAT-PMP port mapping failed. Message: \"%1\"").arg(QString::fromStdString(p->message())), Log::WARNING); } -void Session::handlePortmapAlert(const lt::portmap_alert *p) +void SessionImpl::handlePortmapAlert(const lt::portmap_alert *p) { qDebug("UPnP Success, msg: %s", p->message().c_str()); LogMsg(tr("UPnP/NAT-PMP port mapping succeeded. Message: \"%1\"").arg(QString::fromStdString(p->message())), Log::INFO); } -void Session::handlePeerBlockedAlert(const lt::peer_blocked_alert *p) +void SessionImpl::handlePeerBlockedAlert(const lt::peer_blocked_alert *p) { QString reason; switch (p->reason) @@ -5296,14 +5292,14 @@ void Session::handlePeerBlockedAlert(const lt::peer_blocked_alert *p) Logger::instance()->addPeer(ip, true, reason); } -void Session::handlePeerBanAlert(const lt::peer_ban_alert *p) +void SessionImpl::handlePeerBanAlert(const lt::peer_ban_alert *p) { const QString ip {toString(p->endpoint.address())}; if (!ip.isEmpty()) Logger::instance()->addPeer(ip, false); } -void Session::handleUrlSeedAlert(const lt::url_seed_alert *p) +void SessionImpl::handleUrlSeedAlert(const lt::url_seed_alert *p) { const TorrentImpl *torrent = m_torrents.value(p->handle.info_hash()); if (!torrent) @@ -5323,14 +5319,14 @@ void Session::handleUrlSeedAlert(const lt::url_seed_alert *p) } } -void Session::handleListenSucceededAlert(const lt::listen_succeeded_alert *p) +void SessionImpl::handleListenSucceededAlert(const lt::listen_succeeded_alert *p) { const QString proto {toString(p->socket_type)}; LogMsg(tr("Successfully listening on IP. IP: \"%1\". Port: \"%2/%3\"") .arg(toString(p->address), proto, QString::number(p->port)), Log::INFO); } -void Session::handleListenFailedAlert(const lt::listen_failed_alert *p) +void SessionImpl::handleListenFailedAlert(const lt::listen_failed_alert *p) { const QString proto {toString(p->socket_type)}; LogMsg(tr("Failed to listen on IP. IP: \"%1\". Port: \"%2/%3\". Reason: \"%4\"") @@ -5338,7 +5334,7 @@ void Session::handleListenFailedAlert(const lt::listen_failed_alert *p) , QString::fromLocal8Bit(p->error.message().c_str())), Log::CRITICAL); } -void Session::handleExternalIPAlert(const lt::external_ip_alert *p) +void SessionImpl::handleExternalIPAlert(const lt::external_ip_alert *p) { const QString externalIP {toString(p->external_address)}; LogMsg(tr("Detected external IP. IP: \"%1\"") @@ -5352,7 +5348,7 @@ void Session::handleExternalIPAlert(const lt::external_ip_alert *p) } } -void Session::handleSessionStatsAlert(const lt::session_stats_alert *p) +void SessionImpl::handleSessionStatsAlert(const lt::session_stats_alert *p) { if (m_refreshEnqueued) m_refreshEnqueued = false; @@ -5432,13 +5428,13 @@ void Session::handleSessionStatsAlert(const lt::session_stats_alert *p) emit statsUpdated(); } -void Session::handleAlertsDroppedAlert(const lt::alerts_dropped_alert *p) const +void SessionImpl::handleAlertsDroppedAlert(const lt::alerts_dropped_alert *p) const { LogMsg(tr("Error: Internal alert queue is full and alerts are dropped, you might see degraded performance. Dropped alert type: \"%1\". Message: \"%2\"") .arg(QString::fromStdString(p->dropped_alerts.to_string()), QString::fromStdString(p->message())), Log::CRITICAL); } -void Session::handleStorageMovedAlert(const lt::storage_moved_alert *p) +void SessionImpl::handleStorageMovedAlert(const lt::storage_moved_alert *p) { Q_ASSERT(!m_moveStorageQueue.isEmpty()); @@ -5461,7 +5457,7 @@ void Session::handleStorageMovedAlert(const lt::storage_moved_alert *p) handleMoveTorrentStorageJobFinished(newPath); } -void Session::handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert *p) +void SessionImpl::handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert *p) { Q_ASSERT(!m_moveStorageQueue.isEmpty()); @@ -5485,7 +5481,7 @@ void Session::handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert handleMoveTorrentStorageJobFinished(currentLocation); } -void Session::handleStateUpdateAlert(const lt::state_update_alert *p) +void SessionImpl::handleStateUpdateAlert(const lt::state_update_alert *p) { QVector updatedTorrents; updatedTorrents.reserve(static_cast(p->status.size())); @@ -5514,7 +5510,7 @@ void Session::handleStateUpdateAlert(const lt::state_update_alert *p) enqueueRefresh(); } -void Session::handleSocks5Alert(const lt::socks5_alert *p) const +void SessionImpl::handleSocks5Alert(const lt::socks5_alert *p) const { if (p->error) { @@ -5523,7 +5519,7 @@ void Session::handleSocks5Alert(const lt::socks5_alert *p) const } } -void Session::handleTrackerAlert(const lt::tracker_alert *a) +void SessionImpl::handleTrackerAlert(const lt::tracker_alert *a) { TorrentImpl *torrent = m_torrents.value(a->handle.info_hash()); if (!torrent) @@ -5540,7 +5536,7 @@ void Session::handleTrackerAlert(const lt::tracker_alert *a) } #ifdef QBT_USES_LIBTORRENT2 -void Session::handleTorrentConflictAlert(const lt::torrent_conflict_alert *a) +void SessionImpl::handleTorrentConflictAlert(const lt::torrent_conflict_alert *a) { const auto torrentIDv1 = TorrentID::fromSHA1Hash(a->metadata->info_hashes().v1); const auto torrentIDv2 = TorrentID::fromSHA256Hash(a->metadata->info_hashes().v2); @@ -5573,7 +5569,7 @@ void Session::handleTorrentConflictAlert(const lt::torrent_conflict_alert *a) } #endif -void Session::processTrackerStatuses() +void SessionImpl::processTrackerStatuses() { for (auto it = m_updatedTrackerEntries.cbegin(); it != m_updatedTrackerEntries.cend(); ++it) { diff --git a/src/base/bittorrent/sessionimpl.h b/src/base/bittorrent/sessionimpl.h new file mode 100644 index 000000000..4614dfabf --- /dev/null +++ b/src/base/bittorrent/sessionimpl.h @@ -0,0 +1,730 @@ +/* + * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2015-2022 Vladimir Golovnev + * Copyright (C) 2006 Christophe Dumez + * + * 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 +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#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 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 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 ¶ms = AddTorrentParams()) override; + bool addTorrent(const MagnetUri &magnetUri, const AddTorrentParams ¶ms = AddTorrentParams()) override; + bool addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams ¶ms = 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 &ids) override; + void decreaseTorrentsQueuePos(const QVector &ids) override; + void topTorrentsQueuePos(const QVector &ids) override; + void bottomTorrentsQueuePos(const QVector &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 &newTrackers); + void handleTorrentTrackersRemoved(TorrentImpl *const torrent, const QStringList &deletedTrackers); + void handleTorrentTrackersChanged(TorrentImpl *const torrent); + void handleTorrentUrlSeedsAdded(TorrentImpl *const torrent, const QVector &newUrlSeeds); + void handleTorrentUrlSeedsRemoved(TorrentImpl *const torrent, const QVector &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 &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 &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 ¶ms); + + void saveResumeData(); + void saveTorrentsQueue() const; + void removeTorrentsQueue() const; + + std::vector 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 m_isDHTEnabled; + CachedSettingValue m_isLSDEnabled; + CachedSettingValue m_isPeXEnabled; + CachedSettingValue m_isIPFilteringEnabled; + CachedSettingValue m_isTrackerFilteringEnabled; + CachedSettingValue m_IPFilterFile; + CachedSettingValue m_announceToAllTrackers; + CachedSettingValue m_announceToAllTiers; + CachedSettingValue m_asyncIOThreads; + CachedSettingValue m_hashingThreads; + CachedSettingValue m_filePoolSize; + CachedSettingValue m_checkingMemUsage; + CachedSettingValue m_diskCacheSize; + CachedSettingValue m_diskCacheTTL; + CachedSettingValue m_diskQueueSize; + CachedSettingValue m_diskIOType; + CachedSettingValue m_diskIOReadMode; + CachedSettingValue m_diskIOWriteMode; + CachedSettingValue m_coalesceReadWriteEnabled; + CachedSettingValue m_usePieceExtentAffinity; + CachedSettingValue m_isSuggestMode; + CachedSettingValue m_sendBufferWatermark; + CachedSettingValue m_sendBufferLowWatermark; + CachedSettingValue m_sendBufferWatermarkFactor; + CachedSettingValue m_connectionSpeed; + CachedSettingValue m_socketBacklogSize; + CachedSettingValue m_isAnonymousModeEnabled; + CachedSettingValue m_isQueueingEnabled; + CachedSettingValue m_maxActiveDownloads; + CachedSettingValue m_maxActiveUploads; + CachedSettingValue m_maxActiveTorrents; + CachedSettingValue m_ignoreSlowTorrentsForQueueing; + CachedSettingValue m_downloadRateForSlowTorrents; + CachedSettingValue m_uploadRateForSlowTorrents; + CachedSettingValue m_slowTorrentsInactivityTimer; + CachedSettingValue m_outgoingPortsMin; + CachedSettingValue m_outgoingPortsMax; + CachedSettingValue m_UPnPLeaseDuration; + CachedSettingValue m_peerToS; + CachedSettingValue m_ignoreLimitsOnLAN; + CachedSettingValue m_includeOverheadInLimits; + CachedSettingValue m_announceIP; + CachedSettingValue m_maxConcurrentHTTPAnnounces; + CachedSettingValue m_isReannounceWhenAddressChangedEnabled; + CachedSettingValue m_stopTrackerTimeout; + CachedSettingValue m_maxConnections; + CachedSettingValue m_maxUploads; + CachedSettingValue m_maxConnectionsPerTorrent; + CachedSettingValue m_maxUploadsPerTorrent; + CachedSettingValue m_btProtocol; + CachedSettingValue m_isUTPRateLimited; + CachedSettingValue m_utpMixedMode; + CachedSettingValue m_IDNSupportEnabled; + CachedSettingValue m_multiConnectionsPerIpEnabled; + CachedSettingValue m_validateHTTPSTrackerCertificate; + CachedSettingValue m_SSRFMitigationEnabled; + CachedSettingValue m_blockPeersOnPrivilegedPorts; + CachedSettingValue m_isAddTrackersEnabled; + CachedSettingValue m_additionalTrackers; + CachedSettingValue m_globalMaxRatio; + CachedSettingValue m_globalMaxSeedingMinutes; + CachedSettingValue m_isAddTorrentPaused; + CachedSettingValue m_torrentContentLayout; + CachedSettingValue m_isAppendExtensionEnabled; + CachedSettingValue m_refreshInterval; + CachedSettingValue m_isPreallocationEnabled; + CachedSettingValue m_torrentExportDirectory; + CachedSettingValue m_finishedTorrentExportDirectory; + CachedSettingValue m_globalDownloadSpeedLimit; + CachedSettingValue m_globalUploadSpeedLimit; + CachedSettingValue m_altGlobalDownloadSpeedLimit; + CachedSettingValue m_altGlobalUploadSpeedLimit; + CachedSettingValue m_isAltGlobalSpeedLimitEnabled; + CachedSettingValue m_isBandwidthSchedulerEnabled; + CachedSettingValue m_isPerformanceWarningEnabled; + CachedSettingValue m_saveResumeDataInterval; + CachedSettingValue m_port; + CachedSettingValue m_networkInterface; + CachedSettingValue m_networkInterfaceName; + CachedSettingValue m_networkInterfaceAddress; + CachedSettingValue m_encryption; + CachedSettingValue m_maxActiveCheckingTorrents; + CachedSettingValue m_isProxyPeerConnectionsEnabled; + CachedSettingValue m_chokingAlgorithm; + CachedSettingValue m_seedChokingAlgorithm; + CachedSettingValue m_storedTags; + CachedSettingValue m_maxRatioAction; + CachedSettingValue m_savePath; + CachedSettingValue m_downloadPath; + CachedSettingValue m_isDownloadPathEnabled; + CachedSettingValue m_isSubcategoriesEnabled; + CachedSettingValue m_useCategoryPathsInManualMode; + CachedSettingValue m_isAutoTMMDisabledByDefault; + CachedSettingValue m_isDisableAutoTMMWhenCategoryChanged; + CachedSettingValue m_isDisableAutoTMMWhenDefaultSavePathChanged; + CachedSettingValue m_isDisableAutoTMMWhenCategorySavePathChanged; + CachedSettingValue m_isTrackerEnabled; + CachedSettingValue m_peerTurnover; + CachedSettingValue m_peerTurnoverCutoff; + CachedSettingValue m_peerTurnoverInterval; + CachedSettingValue m_requestQueueSize; + CachedSettingValue m_isExcludedFileNamesEnabled; + CachedSettingValue m_excludedFileNames; + CachedSettingValue m_bannedIPs; + CachedSettingValue 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 m_additionalTrackerList; + QVector m_excludedFileNamesRegExpList; + + bool m_refreshEnqueued = false; + QTimer *m_seedingLimitTimer = nullptr; + QTimer *m_resumeDataTimer = nullptr; + Statistics *m_statistics = nullptr; + // IP filtering + QPointer m_filterParser; + QPointer m_bwScheduler; + // Tracker + QPointer m_tracker; + + QThread *m_ioThread = nullptr; + ResumeDataStorage *m_resumeDataStorage = nullptr; + FileSearcher *m_fileSearcher = nullptr; + + QSet m_downloadedMetadata; + + QHash m_torrents; + QHash m_loadingTorrents; + QHash m_downloadedTorrents; + QHash m_removingTorrents; + QSet m_needSaveResumeDataTorrents; + QHash m_changedTorrentIDs; + QMap m_categories; + QSet m_tags; + + QHash> m_updatedTrackerEntries; + + // I/O errored torrents + QSet 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 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; + }; +} diff --git a/src/base/bittorrent/statistics.cpp b/src/base/bittorrent/statistics.cpp index ddb9220c6..6712fe08d 100644 --- a/src/base/bittorrent/statistics.cpp +++ b/src/base/bittorrent/statistics.cpp @@ -33,7 +33,7 @@ #include #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) { diff --git a/src/base/bittorrent/statistics.h b/src/base/bittorrent/statistics.h index a8d716e55..0107a10b1 100644 --- a/src/base/bittorrent/statistics.h +++ b/src/base/bittorrent/statistics.h @@ -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; diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index 9936467d0..fc8afc9c4 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -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 ¶ms) : 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; diff --git a/src/base/bittorrent/torrentimpl.h b/src/base/bittorrent/torrentimpl.h index d1305f54f..8cde42a99 100644 --- a/src/base/bittorrent/torrentimpl.h +++ b/src/base/bittorrent/torrentimpl.h @@ -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 ¶ms); ~TorrentImpl() override; @@ -287,7 +287,7 @@ namespace BitTorrent nonstd::expected 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; diff --git a/src/gui/categoryfiltermodel.cpp b/src/gui/categoryfiltermodel.cpp index a188356ed..c45351952 100644 --- a/src/gui/categoryfiltermodel.cpp +++ b/src/gui/categoryfiltermodel.cpp @@ -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; diff --git a/src/gui/properties/propertieswidget.cpp b/src/gui/properties/propertieswidget.cpp index 155bfc056..26bc5da9d 100644 --- a/src/gui/properties/propertieswidget.cpp +++ b/src/gui/properties/propertieswidget.cpp @@ -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" diff --git a/src/gui/transferlistmodel.cpp b/src/gui/transferlistmodel.cpp index c71471b3d..c4b842fc3 100644 --- a/src/gui/transferlistmodel.cpp +++ b/src/gui/transferlistmodel.cpp @@ -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" diff --git a/src/webui/api/transfercontroller.cpp b/src/webui/api/transfercontroller.cpp index 207b0787b..69eea87f6 100644 --- a/src/webui/api/transfercontroller.cpp +++ b/src/webui/api/transfercontroller.cpp @@ -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;