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