2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru>
4 * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * In addition, as a special exception, the copyright holders give permission to
21 * link this program with the OpenSSL project's "OpenSSL" library (or with
22 * modified versions of it that use the same license as the "OpenSSL" library),
23 * and distribute the linked executables. You must obey the GNU General Public
24 * License in all respects for all of the code used other than "OpenSSL". If you
25 * modify file(s), you may extend this exception to your version of the file(s),
26 * but you are not obligated to do so. If you do not wish to do so, delete this
27 * exception statement from your version.
36 #include <libtorrent/add_torrent_params.hpp>
37 #include <libtorrent/fwd.hpp>
38 #include <libtorrent/torrent_handle.hpp>
43 #include <QtContainerFwd>
46 #include "base/path.h"
47 #include "base/settingvalue.h"
48 #include "base/types.h"
49 #include "addtorrentparams.h"
50 #include "cachestatus.h"
51 #include "categoryoptions.h"
52 #include "sessionstatus.h"
53 #include "torrentinfo.h"
54 #include "trackerentry.h"
56 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
57 class QNetworkConfiguration
;
58 class QNetworkConfigurationManager
;
65 class BandwidthScheduler
;
67 class FilterParserThread
;
70 // These values should remain unchanged when adding new items
71 // so as not to break the existing user settings.
77 EnableSuperSeeding
= 2
88 struct DownloadResult
;
95 class ResumeDataStorage
;
99 struct LoadTorrentParams
;
101 enum class MoveStorageMode
;
103 // Using `Q_ENUM_NS()` without a wrapper namespace in our case is not advised
104 // since `Q_NAMESPACE` cannot be used when the same namespace resides at different files.
105 // https://www.kdab.com/new-qt-5-8-meta-object-support-namespaces/#comment-143779
106 inline namespace SessionSettingsEnums
110 enum class BTProtocol
: int
116 Q_ENUM_NS(BTProtocol
)
118 enum class ChokingAlgorithm
: int
123 Q_ENUM_NS(ChokingAlgorithm
)
125 enum class DiskIOType
: int
131 Q_ENUM_NS(DiskIOType
)
133 enum class MixedModeAlgorithm
: int
138 Q_ENUM_NS(MixedModeAlgorithm
)
140 enum class SeedChokingAlgorithm
: int
146 Q_ENUM_NS(SeedChokingAlgorithm
)
148 enum class ResumeDataStorageType
153 Q_ENUM_NS(ResumeDataStorageType
)
155 #if defined(Q_OS_WIN)
156 enum class OSMemoryPriority
: int
164 Q_ENUM_NS(OSMemoryPriority
)
168 struct SessionMetricIndices
172 int hasIncomingConnections
= -1;
173 int sentPayloadBytes
= -1;
174 int recvPayloadBytes
= -1;
177 int sentIPOverheadBytes
= -1;
178 int recvIPOverheadBytes
= -1;
179 int sentTrackerBytes
= -1;
180 int recvTrackerBytes
= -1;
181 int recvRedundantBytes
= -1;
182 int recvFailedBytes
= -1;
187 int numPeersConnected
= -1;
188 int numPeersUpDisk
= -1;
189 int numPeersDownDisk
= -1;
195 int dhtBytesOut
= -1;
201 int diskBlocksInUse
= -1;
202 int numBlocksRead
= -1;
203 #ifndef QBT_USES_LIBTORRENT2
204 int numBlocksCacheHits
= -1;
209 int queuedDiskJobs
= -1;
210 int diskJobTime
= -1;
214 class Session final
: public QObject
217 Q_DISABLE_COPY_MOVE(Session
)
220 static void initInstance();
221 static void freeInstance();
222 static Session
*instance();
224 Path
savePath() const;
225 void setSavePath(const Path
&path
);
226 Path
downloadPath() const;
227 void setDownloadPath(const Path
&path
);
228 bool isDownloadPathEnabled() const;
229 void setDownloadPathEnabled(bool enabled
);
231 static bool isValidCategoryName(const QString
&name
);
232 // returns category itself and all top level categories
233 static QStringList
expandCategory(const QString
&category
);
235 QStringList
categories() const;
236 CategoryOptions
categoryOptions(const QString
&categoryName
) const;
237 Path
categorySavePath(const QString
&categoryName
) const;
238 Path
categoryDownloadPath(const QString
&categoryName
) const;
239 bool addCategory(const QString
&name
, const CategoryOptions
&options
= {});
240 bool editCategory(const QString
&name
, const CategoryOptions
&options
);
241 bool removeCategory(const QString
&name
);
242 bool isSubcategoriesEnabled() const;
243 void setSubcategoriesEnabled(bool value
);
244 bool useCategoryPathsInManualMode() const;
245 void setUseCategoryPathsInManualMode(bool value
);
247 static bool isValidTag(const QString
&tag
);
248 QSet
<QString
> tags() const;
249 bool hasTag(const QString
&tag
) const;
250 bool addTag(const QString
&tag
);
251 bool removeTag(const QString
&tag
);
253 // Torrent Management Mode subsystem (TMM)
255 // Each torrent can be either in Manual mode or in Automatic mode
256 // In Manual Mode various torrent properties are set explicitly(eg save path)
257 // In Automatic Mode various torrent properties are set implicitly(eg save path)
258 // based on the associated category.
259 // In Automatic Mode torrent save path can be changed in following cases:
260 // 1. Default save path changed
261 // 2. Torrent category save path changed
262 // 3. Torrent category changed
263 // (unless otherwise is specified)
264 bool isAutoTMMDisabledByDefault() const;
265 void setAutoTMMDisabledByDefault(bool value
);
266 bool isDisableAutoTMMWhenCategoryChanged() const;
267 void setDisableAutoTMMWhenCategoryChanged(bool value
);
268 bool isDisableAutoTMMWhenDefaultSavePathChanged() const;
269 void setDisableAutoTMMWhenDefaultSavePathChanged(bool value
);
270 bool isDisableAutoTMMWhenCategorySavePathChanged() const;
271 void setDisableAutoTMMWhenCategorySavePathChanged(bool value
);
273 qreal
globalMaxRatio() const;
274 void setGlobalMaxRatio(qreal ratio
);
275 int globalMaxSeedingMinutes() const;
276 void setGlobalMaxSeedingMinutes(int minutes
);
277 bool isDHTEnabled() const;
278 void setDHTEnabled(bool enabled
);
279 bool isLSDEnabled() const;
280 void setLSDEnabled(bool enabled
);
281 bool isPeXEnabled() const;
282 void setPeXEnabled(bool enabled
);
283 bool isAddTorrentPaused() const;
284 void setAddTorrentPaused(bool value
);
285 TorrentContentLayout
torrentContentLayout() const;
286 void setTorrentContentLayout(TorrentContentLayout value
);
287 bool isTrackerEnabled() const;
288 void setTrackerEnabled(bool enabled
);
289 bool isAppendExtensionEnabled() const;
290 void setAppendExtensionEnabled(bool enabled
);
291 int refreshInterval() const;
292 void setRefreshInterval(int value
);
293 bool isPreallocationEnabled() const;
294 void setPreallocationEnabled(bool enabled
);
295 Path
torrentExportDirectory() const;
296 void setTorrentExportDirectory(const Path
&path
);
297 Path
finishedTorrentExportDirectory() const;
298 void setFinishedTorrentExportDirectory(const Path
&path
);
300 int globalDownloadSpeedLimit() const;
301 void setGlobalDownloadSpeedLimit(int limit
);
302 int globalUploadSpeedLimit() const;
303 void setGlobalUploadSpeedLimit(int limit
);
304 int altGlobalDownloadSpeedLimit() const;
305 void setAltGlobalDownloadSpeedLimit(int limit
);
306 int altGlobalUploadSpeedLimit() const;
307 void setAltGlobalUploadSpeedLimit(int limit
);
308 int downloadSpeedLimit() const;
309 void setDownloadSpeedLimit(int limit
);
310 int uploadSpeedLimit() const;
311 void setUploadSpeedLimit(int limit
);
312 bool isAltGlobalSpeedLimitEnabled() const;
313 void setAltGlobalSpeedLimitEnabled(bool enabled
);
314 bool isBandwidthSchedulerEnabled() const;
315 void setBandwidthSchedulerEnabled(bool enabled
);
317 bool isPerformanceWarningEnabled() const;
318 void setPerformanceWarningEnabled(bool enable
);
319 int saveResumeDataInterval() const;
320 void setSaveResumeDataInterval(int value
);
322 void setPort(int port
);
323 QString
networkInterface() const;
324 void setNetworkInterface(const QString
&iface
);
325 QString
networkInterfaceName() const;
326 void setNetworkInterfaceName(const QString
&name
);
327 QString
networkInterfaceAddress() const;
328 void setNetworkInterfaceAddress(const QString
&address
);
329 int encryption() const;
330 void setEncryption(int state
);
331 int maxActiveCheckingTorrents() const;
332 void setMaxActiveCheckingTorrents(int val
);
333 bool isProxyPeerConnectionsEnabled() const;
334 void setProxyPeerConnectionsEnabled(bool enabled
);
335 ChokingAlgorithm
chokingAlgorithm() const;
336 void setChokingAlgorithm(ChokingAlgorithm mode
);
337 SeedChokingAlgorithm
seedChokingAlgorithm() const;
338 void setSeedChokingAlgorithm(SeedChokingAlgorithm mode
);
339 bool isAddTrackersEnabled() const;
340 void setAddTrackersEnabled(bool enabled
);
341 QString
additionalTrackers() const;
342 void setAdditionalTrackers(const QString
&trackers
);
343 bool isIPFilteringEnabled() const;
344 void setIPFilteringEnabled(bool enabled
);
345 Path
IPFilterFile() const;
346 void setIPFilterFile(const Path
&path
);
347 bool announceToAllTrackers() const;
348 void setAnnounceToAllTrackers(bool val
);
349 bool announceToAllTiers() const;
350 void setAnnounceToAllTiers(bool val
);
351 int peerTurnover() const;
352 void setPeerTurnover(int val
);
353 int peerTurnoverCutoff() const;
354 void setPeerTurnoverCutoff(int val
);
355 int peerTurnoverInterval() const;
356 void setPeerTurnoverInterval(int val
);
357 int requestQueueSize() const;
358 void setRequestQueueSize(int val
);
359 int asyncIOThreads() const;
360 void setAsyncIOThreads(int num
);
361 int hashingThreads() const;
362 void setHashingThreads(int num
);
363 int filePoolSize() const;
364 void setFilePoolSize(int size
);
365 int checkingMemUsage() const;
366 void setCheckingMemUsage(int size
);
367 int diskCacheSize() const;
368 void setDiskCacheSize(int size
);
369 int diskCacheTTL() const;
370 void setDiskCacheTTL(int ttl
);
371 qint64
diskQueueSize() const;
372 void setDiskQueueSize(qint64 size
);
373 DiskIOType
diskIOType() const;
374 void setDiskIOType(DiskIOType type
);
375 bool useOSCache() const;
376 void setUseOSCache(bool use
);
377 bool isCoalesceReadWriteEnabled() const;
378 void setCoalesceReadWriteEnabled(bool enabled
);
379 bool usePieceExtentAffinity() const;
380 void setPieceExtentAffinity(bool enabled
);
381 bool isSuggestModeEnabled() const;
382 void setSuggestMode(bool mode
);
383 int sendBufferWatermark() const;
384 void setSendBufferWatermark(int value
);
385 int sendBufferLowWatermark() const;
386 void setSendBufferLowWatermark(int value
);
387 int sendBufferWatermarkFactor() const;
388 void setSendBufferWatermarkFactor(int value
);
389 int connectionSpeed() const;
390 void setConnectionSpeed(int value
);
391 int socketBacklogSize() const;
392 void setSocketBacklogSize(int value
);
393 bool isAnonymousModeEnabled() const;
394 void setAnonymousModeEnabled(bool enabled
);
395 bool isQueueingSystemEnabled() const;
396 void setQueueingSystemEnabled(bool enabled
);
397 bool ignoreSlowTorrentsForQueueing() const;
398 void setIgnoreSlowTorrentsForQueueing(bool ignore
);
399 int downloadRateForSlowTorrents() const;
400 void setDownloadRateForSlowTorrents(int rateInKibiBytes
);
401 int uploadRateForSlowTorrents() const;
402 void setUploadRateForSlowTorrents(int rateInKibiBytes
);
403 int slowTorrentsInactivityTimer() const;
404 void setSlowTorrentsInactivityTimer(int timeInSeconds
);
405 int outgoingPortsMin() const;
406 void setOutgoingPortsMin(int min
);
407 int outgoingPortsMax() const;
408 void setOutgoingPortsMax(int max
);
409 int UPnPLeaseDuration() const;
410 void setUPnPLeaseDuration(int duration
);
412 void setPeerToS(int value
);
413 bool ignoreLimitsOnLAN() const;
414 void setIgnoreLimitsOnLAN(bool ignore
);
415 bool includeOverheadInLimits() const;
416 void setIncludeOverheadInLimits(bool include
);
417 QString
announceIP() const;
418 void setAnnounceIP(const QString
&ip
);
419 int maxConcurrentHTTPAnnounces() const;
420 void setMaxConcurrentHTTPAnnounces(int value
);
421 bool isReannounceWhenAddressChangedEnabled() const;
422 void setReannounceWhenAddressChangedEnabled(bool enabled
);
423 void reannounceToAllTrackers() const;
424 int stopTrackerTimeout() const;
425 void setStopTrackerTimeout(int value
);
426 int maxConnections() const;
427 void setMaxConnections(int max
);
428 int maxConnectionsPerTorrent() const;
429 void setMaxConnectionsPerTorrent(int max
);
430 int maxUploads() const;
431 void setMaxUploads(int max
);
432 int maxUploadsPerTorrent() const;
433 void setMaxUploadsPerTorrent(int max
);
434 int maxActiveDownloads() const;
435 void setMaxActiveDownloads(int max
);
436 int maxActiveUploads() const;
437 void setMaxActiveUploads(int max
);
438 int maxActiveTorrents() const;
439 void setMaxActiveTorrents(int max
);
440 BTProtocol
btProtocol() const;
441 void setBTProtocol(BTProtocol protocol
);
442 bool isUTPRateLimited() const;
443 void setUTPRateLimited(bool limited
);
444 MixedModeAlgorithm
utpMixedMode() const;
445 void setUtpMixedMode(MixedModeAlgorithm mode
);
446 bool isIDNSupportEnabled() const;
447 void setIDNSupportEnabled(bool enabled
);
448 bool multiConnectionsPerIpEnabled() const;
449 void setMultiConnectionsPerIpEnabled(bool enabled
);
450 bool validateHTTPSTrackerCertificate() const;
451 void setValidateHTTPSTrackerCertificate(bool enabled
);
452 bool isSSRFMitigationEnabled() const;
453 void setSSRFMitigationEnabled(bool enabled
);
454 bool blockPeersOnPrivilegedPorts() const;
455 void setBlockPeersOnPrivilegedPorts(bool enabled
);
456 bool isTrackerFilteringEnabled() const;
457 void setTrackerFilteringEnabled(bool enabled
);
458 QStringList
bannedIPs() const;
459 void setBannedIPs(const QStringList
&newList
);
460 ResumeDataStorageType
resumeDataStorageType() const;
461 void setResumeDataStorageType(ResumeDataStorageType type
);
462 #if defined(Q_OS_WIN)
463 OSMemoryPriority
getOSMemoryPriority() const;
464 void setOSMemoryPriority(OSMemoryPriority priority
);
467 void startUpTorrents();
468 Torrent
*findTorrent(const TorrentID
&id
) const;
469 QVector
<Torrent
*> torrents() const;
470 qsizetype
torrentsCount() const;
471 bool hasActiveTorrents() const;
472 bool hasUnfinishedTorrents() const;
473 bool hasRunningSeed() const;
474 const SessionStatus
&status() const;
475 const CacheStatus
&cacheStatus() const;
476 qint64
getAlltimeDL() const;
477 qint64
getAlltimeUL() const;
478 bool isListening() const;
480 MaxRatioAction
maxRatioAction() const;
481 void setMaxRatioAction(MaxRatioAction act
);
483 void banIP(const QString
&ip
);
485 bool isKnownTorrent(const TorrentID
&id
) const;
486 bool addTorrent(const QString
&source
, const AddTorrentParams
¶ms
= AddTorrentParams());
487 bool addTorrent(const MagnetUri
&magnetUri
, const AddTorrentParams
¶ms
= AddTorrentParams());
488 bool addTorrent(const TorrentInfo
&torrentInfo
, const AddTorrentParams
¶ms
= AddTorrentParams());
489 bool deleteTorrent(const TorrentID
&id
, DeleteOption deleteOption
= DeleteTorrent
);
490 bool downloadMetadata(const MagnetUri
&magnetUri
);
491 bool cancelDownloadMetadata(const TorrentID
&id
);
493 void recursiveTorrentDownload(const TorrentID
&id
);
494 void increaseTorrentsQueuePos(const QVector
<TorrentID
> &ids
);
495 void decreaseTorrentsQueuePos(const QVector
<TorrentID
> &ids
);
496 void topTorrentsQueuePos(const QVector
<TorrentID
> &ids
);
497 void bottomTorrentsQueuePos(const QVector
<TorrentID
> &ids
);
500 void handleTorrentNeedSaveResumeData(const TorrentImpl
*torrent
);
501 void handleTorrentSaveResumeDataRequested(const TorrentImpl
*torrent
);
502 void handleTorrentShareLimitChanged(TorrentImpl
*const torrent
);
503 void handleTorrentNameChanged(TorrentImpl
*const torrent
);
504 void handleTorrentSavePathChanged(TorrentImpl
*const torrent
);
505 void handleTorrentCategoryChanged(TorrentImpl
*const torrent
, const QString
&oldCategory
);
506 void handleTorrentTagAdded(TorrentImpl
*const torrent
, const QString
&tag
);
507 void handleTorrentTagRemoved(TorrentImpl
*const torrent
, const QString
&tag
);
508 void handleTorrentSavingModeChanged(TorrentImpl
*const torrent
);
509 void handleTorrentMetadataReceived(TorrentImpl
*const torrent
);
510 void handleTorrentPaused(TorrentImpl
*const torrent
);
511 void handleTorrentResumed(TorrentImpl
*const torrent
);
512 void handleTorrentChecked(TorrentImpl
*const torrent
);
513 void handleTorrentFinished(TorrentImpl
*const torrent
);
514 void handleTorrentTrackersAdded(TorrentImpl
*const torrent
, const QVector
<TrackerEntry
> &newTrackers
);
515 void handleTorrentTrackersRemoved(TorrentImpl
*const torrent
, const QStringList
&deletedTrackers
);
516 void handleTorrentTrackersChanged(TorrentImpl
*const torrent
);
517 void handleTorrentUrlSeedsAdded(TorrentImpl
*const torrent
, const QVector
<QUrl
> &newUrlSeeds
);
518 void handleTorrentUrlSeedsRemoved(TorrentImpl
*const torrent
, const QVector
<QUrl
> &urlSeeds
);
519 void handleTorrentResumeDataReady(TorrentImpl
*const torrent
, const LoadTorrentParams
&data
);
521 bool addMoveTorrentStorageJob(TorrentImpl
*torrent
, const Path
&newPath
, MoveStorageMode mode
);
523 void findIncompleteFiles(const TorrentInfo
&torrentInfo
, const Path
&savePath
524 , const Path
&downloadPath
, const PathList
&filePaths
= {}) const;
527 void allTorrentsFinished();
528 void categoryAdded(const QString
&categoryName
);
529 void categoryRemoved(const QString
&categoryName
);
530 void downloadFromUrlFailed(const QString
&url
, const QString
&reason
);
531 void downloadFromUrlFinished(const QString
&url
);
532 void fullDiskError(Torrent
*torrent
, const QString
&msg
);
533 void IPFilterParsed(bool error
, int ruleCount
);
534 void loadTorrentFailed(const QString
&error
);
535 void metadataDownloaded(const TorrentInfo
&info
);
536 void recursiveTorrentDownloadPossible(Torrent
*torrent
);
537 void speedLimitModeChanged(bool alternative
);
539 void subcategoriesSupportChanged();
540 void tagAdded(const QString
&tag
);
541 void tagRemoved(const QString
&tag
);
542 void torrentAboutToBeRemoved(Torrent
*torrent
);
543 void torrentAdded(Torrent
*torrent
);
544 void torrentCategoryChanged(Torrent
*torrent
, const QString
&oldCategory
);
545 void torrentFinished(Torrent
*torrent
);
546 void torrentFinishedChecking(Torrent
*torrent
);
547 void torrentLoaded(Torrent
*torrent
);
548 void torrentMetadataReceived(Torrent
*torrent
);
549 void torrentPaused(Torrent
*torrent
);
550 void torrentResumed(Torrent
*torrent
);
551 void torrentSavePathChanged(Torrent
*torrent
);
552 void torrentSavingModeChanged(Torrent
*torrent
);
553 void torrentsUpdated(const QVector
<Torrent
*> &torrents
);
554 void torrentTagAdded(Torrent
*torrent
, const QString
&tag
);
555 void torrentTagRemoved(Torrent
*torrent
, const QString
&tag
);
556 void trackerError(Torrent
*torrent
, const QString
&tracker
);
557 void trackerlessStateChanged(Torrent
*torrent
, bool trackerless
);
558 void trackersAdded(Torrent
*torrent
, const QVector
<TrackerEntry
> &trackers
);
559 void trackersChanged(Torrent
*torrent
);
560 void trackersRemoved(Torrent
*torrent
, const QStringList
&trackers
);
561 void trackerSuccess(Torrent
*torrent
, const QString
&tracker
);
562 void trackerWarning(Torrent
*torrent
, const QString
&tracker
);
563 void trackerEntriesUpdated(const QHash
<Torrent
*, QSet
<QString
>> &updateInfos
);
566 void configureDeferred();
568 void enqueueRefresh();
569 void processShareLimits();
570 void generateResumeData();
571 void handleIPFilterParsed(int ruleCount
);
572 void handleIPFilterError();
573 void handleDownloadFinished(const Net::DownloadResult
&result
);
574 void fileSearchFinished(const TorrentID
&id
, const Path
&savePath
, const PathList
&fileNames
);
576 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
577 // Session reconfiguration triggers
578 void networkOnlineStateChanged(bool online
);
579 void networkConfigurationChange(const QNetworkConfiguration
&);
583 struct MoveStorageJob
585 lt::torrent_handle torrentHandle
;
587 MoveStorageMode mode
;
590 struct RemovingTorrentData
594 DeleteOption deleteOption
;
597 explicit Session(QObject
*parent
= nullptr);
600 bool hasPerTorrentRatioLimit() const;
601 bool hasPerTorrentSeedingTimeLimit() const;
603 // Session configuration
604 Q_INVOKABLE
void configure();
605 void configureComponents();
606 void initializeNativeSession();
607 void loadLTSettings(lt::settings_pack
&settingsPack
);
608 void configureNetworkInterfaces(lt::settings_pack
&settingsPack
);
609 void configurePeerClasses();
610 void adjustLimits(lt::settings_pack
&settingsPack
) const;
611 void applyBandwidthLimits(lt::settings_pack
&settingsPack
) const;
614 void applyBandwidthLimits();
615 void processBannedIPs(lt::ip_filter
&filter
);
616 QStringList
getListeningIPs() const;
617 void configureListeningInterface();
618 void enableTracker(bool enable
);
619 void enableBandwidthScheduler();
620 void populateAdditionalTrackers();
621 void enableIPFilter();
622 void disableIPFilter();
623 #if defined(Q_OS_WIN)
624 void applyOSMemoryPriority() const;
626 void processTrackerStatuses();
628 bool loadTorrent(LoadTorrentParams params
);
629 LoadTorrentParams
initLoadTorrentParams(const AddTorrentParams
&addTorrentParams
);
630 bool addTorrent_impl(const std::variant
<MagnetUri
, TorrentInfo
> &source
, const AddTorrentParams
&addTorrentParams
);
632 void updateSeedingLimitTimer();
633 void exportTorrentFile(const Torrent
*torrent
, const Path
&folderPath
);
635 void handleAlert(const lt::alert
*a
);
636 void dispatchTorrentAlert(const lt::alert
*a
);
637 void handleAddTorrentAlert(const lt::add_torrent_alert
*p
);
638 void handleStateUpdateAlert(const lt::state_update_alert
*p
);
639 void handleMetadataReceivedAlert(const lt::metadata_received_alert
*p
);
640 void handleFileErrorAlert(const lt::file_error_alert
*p
);
641 void handleTorrentRemovedAlert(const lt::torrent_removed_alert
*p
);
642 void handleTorrentDeletedAlert(const lt::torrent_deleted_alert
*p
);
643 void handleTorrentDeleteFailedAlert(const lt::torrent_delete_failed_alert
*p
);
644 void handlePortmapWarningAlert(const lt::portmap_error_alert
*p
);
645 void handlePortmapAlert(const lt::portmap_alert
*p
);
646 void handlePeerBlockedAlert(const lt::peer_blocked_alert
*p
);
647 void handlePeerBanAlert(const lt::peer_ban_alert
*p
);
648 void handleUrlSeedAlert(const lt::url_seed_alert
*p
);
649 void handleListenSucceededAlert(const lt::listen_succeeded_alert
*p
);
650 void handleListenFailedAlert(const lt::listen_failed_alert
*p
);
651 void handleExternalIPAlert(const lt::external_ip_alert
*p
);
652 void handleSessionStatsAlert(const lt::session_stats_alert
*p
);
653 void handleAlertsDroppedAlert(const lt::alerts_dropped_alert
*p
) const;
654 void handleStorageMovedAlert(const lt::storage_moved_alert
*p
);
655 void handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert
*p
);
656 void handleSocks5Alert(const lt::socks5_alert
*p
) const;
657 void handleTrackerAlert(const lt::tracker_alert
*a
);
659 void createTorrent(const lt::torrent_handle
&nativeHandle
);
661 void saveResumeData();
662 void saveTorrentsQueue() const;
663 void removeTorrentsQueue() const;
665 std::vector
<lt::alert
*> getPendingAlerts(lt::time_duration time
= lt::time_duration::zero()) const;
667 void moveTorrentStorage(const MoveStorageJob
&job
) const;
668 void handleMoveTorrentStorageJobFinished(const Path
&newPath
);
670 void loadCategories();
671 void storeCategories() const;
672 void upgradeCategories();
675 lt::session
*m_nativeSession
= nullptr;
677 bool m_deferredConfigureScheduled
= false;
678 bool m_IPFilteringConfigured
= false;
679 bool m_listenInterfaceConfigured
= false;
681 CachedSettingValue
<bool> m_isDHTEnabled
;
682 CachedSettingValue
<bool> m_isLSDEnabled
;
683 CachedSettingValue
<bool> m_isPeXEnabled
;
684 CachedSettingValue
<bool> m_isIPFilteringEnabled
;
685 CachedSettingValue
<bool> m_isTrackerFilteringEnabled
;
686 CachedSettingValue
<Path
> m_IPFilterFile
;
687 CachedSettingValue
<bool> m_announceToAllTrackers
;
688 CachedSettingValue
<bool> m_announceToAllTiers
;
689 CachedSettingValue
<int> m_asyncIOThreads
;
690 CachedSettingValue
<int> m_hashingThreads
;
691 CachedSettingValue
<int> m_filePoolSize
;
692 CachedSettingValue
<int> m_checkingMemUsage
;
693 CachedSettingValue
<int> m_diskCacheSize
;
694 CachedSettingValue
<int> m_diskCacheTTL
;
695 CachedSettingValue
<qint64
> m_diskQueueSize
;
696 CachedSettingValue
<DiskIOType
> m_diskIOType
;
697 CachedSettingValue
<bool> m_useOSCache
;
698 CachedSettingValue
<bool> m_coalesceReadWriteEnabled
;
699 CachedSettingValue
<bool> m_usePieceExtentAffinity
;
700 CachedSettingValue
<bool> m_isSuggestMode
;
701 CachedSettingValue
<int> m_sendBufferWatermark
;
702 CachedSettingValue
<int> m_sendBufferLowWatermark
;
703 CachedSettingValue
<int> m_sendBufferWatermarkFactor
;
704 CachedSettingValue
<int> m_connectionSpeed
;
705 CachedSettingValue
<int> m_socketBacklogSize
;
706 CachedSettingValue
<bool> m_isAnonymousModeEnabled
;
707 CachedSettingValue
<bool> m_isQueueingEnabled
;
708 CachedSettingValue
<int> m_maxActiveDownloads
;
709 CachedSettingValue
<int> m_maxActiveUploads
;
710 CachedSettingValue
<int> m_maxActiveTorrents
;
711 CachedSettingValue
<bool> m_ignoreSlowTorrentsForQueueing
;
712 CachedSettingValue
<int> m_downloadRateForSlowTorrents
;
713 CachedSettingValue
<int> m_uploadRateForSlowTorrents
;
714 CachedSettingValue
<int> m_slowTorrentsInactivityTimer
;
715 CachedSettingValue
<int> m_outgoingPortsMin
;
716 CachedSettingValue
<int> m_outgoingPortsMax
;
717 CachedSettingValue
<int> m_UPnPLeaseDuration
;
718 CachedSettingValue
<int> m_peerToS
;
719 CachedSettingValue
<bool> m_ignoreLimitsOnLAN
;
720 CachedSettingValue
<bool> m_includeOverheadInLimits
;
721 CachedSettingValue
<QString
> m_announceIP
;
722 CachedSettingValue
<int> m_maxConcurrentHTTPAnnounces
;
723 CachedSettingValue
<bool> m_isReannounceWhenAddressChangedEnabled
;
724 CachedSettingValue
<int> m_stopTrackerTimeout
;
725 CachedSettingValue
<int> m_maxConnections
;
726 CachedSettingValue
<int> m_maxUploads
;
727 CachedSettingValue
<int> m_maxConnectionsPerTorrent
;
728 CachedSettingValue
<int> m_maxUploadsPerTorrent
;
729 CachedSettingValue
<BTProtocol
> m_btProtocol
;
730 CachedSettingValue
<bool> m_isUTPRateLimited
;
731 CachedSettingValue
<MixedModeAlgorithm
> m_utpMixedMode
;
732 CachedSettingValue
<bool> m_IDNSupportEnabled
;
733 CachedSettingValue
<bool> m_multiConnectionsPerIpEnabled
;
734 CachedSettingValue
<bool> m_validateHTTPSTrackerCertificate
;
735 CachedSettingValue
<bool> m_SSRFMitigationEnabled
;
736 CachedSettingValue
<bool> m_blockPeersOnPrivilegedPorts
;
737 CachedSettingValue
<bool> m_isAddTrackersEnabled
;
738 CachedSettingValue
<QString
> m_additionalTrackers
;
739 CachedSettingValue
<qreal
> m_globalMaxRatio
;
740 CachedSettingValue
<int> m_globalMaxSeedingMinutes
;
741 CachedSettingValue
<bool> m_isAddTorrentPaused
;
742 CachedSettingValue
<TorrentContentLayout
> m_torrentContentLayout
;
743 CachedSettingValue
<bool> m_isAppendExtensionEnabled
;
744 CachedSettingValue
<int> m_refreshInterval
;
745 CachedSettingValue
<bool> m_isPreallocationEnabled
;
746 CachedSettingValue
<Path
> m_torrentExportDirectory
;
747 CachedSettingValue
<Path
> m_finishedTorrentExportDirectory
;
748 CachedSettingValue
<int> m_globalDownloadSpeedLimit
;
749 CachedSettingValue
<int> m_globalUploadSpeedLimit
;
750 CachedSettingValue
<int> m_altGlobalDownloadSpeedLimit
;
751 CachedSettingValue
<int> m_altGlobalUploadSpeedLimit
;
752 CachedSettingValue
<bool> m_isAltGlobalSpeedLimitEnabled
;
753 CachedSettingValue
<bool> m_isBandwidthSchedulerEnabled
;
754 CachedSettingValue
<bool> m_isPerformanceWarningEnabled
;
755 CachedSettingValue
<int> m_saveResumeDataInterval
;
756 CachedSettingValue
<int> m_port
;
757 CachedSettingValue
<QString
> m_networkInterface
;
758 CachedSettingValue
<QString
> m_networkInterfaceName
;
759 CachedSettingValue
<QString
> m_networkInterfaceAddress
;
760 CachedSettingValue
<int> m_encryption
;
761 CachedSettingValue
<int> m_maxActiveCheckingTorrents
;
762 CachedSettingValue
<bool> m_isProxyPeerConnectionsEnabled
;
763 CachedSettingValue
<ChokingAlgorithm
> m_chokingAlgorithm
;
764 CachedSettingValue
<SeedChokingAlgorithm
> m_seedChokingAlgorithm
;
765 CachedSettingValue
<QStringList
> m_storedTags
;
766 CachedSettingValue
<int> m_maxRatioAction
;
767 CachedSettingValue
<Path
> m_savePath
;
768 CachedSettingValue
<Path
> m_downloadPath
;
769 CachedSettingValue
<bool> m_isDownloadPathEnabled
;
770 CachedSettingValue
<bool> m_isSubcategoriesEnabled
;
771 CachedSettingValue
<bool> m_useCategoryPathsInManualMode
;
772 CachedSettingValue
<bool> m_isAutoTMMDisabledByDefault
;
773 CachedSettingValue
<bool> m_isDisableAutoTMMWhenCategoryChanged
;
774 CachedSettingValue
<bool> m_isDisableAutoTMMWhenDefaultSavePathChanged
;
775 CachedSettingValue
<bool> m_isDisableAutoTMMWhenCategorySavePathChanged
;
776 CachedSettingValue
<bool> m_isTrackerEnabled
;
777 CachedSettingValue
<int> m_peerTurnover
;
778 CachedSettingValue
<int> m_peerTurnoverCutoff
;
779 CachedSettingValue
<int> m_peerTurnoverInterval
;
780 CachedSettingValue
<int> m_requestQueueSize
;
781 CachedSettingValue
<QStringList
> m_bannedIPs
;
782 CachedSettingValue
<ResumeDataStorageType
> m_resumeDataStorageType
;
783 #if defined(Q_OS_WIN)
784 CachedSettingValue
<OSMemoryPriority
> m_OSMemoryPriority
;
787 // Order is important. This needs to be declared after its CachedSettingsValue
788 // counterpart, because it uses it for initialization in the constructor
789 // initialization list.
790 const bool m_wasPexEnabled
= m_isPeXEnabled
;
792 int m_numResumeData
= 0;
793 int m_extraLimit
= 0;
794 QVector
<TrackerEntry
> m_additionalTrackerList
;
796 bool m_refreshEnqueued
= false;
797 QTimer
*m_seedingLimitTimer
= nullptr;
798 QTimer
*m_resumeDataTimer
= nullptr;
799 Statistics
*m_statistics
= nullptr;
801 QPointer
<FilterParserThread
> m_filterParser
;
802 QPointer
<BandwidthScheduler
> m_bwScheduler
;
804 QPointer
<Tracker
> m_tracker
;
806 QThread
*m_ioThread
= nullptr;
807 ResumeDataStorage
*m_resumeDataStorage
= nullptr;
808 FileSearcher
*m_fileSearcher
= nullptr;
810 QSet
<TorrentID
> m_downloadedMetadata
;
812 QHash
<TorrentID
, TorrentImpl
*> m_torrents
;
813 QHash
<TorrentID
, LoadTorrentParams
> m_loadingTorrents
;
814 QHash
<QString
, AddTorrentParams
> m_downloadedTorrents
;
815 QHash
<TorrentID
, RemovingTorrentData
> m_removingTorrents
;
816 QSet
<TorrentID
> m_needSaveResumeDataTorrents
;
817 QMap
<QString
, CategoryOptions
> m_categories
;
818 QSet
<QString
> m_tags
;
820 QHash
<Torrent
*, QSet
<QString
>> m_updatedTrackerEntries
;
822 // I/O errored torrents
823 QSet
<TorrentID
> m_recentErroredTorrents
;
824 QTimer
*m_recentErroredTorrentsTimer
= nullptr;
826 SessionMetricIndices m_metricIndices
;
827 lt::time_point m_statsLastTimestamp
= lt::clock_type::now();
829 SessionStatus m_status
;
830 CacheStatus m_cacheStatus
;
831 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
832 QNetworkConfigurationManager
*m_networkManager
= nullptr;
835 QList
<MoveStorageJob
> m_moveStorageQueue
;
837 QString m_lastExternalIP
;
839 bool m_needUpgradeDownloadPath
= false;
841 static Session
*m_instance
;