qBittorrent
BitTorrent::Session Class Reference

#include <session.h>

Inheritance diagram for BitTorrent::Session:
Collaboration diagram for BitTorrent::Session:

Classes

struct  MoveStorageJob
 
struct  RemovingTorrentData
 

Signals

void allTorrentsFinished ()
 
void categoryAdded (const QString &categoryName)
 
void categoryRemoved (const QString &categoryName)
 
void downloadFromUrlFailed (const QString &url, const QString &reason)
 
void downloadFromUrlFinished (const QString &url)
 
void fullDiskError (Torrent *torrent, const QString &msg)
 
void IPFilterParsed (bool error, int ruleCount)
 
void loadTorrentFailed (const QString &error)
 
void metadataDownloaded (const TorrentInfo &info)
 
void recursiveTorrentDownloadPossible (Torrent *torrent)
 
void speedLimitModeChanged (bool alternative)
 
void statsUpdated ()
 
void subcategoriesSupportChanged ()
 
void tagAdded (const QString &tag)
 
void tagRemoved (const QString &tag)
 
void torrentAboutToBeRemoved (Torrent *torrent)
 
void torrentAdded (Torrent *torrent)
 
void torrentCategoryChanged (Torrent *torrent, const QString &oldCategory)
 
void torrentFinished (Torrent *torrent)
 
void torrentFinishedChecking (Torrent *torrent)
 
void torrentLoaded (Torrent *torrent)
 
void torrentMetadataReceived (Torrent *torrent)
 
void torrentPaused (Torrent *torrent)
 
void torrentResumed (Torrent *torrent)
 
void torrentSavePathChanged (Torrent *torrent)
 
void torrentSavingModeChanged (Torrent *torrent)
 
void torrentsUpdated (const QVector< Torrent * > &torrents)
 
void torrentTagAdded (Torrent *torrent, const QString &tag)
 
void torrentTagRemoved (Torrent *torrent, const QString &tag)
 
void trackerError (Torrent *torrent, const QString &tracker)
 
void trackerlessStateChanged (Torrent *torrent, bool trackerless)
 
void trackersAdded (Torrent *torrent, const QVector< TrackerEntry > &trackers)
 
void trackersChanged (Torrent *torrent)
 
void trackersRemoved (Torrent *torrent, const QVector< TrackerEntry > &trackers)
 
void trackerSuccess (Torrent *torrent, const QString &tracker)
 
void trackerWarning (Torrent *torrent, const QString &tracker)
 

Public Member Functions

QString savePath () const
 
void setSavePath (const QString &path)
 
QString downloadPath () const
 
void setDownloadPath (const QString &path)
 
bool isDownloadPathEnabled () const
 
void setDownloadPathEnabled (bool enabled)
 
QStringList categories () const
 
CategoryOptions categoryOptions (const QString &categoryName) const
 
QString categorySavePath (const QString &categoryName) const
 
QString 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)
 
QSet< QString > tags () const
 
bool hasTag (const QString &tag) const
 
bool addTag (const QString &tag)
 
bool removeTag (const QString &tag)
 
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)
 
QString torrentExportDirectory () const
 
void setTorrentExportDirectory (QString path)
 
QString finishedTorrentExportDirectory () const
 
void setFinishedTorrentExportDirectory (QString 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)
 
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)
 
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)
 
QString IPFilterFile () const
 
void setIPFilterFile (QString path)
 
bool announceToAllTrackers () const
 
void setAnnounceToAllTrackers (bool val)
 
bool announceToAllTiers () const
 
void setAnnounceToAllTiers (bool val)
 
int peerTurnover () const
 
void setPeerTurnover (int num)
 
int peerTurnoverCutoff () const
 
void setPeerTurnoverCutoff (int num)
 
int peerTurnoverInterval () const
 
void setPeerTurnoverInterval (int num)
 
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)
 
bool useOSCache () const
 
void setUseOSCache (bool use)
 
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)
 
QStringList bannedIPs () const
 
void setBannedIPs (const QStringList &newList)
 
ResumeDataStorageType resumeDataStorageType () const
 
void setResumeDataStorageType (ResumeDataStorageType type)
 
void startUpTorrents ()
 
TorrentfindTorrent (const TorrentID &id) const
 
QVector< Torrent * > torrents () const
 
bool hasActiveTorrents () const
 
bool hasUnfinishedTorrents () const
 
bool hasRunningSeed () const
 
const SessionStatusstatus () const
 
const CacheStatuscacheStatus () const
 
quint64 getAlltimeDL () const
 
quint64 getAlltimeUL () const
 
bool isListening () const
 
MaxRatioAction maxRatioAction () const
 
void setMaxRatioAction (MaxRatioAction act)
 
void banIP (const QString &ip)
 
bool isKnownTorrent (const TorrentID &id) const
 
bool addTorrent (const QString &source, const AddTorrentParams &params=AddTorrentParams())
 
bool addTorrent (const MagnetUri &magnetUri, const AddTorrentParams &params=AddTorrentParams())
 
bool addTorrent (const TorrentInfo &torrentInfo, const AddTorrentParams &params=AddTorrentParams())
 
bool deleteTorrent (const TorrentID &id, DeleteOption deleteOption=DeleteTorrent)
 
bool downloadMetadata (const MagnetUri &magnetUri)
 
bool cancelDownloadMetadata (const TorrentID &id)
 
void recursiveTorrentDownload (const TorrentID &id)
 
void increaseTorrentsQueuePos (const QVector< TorrentID > &ids)
 
void decreaseTorrentsQueuePos (const QVector< TorrentID > &ids)
 
void topTorrentsQueuePos (const QVector< TorrentID > &ids)
 
void bottomTorrentsQueuePos (const QVector< TorrentID > &ids)
 
void handleTorrentNeedSaveResumeData (const TorrentImpl *torrent)
 
void handleTorrentSaveResumeDataRequested (const TorrentImpl *torrent)
 
void handleTorrentShareLimitChanged (TorrentImpl *const torrent)
 
void handleTorrentNameChanged (TorrentImpl *const torrent)
 
void handleTorrentSavePathChanged (TorrentImpl *const torrent)
 
void handleTorrentCategoryChanged (TorrentImpl *const torrent, const QString &oldCategory)
 
void handleTorrentTagAdded (TorrentImpl *const torrent, const QString &tag)
 
void handleTorrentTagRemoved (TorrentImpl *const torrent, const QString &tag)
 
void handleTorrentSavingModeChanged (TorrentImpl *const torrent)
 
void handleTorrentMetadataReceived (TorrentImpl *const torrent)
 
void handleTorrentPaused (TorrentImpl *const torrent)
 
void handleTorrentResumed (TorrentImpl *const torrent)
 
void handleTorrentChecked (TorrentImpl *const torrent)
 
void handleTorrentFinished (TorrentImpl *const torrent)
 
void handleTorrentTrackersAdded (TorrentImpl *const torrent, const QVector< TrackerEntry > &newTrackers)
 
void handleTorrentTrackersRemoved (TorrentImpl *const torrent, const QVector< TrackerEntry > &deletedTrackers)
 
void handleTorrentTrackersChanged (TorrentImpl *const torrent)
 
void handleTorrentUrlSeedsAdded (TorrentImpl *const torrent, const QVector< QUrl > &newUrlSeeds)
 
void handleTorrentUrlSeedsRemoved (TorrentImpl *const torrent, const QVector< QUrl > &urlSeeds)
 
void handleTorrentResumeDataReady (TorrentImpl *const torrent, const LoadTorrentParams &data)
 
void handleTorrentTrackerReply (TorrentImpl *const torrent, const QString &trackerUrl)
 
void handleTorrentTrackerWarning (TorrentImpl *const torrent, const QString &trackerUrl)
 
void handleTorrentTrackerError (TorrentImpl *const torrent, const QString &trackerUrl)
 
bool addMoveTorrentStorageJob (TorrentImpl *torrent, const QString &newPath, MoveStorageMode mode)
 
void findIncompleteFiles (const TorrentInfo &torrentInfo, const QString &savePath, const QString &downloadPath, const QStringList &filePaths={}) const
 

Static Public Member Functions

static void initInstance ()
 
static void freeInstance ()
 
static Sessioninstance ()
 
static bool isValidCategoryName (const QString &name)
 
static QStringList expandCategory (const QString &category)
 
static bool isValidTag (const QString &tag)
 

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 QString &savePath, const QStringList &fileNames)
 

Private Member Functions

 Session (QObject *parent=nullptr)
 
 ~Session ()
 
bool hasPerTorrentRatioLimit () const
 
bool hasPerTorrentSeedingTimeLimit () const
 
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 ()
 
bool loadTorrent (LoadTorrentParams params)
 
LoadTorrentParams initLoadTorrentParams (const AddTorrentParams &addTorrentParams)
 
bool addTorrent_impl (const std::variant< MagnetUri, TorrentInfo > &source, const AddTorrentParams &addTorrentParams)
 
void updateSeedingLimitTimer ()
 
void exportTorrentFile (const TorrentInfo &torrentInfo, const QString &folderPath, const QString &baseName)
 
void handleAlert (const lt::alert *a)
 
void dispatchTorrentAlert (const lt::alert *a)
 
void handleAddTorrentAlert (const lt::add_torrent_alert *p)
 
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 createTorrent (const lt::torrent_handle &nativeHandle)
 
void saveResumeData ()
 
void saveTorrentsQueue () const
 
void removeTorrentsQueue () const
 
std::vector< lt::alert * > getPendingAlerts (lt::time_duration time=lt::time_duration::zero()) const
 
void moveTorrentStorage (const MoveStorageJob &job) const
 
void handleMoveTorrentStorageJobFinished ()
 
void loadCategories ()
 
void storeCategories () const
 
void upgradeCategories ()
 

Private Attributes

lt::session * m_nativeSession = nullptr
 
bool m_deferredConfigureScheduled = false
 
bool m_IPFilteringConfigured = false
 
bool m_listenInterfaceConfigured = false
 
CachedSettingValue< bool > m_isDHTEnabled
 
CachedSettingValue< bool > m_isLSDEnabled
 
CachedSettingValue< bool > m_isPeXEnabled
 
CachedSettingValue< bool > m_isIPFilteringEnabled
 
CachedSettingValue< bool > m_isTrackerFilteringEnabled
 
CachedSettingValue< QString > m_IPFilterFile
 
CachedSettingValue< bool > m_announceToAllTrackers
 
CachedSettingValue< bool > m_announceToAllTiers
 
CachedSettingValue< int > m_asyncIOThreads
 
CachedSettingValue< int > m_hashingThreads
 
CachedSettingValue< int > m_filePoolSize
 
CachedSettingValue< int > m_checkingMemUsage
 
CachedSettingValue< int > m_diskCacheSize
 
CachedSettingValue< int > m_diskCacheTTL
 
CachedSettingValue< bool > m_useOSCache
 
CachedSettingValue< bool > m_coalesceReadWriteEnabled
 
CachedSettingValue< bool > m_usePieceExtentAffinity
 
CachedSettingValue< bool > m_isSuggestMode
 
CachedSettingValue< int > m_sendBufferWatermark
 
CachedSettingValue< int > m_sendBufferLowWatermark
 
CachedSettingValue< int > m_sendBufferWatermarkFactor
 
CachedSettingValue< int > m_connectionSpeed
 
CachedSettingValue< int > m_socketBacklogSize
 
CachedSettingValue< bool > m_isAnonymousModeEnabled
 
CachedSettingValue< bool > m_isQueueingEnabled
 
CachedSettingValue< int > m_maxActiveDownloads
 
CachedSettingValue< int > m_maxActiveUploads
 
CachedSettingValue< int > m_maxActiveTorrents
 
CachedSettingValue< bool > m_ignoreSlowTorrentsForQueueing
 
CachedSettingValue< int > m_downloadRateForSlowTorrents
 
CachedSettingValue< int > m_uploadRateForSlowTorrents
 
CachedSettingValue< int > m_slowTorrentsInactivityTimer
 
CachedSettingValue< int > m_outgoingPortsMin
 
CachedSettingValue< int > m_outgoingPortsMax
 
CachedSettingValue< int > m_UPnPLeaseDuration
 
CachedSettingValue< int > m_peerToS
 
CachedSettingValue< bool > m_ignoreLimitsOnLAN
 
CachedSettingValue< bool > m_includeOverheadInLimits
 
CachedSettingValue< QString > m_announceIP
 
CachedSettingValue< int > m_maxConcurrentHTTPAnnounces
 
CachedSettingValue< bool > m_isReannounceWhenAddressChangedEnabled
 
CachedSettingValue< int > m_stopTrackerTimeout
 
CachedSettingValue< int > m_maxConnections
 
CachedSettingValue< int > m_maxUploads
 
CachedSettingValue< int > m_maxConnectionsPerTorrent
 
CachedSettingValue< int > m_maxUploadsPerTorrent
 
CachedSettingValue< BTProtocolm_btProtocol
 
CachedSettingValue< bool > m_isUTPRateLimited
 
CachedSettingValue< MixedModeAlgorithmm_utpMixedMode
 
CachedSettingValue< bool > m_IDNSupportEnabled
 
CachedSettingValue< bool > m_multiConnectionsPerIpEnabled
 
CachedSettingValue< bool > m_validateHTTPSTrackerCertificate
 
CachedSettingValue< bool > m_SSRFMitigationEnabled
 
CachedSettingValue< bool > m_blockPeersOnPrivilegedPorts
 
CachedSettingValue< bool > m_isAddTrackersEnabled
 
CachedSettingValue< QString > m_additionalTrackers
 
CachedSettingValue< qreal > m_globalMaxRatio
 
CachedSettingValue< int > m_globalMaxSeedingMinutes
 
CachedSettingValue< bool > m_isAddTorrentPaused
 
CachedSettingValue< TorrentContentLayoutm_torrentContentLayout
 
CachedSettingValue< bool > m_isAppendExtensionEnabled
 
CachedSettingValue< int > m_refreshInterval
 
CachedSettingValue< bool > m_isPreallocationEnabled
 
CachedSettingValue< QString > m_torrentExportDirectory
 
CachedSettingValue< QString > m_finishedTorrentExportDirectory
 
CachedSettingValue< int > m_globalDownloadSpeedLimit
 
CachedSettingValue< int > m_globalUploadSpeedLimit
 
CachedSettingValue< int > m_altGlobalDownloadSpeedLimit
 
CachedSettingValue< int > m_altGlobalUploadSpeedLimit
 
CachedSettingValue< bool > m_isAltGlobalSpeedLimitEnabled
 
CachedSettingValue< bool > m_isBandwidthSchedulerEnabled
 
CachedSettingValue< int > m_saveResumeDataInterval
 
CachedSettingValue< int > m_port
 
CachedSettingValue< QString > m_networkInterface
 
CachedSettingValue< QString > m_networkInterfaceName
 
CachedSettingValue< QString > m_networkInterfaceAddress
 
CachedSettingValue< int > m_encryption
 
CachedSettingValue< bool > m_isProxyPeerConnectionsEnabled
 
CachedSettingValue< ChokingAlgorithmm_chokingAlgorithm
 
CachedSettingValue< SeedChokingAlgorithmm_seedChokingAlgorithm
 
CachedSettingValue< QStringList > m_storedTags
 
CachedSettingValue< int > m_maxRatioAction
 
CachedSettingValue< QString > m_savePath
 
CachedSettingValue< QString > m_downloadPath
 
CachedSettingValue< bool > m_isSubcategoriesEnabled
 
CachedSettingValue< bool > m_isDownloadPathEnabled
 
CachedSettingValue< bool > m_isAutoTMMDisabledByDefault
 
CachedSettingValue< bool > m_isDisableAutoTMMWhenCategoryChanged
 
CachedSettingValue< bool > m_isDisableAutoTMMWhenDefaultSavePathChanged
 
CachedSettingValue< bool > m_isDisableAutoTMMWhenCategorySavePathChanged
 
CachedSettingValue< bool > m_isTrackerEnabled
 
CachedSettingValue< int > m_peerTurnover
 
CachedSettingValue< int > m_peerTurnoverCutoff
 
CachedSettingValue< int > m_peerTurnoverInterval
 
CachedSettingValue< QStringList > m_bannedIPs
 
CachedSettingValue< ResumeDataStorageTypem_resumeDataStorageType
 
const bool m_wasPexEnabled = m_isPeXEnabled
 
int m_numResumeData = 0
 
int m_extraLimit = 0
 
QVector< TrackerEntrym_additionalTrackerList
 
bool m_refreshEnqueued = false
 
QTimer * m_seedingLimitTimer = nullptr
 
QTimer * m_resumeDataTimer = nullptr
 
Statisticsm_statistics = nullptr
 
QPointer< FilterParserThreadm_filterParser
 
QPointer< BandwidthSchedulerm_bwScheduler
 
QPointer< Trackerm_tracker
 
QThread * m_ioThread = nullptr
 
ResumeDataStoragem_resumeDataStorage = nullptr
 
FileSearcherm_fileSearcher = nullptr
 
QSet< TorrentIDm_downloadedMetadata
 
QHash< TorrentID, TorrentImpl * > m_torrents
 
QHash< TorrentID, LoadTorrentParamsm_loadingTorrents
 
QHash< QString, AddTorrentParamsm_downloadedTorrents
 
QHash< TorrentID, RemovingTorrentDatam_removingTorrents
 
QSet< TorrentIDm_needSaveResumeDataTorrents
 
QMap< QString, CategoryOptionsm_categories
 
QSet< QString > m_tags
 
QSet< TorrentIDm_recentErroredTorrents
 
QTimer * m_recentErroredTorrentsTimer = nullptr
 
SessionMetricIndices m_metricIndices
 
lt::time_point m_statsLastTimestamp = lt::clock_type::now()
 
SessionStatus m_status
 
CacheStatus m_cacheStatus
 
QList< MoveStorageJobm_moveStorageQueue
 
QString m_lastExternalIP
 
bool m_needUpgradeDownloadPath = false
 

Static Private Attributes

static Sessionm_instance = nullptr
 

Detailed Description

Definition at line 205 of file session.h.

Constructor & Destructor Documentation

◆ Session()

Session::Session ( QObject *  parent = nullptr)
explicitprivate

Definition at line 305 of file session.cpp.

306  : QObject(parent)
307  , m_isDHTEnabled(BITTORRENT_SESSION_KEY("DHTEnabled"), true)
308  , m_isLSDEnabled(BITTORRENT_SESSION_KEY("LSDEnabled"), true)
309  , m_isPeXEnabled(BITTORRENT_SESSION_KEY("PeXEnabled"), true)
310  , m_isIPFilteringEnabled(BITTORRENT_SESSION_KEY("IPFilteringEnabled"), false)
311  , m_isTrackerFilteringEnabled(BITTORRENT_SESSION_KEY("TrackerFilteringEnabled"), false)
313  , m_announceToAllTrackers(BITTORRENT_SESSION_KEY("AnnounceToAllTrackers"), false)
314  , m_announceToAllTiers(BITTORRENT_SESSION_KEY("AnnounceToAllTiers"), true)
315  , m_asyncIOThreads(BITTORRENT_SESSION_KEY("AsyncIOThreadsCount"), 10)
316  , m_hashingThreads(BITTORRENT_SESSION_KEY("HashingThreadsCount"), 2)
317  , m_filePoolSize(BITTORRENT_SESSION_KEY("FilePoolSize"), 5000)
318  , m_checkingMemUsage(BITTORRENT_SESSION_KEY("CheckingMemUsageSize"), 32)
319  , m_diskCacheSize(BITTORRENT_SESSION_KEY("DiskCacheSize"), -1)
320  , m_diskCacheTTL(BITTORRENT_SESSION_KEY("DiskCacheTTL"), 60)
321  , m_useOSCache(BITTORRENT_SESSION_KEY("UseOSCache"), true)
322 #ifdef Q_OS_WIN
323  , m_coalesceReadWriteEnabled(BITTORRENT_SESSION_KEY("CoalesceReadWrite"), true)
324 #else
325  , m_coalesceReadWriteEnabled(BITTORRENT_SESSION_KEY("CoalesceReadWrite"), false)
326 #endif
327  , m_usePieceExtentAffinity(BITTORRENT_SESSION_KEY("PieceExtentAffinity"), false)
328  , m_isSuggestMode(BITTORRENT_SESSION_KEY("SuggestMode"), false)
329  , m_sendBufferWatermark(BITTORRENT_SESSION_KEY("SendBufferWatermark"), 500)
330  , m_sendBufferLowWatermark(BITTORRENT_SESSION_KEY("SendBufferLowWatermark"), 10)
331  , m_sendBufferWatermarkFactor(BITTORRENT_SESSION_KEY("SendBufferWatermarkFactor"), 50)
332  , m_connectionSpeed(BITTORRENT_SESSION_KEY("ConnectionSpeed"), 30)
333  , m_socketBacklogSize(BITTORRENT_SESSION_KEY("SocketBacklogSize"), 30)
334  , m_isAnonymousModeEnabled(BITTORRENT_SESSION_KEY("AnonymousModeEnabled"), false)
335  , m_isQueueingEnabled(BITTORRENT_SESSION_KEY("QueueingSystemEnabled"), false)
336  , m_maxActiveDownloads(BITTORRENT_SESSION_KEY("MaxActiveDownloads"), 3, lowerLimited(-1))
337  , m_maxActiveUploads(BITTORRENT_SESSION_KEY("MaxActiveUploads"), 3, lowerLimited(-1))
338  , m_maxActiveTorrents(BITTORRENT_SESSION_KEY("MaxActiveTorrents"), 5, lowerLimited(-1))
339  , m_ignoreSlowTorrentsForQueueing(BITTORRENT_SESSION_KEY("IgnoreSlowTorrentsForQueueing"), false)
340  , m_downloadRateForSlowTorrents(BITTORRENT_SESSION_KEY("SlowTorrentsDownloadRate"), 2)
341  , m_uploadRateForSlowTorrents(BITTORRENT_SESSION_KEY("SlowTorrentsUploadRate"), 2)
342  , m_slowTorrentsInactivityTimer(BITTORRENT_SESSION_KEY("SlowTorrentsInactivityTimer"), 60)
343  , m_outgoingPortsMin(BITTORRENT_SESSION_KEY("OutgoingPortsMin"), 0)
344  , m_outgoingPortsMax(BITTORRENT_SESSION_KEY("OutgoingPortsMax"), 0)
345  , m_UPnPLeaseDuration(BITTORRENT_SESSION_KEY("UPnPLeaseDuration"), 0)
346  , m_peerToS(BITTORRENT_SESSION_KEY("PeerToS"), 0x20)
347  , m_ignoreLimitsOnLAN(BITTORRENT_SESSION_KEY("IgnoreLimitsOnLAN"), false)
348  , m_includeOverheadInLimits(BITTORRENT_SESSION_KEY("IncludeOverheadInLimits"), false)
349  , m_announceIP(BITTORRENT_SESSION_KEY("AnnounceIP"))
350  , m_maxConcurrentHTTPAnnounces(BITTORRENT_SESSION_KEY("MaxConcurrentHTTPAnnounces"), 50)
351  , m_isReannounceWhenAddressChangedEnabled(BITTORRENT_SESSION_KEY("ReannounceWhenAddressChanged"), false)
352  , m_stopTrackerTimeout(BITTORRENT_SESSION_KEY("StopTrackerTimeout"), 5)
353  , m_maxConnections(BITTORRENT_SESSION_KEY("MaxConnections"), 500, lowerLimited(0, -1))
354  , m_maxUploads(BITTORRENT_SESSION_KEY("MaxUploads"), 20, lowerLimited(0, -1))
355  , m_maxConnectionsPerTorrent(BITTORRENT_SESSION_KEY("MaxConnectionsPerTorrent"), 100, lowerLimited(0, -1))
356  , m_maxUploadsPerTorrent(BITTORRENT_SESSION_KEY("MaxUploadsPerTorrent"), 4, lowerLimited(0, -1))
357  , m_btProtocol(BITTORRENT_SESSION_KEY("BTProtocol"), BTProtocol::Both
358  , clampValue(BTProtocol::Both, BTProtocol::UTP))
359  , m_isUTPRateLimited(BITTORRENT_SESSION_KEY("uTPRateLimited"), true)
360  , m_utpMixedMode(BITTORRENT_SESSION_KEY("uTPMixedMode"), MixedModeAlgorithm::TCP
361  , clampValue(MixedModeAlgorithm::TCP, MixedModeAlgorithm::Proportional))
362  , m_IDNSupportEnabled(BITTORRENT_SESSION_KEY("IDNSupportEnabled"), false)
363  , m_multiConnectionsPerIpEnabled(BITTORRENT_SESSION_KEY("MultiConnectionsPerIp"), false)
364  , m_validateHTTPSTrackerCertificate(BITTORRENT_SESSION_KEY("ValidateHTTPSTrackerCertificate"), true)
365  , m_SSRFMitigationEnabled(BITTORRENT_SESSION_KEY("SSRFMitigation"), true)
366  , m_blockPeersOnPrivilegedPorts(BITTORRENT_SESSION_KEY("BlockPeersOnPrivilegedPorts"), false)
367  , m_isAddTrackersEnabled(BITTORRENT_SESSION_KEY("AddTrackersEnabled"), false)
368  , m_additionalTrackers(BITTORRENT_SESSION_KEY("AdditionalTrackers"))
369  , m_globalMaxRatio(BITTORRENT_SESSION_KEY("GlobalMaxRatio"), -1, [](qreal r) { return r < 0 ? -1. : r;})
370  , m_globalMaxSeedingMinutes(BITTORRENT_SESSION_KEY("GlobalMaxSeedingMinutes"), -1, lowerLimited(-1))
371  , m_isAddTorrentPaused(BITTORRENT_SESSION_KEY("AddTorrentPaused"), false)
372  , m_torrentContentLayout(BITTORRENT_SESSION_KEY("TorrentContentLayout"), TorrentContentLayout::Original)
373  , m_isAppendExtensionEnabled(BITTORRENT_SESSION_KEY("AddExtensionToIncompleteFiles"), false)
374  , m_refreshInterval(BITTORRENT_SESSION_KEY("RefreshInterval"), 1500)
375  , m_isPreallocationEnabled(BITTORRENT_SESSION_KEY("Preallocation"), false)
376  , m_torrentExportDirectory(BITTORRENT_SESSION_KEY("TorrentExportDirectory"))
377  , m_finishedTorrentExportDirectory(BITTORRENT_SESSION_KEY("FinishedTorrentExportDirectory"))
378  , m_globalDownloadSpeedLimit(BITTORRENT_SESSION_KEY("GlobalDLSpeedLimit"), 0, lowerLimited(0))
379  , m_globalUploadSpeedLimit(BITTORRENT_SESSION_KEY("GlobalUPSpeedLimit"), 0, lowerLimited(0))
380  , m_altGlobalDownloadSpeedLimit(BITTORRENT_SESSION_KEY("AlternativeGlobalDLSpeedLimit"), 10, lowerLimited(0))
381  , m_altGlobalUploadSpeedLimit(BITTORRENT_SESSION_KEY("AlternativeGlobalUPSpeedLimit"), 10, lowerLimited(0))
382  , m_isAltGlobalSpeedLimitEnabled(BITTORRENT_SESSION_KEY("UseAlternativeGlobalSpeedLimit"), false)
383  , m_isBandwidthSchedulerEnabled(BITTORRENT_SESSION_KEY("BandwidthSchedulerEnabled"), false)
384  , m_saveResumeDataInterval(BITTORRENT_SESSION_KEY("SaveResumeDataInterval"), 60)
385  , m_port(BITTORRENT_SESSION_KEY("Port"), -1)
389  , m_encryption(BITTORRENT_SESSION_KEY("Encryption"), 0)
390  , m_isProxyPeerConnectionsEnabled(BITTORRENT_SESSION_KEY("ProxyPeerConnections"), false)
391  , m_chokingAlgorithm(BITTORRENT_SESSION_KEY("ChokingAlgorithm"), ChokingAlgorithm::FixedSlots
392  , clampValue(ChokingAlgorithm::FixedSlots, ChokingAlgorithm::RateBased))
393  , m_seedChokingAlgorithm(BITTORRENT_SESSION_KEY("SeedChokingAlgorithm"), SeedChokingAlgorithm::FastestUpload
394  , clampValue(SeedChokingAlgorithm::RoundRobin, SeedChokingAlgorithm::AntiLeech))
396  , m_maxRatioAction(BITTORRENT_SESSION_KEY("MaxRatioAction"), Pause)
399  , m_isSubcategoriesEnabled(BITTORRENT_SESSION_KEY("SubcategoriesEnabled"), false)
400  , m_isDownloadPathEnabled(BITTORRENT_SESSION_KEY("TempPathEnabled"), false)
401  , m_isAutoTMMDisabledByDefault(BITTORRENT_SESSION_KEY("DisableAutoTMMByDefault"), true)
402  , m_isDisableAutoTMMWhenCategoryChanged(BITTORRENT_SESSION_KEY("DisableAutoTMMTriggers/CategoryChanged"), false)
403  , m_isDisableAutoTMMWhenDefaultSavePathChanged(BITTORRENT_SESSION_KEY("DisableAutoTMMTriggers/DefaultSavePathChanged"), true)
404  , m_isDisableAutoTMMWhenCategorySavePathChanged(BITTORRENT_SESSION_KEY("DisableAutoTMMTriggers/CategorySavePathChanged"), true)
405  , m_isTrackerEnabled(BITTORRENT_KEY("TrackerEnabled"), false)
406  , m_peerTurnover(BITTORRENT_SESSION_KEY("PeerTurnover"), 4)
407  , m_peerTurnoverCutoff(BITTORRENT_SESSION_KEY("PeerTurnoverCutOff"), 90)
408  , m_peerTurnoverInterval(BITTORRENT_SESSION_KEY("PeerTurnoverInterval"), 300)
409  , m_bannedIPs("State/BannedIPs"
410  , QStringList()
411  , [](const QStringList &value)
412  {
413  QStringList tmp = value;
414  tmp.sort();
415  return tmp;
416  }
417  )
419 #if defined(Q_OS_WIN)
420  , m_OSMemoryPriority(BITTORRENT_KEY("OSMemoryPriority"), OSMemoryPriority::BelowNormal)
421 #endif
422  , m_seedingLimitTimer {new QTimer {this}}
423  , m_resumeDataTimer {new QTimer {this}}
424  , m_statistics {new Statistics {this}}
425  , m_ioThread {new QThread {this}}
426  , m_recentErroredTorrentsTimer {new QTimer {this}}
427 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
428  , m_networkManager {new QNetworkConfigurationManager {this}}
429 #endif
430 {
431  if (port() < 0)
432  m_port = Utils::Random::rand(1024, 65535);
433 
434  m_recentErroredTorrentsTimer->setSingleShot(true);
435  m_recentErroredTorrentsTimer->setInterval(1000);
436  connect(m_recentErroredTorrentsTimer, &QTimer::timeout
437  , this, [this]() { m_recentErroredTorrents.clear(); });
438 
439  m_seedingLimitTimer->setInterval(10000);
440  connect(m_seedingLimitTimer, &QTimer::timeout, this, &Session::processShareLimits);
441 
444 
447 
448  loadCategories();
450  {
451  // if subcategories support changed manually
453  }
454 
455  const QStringList storedTags = m_storedTags.get();
456  m_tags = {storedTags.cbegin(), storedTags.cend()};
457 
458  enqueueRefresh();
461 
463 
466  , this, &Session::configureDeferred);
467 
468 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
469  // Network configuration monitor
470  connect(m_networkManager, &QNetworkConfigurationManager::onlineStateChanged, this, &Session::networkOnlineStateChanged);
471  connect(m_networkManager, &QNetworkConfigurationManager::configurationAdded, this, &Session::networkConfigurationChange);
472  connect(m_networkManager, &QNetworkConfigurationManager::configurationRemoved, this, &Session::networkConfigurationChange);
473  connect(m_networkManager, &QNetworkConfigurationManager::configurationChanged, this, &Session::networkConfigurationChange);
474 #endif
475 
477  m_fileSearcher->moveToThread(m_ioThread);
478  connect(m_ioThread, &QThread::finished, m_fileSearcher, &QObject::deleteLater);
480 
481  m_ioThread->start();
482 
483  // Regular saving of fastresume data
484  connect(m_resumeDataTimer, &QTimer::timeout, this, [this]() { generateResumeData(); });
485  const int saveInterval = saveResumeDataInterval();
486  if (saveInterval > 0)
487  {
488  m_resumeDataTimer->setInterval(saveInterval * 60 * 1000);
489  m_resumeDataTimer->start();
490  }
491 
492  // initialize PortForwarder instance
494 
495  initMetrics();
496 }
void populateAdditionalTrackers()
Definition: session.cpp:1589
CachedSettingValue< int > m_globalMaxSeedingMinutes
Definition: session.h:716
QSet< QString > m_tags
Definition: session.h:790
CachedSettingValue< int > m_stopTrackerTimeout
Definition: session.h:700
CachedSettingValue< int > m_socketBacklogSize
Definition: session.h:681
CachedSettingValue< SeedChokingAlgorithm > m_seedChokingAlgorithm
Definition: session.h:738
CachedSettingValue< QStringList > m_bannedIPs
Definition: session.h:753
CachedSettingValue< bool > m_isTrackerFilteringEnabled
Definition: session.h:663
CachedSettingValue< int > m_saveResumeDataInterval
Definition: session.h:730
CachedSettingValue< bool > m_isLSDEnabled
Definition: session.h:660
CachedSettingValue< bool > m_isAltGlobalSpeedLimitEnabled
Definition: session.h:728
QTimer * m_resumeDataTimer
Definition: session.h:770
CachedSettingValue< int > m_UPnPLeaseDuration
Definition: session.h:693
bool isTrackerEnabled() const
Definition: session.cpp:913
CachedSettingValue< int > m_peerTurnoverCutoff
Definition: session.h:751
CachedSettingValue< bool > m_isPreallocationEnabled
Definition: session.h:721
CachedSettingValue< QString > m_savePath
Definition: session.h:741
CachedSettingValue< int > m_globalDownloadSpeedLimit
Definition: session.h:724
CachedSettingValue< bool > m_isReannounceWhenAddressChangedEnabled
Definition: session.h:699
QThread * m_ioThread
Definition: session.h:778
CachedSettingValue< int > m_refreshInterval
Definition: session.h:720
CachedSettingValue< bool > m_usePieceExtentAffinity
Definition: session.h:675
CachedSettingValue< MixedModeAlgorithm > m_utpMixedMode
Definition: session.h:707
CachedSettingValue< bool > m_isAutoTMMDisabledByDefault
Definition: session.h:745
CachedSettingValue< int > m_uploadRateForSlowTorrents
Definition: session.h:689
CachedSettingValue< bool > m_isAddTrackersEnabled
Definition: session.h:713
CachedSettingValue< int > m_globalUploadSpeedLimit
Definition: session.h:725
CachedSettingValue< int > m_port
Definition: session.h:731
CachedSettingValue< bool > m_isIPFilteringEnabled
Definition: session.h:662
CachedSettingValue< QString > m_torrentExportDirectory
Definition: session.h:722
void initializeNativeSession()
Definition: session.cpp:1052
CachedSettingValue< bool > m_isDownloadPathEnabled
Definition: session.h:744
CachedSettingValue< bool > m_isDisableAutoTMMWhenDefaultSavePathChanged
Definition: session.h:747
CachedSettingValue< bool > m_isDHTEnabled
Definition: session.h:659
CachedSettingValue< qreal > m_globalMaxRatio
Definition: session.h:715
int port() const
Definition: session.cpp:2782
CachedSettingValue< int > m_connectionSpeed
Definition: session.h:680
CachedSettingValue< int > m_asyncIOThreads
Definition: session.h:667
CachedSettingValue< bool > m_isDisableAutoTMMWhenCategoryChanged
Definition: session.h:746
void configureDeferred()
Definition: session.cpp:4230
CachedSettingValue< QString > m_networkInterfaceName
Definition: session.h:733
CachedSettingValue< QString > m_IPFilterFile
Definition: session.h:664
FileSearcher * m_fileSearcher
Definition: session.h:780
CachedSettingValue< int > m_maxConcurrentHTTPAnnounces
Definition: session.h:698
CachedSettingValue< QString > m_finishedTorrentExportDirectory
Definition: session.h:723
CachedSettingValue< int > m_maxActiveUploads
Definition: session.h:685
CachedSettingValue< int > m_altGlobalDownloadSpeedLimit
Definition: session.h:726
CachedSettingValue< int > m_peerTurnover
Definition: session.h:750
void configureComponents()
Definition: session.cpp:1030
CachedSettingValue< bool > m_isSuggestMode
Definition: session.h:676
CachedSettingValue< int > m_slowTorrentsInactivityTimer
Definition: session.h:690
Statistics * m_statistics
Definition: session.h:771
CachedSettingValue< ResumeDataStorageType > m_resumeDataStorageType
Definition: session.h:754
CachedSettingValue< int > m_maxConnections
Definition: session.h:701
CachedSettingValue< int > m_checkingMemUsage
Definition: session.h:670
bool isSubcategoriesEnabled() const
Definition: session.cpp:798
CachedSettingValue< bool > m_useOSCache
Definition: session.h:673
QTimer * m_seedingLimitTimer
Definition: session.h:769
CachedSettingValue< ChokingAlgorithm > m_chokingAlgorithm
Definition: session.h:737
CachedSettingValue< bool > m_isAppendExtensionEnabled
Definition: session.h:719
CachedSettingValue< int > m_diskCacheTTL
Definition: session.h:672
CachedSettingValue< int > m_sendBufferWatermarkFactor
Definition: session.h:679
CachedSettingValue< int > m_altGlobalUploadSpeedLimit
Definition: session.h:727
CachedSettingValue< int > m_maxUploads
Definition: session.h:702
CachedSettingValue< int > m_maxRatioAction
Definition: session.h:740
void enableTracker(bool enable)
Definition: session.cpp:1563
CachedSettingValue< QString > m_networkInterfaceAddress
Definition: session.h:734
CachedSettingValue< bool > m_IDNSupportEnabled
Definition: session.h:708
void processShareLimits()
Definition: session.cpp:1602
CachedSettingValue< int > m_peerTurnoverInterval
Definition: session.h:752
CachedSettingValue< bool > m_multiConnectionsPerIpEnabled
Definition: session.h:709
CachedSettingValue< int > m_encryption
Definition: session.h:735
bool isBandwidthSchedulerEnabled() const
Definition: session.cpp:2742
CachedSettingValue< bool > m_isDisableAutoTMMWhenCategorySavePathChanged
Definition: session.h:748
lt::session * m_nativeSession
Definition: session.h:653
CachedSettingValue< int > m_peerToS
Definition: session.h:694
QMap< QString, CategoryOptions > m_categories
Definition: session.h:789
CachedSettingValue< int > m_maxUploadsPerTorrent
Definition: session.h:704
CachedSettingValue< BTProtocol > m_btProtocol
Definition: session.h:705
CachedSettingValue< int > m_hashingThreads
Definition: session.h:668
CachedSettingValue< int > m_outgoingPortsMax
Definition: session.h:692
CachedSettingValue< bool > m_isBandwidthSchedulerEnabled
Definition: session.h:729
QSet< TorrentID > m_recentErroredTorrents
Definition: session.h:793
CachedSettingValue< bool > m_isTrackerEnabled
Definition: session.h:749
CachedSettingValue< bool > m_coalesceReadWriteEnabled
Definition: session.h:674
CachedSettingValue< int > m_maxActiveTorrents
Definition: session.h:686
CachedSettingValue< bool > m_includeOverheadInLimits
Definition: session.h:696
int saveResumeDataInterval() const
Definition: session.cpp:2759
CachedSettingValue< QString > m_networkInterface
Definition: session.h:732
CachedSettingValue< int > m_downloadRateForSlowTorrents
Definition: session.h:688
CachedSettingValue< bool > m_isUTPRateLimited
Definition: session.h:706
CachedSettingValue< bool > m_SSRFMitigationEnabled
Definition: session.h:711
CachedSettingValue< int > m_sendBufferLowWatermark
Definition: session.h:678
CachedSettingValue< int > m_maxActiveDownloads
Definition: session.h:684
CachedSettingValue< bool > m_ignoreLimitsOnLAN
Definition: session.h:695
void generateResumeData()
Definition: session.cpp:2365
CachedSettingValue< QString > m_additionalTrackers
Definition: session.h:714
CachedSettingValue< bool > m_blockPeersOnPrivilegedPorts
Definition: session.h:712
void enableBandwidthScheduler()
Definition: session.cpp:1578
CachedSettingValue< int > m_filePoolSize
Definition: session.h:669
CachedSettingValue< TorrentContentLayout > m_torrentContentLayout
Definition: session.h:718
CachedSettingValue< bool > m_isAddTorrentPaused
Definition: session.h:717
CachedSettingValue< bool > m_announceToAllTiers
Definition: session.h:666
CachedSettingValue< bool > m_isProxyPeerConnectionsEnabled
Definition: session.h:736
CachedSettingValue< int > m_sendBufferWatermark
Definition: session.h:677
void fileSearchFinished(const TorrentID &id, const QString &savePath, const QStringList &fileNames)
Definition: session.cpp:1714
CachedSettingValue< QString > m_downloadPath
Definition: session.h:742
CachedSettingValue< bool > m_announceToAllTrackers
Definition: session.h:665
QTimer * m_recentErroredTorrentsTimer
Definition: session.h:794
CachedSettingValue< bool > m_ignoreSlowTorrentsForQueueing
Definition: session.h:687
CachedSettingValue< QString > m_announceIP
Definition: session.h:697
CachedSettingValue< int > m_maxConnectionsPerTorrent
Definition: session.h:703
CachedSettingValue< bool > m_isPeXEnabled
Definition: session.h:661
CachedSettingValue< bool > m_isQueueingEnabled
Definition: session.h:683
CachedSettingValue< QStringList > m_storedTags
Definition: session.h:739
CachedSettingValue< int > m_diskCacheSize
Definition: session.h:671
CachedSettingValue< bool > m_isAnonymousModeEnabled
Definition: session.h:682
CachedSettingValue< bool > m_isSubcategoriesEnabled
Definition: session.h:743
void updateSeedingLimitTimer()
Definition: session.cpp:3852
CachedSettingValue< int > m_outgoingPortsMin
Definition: session.h:691
CachedSettingValue< bool > m_validateHTTPSTrackerCertificate
Definition: session.h:710
void searchFinished(const BitTorrent::TorrentID &id, const QString &savePath, const QStringList &fileNames)
static ProxyConfigurationManager * instance()
QString toUniformPath(const QString &path)
Definition: fs.cpp:69
uint32_t rand(uint32_t min=0, uint32_t max=std::numeric_limits< uint32_t >::max())
Definition: random.cpp:132
T value(const QString &key, const T &defaultValue={})
Definition: preferences.cpp:64
QMap< QString, CategoryOptions > expandCategories(const QMap< QString, CategoryOptions > &categories)
Definition: session.cpp:166
LowerLimited< T > lowerLimited(T limit, T ret)
Definition: session.cpp:259
auto clampValue(const T lower, const T upper)
Definition: session.cpp:262
QString specialFolderLocation(const SpecialFolder folder)
Definition: profile.cpp:131
#define BITTORRENT_KEY(name)
Definition: session.cpp:302
#define BITTORRENT_SESSION_KEY(name)
Definition: session.cpp:303
@ Pause
Definition: session.h:73

Referenced by initInstance().

Here is the caller graph for this function:

◆ ~Session()

Session::~Session ( )
private

Definition at line 965 of file session.cpp.

966 {
967  // Do some BT related saving
968  saveResumeData();
969 
970  // We must delete FilterParserThread
971  // before we delete lt::session
972  delete m_filterParser;
973 
974  // We must delete PortForwarderImpl before
975  // we delete lt::session
977 
978  qDebug("Deleting the session");
979  delete m_nativeSession;
980 
981  m_ioThread->quit();
982  m_ioThread->wait();
983 }
QPointer< FilterParserThread > m_filterParser
Definition: session.h:773
static PortForwarder * instance()

References Net::PortForwarder::instance(), m_filterParser, m_ioThread, m_nativeSession, and saveResumeData().

Here is the call graph for this function:

Member Function Documentation

◆ addCategory()

bool Session::addCategory ( const QString &  name,
const CategoryOptions options = {} 
)

Definition at line 701 of file session.cpp.

702 {
703  if (name.isEmpty())
704  return false;
705 
706  if (!isValidCategoryName(name) || m_categories.contains(name))
707  return false;
708 
710  {
711  for (const QString &parent : asConst(expandCategory(name)))
712  {
713  if ((parent != name) && !m_categories.contains(parent))
714  {
715  m_categories[parent] = {};
716  emit categoryAdded(parent);
717  }
718  }
719  }
720 
721  m_categories[name] = options;
722  storeCategories();
723  emit categoryAdded(name);
724 
725  return true;
726 }
static bool isValidCategoryName(const QString &name)
Definition: session.cpp:630
void storeCategories() const
Definition: session.cpp:4126
void categoryAdded(const QString &categoryName)
static QStringList expandCategory(const QString &category)
Definition: session.cpp:642
constexpr std::add_const_t< T > & asConst(T &t) noexcept
Definition: global.h:42

References asConst(), categoryAdded(), expandCategory(), isSubcategoriesEnabled(), isValidCategoryName(), m_categories, and storeCategories().

Referenced by initLoadTorrentParams().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ additionalTrackers()

QString Session::additionalTrackers ( ) const

Definition at line 2904 of file session.cpp.

2905 {
2906  return m_additionalTrackers;
2907 }

References m_additionalTrackers.

Referenced by populateAdditionalTrackers(), and setAdditionalTrackers().

Here is the caller graph for this function:

◆ addMoveTorrentStorageJob()

bool Session::addMoveTorrentStorageJob ( TorrentImpl torrent,
const QString &  newPath,
MoveStorageMode  mode 
)

Definition at line 4027 of file session.cpp.

4028 {
4029  Q_ASSERT(torrent);
4030 
4031  const lt::torrent_handle torrentHandle = torrent->nativeHandle();
4032  const QString currentLocation = Utils::Fs::toNativePath(torrent->actualStorageLocation());
4033 
4034  if (m_moveStorageQueue.size() > 1)
4035  {
4036  const auto iter = std::find_if(m_moveStorageQueue.begin() + 1, m_moveStorageQueue.end()
4037  , [&torrentHandle](const MoveStorageJob &job)
4038  {
4039  return job.torrentHandle == torrentHandle;
4040  });
4041 
4042  if (iter != m_moveStorageQueue.end())
4043  {
4044  // remove existing inactive job
4045  m_moveStorageQueue.erase(iter);
4046  LogMsg(tr("Cancelled moving \"%1\" from \"%2\" to \"%3\".").arg(torrent->name(), currentLocation, iter->path));
4047  }
4048  }
4049 
4050  if (!m_moveStorageQueue.isEmpty() && (m_moveStorageQueue.first().torrentHandle == torrentHandle))
4051  {
4052  // if there is active job for this torrent prevent creating meaningless
4053  // job that will move torrent to the same location as current one
4054  if (QDir {m_moveStorageQueue.first().path} == QDir {newPath})
4055  {
4056  LogMsg(tr("Couldn't enqueue move of \"%1\" to \"%2\". Torrent is currently moving to the same destination location.")
4057  .arg(torrent->name(), newPath));
4058  return false;
4059  }
4060  }
4061  else
4062  {
4063  if (QDir {currentLocation} == QDir {newPath})
4064  {
4065  LogMsg(tr("Couldn't enqueue move of \"%1\" from \"%2\" to \"%3\". Both paths point to the same location.")
4066  .arg(torrent->name(), currentLocation, newPath));
4067  return false;
4068  }
4069  }
4070 
4071  const MoveStorageJob moveStorageJob {torrentHandle, newPath, mode};
4072  m_moveStorageQueue << moveStorageJob;
4073  LogMsg(tr("Enqueued to move \"%1\" from \"%2\" to \"%3\".").arg(torrent->name(), currentLocation, newPath));
4074 
4075  if (m_moveStorageQueue.size() == 1)
4076  moveTorrentStorage(moveStorageJob);
4077 
4078  return true;
4079 }
void moveTorrentStorage(const MoveStorageJob &job) const
Definition: session.cpp:4081
QList< MoveStorageJob > m_moveStorageQueue
Definition: session.h:805
lt::torrent_handle nativeHandle() const
QString name() const override
QString actualStorageLocation() const override
void LogMsg(const QString &message, const Log::MsgType &type)
Definition: logger.cpp:125
QString toNativePath(const QString &path)
Definition: fs.cpp:64

References BitTorrent::TorrentImpl::actualStorageLocation(), LogMsg(), m_moveStorageQueue, moveTorrentStorage(), BitTorrent::TorrentImpl::name(), BitTorrent::TorrentImpl::nativeHandle(), and Utils::Fs::toNativePath().

Referenced by BitTorrent::TorrentImpl::moveStorage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addTag()

bool Session::addTag ( const QString &  tag)

Definition at line 839 of file session.cpp.

840 {
841  if (!isValidTag(tag) || hasTag(tag))
842  return false;
843 
844  m_tags.insert(tag);
845  m_storedTags = m_tags.values();
846  emit tagAdded(tag);
847  return true;
848 }
bool hasTag(const QString &tag) const
Definition: session.cpp:834
void tagAdded(const QString &tag)
static bool isValidTag(const QString &tag)
Definition: session.cpp:829

References hasTag(), isValidTag(), m_storedTags, m_tags, and tagAdded().

Referenced by TagFilterWidget::addTag(), BitTorrent::TorrentImpl::addTag(), TorrentsController::createTagsAction(), and initLoadTorrentParams().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addTorrent() [1/3]

bool Session::addTorrent ( const MagnetUri magnetUri,
const AddTorrentParams params = AddTorrentParams() 
)

Definition at line 2037 of file session.cpp.

2038 {
2039  if (!magnetUri.isValid()) return false;
2040 
2041  return addTorrent_impl(magnetUri, params);
2042 }
bool isValid() const
Definition: magneturi.cpp:110
bool addTorrent_impl(const std::variant< MagnetUri, TorrentInfo > &source, const AddTorrentParams &addTorrentParams)
Definition: session.cpp:2094

References addTorrent_impl(), and BitTorrent::MagnetUri::isValid().

Here is the call graph for this function:

◆ addTorrent() [2/3]

bool Session::addTorrent ( const QString &  source,
const AddTorrentParams params = AddTorrentParams() 
)

Definition at line 2007 of file session.cpp.

2008 {
2009  // `source`: .torrent file path/url or magnet uri
2010 
2012  {
2013  LogMsg(tr("Downloading '%1', please wait...", "e.g: Downloading 'xxx.torrent', please wait...").arg(source));
2014  // Launch downloader
2017  m_downloadedTorrents[source] = params;
2018  return true;
2019  }
2020 
2021  const MagnetUri magnetUri {source};
2022  if (magnetUri.isValid())
2023  return addTorrent(magnetUri, params);
2024 
2025  TorrentFileGuard guard {source};
2026  const nonstd::expected<TorrentInfo, QString> loadResult = TorrentInfo::loadFromFile(source);
2027  if (!loadResult)
2028  {
2029  LogMsg(tr("Couldn't load torrent: %1").arg(loadResult.error()), Log::WARNING);
2030  return false;
2031  }
2032 
2033  guard.markAsAddedToSession();
2034  return addTorrent(loadResult.value(), params);
2035 }
void handleDownloadFinished(const Net::DownloadResult &result)
Definition: session.cpp:1694
QHash< QString, AddTorrentParams > m_downloadedTorrents
Definition: session.h:786
bool addTorrent(const QString &source, const AddTorrentParams &params=AddTorrentParams())
Definition: session.cpp:2007
static nonstd::expected< TorrentInfo, QString > loadFromFile(const QString &path) noexcept
static bool hasSupportedScheme(const QString &url)
DownloadHandler * download(const DownloadRequest &downloadRequest)
static DownloadManager * instance()
const int MAX_TORRENT_SIZE
Definition: global.h:39
@ WARNING
Definition: logger.h:47

References Net::DownloadManager::download(), handleDownloadFinished(), Net::DownloadManager::hasSupportedScheme(), Net::DownloadManager::instance(), BitTorrent::TorrentInfo::loadFromFile(), LogMsg(), m_downloadedTorrents, MAX_TORRENT_SIZE, anonymous_namespace{misc.cpp}::source, and Log::WARNING.

Referenced by AddNewTorrentDialog::accept(), TorrentsController::addAction(), SearchJobWidget::addTorrentToSession(), MainWindow::downloadFromURLList(), RSSWidget::downloadSelectedTorrents(), MainWindow::dropEvent(), TorrentCreatorDialog::handleCreationSuccess(), handleDownloadFinished(), MainWindow::keyPressEvent(), MainWindow::on_actionOpen_triggered(), TorrentFilesWatcher::onMagnetFound(), TorrentFilesWatcher::onTorrentFound(), RSS::AutoDownloader::processJob(), Application::processParams(), and recursiveTorrentDownload().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addTorrent() [3/3]

bool Session::addTorrent ( const TorrentInfo torrentInfo,
const AddTorrentParams params = AddTorrentParams() 
)

Definition at line 2044 of file session.cpp.

2045 {
2046  return addTorrent_impl(torrentInfo, params);
2047 }

References addTorrent_impl().

Here is the call graph for this function:

◆ addTorrent_impl()

bool Session::addTorrent_impl ( const std::variant< MagnetUri, TorrentInfo > &  source,
const AddTorrentParams addTorrentParams 
)
private

Definition at line 2094 of file session.cpp.

2095 {
2096  const bool hasMetadata = std::holds_alternative<TorrentInfo>(source);
2097  const auto id = TorrentID::fromInfoHash(hasMetadata ? std::get<TorrentInfo>(source).infoHash() : std::get<MagnetUri>(source).infoHash());
2098 
2099  // It looks illogical that we don't just use an existing handle,
2100  // but as previous experience has shown, it actually creates unnecessary
2101  // problems and unwanted behavior due to the fact that it was originally
2102  // added with parameters other than those provided by the user.
2104 
2105  // We should not add the torrent if it is already
2106  // processed or is pending to add to session
2107  if (m_loadingTorrents.contains(id))
2108  return false;
2109 
2110  TorrentImpl *const torrent = m_torrents.value(id);
2111  if (torrent)
2112  { // a duplicate torrent is added
2113  if (torrent->isPrivate())
2114  return false;
2115 
2116  if (hasMetadata)
2117  {
2118  const TorrentInfo &torrentInfo = std::get<TorrentInfo>(source);
2119 
2120  if (torrentInfo.isPrivate())
2121  return false;
2122 
2123  // merge trackers and web seeds
2124  torrent->addTrackers(torrentInfo.trackers());
2125  torrent->addUrlSeeds(torrentInfo.urlSeeds());
2126  }
2127  else
2128  {
2129  const MagnetUri &magnetUri = std::get<MagnetUri>(source);
2130 
2131  // merge trackers and web seeds
2132  torrent->addTrackers(magnetUri.trackers());
2133  torrent->addUrlSeeds(magnetUri.urlSeeds());
2134  }
2135 
2136  return true;
2137  }
2138 
2139  LoadTorrentParams loadTorrentParams = initLoadTorrentParams(addTorrentParams);
2140  lt::add_torrent_params &p = loadTorrentParams.ltAddTorrentParams;
2141 
2142  bool isFindingIncompleteFiles = false;
2143 
2144  const bool useAutoTMM = loadTorrentParams.useAutoTMM;
2145  const QString actualSavePath = useAutoTMM ? categorySavePath(loadTorrentParams.category) : loadTorrentParams.savePath;
2146 
2147  if (hasMetadata)
2148  {
2149  const TorrentInfo &torrentInfo = std::get<TorrentInfo>(source);
2150 
2151  // if torrent name wasn't explicitly set we handle the case of
2152  // initial renaming of torrent content and rename torrent accordingly
2153  if (loadTorrentParams.name.isEmpty())
2154  {
2155  QString contentName = torrentInfo.rootFolder();
2156  if (contentName.isEmpty() && (torrentInfo.filesCount() == 1))
2157  contentName = Utils::Fs::fileName(torrentInfo.filePath(0));
2158 
2159  if (!contentName.isEmpty() && (contentName != torrentInfo.name()))
2160  loadTorrentParams.name = contentName;
2161  }
2162 
2163  Q_ASSERT(addTorrentParams.filePaths.isEmpty() || (addTorrentParams.filePaths.size() == torrentInfo.filesCount()));
2164 
2165  const TorrentContentLayout contentLayout = ((loadTorrentParams.contentLayout == TorrentContentLayout::Original)
2166  ? detectContentLayout(torrentInfo.filePaths()) : loadTorrentParams.contentLayout);
2167  QStringList filePaths = (!addTorrentParams.filePaths.isEmpty() ? addTorrentParams.filePaths : torrentInfo.filePaths());
2168  applyContentLayout(filePaths, contentLayout, Utils::Fs::findRootFolder(torrentInfo.filePaths()));
2169 
2170  if (!loadTorrentParams.hasSeedStatus)
2171  {
2172  const QString actualDownloadPath = useAutoTMM
2173  ? categoryDownloadPath(loadTorrentParams.category) : loadTorrentParams.downloadPath;
2174  findIncompleteFiles(torrentInfo, actualSavePath, actualDownloadPath, filePaths);
2175  isFindingIncompleteFiles = true;
2176  }
2177 
2178  const auto nativeIndexes = torrentInfo.nativeIndexes();
2179  if (!filePaths.isEmpty())
2180  {
2181  for (int index = 0; index < addTorrentParams.filePaths.size(); ++index)
2182  p.renamed_files[nativeIndexes[index]] = Utils::Fs::toNativePath(addTorrentParams.filePaths.at(index)).toStdString();
2183  }
2184 
2185  Q_ASSERT(p.file_priorities.empty());
2186  const int internalFilesCount = torrentInfo.nativeInfo()->files().num_files(); // including .pad files
2187  // Use qBittorrent default priority rather than libtorrent's (4)
2188  p.file_priorities = std::vector(internalFilesCount, LT::toNative(DownloadPriority::Normal));
2189  Q_ASSERT(addTorrentParams.filePriorities.isEmpty() || (addTorrentParams.filePriorities.size() == nativeIndexes.size()));
2190  for (int i = 0; i < addTorrentParams.filePriorities.size(); ++i)
2191  p.file_priorities[LT::toUnderlyingType(nativeIndexes[i])] = LT::toNative(addTorrentParams.filePriorities[i]);
2192 
2193  p.ti = torrentInfo.nativeInfo();
2194  }
2195  else
2196  {
2197  const MagnetUri &magnetUri = std::get<MagnetUri>(source);
2198  p = magnetUri.addTorrentParams();
2199 
2200  if (loadTorrentParams.name.isEmpty() && !p.name.empty())
2201  loadTorrentParams.name = QString::fromStdString(p.name);
2202  }
2203 
2204  p.save_path = Utils::Fs::toNativePath(actualSavePath).toStdString();
2205 
2206  p.upload_limit = addTorrentParams.uploadLimit;
2207  p.download_limit = addTorrentParams.downloadLimit;
2208 
2209  // Preallocation mode
2210  p.storage_mode = isPreallocationEnabled() ? lt::storage_mode_allocate : lt::storage_mode_sparse;
2211 
2212  if (addTorrentParams.sequential)
2213  p.flags |= lt::torrent_flags::sequential_download;
2214  else
2215  p.flags &= ~lt::torrent_flags::sequential_download;
2216 
2217  // Seeding mode
2218  // Skip checking and directly start seeding
2219  if (addTorrentParams.skipChecking)
2220  p.flags |= lt::torrent_flags::seed_mode;
2221  else
2222  p.flags &= ~lt::torrent_flags::seed_mode;
2223 
2224  if (loadTorrentParams.stopped || (loadTorrentParams.operatingMode == TorrentOperatingMode::AutoManaged))
2225  p.flags |= lt::torrent_flags::paused;
2226  else
2227  p.flags &= ~lt::torrent_flags::paused;
2228  if (loadTorrentParams.stopped || (loadTorrentParams.operatingMode == TorrentOperatingMode::Forced))
2229  p.flags &= ~lt::torrent_flags::auto_managed;
2230  else
2231  p.flags |= lt::torrent_flags::auto_managed;
2232 
2233  p.added_time = std::time(nullptr);
2234 
2235  if (!isFindingIncompleteFiles)
2236  return loadTorrent(loadTorrentParams);
2237 
2238  m_loadingTorrents.insert(id, loadTorrentParams);
2239  return true;
2240 }
QVector< TrackerEntry > trackers() const
Definition: magneturi.cpp:125
lt::add_torrent_params addTorrentParams() const
Definition: magneturi.cpp:140
QVector< QUrl > urlSeeds() const
Definition: magneturi.cpp:130
bool cancelDownloadMetadata(const TorrentID &id)
Definition: session.cpp:1850
QHash< TorrentID, LoadTorrentParams > m_loadingTorrents
Definition: session.h:785
LoadTorrentParams initLoadTorrentParams(const AddTorrentParams &addTorrentParams)
Definition: session.cpp:2049
QString downloadPath() const
Definition: session.cpp:625
bool isPreallocationEnabled() const
Definition: session.cpp:586
QHash< TorrentID, TorrentImpl * > m_torrents
Definition: session.h:784
void findIncompleteFiles(const TorrentInfo &torrentInfo, const QString &savePath, const QString &downloadPath, const QStringList &filePaths={}) const
Definition: session.cpp:2268
bool loadTorrent(LoadTorrentParams params)
Definition: session.cpp:2243
QString savePath() const
Definition: session.cpp:620
QString categorySavePath(const QString &categoryName) const
Definition: session.cpp:669
QString categoryDownloadPath(const QString &categoryName) const
Definition: session.cpp:682
static TorrentID fromInfoHash(const InfoHash &infoHash)
Definition: infohash.cpp:81
void addTrackers(const QVector< TrackerEntry > &trackers) override
bool isPrivate() const override
void addUrlSeeds(const QVector< QUrl > &urlSeeds) override
QVector< QUrl > urlSeeds() const
QVector< lt::file_index_t > nativeIndexes() const
QVector< TrackerEntry > trackers() const
QString filePath(int index) const
std::shared_ptr< lt::torrent_info > nativeInfo() const
QStringList filePaths() const
QString name() const
QString rootFolder() const
constexpr lt::download_priority_t toNative(const DownloadPriority priority) noexcept
Definition: lttypecast.h:43
constexpr T::underlying_type toUnderlyingType(const T &t) noexcept
Definition: lttypecast.h:38
TorrentContentLayout detectContentLayout(const QStringList &filePaths)
void applyContentLayout(QStringList &filePaths, TorrentContentLayout contentLayout, const QString &rootFolder={})
QString fileName(const QString &filePath)
Definition: fs.cpp:87
QString findRootFolder(const QStringList &filePaths)
Definition: fs.cpp:403
QVector< DownloadPriority > filePriorities
TorrentContentLayout contentLayout
lt::add_torrent_params ltAddTorrentParams
TorrentOperatingMode operatingMode

References BitTorrent::MagnetUri::addTorrentParams(), BitTorrent::TorrentImpl::addTrackers(), BitTorrent::TorrentImpl::addUrlSeeds(), BitTorrent::applyContentLayout(), cancelDownloadMetadata(), BitTorrent::LoadTorrentParams::category, categoryDownloadPath(), categorySavePath(), BitTorrent::LoadTorrentParams::contentLayout, BitTorrent::detectContentLayout(), BitTorrent::AddTorrentParams::downloadLimit, BitTorrent::LoadTorrentParams::downloadPath, Utils::Fs::fileName(), BitTorrent::TorrentInfo::filePath(), BitTorrent::AddTorrentParams::filePaths, BitTorrent::TorrentInfo::filePaths(), BitTorrent::AddTorrentParams::filePriorities, BitTorrent::TorrentInfo::filesCount(), findIncompleteFiles(), Utils::Fs::findRootFolder(), BitTorrent::TorrentID::fromInfoHash(), BitTorrent::LoadTorrentParams::hasSeedStatus, initLoadTorrentParams(), isPreallocationEnabled(), BitTorrent::TorrentInfo::isPrivate(), BitTorrent::TorrentImpl::isPrivate(), loadTorrent(), BitTorrent::LoadTorrentParams::ltAddTorrentParams, m_loadingTorrents, m_torrents, BitTorrent::LoadTorrentParams::name, BitTorrent::TorrentInfo::name(), BitTorrent::TorrentInfo::nativeIndexes(), BitTorrent::TorrentInfo::nativeInfo(), BitTorrent::Normal, BitTorrent::LoadTorrentParams::operatingMode, BitTorrent::TorrentInfo::rootFolder(), BitTorrent::LoadTorrentParams::savePath, BitTorrent::AddTorrentParams::sequential, BitTorrent::AddTorrentParams::skipChecking, anonymous_namespace{misc.cpp}::source, BitTorrent::LoadTorrentParams::stopped, BitTorrent::LT::toNative(), Utils::Fs::toNativePath(), BitTorrent::LT::toUnderlyingType(), BitTorrent::MagnetUri::trackers(), BitTorrent::TorrentInfo::trackers(), BitTorrent::AddTorrentParams::uploadLimit, BitTorrent::MagnetUri::urlSeeds(), BitTorrent::TorrentInfo::urlSeeds(), and BitTorrent::LoadTorrentParams::useAutoTMM.

Referenced by addTorrent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ adjustLimits() [1/2]

void Session::adjustLimits ( )
private

Definition at line 1002 of file session.cpp.

1003 {
1005  {
1006  lt::settings_pack settingsPack = m_nativeSession->get_settings();
1007  adjustLimits(settingsPack);
1008  m_nativeSession->apply_settings(settingsPack);
1009  }
1010 }
bool isQueueingSystemEnabled() const
Definition: session.cpp:3411

References isQueueingSystemEnabled(), and m_nativeSession.

Referenced by cancelDownloadMetadata(), downloadMetadata(), handleMetadataReceivedAlert(), and loadLTSettings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ adjustLimits() [2/2]

void Session::adjustLimits ( lt::settings_pack &  settingsPack) const
private

Definition at line 1127 of file session.cpp.

1128 {
1129  // Internally increase the queue limits to ensure that the magnet is started
1130  const int maxDownloads = maxActiveDownloads();
1131  const int maxActive = maxActiveTorrents();
1132 
1133  settingsPack.set_int(lt::settings_pack::active_downloads
1134  , maxDownloads > -1 ? maxDownloads + m_extraLimit : maxDownloads);
1135  settingsPack.set_int(lt::settings_pack::active_limit
1136  , maxActive > -1 ? maxActive + m_extraLimit : maxActive);
1137 }
int maxActiveDownloads() const
Definition: session.cpp:3430
int maxActiveTorrents() const
Definition: session.cpp:3460

References m_extraLimit, maxActiveDownloads(), and maxActiveTorrents().

Here is the call graph for this function:

◆ allTorrentsFinished

void BitTorrent::Session::allTorrentsFinished ( )
signal

Referenced by Application::exec(), and handleTorrentFinished().

Here is the caller graph for this function:

◆ altGlobalDownloadSpeedLimit()

int Session::altGlobalDownloadSpeedLimit ( ) const

Definition at line 2646 of file session.cpp.

2647 {
2648  // Unfortunately the value was saved as KiB instead of B.
2649  // But it is better to pass it around internally(+ webui) as Bytes.
2650  return m_altGlobalDownloadSpeedLimit * 1024;
2651 }

References m_altGlobalDownloadSpeedLimit.

Referenced by applyBandwidthLimits(), downloadSpeedLimit(), and setAltGlobalDownloadSpeedLimit().

Here is the caller graph for this function:

◆ altGlobalUploadSpeedLimit()

int Session::altGlobalUploadSpeedLimit ( ) const

Definition at line 2671 of file session.cpp.

2672 {
2673  // Unfortunately the value was saved as KiB instead of B.
2674  // But it is better to pass it around internally(+ webui) as Bytes.
2675  return m_altGlobalUploadSpeedLimit * 1024;
2676 }

References m_altGlobalUploadSpeedLimit.

Referenced by applyBandwidthLimits(), setAltGlobalUploadSpeedLimit(), and uploadSpeedLimit().

Here is the caller graph for this function:

◆ announceIP()

QString Session::announceIP ( ) const

Definition at line 3615 of file session.cpp.

3616 {
3617  return m_announceIP;
3618 }

References m_announceIP.

Referenced by AdvancedSettings::loadAdvancedSettings(), and loadLTSettings().

Here is the caller graph for this function:

◆ announceToAllTiers()

bool Session::announceToAllTiers ( ) const

Definition at line 3123 of file session.cpp.

3124 {
3125  return m_announceToAllTiers;
3126 }

References m_announceToAllTiers.

Referenced by AdvancedSettings::loadAdvancedSettings(), and loadLTSettings().

Here is the caller graph for this function:

◆ announceToAllTrackers()

bool Session::announceToAllTrackers ( ) const

Definition at line 3109 of file session.cpp.

3110 {
3111  return m_announceToAllTrackers;
3112 }

References m_announceToAllTrackers.

Referenced by AdvancedSettings::loadAdvancedSettings(), and loadLTSettings().

Here is the caller graph for this function:

◆ applyBandwidthLimits() [1/2]

void Session::applyBandwidthLimits ( )
private

Definition at line 1012 of file session.cpp.

1013 {
1014  lt::settings_pack settingsPack = m_nativeSession->get_settings();
1015  applyBandwidthLimits(settingsPack);
1016  m_nativeSession->apply_settings(settingsPack);
1017 }
void applyBandwidthLimits()
Definition: session.cpp:1012

References m_nativeSession.

Referenced by loadLTSettings(), and setAltGlobalSpeedLimitEnabled().

Here is the caller graph for this function:

◆ applyBandwidthLimits() [2/2]

void Session::applyBandwidthLimits ( lt::settings_pack &  settingsPack) const
private

Definition at line 1139 of file session.cpp.

1140 {
1141  const bool altSpeedLimitEnabled = isAltGlobalSpeedLimitEnabled();
1142  settingsPack.set_int(lt::settings_pack::download_rate_limit, altSpeedLimitEnabled ? altGlobalDownloadSpeedLimit() : globalDownloadSpeedLimit());
1143  settingsPack.set_int(lt::settings_pack::upload_rate_limit, altSpeedLimitEnabled ? altGlobalUploadSpeedLimit() : globalUploadSpeedLimit());
1144 }
bool isAltGlobalSpeedLimitEnabled() const
Definition: session.cpp:2726
int globalDownloadSpeedLimit() const
Definition: session.cpp:2596
int altGlobalDownloadSpeedLimit() const
Definition: session.cpp:2646
int globalUploadSpeedLimit() const
Definition: session.cpp:2621
int altGlobalUploadSpeedLimit() const
Definition: session.cpp:2671

References altGlobalDownloadSpeedLimit(), altGlobalUploadSpeedLimit(), globalDownloadSpeedLimit(), globalUploadSpeedLimit(), and isAltGlobalSpeedLimitEnabled().

Here is the call graph for this function:

◆ asyncIOThreads()

int Session::asyncIOThreads ( ) const

Definition at line 3179 of file session.cpp.

3180 {
3181  return std::clamp(m_asyncIOThreads.get(), 1, 1024);
3182 }

References CachedSettingValue< T >::get(), and m_asyncIOThreads.

Referenced by AdvancedSettings::loadAdvancedSettings(), and loadLTSettings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ banIP()

void Session::banIP ( const QString &  ip)

Definition at line 1771 of file session.cpp.

1772 {
1773  QStringList bannedIPs = m_bannedIPs;
1774  if (!bannedIPs.contains(ip))
1775  {
1776  lt::ip_filter filter = m_nativeSession->get_ip_filter();
1777  lt::error_code ec;
1778  const lt::address addr = lt::make_address(ip.toLatin1().constData(), ec);
1779  Q_ASSERT(!ec);
1780  if (ec) return;
1781  filter.add_rule(addr, addr, lt::ip_filter::blocked);
1782  m_nativeSession->set_ip_filter(filter);
1783 
1784  bannedIPs << ip;
1785  bannedIPs.sort();
1787  }
1788 }
QStringList bannedIPs() const
Definition: session.cpp:2995

References bannedIPs(), m_bannedIPs, and m_nativeSession.

Referenced by TransferController::banPeersAction(), and PeerListWidget::banSelectedPeers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bannedIPs()

QStringList Session::bannedIPs ( ) const

Definition at line 2995 of file session.cpp.

2996 {
2997  return m_bannedIPs;
2998 }

References m_bannedIPs.

Referenced by banIP().

Here is the caller graph for this function:

◆ blockPeersOnPrivilegedPorts()

bool Session::blockPeersOnPrivilegedPorts ( ) const

Definition at line 3801 of file session.cpp.

3802 {
3804 }

References m_blockPeersOnPrivilegedPorts.

Referenced by AdvancedSettings::loadAdvancedSettings(), and loadLTSettings().

Here is the caller graph for this function:

◆ bottomTorrentsQueuePos()

void Session::bottomTorrentsQueuePos ( const QVector< TorrentID > &  ids)

Definition at line 1942 of file session.cpp.

1943 {
1944  using ElementType = std::pair<int, const TorrentImpl *>;
1945  std::priority_queue<ElementType
1946  , std::vector<ElementType>
1947  , std::greater<ElementType>> torrentQueue;
1948 
1949  // Sort torrents by queue position
1950  for (const TorrentID &id : ids)
1951  {
1952  const TorrentImpl *torrent = m_torrents.value(id);
1953  if (!torrent) continue;
1954  if (const int position = torrent->queuePosition(); position >= 0)
1955  torrentQueue.emplace(position, torrent);
1956  }
1957 
1958  // Bottom torrents queue position (starting with the one in the highest queue position)
1959  while (!torrentQueue.empty())
1960  {
1961  const TorrentImpl *torrent = torrentQueue.top().second;
1963  torrentQueue.pop();
1964  }
1965 
1966  for (auto i = m_downloadedMetadata.cbegin(); i != m_downloadedMetadata.cend(); ++i)
1967  torrentQueuePositionBottom(m_nativeSession->find_torrent(*i));
1968 
1970 }
void saveTorrentsQueue() const
Definition: session.cpp:2412
QSet< TorrentID > m_downloadedMetadata
Definition: session.h:782
int queuePosition() const override
void torrentQueuePositionBottom(const lt::torrent_handle &handle)
Definition: session.cpp:154

References m_downloadedMetadata, m_nativeSession, m_torrents, BitTorrent::TorrentImpl::nativeHandle(), BitTorrent::TorrentImpl::queuePosition(), saveTorrentsQueue(), and anonymous_namespace{session.cpp}::torrentQueuePositionBottom().

Referenced by TorrentsController::bottomPrioAction(), and TransferListWidget::bottomQueuePosSelectedTorrents().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ btProtocol()

BTProtocol Session::btProtocol ( ) const

Definition at line 3706 of file session.cpp.

3707 {
3708  return m_btProtocol;
3709 }

References m_btProtocol.

Referenced by loadLTSettings().

Here is the caller graph for this function:

◆ cacheStatus()

const CacheStatus & Session::cacheStatus ( ) const

Definition at line 4306 of file session.cpp.

4307 {
4308  return m_cacheStatus;
4309 }
CacheStatus m_cacheStatus
Definition: session.h:800

References m_cacheStatus.

Referenced by StatsDialog::update().

Here is the caller graph for this function:

◆ cancelDownloadMetadata()

bool Session::cancelDownloadMetadata ( const TorrentID id)

Definition at line 1850 of file session.cpp.

1851 {
1852  const auto downloadedMetadataIter = m_downloadedMetadata.find(id);
1853  if (downloadedMetadataIter == m_downloadedMetadata.end()) return false;
1854 
1855  m_downloadedMetadata.erase(downloadedMetadataIter);
1856  --m_extraLimit;
1857  adjustLimits();
1858  m_nativeSession->remove_torrent(m_nativeSession->find_torrent(id), lt::session::delete_files);
1859  return true;
1860 }

References adjustLimits(), m_downloadedMetadata, m_extraLimit, and m_nativeSession.

Referenced by addTorrent_impl(), and AddNewTorrentDialog::reject().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ categories()

QStringList Session::categories ( ) const

Definition at line 659 of file session.cpp.

660 {
661  return m_categories.keys();
662 }

References m_categories.

Referenced by AutomatedRssDownloader::initCategoryCombobox(), and BitTorrent::TorrentImpl::setCategory().

Here is the caller graph for this function:

◆ categoryAdded

void BitTorrent::Session::categoryAdded ( const QString &  categoryName)
signal

Referenced by addCategory().

Here is the caller graph for this function:

◆ categoryDownloadPath()

QString Session::categoryDownloadPath ( const QString &  categoryName) const

Definition at line 682 of file session.cpp.

683 {
684  const CategoryOptions categoryOptions = m_categories.value(categoryName);
685  const CategoryOptions::DownloadPathOption downloadPathOption =
687  if (!downloadPathOption.enabled)
688  return {};
689 
690  const QString basePath = downloadPath();
691  if (categoryName.isEmpty())
692  return basePath;
693 
694  const QString path = (!downloadPathOption.path.isEmpty()
695  ? downloadPathOption.path
696  : Utils::Fs::toValidFileSystemName(categoryName, true)); // use implicit download path
697 
698  return (QDir::isAbsolutePath(path) ? path : Utils::Fs::resolvePath(path, basePath));
699 }
bool isDownloadPathEnabled() const
Definition: session.cpp:541
CategoryOptions categoryOptions(const QString &categoryName) const
Definition: session.cpp:664
QString toValidFileSystemName(const QString &name, bool allowSeparators=false, const QString &pad=QLatin1String(" "))
Definition: fs.cpp:237
QString resolvePath(const QString &relativePath, const QString &basePath)
Definition: fs.cpp:74
std::optional< DownloadPathOption > downloadPath

References categoryOptions(), BitTorrent::CategoryOptions::downloadPath, downloadPath(), BitTorrent::CategoryOptions::DownloadPathOption::enabled, isDownloadPathEnabled(), m_categories, BitTorrent::CategoryOptions::DownloadPathOption::path, Utils::Fs::resolvePath(), and Utils::Fs::toValidFileSystemName().

Referenced by addTorrent_impl(), BitTorrent::TorrentImpl::downloadPath(), TorrentOptionsDialog::handleTMMChanged(), and BitTorrent::TorrentImpl::setAutoTMMEnabled().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ categoryOptions()

CategoryOptions Session::categoryOptions ( const QString &  categoryName) const

Definition at line 664 of file session.cpp.

665 {
666  return m_categories.value(categoryName);
667 }

References m_categories.

Referenced by categoryDownloadPath(), loadCategories(), storeCategories(), and upgradeCategories().

Here is the caller graph for this function:

◆ categoryRemoved

void BitTorrent::Session::categoryRemoved ( const QString &  categoryName)
signal

Referenced by removeCategory().

Here is the caller graph for this function:

◆ categorySavePath()

QString Session::categorySavePath ( const QString &  categoryName) const

Definition at line 669 of file session.cpp.

670 {
671  const QString basePath = savePath();
672  if (categoryName.isEmpty())
673  return basePath;
674 
675  QString path = m_categories.value(categoryName).savePath;
676  if (path.isEmpty()) // use implicit save path
677  path = Utils::Fs::toValidFileSystemName(categoryName, true);
678 
679  return (QDir::isAbsolutePath(path) ? path : Utils::Fs::resolvePath(path, basePath));
680 }

References m_categories, Utils::Fs::resolvePath(), savePath(), and Utils::Fs::toValidFileSystemName().

Referenced by addTorrent_impl(), TorrentOptionsDialog::handleCategoryChanged(), TorrentOptionsDialog::handleTMMChanged(), BitTorrent::TorrentImpl::savePath(), and BitTorrent::TorrentImpl::setAutoTMMEnabled().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkingMemUsage()

int Session::checkingMemUsage ( ) const

Definition at line 3221 of file session.cpp.

3222 {
3223  return std::max(1, m_checkingMemUsage.get());
3224 }

References CachedSettingValue< T >::get(), and m_checkingMemUsage.

Referenced by AdvancedSettings::loadAdvancedSettings(), and loadLTSettings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ chokingAlgorithm()

ChokingAlgorithm Session::chokingAlgorithm ( ) const

Definition at line 2868 of file session.cpp.

2869 {
2870  return m_chokingAlgorithm;
2871 }

References m_chokingAlgorithm.

Referenced by AdvancedSettings::loadAdvancedSettings(), and loadLTSettings().

Here is the caller graph for this function:

◆ configure()

void Session::configure ( )
private

Definition at line 1019 of file session.cpp.

1020 {
1021  lt::settings_pack settingsPack = m_nativeSession->get_settings();
1022  loadLTSettings(settingsPack);
1023  m_nativeSession->apply_settings(settingsPack);
1024 
1026 
1028 }
void loadLTSettings(lt::settings_pack &settingsPack)
Definition: session.cpp:1188
bool m_deferredConfigureScheduled
Definition: session.h:655

References configureComponents(), loadLTSettings(), m_deferredConfigureScheduled, and m_nativeSession.

Referenced by configureDeferred().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ configureComponents()

void Session::configureComponents ( )
private

Definition at line 1030 of file session.cpp.

1031 {
1032  // This function contains components/actions that:
1033  // 1. Need to be setup at start up
1034  // 2. When deferred configure is called
1035 
1037 
1039  {
1040  if (isIPFilteringEnabled())
1041  enableIPFilter();
1042  else
1043  disableIPFilter();
1044  m_IPFilteringConfigured = true;
1045  }
1046 
1047 #if defined(Q_OS_WIN)
1048  applyOSMemoryPriority();
1049 #endif
1050 }
bool m_IPFilteringConfigured
Definition: session.h:656
bool isIPFilteringEnabled() const
Definition: session.cpp:2918
void configurePeerClasses()
Definition: session.cpp:1485

References configurePeerClasses(), disableIPFilter(), enableIPFilter(), isIPFilteringEnabled(), and m_IPFilteringConfigured.

Referenced by configure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ configureDeferred

void Session::configureDeferred ( )
privateslot

Definition at line 4230 of file session.cpp.

4231 {
4233  return;
4234 
4236  QMetaObject::invokeMethod(this, qOverload<>(&Session::configure), Qt::QueuedConnection);
4237 }
Q_INVOKABLE void configure()
Definition: session.cpp:1019

References configure(), and m_deferredConfigureScheduled.

Referenced by configureListeningInterface(), setAltGlobalDownloadSpeedLimit(), setAltGlobalUploadSpeedLimit(), setAnnounceIP(), setAnnounceToAllTiers(), setAnnounceToAllTrackers(), setAnonymousModeEnabled(), setAsyncIOThreads(), setBannedIPs(), setBlockPeersOnPrivilegedPorts(), setBTProtocol(), setCheckingMemUsage(), setChokingAlgorithm(), setCoalesceReadWriteEnabled(), setConnectionSpeed(), setDHTEnabled(), setDiskCacheSize(), setDiskCacheTTL(), setDownloadRateForSlowTorrents(), setEncryption(), setFilePoolSize(), setGlobalDownloadSpeedLimit(), setGlobalUploadSpeedLimit(), setHashingThreads(), setIDNSupportEnabled(), setIgnoreLimitsOnLAN(), setIgnoreSlowTorrentsForQueueing(), setIncludeOverheadInLimits(), setIPFilterFile(), setIPFilteringEnabled(), setLSDEnabled(), setMaxActiveDownloads(), setMaxActiveTorrents(), setMaxActiveUploads(), setMaxConcurrentHTTPAnnounces(), setMaxConnections(), setMaxUploads(), setMultiConnectionsPerIpEnabled(), setOutgoingPortsMax(), setOutgoingPortsMin(), setPeerToS(), setPeerTurnover(), setPeerTurnoverCutoff(), setPeerTurnoverInterval(), setPieceExtentAffinity(), setProxyPeerConnectionsEnabled(), setQueueingSystemEnabled(), setSeedChokingAlgorithm(), setSendBufferLowWatermark(), setSendBufferWatermark(), setSendBufferWatermarkFactor(), setSlowTorrentsInactivityTimer(), setSocketBacklogSize(), setSSRFMitigationEnabled(), setStopTrackerTimeout(), setSuggestMode(), setTrackerFilteringEnabled(), setUploadRateForSlowTorrents(), setUPnPLeaseDuration(), setUseOSCache(), setUtpMixedMode(), setUTPRateLimited(), and setValidateHTTPSTrackerCertificate().

Here is the call graph for this function:

◆ configureListeningInterface()

void Session::configureListeningInterface ( )
private

Definition at line 2590 of file session.cpp.

2591 {
2594 }
bool m_listenInterfaceConfigured
Definition: session.h:657

References configureDeferred(), and m_listenInterfaceConfigured.

Referenced by setNetworkInterface(), setNetworkInterfaceAddress(), and setPort().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ configureNetworkInterfaces()

void Session::configureNetworkInterfaces ( lt::settings_pack &  settingsPack)
private

Definition at line 1421 of file session.cpp.

1422 {
1424  return;
1425 
1426  if (port() > 0) // user has specified port number
1427  settingsPack.set_int(lt::settings_pack::max_retry_port_bind, 0);
1428 
1429  QStringList endpoints;
1430  QStringList outgoingInterfaces;
1431  const QString portString = ':' + QString::number(port());
1432 
1433  for (const QString &ip : asConst(getListeningIPs()))
1434  {
1435  const QHostAddress addr {ip};
1436  if (!addr.isNull())
1437  {
1438  const bool isIPv6 = (addr.protocol() == QAbstractSocket::IPv6Protocol);
1439  const QString ip = isIPv6
1440  ? Utils::Net::canonicalIPv6Addr(addr).toString()
1441  : addr.toString();
1442 
1443  endpoints << ((isIPv6 ? ('[' + ip + ']') : ip) + portString);
1444 
1445  if ((ip != QLatin1String("0.0.0.0")) && (ip != QLatin1String("::")))
1446  outgoingInterfaces << ip;
1447  }
1448  else
1449  {
1450  // ip holds an interface name
1451 #ifdef Q_OS_WIN
1452  // On Vista+ versions and after Qt 5.5 QNetworkInterface::name() returns
1453  // the interface's LUID and not the GUID.
1454  // Libtorrent expects GUIDs for the 'listen_interfaces' setting.
1455  const QString guid = convertIfaceNameToGuid(ip);
1456  if (!guid.isEmpty())
1457  {
1458  endpoints << (guid + portString);
1459  outgoingInterfaces << guid;
1460  }
1461  else
1462  {
1463  LogMsg(tr("Could not get GUID of network interface: %1").arg(ip) , Log::WARNING);
1464  // Since we can't get the GUID, we'll pass the interface name instead.
1465  // Otherwise an empty string will be passed to outgoing_interface which will cause IP leak.
1466  endpoints << (ip + portString);
1467  outgoingInterfaces << ip;
1468  }
1469 #else
1470  endpoints << (ip + portString);
1471  outgoingInterfaces << ip;
1472 #endif
1473  }
1474  }
1475 
1476  const QString finalEndpoints = endpoints.join(',');
1477  settingsPack.set_str(lt::settings_pack::listen_interfaces, finalEndpoints.toStdString());
1478  LogMsg(tr("Trying to listen on: %1", "e.g: Trying to listen on: 192.168.0.1:6881")
1479  .arg(finalEndpoints), Log::INFO);
1480 
1481  settingsPack.set_str(lt::settings_pack::outgoing_interfaces, outgoingInterfaces.join(',').toStdString());
1483 }
QStringList getListeningIPs() const
Definition: session.cpp:2491
@ INFO
Definition: logger.h:46
QHostAddress canonicalIPv6Addr(const QHostAddress &addr)
Definition: net.cpp:100

References asConst(), Utils::Net::canonicalIPv6Addr(), getListeningIPs(), Log::INFO, LogMsg(), m_listenInterfaceConfigured, port(), and Log::WARNING.

Referenced by loadLTSettings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ configurePeerClasses()

void Session::configurePeerClasses ( )
private

Definition at line 1485 of file session.cpp.

1486 {
1487  lt::ip_filter f;
1488  // lt::make_address("255.255.255.255") crashes on some people's systems
1489  // so instead we use address_v4::broadcast()
1490  // Proactively do the same for 0.0.0.0 and address_v4::any()
1491  f.add_rule(lt::address_v4::any()
1492  , lt::address_v4::broadcast()
1493  , 1 << LT::toUnderlyingType(lt::session::global_peer_class_id));
1494 
1495  // IPv6 may not be available on OS and the parsing
1496  // would result in an exception -> abnormal program termination
1497  // Affects Windows XP
1498  try
1499  {
1500  f.add_rule(lt::address_v6::any()
1501  , lt::make_address("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")
1502  , 1 << LT::toUnderlyingType(lt::session::global_peer_class_id));
1503  }
1504  catch (const std::exception &) {}
1505 
1506  if (ignoreLimitsOnLAN())
1507  {
1508  // local networks
1509  f.add_rule(lt::make_address("10.0.0.0")
1510  , lt::make_address("10.255.255.255")
1511  , 1 << LT::toUnderlyingType(lt::session::local_peer_class_id));
1512  f.add_rule(lt::make_address("172.16.0.0")
1513  , lt::make_address("172.31.255.255")
1514  , 1 << LT::toUnderlyingType(lt::session::local_peer_class_id));
1515  f.add_rule(lt::make_address("192.168.0.0")
1516  , lt::make_address("192.168.255.255")
1517  , 1 << LT::toUnderlyingType(lt::session::local_peer_class_id));
1518  // link local
1519  f.add_rule(lt::make_address("169.254.0.0")
1520  , lt::make_address("169.254.255.255")
1521  , 1 << LT::toUnderlyingType(lt::session::local_peer_class_id));
1522  // loopback
1523  f.add_rule(lt::make_address("127.0.0.0")
1524  , lt::make_address("127.255.255.255")
1525  , 1 << LT::toUnderlyingType(lt::session::local_peer_class_id));
1526 
1527  // IPv6 may not be available on OS and the parsing
1528  // would result in an exception -> abnormal program termination
1529  // Affects Windows XP
1530  try
1531  {
1532  // link local
1533  f.add_rule(lt::make_address("fe80::")
1534  , lt::make_address("febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff")
1535  , 1 << LT::toUnderlyingType(lt::session::local_peer_class_id));
1536  // unique local addresses
1537  f.add_rule(lt::make_address("fc00::")
1538  , lt::make_address("fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")
1539  , 1 << LT::toUnderlyingType(lt::session::local_peer_class_id));
1540  // loopback
1541  f.add_rule(lt::address_v6::loopback()
1542  , lt::address_v6::loopback()
1543  , 1 << LT::toUnderlyingType(lt::session::local_peer_class_id));
1544  }
1545  catch (const std::exception &) {}
1546  }
1547  m_nativeSession->set_peer_class_filter(f);
1548 
1549  lt::peer_class_type_filter peerClassTypeFilter;
1550  peerClassTypeFilter.add(lt::peer_class_type_filter::tcp_socket, lt::session::tcp_peer_class_id);
1551  peerClassTypeFilter.add(lt::peer_class_type_filter::ssl_tcp_socket, lt::session::tcp_peer_class_id);
1552  peerClassTypeFilter.add(lt::peer_class_type_filter::i2p_socket, lt::session::tcp_peer_class_id);
1553  if (!isUTPRateLimited())
1554  {
1555  peerClassTypeFilter.disallow(lt::peer_class_type_filter::utp_socket
1556  , lt::session::global_peer_class_id);
1557  peerClassTypeFilter.disallow(lt::peer_class_type_filter::ssl_utp_socket
1558  , lt::session::global_peer_class_id);
1559  }
1560  m_nativeSession->set_peer_class_type_filter(peerClassTypeFilter);
1561 }
bool ignoreLimitsOnLAN() const
Definition: session.cpp:3587
bool isUTPRateLimited() const
Definition: session.cpp:3722
void f()
Definition: test2.c:1

References f(), ignoreLimitsOnLAN(), isUTPRateLimited(), m_nativeSession, and BitTorrent::LT::toUnderlyingType().

Referenced by configureComponents().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ connectionSpeed()

int Session::connectionSpeed ( ) const

Definition at line 3369 of file session.cpp.

3370 {
3371  return m_connectionSpeed;
3372 }

References m_connectionSpeed.

Referenced by AdvancedSettings::loadAdvancedSettings(), and loadLTSettings().

Here is the caller graph for this function:

◆ createTorrent()

void Session::createTorrent ( const lt::torrent_handle &  nativeHandle)
private

Definition at line 4588 of file session.cpp.

4589 {
4590 #ifdef QBT_USES_LIBTORRENT2
4591  const auto torrentID = TorrentID::fromInfoHash(nativeHandle.info_hashes());
4592 #else
4593  const auto torrentID = TorrentID::fromInfoHash(nativeHandle.info_hash());
4594 #endif
4595 
4596  Q_ASSERT(m_loadingTorrents.contains(torrentID));
4597 
4598  const LoadTorrentParams params = m_loadingTorrents.take(torrentID);
4599 
4600  auto *const torrent = new TorrentImpl {this, m_nativeSession, nativeHandle, params};
4601  m_torrents.insert(torrent->id(), torrent);
4602 
4603  const bool hasMetadata = torrent->hasMetadata();
4604 
4605  if (params.restored)
4606  {
4607  LogMsg(tr("'%1' restored.", "'torrent name' restored.").arg(torrent->name()));
4608  }
4609  else
4610  {
4611  m_resumeDataStorage->store(torrent->id(), params);
4612 
4613  // The following is useless for newly added magnet
4614  if (hasMetadata)
4615  {
4616  // Copy the torrent file to the export folder
4617  if (!torrentExportDirectory().isEmpty())
4618  {
4619  const TorrentInfo torrentInfo {*params.ltAddTorrentParams.ti};
4620  exportTorrentFile(torrentInfo, torrentExportDirectory(), torrent->name());
4621  }
4622  }
4623 
4624  if (isAddTrackersEnabled() && !torrent->isPrivate())
4625  torrent->addTrackers(m_additionalTrackerList);
4626 
4627  LogMsg(tr("'%1' added to download list.", "'torrent name' was added to download list.")
4628  .arg(torrent->name()));
4629  }
4630 
4631  if (((torrent->ratioLimit() >= 0) || (torrent->seedingTimeLimit() >= 0))
4632  && !m_seedingLimitTimer->isActive())
4633  m_seedingLimitTimer->start();
4634 
4635  // Send torrent addition signal
4636  emit torrentLoaded(torrent);
4637  // Send new torrent signal
4638  if (!params.restored)
4639  emit torrentAdded(torrent);
4640 
4641  // Torrent could have error just after adding to libtorrent
4642  if (torrent->hasError())
4643  LogMsg(tr("Torrent errored. Torrent: \"%1\". Error: %2.").arg(torrent->name(), torrent->error()), Log::WARNING);
4644 }
virtual void store(const TorrentID &id, const LoadTorrentParams &resumeData) const =0
QString torrentExportDirectory() const
Definition: session.cpp:596
QVector< TrackerEntry > m_additionalTrackerList
Definition: session.h:766
bool isAddTrackersEnabled() const
Definition: session.cpp:2894
void exportTorrentFile(const TorrentInfo &torrentInfo, const QString &folderPath, const QString &baseName)
Definition: session.cpp:2340
void torrentAdded(Torrent *torrent)
ResumeDataStorage * m_resumeDataStorage
Definition: session.h:779
void torrentLoaded(Torrent *torrent)

References exportTorrentFile(), BitTorrent::TorrentID::fromInfoHash(), isAddTrackersEnabled(), LogMsg(), BitTorrent::LoadTorrentParams::ltAddTorrentParams, m_additionalTrackerList, m_loadingTorrents, m_nativeSession, m_resumeDataStorage, m_seedingLimitTimer, m_torrents, BitTorrent::LoadTorrentParams::restored, BitTorrent::ResumeDataStorage::store(), torrentAdded(), torrentExportDirectory(), torrentLoaded(), and Log::WARNING.

Referenced by handleAddTorrentAlert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decreaseTorrentsQueuePos()

void Session::decreaseTorrentsQueuePos ( const QVector< TorrentID > &  ids)

Definition at line 1889 of file session.cpp.

1890 {
1891  using ElementType = std::pair<int, const TorrentImpl *>;
1892  std::priority_queue<ElementType> torrentQueue;
1893 
1894  // Sort torrents by queue position
1895  for (const TorrentID &id : ids)
1896  {
1897  const TorrentImpl *torrent = m_torrents.value(id);
1898  if (!torrent) continue;
1899  if (const int position = torrent->queuePosition(); position >= 0)
1900  torrentQueue.emplace(position, torrent);
1901  }
1902 
1903  // Decrease torrents queue position (starting with the one in the lowest queue position)
1904  while (!torrentQueue.empty())
1905  {
1906  const TorrentImpl *torrent = torrentQueue.top().second;
1908  torrentQueue.pop();
1909  }
1910 
1911  for (auto i = m_downloadedMetadata.cbegin(); i != m_downloadedMetadata.cend(); ++i)
1912  torrentQueuePositionBottom(m_nativeSession->find_torrent(*i));
1913 
1915 }
void torrentQueuePositionDown(const lt::torrent_handle &handle)
Definition: session.cpp:130

References m_downloadedMetadata, m_nativeSession, m_torrents, BitTorrent::TorrentImpl::nativeHandle(), BitTorrent::TorrentImpl::queuePosition(), saveTorrentsQueue(), anonymous_namespace{session.cpp}::torrentQueuePositionBottom(), and anonymous_namespace{session.cpp}::torrentQueuePositionDown().

Referenced by TorrentsController::decreasePrioAction(), and TransferListWidget::decreaseQueuePosSelectedTorrents().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deleteTorrent()

bool Session::deleteTorrent ( const TorrentID id,
DeleteOption  deleteOption = DeleteTorrent 
)

Definition at line 1792 of file session.cpp.

1793 {
1794  TorrentImpl *const torrent = m_torrents.take(id);
1795  if (!torrent) return false;
1796 
1797  qDebug("Deleting torrent with ID: %s", qUtf8Printable(torrent->id().toString()));
1798  emit torrentAboutToBeRemoved(torrent);
1799 
1800  // Remove it from session
1801  if (deleteOption == DeleteTorrent)
1802  {
1803  m_removingTorrents[torrent->id()] = {torrent->name(), "", deleteOption};
1804 
1805  const lt::torrent_handle nativeHandle {torrent->nativeHandle()};
1806  const auto iter = std::find_if(m_moveStorageQueue.begin(), m_moveStorageQueue.end()
1807  , [&nativeHandle](const MoveStorageJob &job)
1808  {
1809  return job.torrentHandle == nativeHandle;
1810  });
1811  if (iter != m_moveStorageQueue.end())
1812  {
1813  // We shouldn't actually remove torrent until existing "move storage jobs" are done
1814  torrentQueuePositionBottom(nativeHandle);
1815  nativeHandle.unset_flags(lt::torrent_flags::auto_managed);
1816  nativeHandle.pause();
1817  }
1818  else
1819  {
1820  m_nativeSession->remove_torrent(nativeHandle, lt::session::delete_partfile);
1821  }
1822  }
1823  else
1824  {
1825  m_removingTorrents[torrent->id()] = {torrent->name(), torrent->rootPath(), deleteOption};
1826 
1827  if (m_moveStorageQueue.size() > 1)
1828  {
1829  // Delete "move storage job" for the deleted torrent
1830  // (note: we shouldn't delete active job)
1831  const auto iter = std::find_if(m_moveStorageQueue.begin() + 1, m_moveStorageQueue.end()
1832  , [torrent](const MoveStorageJob &job)
1833  {
1834  return job.torrentHandle == torrent->nativeHandle();
1835  });
1836  if (iter != m_moveStorageQueue.end())
1837  m_moveStorageQueue.erase(iter);
1838  }
1839 
1840  m_nativeSession->remove_torrent(torrent->nativeHandle(), lt::session::delete_files);
1841  }
1842 
1843  // Remove it from torrent resume directory
1844  m_resumeDataStorage->remove(torrent->id());
1845 
1846  delete torrent;
1847  return true;
1848 }
virtual void remove(const TorrentID &id) const =0
void torrentAboutToBeRemoved(Torrent *torrent)
QHash< TorrentID, RemovingTorrentData > m_removingTorrents
Definition: session.h:787
TorrentID id() const
Definition: torrent.cpp:54
QString rootPath() const override
QString toString() const
Definition: digest32.h:85
@ DeleteTorrent
Definition: session.h:81

References DeleteTorrent, BitTorrent::Torrent::id(), m_moveStorageQueue, m_nativeSession, m_removingTorrents, m_resumeDataStorage, m_torrents, BitTorrent::TorrentImpl::name(), BitTorrent::TorrentImpl::nativeHandle(), BitTorrent::ResumeDataStorage::remove(), BitTorrent::TorrentImpl::rootPath(), torrentAboutToBeRemoved(), anonymous_namespace{session.cpp}::torrentQueuePositionBottom(), and Digest32< N >::toString().

Referenced by TorrentsController::deleteAction(), and processShareLimits().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ disableIPFilter()

void Session::disableIPFilter ( )
private

Definition at line 4258 of file session.cpp.

4259 {
4260  qDebug("Disabling IPFilter");
4261  if (m_filterParser)
4262  {
4263  disconnect(m_filterParser.data(), nullptr, this, nullptr);
4264  delete m_filterParser;
4265  }
4266 
4267  // Add the banned IPs after the IPFilter disabling
4268  // which creates an empty filter and overrides all previously
4269  // applied bans.
4270  lt::ip_filter filter;
4271  processBannedIPs(filter);
4272  m_nativeSession->set_ip_filter(filter);
4273 }
void processBannedIPs(lt::ip_filter &filter)
Definition: session.cpp:1114

References m_filterParser, m_nativeSession, and processBannedIPs().

Referenced by configureComponents().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ diskCacheSize()

int Session::diskCacheSize ( ) const

Definition at line 3237 of file session.cpp.

3238 {
3239 #ifdef QBT_APP_64BIT
3240  return std::min(m_diskCacheSize.get(), 33554431); // 32768GiB
3241 #else
3242  // When build as 32bit binary, set the maximum at less than 2GB to prevent crashes
3243  // allocate 1536MiB and leave 512MiB to the rest of program data in RAM
3244  return std::min(m_diskCacheSize.get(), 1536);
3245 #endif
3246 }

References CachedSettingValue< T >::get(), and m_diskCacheSize.

Referenced by AdvancedSettings::loadAdvancedSettings(), and loadLTSettings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ diskCacheTTL()

int Session::diskCacheTTL ( ) const

Definition at line 3263 of file session.cpp.

3264 {
3265  return m_diskCacheTTL;
3266 }

References m_diskCacheTTL.

Referenced by AdvancedSettings::loadAdvancedSettings(), and loadLTSettings().

Here is the caller graph for this function:

◆ dispatchTorrentAlert()

void Session::dispatchTorrentAlert ( const lt::alert *  a)
private

Definition at line 4571 of file session.cpp.

4572 {
4573  TorrentImpl *const torrent = m_torrents.value(static_cast<const lt::torrent_alert*>(a)->handle.info_hash());
4574  if (torrent)
4575  {
4576  torrent->handleAlert(a);
4577  return;
4578  }
4579 
4580  switch (a->type())
4581  {
4582  case lt::metadata_received_alert::alert_type:
4583  handleMetadataReceivedAlert(static_cast<const lt::metadata_received_alert*>(a));
4584  break;
4585  }
4586 }
void handleMetadataReceivedAlert(const lt::metadata_received_alert *p)
Definition: session.cpp:4736
void handleAlert(const lt::alert *a)

References BitTorrent::TorrentImpl::handleAlert(), handleMetadataReceivedAlert(), and m_torrents.

Referenced by handleAlert(), and saveResumeData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ downloadFromUrlFailed

void BitTorrent::Session::downloadFromUrlFailed ( const QString &  url,
const QString &  reason 
)
signal

Referenced by RSS::AutoDownloader::AutoDownloader(), handleDownloadFinished(), and MainWindow::MainWindow().

Here is the caller graph for this function:

◆ downloadFromUrlFinished

void BitTorrent::Session::downloadFromUrlFinished ( const QString &  url)
signal

Referenced by RSS::AutoDownloader::AutoDownloader(), and handleDownloadFinished().

Here is the caller graph for this function:

◆ downloadMetadata()

bool Session::downloadMetadata ( const MagnetUri magnetUri)

Definition at line 2283 of file session.cpp.

2284 {
2285  if (!magnetUri.isValid()) return false;
2286 
2287  const auto id = TorrentID::fromInfoHash(magnetUri.infoHash());
2288  const QString name = magnetUri.name();
2289 
2290  // We should not add torrent if it's already
2291  // processed or adding to session
2292  if (m_torrents.contains(id)) return false;
2293  if (m_loadingTorrents.contains(id)) return false;
2294  if (m_downloadedMetadata.contains(id)) return false;
2295 
2296  qDebug("Adding torrent to preload metadata...");
2297  qDebug(" -> Torrent ID: %s", qUtf8Printable(id.toString()));
2298  qDebug(" -> Name: %s", qUtf8Printable(name));
2299 
2300  lt::add_torrent_params p = magnetUri.addTorrentParams();
2301 
2302  // Flags
2303  // Preallocation mode
2304  if (isPreallocationEnabled())
2305  p.storage_mode = lt::storage_mode_allocate;
2306  else
2307  p.storage_mode = lt::storage_mode_sparse;
2308 
2309  // Limits
2310  p.max_connections = maxConnectionsPerTorrent();
2311  p.max_uploads = maxUploadsPerTorrent();
2312 
2313  const QString savePath = Utils::Fs::tempPath() + id.toString();
2314  p.save_path = Utils::Fs::toNativePath(savePath).toStdString();
2315 
2316  // Forced start
2317  p.flags &= ~lt::torrent_flags::paused;
2318  p.flags &= ~lt::torrent_flags::auto_managed;
2319 
2320  // Solution to avoid accidental file writes
2321  p.flags |= lt::torrent_flags::upload_mode;
2322 
2323 #ifndef QBT_USES_LIBTORRENT2
2324  p.storage = customStorageConstructor;
2325 #endif
2326 
2327  // Adding torrent to libtorrent session
2328  lt::error_code ec;
2329  lt::torrent_handle h = m_nativeSession->add_torrent(p, ec);
2330  if (ec) return false;
2331 
2332  // waiting for metadata...
2333  m_downloadedMetadata.insert(h.info_hash());
2334  ++m_extraLimit;
2335  adjustLimits();
2336 
2337  return true;
2338 }
InfoHash infoHash() const
Definition: magneturi.cpp:115
QString name() const
Definition: magneturi.cpp:120
int maxConnectionsPerTorrent() const
Definition: session.cpp:3061
int maxUploadsPerTorrent() const
Definition: session.cpp:3085
lt::storage_interface * customStorageConstructor(const lt::storage_params &params, lt::file_pool &pool)
QString tempPath()
Definition: fs.cpp:314
QString toString(const lt::address &address)
Definition: session.cpp:218

References BitTorrent::MagnetUri::addTorrentParams(), adjustLimits(), customStorageConstructor(), BitTorrent::TorrentID::fromInfoHash(), BitTorrent::MagnetUri::infoHash(), isPreallocationEnabled(), BitTorrent::MagnetUri::isValid(), m_downloadedMetadata, m_extraLimit, m_loadingTorrents, m_nativeSession, m_torrents, maxConnectionsPerTorrent(), maxUploadsPerTorrent(), BitTorrent::MagnetUri::name(), savePath(), Utils::Fs::tempPath(), Utils::Fs::toNativePath(), and anonymous_namespace{session.cpp}::toString().

Referenced by AddNewTorrentDialog::loadMagnet().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ downloadPath()

QString Session::downloadPath ( ) const

Definition at line 625 of file session.cpp.

626 {
627  return m_downloadPath;
628 }

References m_downloadPath.

Referenced by categoryDownloadPath(), findIncompleteFiles(), initLoadTorrentParams(), BitTorrent::TorrentImpl::setDownloadPath(), and startUpTorrents().

Here is the caller graph for this function:

◆ downloadRateForSlowTorrents()

int Session::downloadRateForSlowTorrents ( ) const

Definition at line 3489 of file session.cpp.

3490 {
3492 }

References m_downloadRateForSlowTorrents.

Referenced by loadLTSettings().

Here is the caller graph for this function:

◆ downloadSpeedLimit()

int Session::downloadSpeedLimit ( ) const

Definition at line 2696 of file session.cpp.

2697 {
2701 }

References altGlobalDownloadSpeedLimit(), globalDownloadSpeedLimit(), and isAltGlobalSpeedLimitEnabled().

Referenced by TransferController::infoAction(), and StatusBar::updateSpeedLabels().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ editCategory()

bool Session::editCategory ( const QString &  name,
const CategoryOptions options 
)

Definition at line 728 of file session.cpp.

729 {
730  const auto it = m_categories.find(name);
731  if (it == m_categories.end())
732  return false;
733 
734  CategoryOptions &currentOptions = it.value();
735  if (options == currentOptions)
736  return false;
737 
738  currentOptions = options;
739  storeCategories();
741  {
742  for (TorrentImpl *const torrent : asConst(m_torrents))
743  {
744  if (torrent->category() == name)
745  torrent->setAutoTMMEnabled(false);
746  }
747  }
748  else
749  {
750  for (TorrentImpl *const torrent : asConst(m_torrents))
751  {
752  if (torrent->category() == name)
753  torrent->handleCategoryOptionsChanged();
754  }
755  }
756 
757  return true;
758 }
bool isDisableAutoTMMWhenCategorySavePathChanged() const
Definition: session.cpp:893

References asConst(), isDisableAutoTMMWhenCategorySavePathChanged(), m_categories, m_torrents, and storeCategories().

Here is the call graph for this function:

◆ enableBandwidthScheduler()

void Session::enableBandwidthScheduler ( )
private

Definition at line 1578 of file session.cpp.

1579 {
1580  if (!m_bwScheduler)
1581  {
1582  m_bwScheduler = new BandwidthScheduler(this);
1585  }
1586  m_bwScheduler->start();
1587 }
void bandwidthLimitRequested(bool alternative)
void setAltGlobalSpeedLimitEnabled(bool enabled)
Definition: session.cpp:2731
QPointer< BandwidthScheduler > m_bwScheduler
Definition: session.h:774

References BandwidthScheduler::bandwidthLimitRequested(), m_bwScheduler, and setAltGlobalSpeedLimitEnabled().

Referenced by setBandwidthSchedulerEnabled().

Here is the call graph for this function:
Here is the caller graph for this function: