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/settingvalue.h"
47 #include "base/types.h"
48 #include "addtorrentparams.h"
49 #include "cachestatus.h"
50 #include "sessionstatus.h"
51 #include "torrentinfo.h"
52 #include "trackerentry.h"
54 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
55 class QNetworkConfiguration
;
56 class QNetworkConfigurationManager
;
63 class BandwidthScheduler
;
65 class FilterParserThread
;
68 // These values should remain unchanged when adding new items
69 // so as not to break the existing user settings.
75 EnableSuperSeeding
= 2
86 struct DownloadResult
;
93 class ResumeDataStorage
;
97 struct LoadTorrentParams
;
99 enum class MoveStorageMode
;
101 // Using `Q_ENUM_NS()` without a wrapper namespace in our case is not advised
102 // since `Q_NAMESPACE` cannot be used when the same namespace resides at different files.
103 // https://www.kdab.com/new-qt-5-8-meta-object-support-namespaces/#comment-143779
104 inline namespace SessionSettingsEnums
108 enum class BTProtocol
: int
114 Q_ENUM_NS(BTProtocol
)
116 enum class ChokingAlgorithm
: int
121 Q_ENUM_NS(ChokingAlgorithm
)
123 enum class MixedModeAlgorithm
: int
128 Q_ENUM_NS(MixedModeAlgorithm
)
130 enum class SeedChokingAlgorithm
: int
136 Q_ENUM_NS(SeedChokingAlgorithm
)
138 enum class ResumeDataStorageType
143 Q_ENUM_NS(ResumeDataStorageType
)
145 #if defined(Q_OS_WIN)
146 enum class OSMemoryPriority
: int
154 Q_ENUM_NS(OSMemoryPriority
)
158 struct SessionMetricIndices
162 int hasIncomingConnections
= -1;
163 int sentPayloadBytes
= -1;
164 int recvPayloadBytes
= -1;
167 int sentIPOverheadBytes
= -1;
168 int recvIPOverheadBytes
= -1;
169 int sentTrackerBytes
= -1;
170 int recvTrackerBytes
= -1;
171 int recvRedundantBytes
= -1;
172 int recvFailedBytes
= -1;
177 int numPeersConnected
= -1;
178 int numPeersUpDisk
= -1;
179 int numPeersDownDisk
= -1;
185 int dhtBytesOut
= -1;
191 int diskBlocksInUse
= -1;
192 int numBlocksRead
= -1;
193 #ifndef QBT_USES_LIBTORRENT2
194 int numBlocksCacheHits
= -1;
199 int queuedDiskJobs
= -1;
200 int diskJobTime
= -1;
204 class Session
: public QObject
207 Q_DISABLE_COPY_MOVE(Session
)
210 static void initInstance();
211 static void freeInstance();
212 static Session
*instance();
214 QString
defaultSavePath() const;
215 void setDefaultSavePath(QString path
);
216 QString
tempPath() const;
217 void setTempPath(QString path
);
218 bool isTempPathEnabled() const;
219 void setTempPathEnabled(bool enabled
);
220 QString
torrentTempPath(const TorrentInfo
&torrentInfo
) const;
222 static bool isValidCategoryName(const QString
&name
);
223 // returns category itself and all top level categories
224 static QStringList
expandCategory(const QString
&category
);
226 QStringMap
categories() const;
227 QString
categorySavePath(const QString
&categoryName
) const;
228 bool addCategory(const QString
&name
, const QString
&savePath
= "");
229 bool editCategory(const QString
&name
, const QString
&savePath
);
230 bool removeCategory(const QString
&name
);
231 bool isSubcategoriesEnabled() const;
232 void setSubcategoriesEnabled(bool value
);
234 static bool isValidTag(const QString
&tag
);
235 QSet
<QString
> tags() const;
236 bool hasTag(const QString
&tag
) const;
237 bool addTag(const QString
&tag
);
238 bool removeTag(const QString
&tag
);
240 // Torrent Management Mode subsystem (TMM)
242 // Each torrent can be either in Manual mode or in Automatic mode
243 // In Manual Mode various torrent properties are set explicitly(eg save path)
244 // In Automatic Mode various torrent properties are set implicitly(eg save path)
245 // based on the associated category.
246 // In Automatic Mode torrent save path can be changed in following cases:
247 // 1. Default save path changed
248 // 2. Torrent category save path changed
249 // 3. Torrent category changed
250 // (unless otherwise is specified)
251 bool isAutoTMMDisabledByDefault() const;
252 void setAutoTMMDisabledByDefault(bool value
);
253 bool isDisableAutoTMMWhenCategoryChanged() const;
254 void setDisableAutoTMMWhenCategoryChanged(bool value
);
255 bool isDisableAutoTMMWhenDefaultSavePathChanged() const;
256 void setDisableAutoTMMWhenDefaultSavePathChanged(bool value
);
257 bool isDisableAutoTMMWhenCategorySavePathChanged() const;
258 void setDisableAutoTMMWhenCategorySavePathChanged(bool value
);
260 qreal
globalMaxRatio() const;
261 void setGlobalMaxRatio(qreal ratio
);
262 int globalMaxSeedingMinutes() const;
263 void setGlobalMaxSeedingMinutes(int minutes
);
264 bool isDHTEnabled() const;
265 void setDHTEnabled(bool enabled
);
266 bool isLSDEnabled() const;
267 void setLSDEnabled(bool enabled
);
268 bool isPeXEnabled() const;
269 void setPeXEnabled(bool enabled
);
270 bool isAddTorrentPaused() const;
271 void setAddTorrentPaused(bool value
);
272 TorrentContentLayout
torrentContentLayout() const;
273 void setTorrentContentLayout(TorrentContentLayout value
);
274 bool isTrackerEnabled() const;
275 void setTrackerEnabled(bool enabled
);
276 bool isAppendExtensionEnabled() const;
277 void setAppendExtensionEnabled(bool enabled
);
278 int refreshInterval() const;
279 void setRefreshInterval(int value
);
280 bool isPreallocationEnabled() const;
281 void setPreallocationEnabled(bool enabled
);
282 QString
torrentExportDirectory() const;
283 void setTorrentExportDirectory(QString path
);
284 QString
finishedTorrentExportDirectory() const;
285 void setFinishedTorrentExportDirectory(QString path
);
287 int globalDownloadSpeedLimit() const;
288 void setGlobalDownloadSpeedLimit(int limit
);
289 int globalUploadSpeedLimit() const;
290 void setGlobalUploadSpeedLimit(int limit
);
291 int altGlobalDownloadSpeedLimit() const;
292 void setAltGlobalDownloadSpeedLimit(int limit
);
293 int altGlobalUploadSpeedLimit() const;
294 void setAltGlobalUploadSpeedLimit(int limit
);
295 int downloadSpeedLimit() const;
296 void setDownloadSpeedLimit(int limit
);
297 int uploadSpeedLimit() const;
298 void setUploadSpeedLimit(int limit
);
299 bool isAltGlobalSpeedLimitEnabled() const;
300 void setAltGlobalSpeedLimitEnabled(bool enabled
);
301 bool isBandwidthSchedulerEnabled() const;
302 void setBandwidthSchedulerEnabled(bool enabled
);
304 int saveResumeDataInterval() const;
305 void setSaveResumeDataInterval(int value
);
307 void setPort(int port
);
308 QString
networkInterface() const;
309 void setNetworkInterface(const QString
&iface
);
310 QString
networkInterfaceName() const;
311 void setNetworkInterfaceName(const QString
&name
);
312 QString
networkInterfaceAddress() const;
313 void setNetworkInterfaceAddress(const QString
&address
);
314 int encryption() const;
315 void setEncryption(int state
);
316 bool isProxyPeerConnectionsEnabled() const;
317 void setProxyPeerConnectionsEnabled(bool enabled
);
318 ChokingAlgorithm
chokingAlgorithm() const;
319 void setChokingAlgorithm(ChokingAlgorithm mode
);
320 SeedChokingAlgorithm
seedChokingAlgorithm() const;
321 void setSeedChokingAlgorithm(SeedChokingAlgorithm mode
);
322 bool isAddTrackersEnabled() const;
323 void setAddTrackersEnabled(bool enabled
);
324 QString
additionalTrackers() const;
325 void setAdditionalTrackers(const QString
&trackers
);
326 bool isIPFilteringEnabled() const;
327 void setIPFilteringEnabled(bool enabled
);
328 QString
IPFilterFile() const;
329 void setIPFilterFile(QString path
);
330 bool announceToAllTrackers() const;
331 void setAnnounceToAllTrackers(bool val
);
332 bool announceToAllTiers() const;
333 void setAnnounceToAllTiers(bool val
);
334 int peerTurnover() const;
335 void setPeerTurnover(int num
);
336 int peerTurnoverCutoff() const;
337 void setPeerTurnoverCutoff(int num
);
338 int peerTurnoverInterval() const;
339 void setPeerTurnoverInterval(int num
);
340 int asyncIOThreads() const;
341 void setAsyncIOThreads(int num
);
342 int hashingThreads() const;
343 void setHashingThreads(int num
);
344 int filePoolSize() const;
345 void setFilePoolSize(int size
);
346 int checkingMemUsage() const;
347 void setCheckingMemUsage(int size
);
348 int diskCacheSize() const;
349 void setDiskCacheSize(int size
);
350 int diskCacheTTL() const;
351 void setDiskCacheTTL(int ttl
);
352 bool useOSCache() const;
353 void setUseOSCache(bool use
);
354 bool isCoalesceReadWriteEnabled() const;
355 void setCoalesceReadWriteEnabled(bool enabled
);
356 bool usePieceExtentAffinity() const;
357 void setPieceExtentAffinity(bool enabled
);
358 bool isSuggestModeEnabled() const;
359 void setSuggestMode(bool mode
);
360 int sendBufferWatermark() const;
361 void setSendBufferWatermark(int value
);
362 int sendBufferLowWatermark() const;
363 void setSendBufferLowWatermark(int value
);
364 int sendBufferWatermarkFactor() const;
365 void setSendBufferWatermarkFactor(int value
);
366 int connectionSpeed() const;
367 void setConnectionSpeed(int value
);
368 int socketBacklogSize() const;
369 void setSocketBacklogSize(int value
);
370 bool isAnonymousModeEnabled() const;
371 void setAnonymousModeEnabled(bool enabled
);
372 bool isQueueingSystemEnabled() const;
373 void setQueueingSystemEnabled(bool enabled
);
374 bool ignoreSlowTorrentsForQueueing() const;
375 void setIgnoreSlowTorrentsForQueueing(bool ignore
);
376 int downloadRateForSlowTorrents() const;
377 void setDownloadRateForSlowTorrents(int rateInKibiBytes
);
378 int uploadRateForSlowTorrents() const;
379 void setUploadRateForSlowTorrents(int rateInKibiBytes
);
380 int slowTorrentsInactivityTimer() const;
381 void setSlowTorrentsInactivityTimer(int timeInSeconds
);
382 int outgoingPortsMin() const;
383 void setOutgoingPortsMin(int min
);
384 int outgoingPortsMax() const;
385 void setOutgoingPortsMax(int max
);
386 int UPnPLeaseDuration() const;
387 void setUPnPLeaseDuration(int duration
);
389 void setPeerToS(int value
);
390 bool ignoreLimitsOnLAN() const;
391 void setIgnoreLimitsOnLAN(bool ignore
);
392 bool includeOverheadInLimits() const;
393 void setIncludeOverheadInLimits(bool include
);
394 QString
announceIP() const;
395 void setAnnounceIP(const QString
&ip
);
396 int maxConcurrentHTTPAnnounces() const;
397 void setMaxConcurrentHTTPAnnounces(int value
);
398 bool isReannounceWhenAddressChangedEnabled() const;
399 void setReannounceWhenAddressChangedEnabled(bool enabled
);
400 void reannounceToAllTrackers() const;
401 int stopTrackerTimeout() const;
402 void setStopTrackerTimeout(int value
);
403 int maxConnections() const;
404 void setMaxConnections(int max
);
405 int maxConnectionsPerTorrent() const;
406 void setMaxConnectionsPerTorrent(int max
);
407 int maxUploads() const;
408 void setMaxUploads(int max
);
409 int maxUploadsPerTorrent() const;
410 void setMaxUploadsPerTorrent(int max
);
411 int maxActiveDownloads() const;
412 void setMaxActiveDownloads(int max
);
413 int maxActiveUploads() const;
414 void setMaxActiveUploads(int max
);
415 int maxActiveTorrents() const;
416 void setMaxActiveTorrents(int max
);
417 BTProtocol
btProtocol() const;
418 void setBTProtocol(BTProtocol protocol
);
419 bool isUTPRateLimited() const;
420 void setUTPRateLimited(bool limited
);
421 MixedModeAlgorithm
utpMixedMode() const;
422 void setUtpMixedMode(MixedModeAlgorithm mode
);
423 bool isIDNSupportEnabled() const;
424 void setIDNSupportEnabled(bool enabled
);
425 bool multiConnectionsPerIpEnabled() const;
426 void setMultiConnectionsPerIpEnabled(bool enabled
);
427 bool validateHTTPSTrackerCertificate() const;
428 void setValidateHTTPSTrackerCertificate(bool enabled
);
429 bool isSSRFMitigationEnabled() const;
430 void setSSRFMitigationEnabled(bool enabled
);
431 bool blockPeersOnPrivilegedPorts() const;
432 void setBlockPeersOnPrivilegedPorts(bool enabled
);
433 bool isTrackerFilteringEnabled() const;
434 void setTrackerFilteringEnabled(bool enabled
);
435 QStringList
bannedIPs() const;
436 void setBannedIPs(const QStringList
&newList
);
437 ResumeDataStorageType
resumeDataStorageType() const;
438 void setResumeDataStorageType(ResumeDataStorageType type
);
439 #if defined(Q_OS_WIN)
440 OSMemoryPriority
getOSMemoryPriority() const;
441 void setOSMemoryPriority(OSMemoryPriority priority
);
444 void startUpTorrents();
445 Torrent
*findTorrent(const TorrentID
&id
) const;
446 QVector
<Torrent
*> torrents() const;
447 bool hasActiveTorrents() const;
448 bool hasUnfinishedTorrents() const;
449 bool hasRunningSeed() const;
450 const SessionStatus
&status() const;
451 const CacheStatus
&cacheStatus() const;
452 quint64
getAlltimeDL() const;
453 quint64
getAlltimeUL() const;
454 bool isListening() const;
456 MaxRatioAction
maxRatioAction() const;
457 void setMaxRatioAction(MaxRatioAction act
);
459 void banIP(const QString
&ip
);
461 bool isKnownTorrent(const TorrentID
&id
) const;
462 bool addTorrent(const QString
&source
, const AddTorrentParams
¶ms
= AddTorrentParams());
463 bool addTorrent(const MagnetUri
&magnetUri
, const AddTorrentParams
¶ms
= AddTorrentParams());
464 bool addTorrent(const TorrentInfo
&torrentInfo
, const AddTorrentParams
¶ms
= AddTorrentParams());
465 bool deleteTorrent(const TorrentID
&id
, DeleteOption deleteOption
= DeleteTorrent
);
466 bool downloadMetadata(const MagnetUri
&magnetUri
);
467 bool cancelDownloadMetadata(const TorrentID
&id
);
469 void recursiveTorrentDownload(const TorrentID
&id
);
470 void increaseTorrentsQueuePos(const QVector
<TorrentID
> &ids
);
471 void decreaseTorrentsQueuePos(const QVector
<TorrentID
> &ids
);
472 void topTorrentsQueuePos(const QVector
<TorrentID
> &ids
);
473 void bottomTorrentsQueuePos(const QVector
<TorrentID
> &ids
);
476 void handleTorrentNeedSaveResumeData(const TorrentImpl
*torrent
);
477 void handleTorrentSaveResumeDataRequested(const TorrentImpl
*torrent
);
478 void handleTorrentShareLimitChanged(TorrentImpl
*const torrent
);
479 void handleTorrentNameChanged(TorrentImpl
*const torrent
);
480 void handleTorrentSavePathChanged(TorrentImpl
*const torrent
);
481 void handleTorrentCategoryChanged(TorrentImpl
*const torrent
, const QString
&oldCategory
);
482 void handleTorrentTagAdded(TorrentImpl
*const torrent
, const QString
&tag
);
483 void handleTorrentTagRemoved(TorrentImpl
*const torrent
, const QString
&tag
);
484 void handleTorrentSavingModeChanged(TorrentImpl
*const torrent
);
485 void handleTorrentMetadataReceived(TorrentImpl
*const torrent
);
486 void handleTorrentPaused(TorrentImpl
*const torrent
);
487 void handleTorrentResumed(TorrentImpl
*const torrent
);
488 void handleTorrentChecked(TorrentImpl
*const torrent
);
489 void handleTorrentFinished(TorrentImpl
*const torrent
);
490 void handleTorrentTrackersAdded(TorrentImpl
*const torrent
, const QVector
<TrackerEntry
> &newTrackers
);
491 void handleTorrentTrackersRemoved(TorrentImpl
*const torrent
, const QVector
<TrackerEntry
> &deletedTrackers
);
492 void handleTorrentTrackersChanged(TorrentImpl
*const torrent
);
493 void handleTorrentUrlSeedsAdded(TorrentImpl
*const torrent
, const QVector
<QUrl
> &newUrlSeeds
);
494 void handleTorrentUrlSeedsRemoved(TorrentImpl
*const torrent
, const QVector
<QUrl
> &urlSeeds
);
495 void handleTorrentResumeDataReady(TorrentImpl
*const torrent
, const LoadTorrentParams
&data
);
496 void handleTorrentTrackerReply(TorrentImpl
*const torrent
, const QString
&trackerUrl
);
497 void handleTorrentTrackerWarning(TorrentImpl
*const torrent
, const QString
&trackerUrl
);
498 void handleTorrentTrackerError(TorrentImpl
*const torrent
, const QString
&trackerUrl
);
500 bool addMoveTorrentStorageJob(TorrentImpl
*torrent
, const QString
&newPath
, MoveStorageMode mode
);
502 void findIncompleteFiles(const TorrentInfo
&torrentInfo
, const QString
&savePath
) const;
505 void allTorrentsFinished();
506 void categoryAdded(const QString
&categoryName
);
507 void categoryRemoved(const QString
&categoryName
);
508 void downloadFromUrlFailed(const QString
&url
, const QString
&reason
);
509 void downloadFromUrlFinished(const QString
&url
);
510 void fullDiskError(Torrent
*torrent
, const QString
&msg
);
511 void IPFilterParsed(bool error
, int ruleCount
);
512 void loadTorrentFailed(const QString
&error
);
513 void metadataDownloaded(const TorrentInfo
&info
);
514 void recursiveTorrentDownloadPossible(Torrent
*torrent
);
515 void speedLimitModeChanged(bool alternative
);
517 void subcategoriesSupportChanged();
518 void tagAdded(const QString
&tag
);
519 void tagRemoved(const QString
&tag
);
520 void torrentAboutToBeRemoved(Torrent
*torrent
);
521 void torrentAdded(Torrent
*torrent
);
522 void torrentCategoryChanged(Torrent
*torrent
, const QString
&oldCategory
);
523 void torrentFinished(Torrent
*torrent
);
524 void torrentFinishedChecking(Torrent
*torrent
);
525 void torrentLoaded(Torrent
*torrent
);
526 void torrentMetadataReceived(Torrent
*torrent
);
527 void torrentPaused(Torrent
*torrent
);
528 void torrentResumed(Torrent
*torrent
);
529 void torrentSavePathChanged(Torrent
*torrent
);
530 void torrentSavingModeChanged(Torrent
*torrent
);
531 void torrentsUpdated(const QVector
<Torrent
*> &torrents
);
532 void torrentTagAdded(Torrent
*torrent
, const QString
&tag
);
533 void torrentTagRemoved(Torrent
*torrent
, const QString
&tag
);
534 void trackerError(Torrent
*torrent
, const QString
&tracker
);
535 void trackerlessStateChanged(Torrent
*torrent
, bool trackerless
);
536 void trackersAdded(Torrent
*torrent
, const QVector
<TrackerEntry
> &trackers
);
537 void trackersChanged(Torrent
*torrent
);
538 void trackersRemoved(Torrent
*torrent
, const QVector
<TrackerEntry
> &trackers
);
539 void trackerSuccess(Torrent
*torrent
, const QString
&tracker
);
540 void trackerWarning(Torrent
*torrent
, const QString
&tracker
);
543 void configureDeferred();
545 void enqueueRefresh();
546 void processShareLimits();
547 void generateResumeData();
548 void handleIPFilterParsed(int ruleCount
);
549 void handleIPFilterError();
550 void handleDownloadFinished(const Net::DownloadResult
&result
);
551 void fileSearchFinished(const TorrentID
&id
, const QString
&savePath
, const QStringList
&fileNames
);
553 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
554 // Session reconfiguration triggers
555 void networkOnlineStateChanged(bool online
);
556 void networkConfigurationChange(const QNetworkConfiguration
&);
560 struct MoveStorageJob
562 lt::torrent_handle torrentHandle
;
564 MoveStorageMode mode
;
567 struct RemovingTorrentData
570 QString pathToRemove
;
571 DeleteOption deleteOption
;
574 explicit Session(QObject
*parent
= nullptr);
577 bool hasPerTorrentRatioLimit() const;
578 bool hasPerTorrentSeedingTimeLimit() const;
580 // Session configuration
581 Q_INVOKABLE
void configure();
582 void configureComponents();
583 void initializeNativeSession();
584 void loadLTSettings(lt::settings_pack
&settingsPack
);
585 void configureNetworkInterfaces(lt::settings_pack
&settingsPack
);
586 void configurePeerClasses();
587 void adjustLimits(lt::settings_pack
&settingsPack
) const;
588 void applyBandwidthLimits(lt::settings_pack
&settingsPack
) const;
591 void applyBandwidthLimits();
592 void processBannedIPs(lt::ip_filter
&filter
);
593 QStringList
getListeningIPs() const;
594 void configureListeningInterface();
595 void enableTracker(bool enable
);
596 void enableBandwidthScheduler();
597 void populateAdditionalTrackers();
598 void enableIPFilter();
599 void disableIPFilter();
600 #if defined(Q_OS_WIN)
601 void applyOSMemoryPriority() const;
604 bool loadTorrent(LoadTorrentParams params
);
605 LoadTorrentParams
initLoadTorrentParams(const AddTorrentParams
&addTorrentParams
);
606 bool addTorrent_impl(const std::variant
<MagnetUri
, TorrentInfo
> &source
, const AddTorrentParams
&addTorrentParams
);
608 void updateSeedingLimitTimer();
609 void exportTorrentFile(const TorrentInfo
&torrentInfo
, const QString
&folderPath
, const QString
&baseName
);
611 void handleAlert(const lt::alert
*a
);
612 void dispatchTorrentAlert(const lt::alert
*a
);
613 void handleAddTorrentAlert(const lt::add_torrent_alert
*p
);
614 void handleStateUpdateAlert(const lt::state_update_alert
*p
);
615 void handleMetadataReceivedAlert(const lt::metadata_received_alert
*p
);
616 void handleFileErrorAlert(const lt::file_error_alert
*p
);
617 void handleTorrentRemovedAlert(const lt::torrent_removed_alert
*p
);
618 void handleTorrentDeletedAlert(const lt::torrent_deleted_alert
*p
);
619 void handleTorrentDeleteFailedAlert(const lt::torrent_delete_failed_alert
*p
);
620 void handlePortmapWarningAlert(const lt::portmap_error_alert
*p
);
621 void handlePortmapAlert(const lt::portmap_alert
*p
);
622 void handlePeerBlockedAlert(const lt::peer_blocked_alert
*p
);
623 void handlePeerBanAlert(const lt::peer_ban_alert
*p
);
624 void handleUrlSeedAlert(const lt::url_seed_alert
*p
);
625 void handleListenSucceededAlert(const lt::listen_succeeded_alert
*p
);
626 void handleListenFailedAlert(const lt::listen_failed_alert
*p
);
627 void handleExternalIPAlert(const lt::external_ip_alert
*p
);
628 void handleSessionStatsAlert(const lt::session_stats_alert
*p
);
629 void handleAlertsDroppedAlert(const lt::alerts_dropped_alert
*p
) const;
630 void handleStorageMovedAlert(const lt::storage_moved_alert
*p
);
631 void handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert
*p
);
632 void handleSocks5Alert(const lt::socks5_alert
*p
) const;
634 void createTorrent(const lt::torrent_handle
&nativeHandle
);
636 void saveResumeData();
637 void saveTorrentsQueue() const;
638 void removeTorrentsQueue() const;
640 std::vector
<lt::alert
*> getPendingAlerts(lt::time_duration time
= lt::time_duration::zero()) const;
642 void moveTorrentStorage(const MoveStorageJob
&job
) const;
643 void handleMoveTorrentStorageJobFinished();
646 lt::session
*m_nativeSession
= nullptr;
648 bool m_deferredConfigureScheduled
= false;
649 bool m_IPFilteringConfigured
= false;
650 bool m_listenInterfaceConfigured
= false;
652 CachedSettingValue
<bool> m_isDHTEnabled
;
653 CachedSettingValue
<bool> m_isLSDEnabled
;
654 CachedSettingValue
<bool> m_isPeXEnabled
;
655 CachedSettingValue
<bool> m_isIPFilteringEnabled
;
656 CachedSettingValue
<bool> m_isTrackerFilteringEnabled
;
657 CachedSettingValue
<QString
> m_IPFilterFile
;
658 CachedSettingValue
<bool> m_announceToAllTrackers
;
659 CachedSettingValue
<bool> m_announceToAllTiers
;
660 CachedSettingValue
<int> m_asyncIOThreads
;
661 CachedSettingValue
<int> m_hashingThreads
;
662 CachedSettingValue
<int> m_filePoolSize
;
663 CachedSettingValue
<int> m_checkingMemUsage
;
664 CachedSettingValue
<int> m_diskCacheSize
;
665 CachedSettingValue
<int> m_diskCacheTTL
;
666 CachedSettingValue
<bool> m_useOSCache
;
667 CachedSettingValue
<bool> m_coalesceReadWriteEnabled
;
668 CachedSettingValue
<bool> m_usePieceExtentAffinity
;
669 CachedSettingValue
<bool> m_isSuggestMode
;
670 CachedSettingValue
<int> m_sendBufferWatermark
;
671 CachedSettingValue
<int> m_sendBufferLowWatermark
;
672 CachedSettingValue
<int> m_sendBufferWatermarkFactor
;
673 CachedSettingValue
<int> m_connectionSpeed
;
674 CachedSettingValue
<int> m_socketBacklogSize
;
675 CachedSettingValue
<bool> m_isAnonymousModeEnabled
;
676 CachedSettingValue
<bool> m_isQueueingEnabled
;
677 CachedSettingValue
<int> m_maxActiveDownloads
;
678 CachedSettingValue
<int> m_maxActiveUploads
;
679 CachedSettingValue
<int> m_maxActiveTorrents
;
680 CachedSettingValue
<bool> m_ignoreSlowTorrentsForQueueing
;
681 CachedSettingValue
<int> m_downloadRateForSlowTorrents
;
682 CachedSettingValue
<int> m_uploadRateForSlowTorrents
;
683 CachedSettingValue
<int> m_slowTorrentsInactivityTimer
;
684 CachedSettingValue
<int> m_outgoingPortsMin
;
685 CachedSettingValue
<int> m_outgoingPortsMax
;
686 CachedSettingValue
<int> m_UPnPLeaseDuration
;
687 CachedSettingValue
<int> m_peerToS
;
688 CachedSettingValue
<bool> m_ignoreLimitsOnLAN
;
689 CachedSettingValue
<bool> m_includeOverheadInLimits
;
690 CachedSettingValue
<QString
> m_announceIP
;
691 CachedSettingValue
<int> m_maxConcurrentHTTPAnnounces
;
692 CachedSettingValue
<bool> m_isReannounceWhenAddressChangedEnabled
;
693 CachedSettingValue
<int> m_stopTrackerTimeout
;
694 CachedSettingValue
<int> m_maxConnections
;
695 CachedSettingValue
<int> m_maxUploads
;
696 CachedSettingValue
<int> m_maxConnectionsPerTorrent
;
697 CachedSettingValue
<int> m_maxUploadsPerTorrent
;
698 CachedSettingValue
<BTProtocol
> m_btProtocol
;
699 CachedSettingValue
<bool> m_isUTPRateLimited
;
700 CachedSettingValue
<MixedModeAlgorithm
> m_utpMixedMode
;
701 CachedSettingValue
<bool> m_IDNSupportEnabled
;
702 CachedSettingValue
<bool> m_multiConnectionsPerIpEnabled
;
703 CachedSettingValue
<bool> m_validateHTTPSTrackerCertificate
;
704 CachedSettingValue
<bool> m_SSRFMitigationEnabled
;
705 CachedSettingValue
<bool> m_blockPeersOnPrivilegedPorts
;
706 CachedSettingValue
<bool> m_isAddTrackersEnabled
;
707 CachedSettingValue
<QString
> m_additionalTrackers
;
708 CachedSettingValue
<qreal
> m_globalMaxRatio
;
709 CachedSettingValue
<int> m_globalMaxSeedingMinutes
;
710 CachedSettingValue
<bool> m_isAddTorrentPaused
;
711 CachedSettingValue
<TorrentContentLayout
> m_torrentContentLayout
;
712 CachedSettingValue
<bool> m_isAppendExtensionEnabled
;
713 CachedSettingValue
<int> m_refreshInterval
;
714 CachedSettingValue
<bool> m_isPreallocationEnabled
;
715 CachedSettingValue
<QString
> m_torrentExportDirectory
;
716 CachedSettingValue
<QString
> m_finishedTorrentExportDirectory
;
717 CachedSettingValue
<int> m_globalDownloadSpeedLimit
;
718 CachedSettingValue
<int> m_globalUploadSpeedLimit
;
719 CachedSettingValue
<int> m_altGlobalDownloadSpeedLimit
;
720 CachedSettingValue
<int> m_altGlobalUploadSpeedLimit
;
721 CachedSettingValue
<bool> m_isAltGlobalSpeedLimitEnabled
;
722 CachedSettingValue
<bool> m_isBandwidthSchedulerEnabled
;
723 CachedSettingValue
<int> m_saveResumeDataInterval
;
724 CachedSettingValue
<int> m_port
;
725 CachedSettingValue
<QString
> m_networkInterface
;
726 CachedSettingValue
<QString
> m_networkInterfaceName
;
727 CachedSettingValue
<QString
> m_networkInterfaceAddress
;
728 CachedSettingValue
<int> m_encryption
;
729 CachedSettingValue
<bool> m_isProxyPeerConnectionsEnabled
;
730 CachedSettingValue
<ChokingAlgorithm
> m_chokingAlgorithm
;
731 CachedSettingValue
<SeedChokingAlgorithm
> m_seedChokingAlgorithm
;
732 CachedSettingValue
<QVariantMap
> m_storedCategories
;
733 CachedSettingValue
<QStringList
> m_storedTags
;
734 CachedSettingValue
<int> m_maxRatioAction
;
735 CachedSettingValue
<QString
> m_defaultSavePath
;
736 CachedSettingValue
<QString
> m_tempPath
;
737 CachedSettingValue
<bool> m_isSubcategoriesEnabled
;
738 CachedSettingValue
<bool> m_isTempPathEnabled
;
739 CachedSettingValue
<bool> m_isAutoTMMDisabledByDefault
;
740 CachedSettingValue
<bool> m_isDisableAutoTMMWhenCategoryChanged
;
741 CachedSettingValue
<bool> m_isDisableAutoTMMWhenDefaultSavePathChanged
;
742 CachedSettingValue
<bool> m_isDisableAutoTMMWhenCategorySavePathChanged
;
743 CachedSettingValue
<bool> m_isTrackerEnabled
;
744 CachedSettingValue
<int> m_peerTurnover
;
745 CachedSettingValue
<int> m_peerTurnoverCutoff
;
746 CachedSettingValue
<int> m_peerTurnoverInterval
;
747 CachedSettingValue
<QStringList
> m_bannedIPs
;
748 CachedSettingValue
<ResumeDataStorageType
> m_resumeDataStorageType
;
749 #if defined(Q_OS_WIN)
750 CachedSettingValue
<OSMemoryPriority
> m_OSMemoryPriority
;
753 // Order is important. This needs to be declared after its CachedSettingsValue
754 // counterpart, because it uses it for initialization in the constructor
755 // initialization list.
756 const bool m_wasPexEnabled
= m_isPeXEnabled
;
758 int m_numResumeData
= 0;
759 int m_extraLimit
= 0;
760 QVector
<TrackerEntry
> m_additionalTrackerList
;
762 bool m_refreshEnqueued
= false;
763 QTimer
*m_seedingLimitTimer
= nullptr;
764 QTimer
*m_resumeDataTimer
= nullptr;
765 Statistics
*m_statistics
= nullptr;
767 QPointer
<FilterParserThread
> m_filterParser
;
768 QPointer
<BandwidthScheduler
> m_bwScheduler
;
770 QPointer
<Tracker
> m_tracker
;
772 QThread
*m_ioThread
= nullptr;
773 ResumeDataStorage
*m_resumeDataStorage
= nullptr;
774 FileSearcher
*m_fileSearcher
= nullptr;
776 QSet
<TorrentID
> m_downloadedMetadata
;
778 QHash
<TorrentID
, TorrentImpl
*> m_torrents
;
779 QHash
<TorrentID
, LoadTorrentParams
> m_loadingTorrents
;
780 QHash
<QString
, AddTorrentParams
> m_downloadedTorrents
;
781 QHash
<TorrentID
, RemovingTorrentData
> m_removingTorrents
;
782 QSet
<TorrentID
> m_needSaveResumeDataTorrents
;
783 QStringMap m_categories
;
784 QSet
<QString
> m_tags
;
786 // I/O errored torrents
787 QSet
<TorrentID
> m_recentErroredTorrents
;
788 QTimer
*m_recentErroredTorrentsTimer
= nullptr;
790 SessionMetricIndices m_metricIndices
;
791 lt::time_point m_statsLastTimestamp
= lt::clock_type::now();
793 SessionStatus m_status
;
794 CacheStatus m_cacheStatus
;
795 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
796 QNetworkConfigurationManager
*m_networkManager
= nullptr;
799 QList
<MoveStorageJob
> m_moveStorageQueue
;
801 QString m_lastExternalIP
;
803 static Session
*m_instance
;