2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2015-2022 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/fwd.hpp>
37 #include <libtorrent/portmap.hpp>
38 #include <libtorrent/torrent_handle.hpp>
40 #include <QtContainerFwd>
41 #include <QElapsedTimer>
47 #include "base/path.h"
48 #include "base/settingvalue.h"
49 #include "base/types.h"
50 #include "base/utils/thread.h"
51 #include "addtorrentparams.h"
52 #include "cachestatus.h"
53 #include "categoryoptions.h"
55 #include "sessionstatus.h"
56 #include "torrentinfo.h"
57 #include "trackerentry.h"
59 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
60 class QNetworkConfiguration
;
61 class QNetworkConfigurationManager
;
69 class BandwidthScheduler
;
71 class FilterParserThread
;
72 class NativeSessionExtension
;
76 struct DownloadResult
;
83 class ResumeDataStorage
;
87 struct LoadTorrentParams
;
89 enum class MoveStorageMode
;
91 struct SessionMetricIndices
95 int hasIncomingConnections
= -1;
96 int sentPayloadBytes
= -1;
97 int recvPayloadBytes
= -1;
100 int sentIPOverheadBytes
= -1;
101 int recvIPOverheadBytes
= -1;
102 int sentTrackerBytes
= -1;
103 int recvTrackerBytes
= -1;
104 int recvRedundantBytes
= -1;
105 int recvFailedBytes
= -1;
110 int numPeersConnected
= -1;
111 int numPeersUpDisk
= -1;
112 int numPeersDownDisk
= -1;
118 int dhtBytesOut
= -1;
124 int diskBlocksInUse
= -1;
125 int numBlocksRead
= -1;
126 #ifndef QBT_USES_LIBTORRENT2
127 int numBlocksCacheHits
= -1;
132 int queuedDiskJobs
= -1;
133 int diskJobTime
= -1;
137 class SessionImpl final
: public Session
140 Q_DISABLE_COPY_MOVE(SessionImpl
)
143 Path
savePath() const override
;
144 void setSavePath(const Path
&path
) override
;
145 Path
downloadPath() const override
;
146 void setDownloadPath(const Path
&path
) override
;
147 bool isDownloadPathEnabled() const override
;
148 void setDownloadPathEnabled(bool enabled
) override
;
150 QStringList
categories() const override
;
151 CategoryOptions
categoryOptions(const QString
&categoryName
) const override
;
152 Path
categorySavePath(const QString
&categoryName
) const override
;
153 Path
categoryDownloadPath(const QString
&categoryName
) const override
;
154 bool addCategory(const QString
&name
, const CategoryOptions
&options
= {}) override
;
155 bool editCategory(const QString
&name
, const CategoryOptions
&options
) override
;
156 bool removeCategory(const QString
&name
) override
;
157 bool isSubcategoriesEnabled() const override
;
158 void setSubcategoriesEnabled(bool value
) override
;
159 bool useCategoryPathsInManualMode() const override
;
160 void setUseCategoryPathsInManualMode(bool value
) override
;
162 QSet
<QString
> tags() const override
;
163 bool hasTag(const QString
&tag
) const override
;
164 bool addTag(const QString
&tag
) override
;
165 bool removeTag(const QString
&tag
) override
;
167 bool isAutoTMMDisabledByDefault() const override
;
168 void setAutoTMMDisabledByDefault(bool value
) override
;
169 bool isDisableAutoTMMWhenCategoryChanged() const override
;
170 void setDisableAutoTMMWhenCategoryChanged(bool value
) override
;
171 bool isDisableAutoTMMWhenDefaultSavePathChanged() const override
;
172 void setDisableAutoTMMWhenDefaultSavePathChanged(bool value
) override
;
173 bool isDisableAutoTMMWhenCategorySavePathChanged() const override
;
174 void setDisableAutoTMMWhenCategorySavePathChanged(bool value
) override
;
176 qreal
globalMaxRatio() const override
;
177 void setGlobalMaxRatio(qreal ratio
) override
;
178 int globalMaxSeedingMinutes() const override
;
179 void setGlobalMaxSeedingMinutes(int minutes
) override
;
180 bool isDHTEnabled() const override
;
181 void setDHTEnabled(bool enabled
) override
;
182 bool isLSDEnabled() const override
;
183 void setLSDEnabled(bool enabled
) override
;
184 bool isPeXEnabled() const override
;
185 void setPeXEnabled(bool enabled
) override
;
186 bool isAddTorrentToQueueTop() const override
;
187 void setAddTorrentToQueueTop(bool value
) override
;
188 bool isAddTorrentPaused() const override
;
189 void setAddTorrentPaused(bool value
) override
;
190 Torrent::StopCondition
torrentStopCondition() const override
;
191 void setTorrentStopCondition(Torrent::StopCondition stopCondition
) override
;
192 TorrentContentLayout
torrentContentLayout() const override
;
193 void setTorrentContentLayout(TorrentContentLayout value
) override
;
194 bool isTrackerEnabled() const override
;
195 void setTrackerEnabled(bool enabled
) override
;
196 bool isAppendExtensionEnabled() const override
;
197 void setAppendExtensionEnabled(bool enabled
) override
;
198 int refreshInterval() const override
;
199 void setRefreshInterval(int value
) override
;
200 bool isPreallocationEnabled() const override
;
201 void setPreallocationEnabled(bool enabled
) override
;
202 Path
torrentExportDirectory() const override
;
203 void setTorrentExportDirectory(const Path
&path
) override
;
204 Path
finishedTorrentExportDirectory() const override
;
205 void setFinishedTorrentExportDirectory(const Path
&path
) override
;
207 int globalDownloadSpeedLimit() const override
;
208 void setGlobalDownloadSpeedLimit(int limit
) override
;
209 int globalUploadSpeedLimit() const override
;
210 void setGlobalUploadSpeedLimit(int limit
) override
;
211 int altGlobalDownloadSpeedLimit() const override
;
212 void setAltGlobalDownloadSpeedLimit(int limit
) override
;
213 int altGlobalUploadSpeedLimit() const override
;
214 void setAltGlobalUploadSpeedLimit(int limit
) override
;
215 int downloadSpeedLimit() const override
;
216 void setDownloadSpeedLimit(int limit
) override
;
217 int uploadSpeedLimit() const override
;
218 void setUploadSpeedLimit(int limit
) override
;
219 bool isAltGlobalSpeedLimitEnabled() const override
;
220 void setAltGlobalSpeedLimitEnabled(bool enabled
) override
;
221 bool isBandwidthSchedulerEnabled() const override
;
222 void setBandwidthSchedulerEnabled(bool enabled
) override
;
224 bool isPerformanceWarningEnabled() const override
;
225 void setPerformanceWarningEnabled(bool enable
) override
;
226 int saveResumeDataInterval() const override
;
227 void setSaveResumeDataInterval(int value
) override
;
228 int port() const override
;
229 void setPort(int port
) override
;
230 QString
networkInterface() const override
;
231 void setNetworkInterface(const QString
&iface
) override
;
232 QString
networkInterfaceName() const override
;
233 void setNetworkInterfaceName(const QString
&name
) override
;
234 QString
networkInterfaceAddress() const override
;
235 void setNetworkInterfaceAddress(const QString
&address
) override
;
236 int encryption() const override
;
237 void setEncryption(int state
) override
;
238 int maxActiveCheckingTorrents() const override
;
239 void setMaxActiveCheckingTorrents(int val
) override
;
240 bool isI2PEnabled() const override
;
241 void setI2PEnabled(bool enabled
) override
;
242 QString
I2PAddress() const override
;
243 void setI2PAddress(const QString
&address
) override
;
244 int I2PPort() const override
;
245 void setI2PPort(int port
) override
;
246 bool I2PMixedMode() const override
;
247 void setI2PMixedMode(bool enabled
) override
;
248 bool isProxyPeerConnectionsEnabled() const override
;
249 void setProxyPeerConnectionsEnabled(bool enabled
) override
;
250 ChokingAlgorithm
chokingAlgorithm() const override
;
251 void setChokingAlgorithm(ChokingAlgorithm mode
) override
;
252 SeedChokingAlgorithm
seedChokingAlgorithm() const override
;
253 void setSeedChokingAlgorithm(SeedChokingAlgorithm mode
) override
;
254 bool isAddTrackersEnabled() const override
;
255 void setAddTrackersEnabled(bool enabled
) override
;
256 QString
additionalTrackers() const override
;
257 void setAdditionalTrackers(const QString
&trackers
) override
;
258 bool isIPFilteringEnabled() const override
;
259 void setIPFilteringEnabled(bool enabled
) override
;
260 Path
IPFilterFile() const override
;
261 void setIPFilterFile(const Path
&path
) override
;
262 bool announceToAllTrackers() const override
;
263 void setAnnounceToAllTrackers(bool val
) override
;
264 bool announceToAllTiers() const override
;
265 void setAnnounceToAllTiers(bool val
) override
;
266 int peerTurnover() const override
;
267 void setPeerTurnover(int val
) override
;
268 int peerTurnoverCutoff() const override
;
269 void setPeerTurnoverCutoff(int val
) override
;
270 int peerTurnoverInterval() const override
;
271 void setPeerTurnoverInterval(int val
) override
;
272 int requestQueueSize() const override
;
273 void setRequestQueueSize(int val
) override
;
274 int asyncIOThreads() const override
;
275 void setAsyncIOThreads(int num
) override
;
276 int hashingThreads() const override
;
277 void setHashingThreads(int num
) override
;
278 int filePoolSize() const override
;
279 void setFilePoolSize(int size
) override
;
280 int checkingMemUsage() const override
;
281 void setCheckingMemUsage(int size
) override
;
282 int diskCacheSize() const override
;
283 void setDiskCacheSize(int size
) override
;
284 int diskCacheTTL() const override
;
285 void setDiskCacheTTL(int ttl
) override
;
286 qint64
diskQueueSize() const override
;
287 void setDiskQueueSize(qint64 size
) override
;
288 DiskIOType
diskIOType() const override
;
289 void setDiskIOType(DiskIOType type
) override
;
290 DiskIOReadMode
diskIOReadMode() const override
;
291 void setDiskIOReadMode(DiskIOReadMode mode
) override
;
292 DiskIOWriteMode
diskIOWriteMode() const override
;
293 void setDiskIOWriteMode(DiskIOWriteMode mode
) override
;
294 bool isCoalesceReadWriteEnabled() const override
;
295 void setCoalesceReadWriteEnabled(bool enabled
) override
;
296 bool usePieceExtentAffinity() const override
;
297 void setPieceExtentAffinity(bool enabled
) override
;
298 bool isSuggestModeEnabled() const override
;
299 void setSuggestMode(bool mode
) override
;
300 int sendBufferWatermark() const override
;
301 void setSendBufferWatermark(int value
) override
;
302 int sendBufferLowWatermark() const override
;
303 void setSendBufferLowWatermark(int value
) override
;
304 int sendBufferWatermarkFactor() const override
;
305 void setSendBufferWatermarkFactor(int value
) override
;
306 int connectionSpeed() const override
;
307 void setConnectionSpeed(int value
) override
;
308 int socketBacklogSize() const override
;
309 void setSocketBacklogSize(int value
) override
;
310 bool isAnonymousModeEnabled() const override
;
311 void setAnonymousModeEnabled(bool enabled
) override
;
312 bool isQueueingSystemEnabled() const override
;
313 void setQueueingSystemEnabled(bool enabled
) override
;
314 bool ignoreSlowTorrentsForQueueing() const override
;
315 void setIgnoreSlowTorrentsForQueueing(bool ignore
) override
;
316 int downloadRateForSlowTorrents() const override
;
317 void setDownloadRateForSlowTorrents(int rateInKibiBytes
) override
;
318 int uploadRateForSlowTorrents() const override
;
319 void setUploadRateForSlowTorrents(int rateInKibiBytes
) override
;
320 int slowTorrentsInactivityTimer() const override
;
321 void setSlowTorrentsInactivityTimer(int timeInSeconds
) override
;
322 int outgoingPortsMin() const override
;
323 void setOutgoingPortsMin(int min
) override
;
324 int outgoingPortsMax() const override
;
325 void setOutgoingPortsMax(int max
) override
;
326 int UPnPLeaseDuration() const override
;
327 void setUPnPLeaseDuration(int duration
) override
;
328 int peerToS() const override
;
329 void setPeerToS(int value
) override
;
330 bool ignoreLimitsOnLAN() const override
;
331 void setIgnoreLimitsOnLAN(bool ignore
) override
;
332 bool includeOverheadInLimits() const override
;
333 void setIncludeOverheadInLimits(bool include
) override
;
334 QString
announceIP() const override
;
335 void setAnnounceIP(const QString
&ip
) override
;
336 int maxConcurrentHTTPAnnounces() const override
;
337 void setMaxConcurrentHTTPAnnounces(int value
) override
;
338 bool isReannounceWhenAddressChangedEnabled() const override
;
339 void setReannounceWhenAddressChangedEnabled(bool enabled
) override
;
340 void reannounceToAllTrackers() const override
;
341 int stopTrackerTimeout() const override
;
342 void setStopTrackerTimeout(int value
) override
;
343 int maxConnections() const override
;
344 void setMaxConnections(int max
) override
;
345 int maxConnectionsPerTorrent() const override
;
346 void setMaxConnectionsPerTorrent(int max
) override
;
347 int maxUploads() const override
;
348 void setMaxUploads(int max
) override
;
349 int maxUploadsPerTorrent() const override
;
350 void setMaxUploadsPerTorrent(int max
) override
;
351 int maxActiveDownloads() const override
;
352 void setMaxActiveDownloads(int max
) override
;
353 int maxActiveUploads() const override
;
354 void setMaxActiveUploads(int max
) override
;
355 int maxActiveTorrents() const override
;
356 void setMaxActiveTorrents(int max
) override
;
357 BTProtocol
btProtocol() const override
;
358 void setBTProtocol(BTProtocol protocol
) override
;
359 bool isUTPRateLimited() const override
;
360 void setUTPRateLimited(bool limited
) override
;
361 MixedModeAlgorithm
utpMixedMode() const override
;
362 void setUtpMixedMode(MixedModeAlgorithm mode
) override
;
363 bool isIDNSupportEnabled() const override
;
364 void setIDNSupportEnabled(bool enabled
) override
;
365 bool multiConnectionsPerIpEnabled() const override
;
366 void setMultiConnectionsPerIpEnabled(bool enabled
) override
;
367 bool validateHTTPSTrackerCertificate() const override
;
368 void setValidateHTTPSTrackerCertificate(bool enabled
) override
;
369 bool isSSRFMitigationEnabled() const override
;
370 void setSSRFMitigationEnabled(bool enabled
) override
;
371 bool blockPeersOnPrivilegedPorts() const override
;
372 void setBlockPeersOnPrivilegedPorts(bool enabled
) override
;
373 bool isTrackerFilteringEnabled() const override
;
374 void setTrackerFilteringEnabled(bool enabled
) override
;
375 bool isExcludedFileNamesEnabled() const override
;
376 void setExcludedFileNamesEnabled(const bool enabled
) override
;
377 QStringList
excludedFileNames() const override
;
378 void setExcludedFileNames(const QStringList
&newList
) override
;
379 bool isFilenameExcluded(const QString
&fileName
) const override
;
380 QStringList
bannedIPs() const override
;
381 void setBannedIPs(const QStringList
&newList
) override
;
382 ResumeDataStorageType
resumeDataStorageType() const override
;
383 void setResumeDataStorageType(ResumeDataStorageType type
) override
;
385 bool isRestored() const override
;
387 Torrent
*getTorrent(const TorrentID
&id
) const override
;
388 Torrent
*findTorrent(const InfoHash
&infoHash
) const override
;
389 QVector
<Torrent
*> torrents() const override
;
390 qsizetype
torrentsCount() const override
;
391 const SessionStatus
&status() const override
;
392 const CacheStatus
&cacheStatus() const override
;
393 bool isListening() const override
;
395 MaxRatioAction
maxRatioAction() const override
;
396 void setMaxRatioAction(MaxRatioAction act
) override
;
398 void banIP(const QString
&ip
) override
;
400 bool isKnownTorrent(const InfoHash
&infoHash
) const override
;
401 bool addTorrent(const QString
&source
, const AddTorrentParams
¶ms
= {}) override
;
402 bool addTorrent(const MagnetUri
&magnetUri
, const AddTorrentParams
¶ms
= {}) override
;
403 bool addTorrent(const TorrentInfo
&torrentInfo
, const AddTorrentParams
¶ms
= {}) override
;
404 bool deleteTorrent(const TorrentID
&id
, DeleteOption deleteOption
= DeleteTorrent
) override
;
405 bool downloadMetadata(const MagnetUri
&magnetUri
) override
;
406 bool cancelDownloadMetadata(const TorrentID
&id
) override
;
408 void recursiveTorrentDownload(const TorrentID
&id
) override
;
409 void increaseTorrentsQueuePos(const QVector
<TorrentID
> &ids
) override
;
410 void decreaseTorrentsQueuePos(const QVector
<TorrentID
> &ids
) override
;
411 void topTorrentsQueuePos(const QVector
<TorrentID
> &ids
) override
;
412 void bottomTorrentsQueuePos(const QVector
<TorrentID
> &ids
) override
;
415 void handleTorrentNeedSaveResumeData(const TorrentImpl
*torrent
);
416 void handleTorrentSaveResumeDataRequested(const TorrentImpl
*torrent
);
417 void handleTorrentSaveResumeDataFailed(const TorrentImpl
*torrent
);
418 void handleTorrentShareLimitChanged(TorrentImpl
*const torrent
);
419 void handleTorrentNameChanged(TorrentImpl
*const torrent
);
420 void handleTorrentSavePathChanged(TorrentImpl
*const torrent
);
421 void handleTorrentCategoryChanged(TorrentImpl
*const torrent
, const QString
&oldCategory
);
422 void handleTorrentTagAdded(TorrentImpl
*const torrent
, const QString
&tag
);
423 void handleTorrentTagRemoved(TorrentImpl
*const torrent
, const QString
&tag
);
424 void handleTorrentSavingModeChanged(TorrentImpl
*const torrent
);
425 void handleTorrentMetadataReceived(TorrentImpl
*const torrent
);
426 void handleTorrentPaused(TorrentImpl
*const torrent
);
427 void handleTorrentResumed(TorrentImpl
*const torrent
);
428 void handleTorrentChecked(TorrentImpl
*const torrent
);
429 void handleTorrentFinished(TorrentImpl
*const torrent
);
430 void handleTorrentTrackersAdded(TorrentImpl
*const torrent
, const QVector
<TrackerEntry
> &newTrackers
);
431 void handleTorrentTrackersRemoved(TorrentImpl
*const torrent
, const QStringList
&deletedTrackers
);
432 void handleTorrentTrackersChanged(TorrentImpl
*const torrent
);
433 void handleTorrentUrlSeedsAdded(TorrentImpl
*const torrent
, const QVector
<QUrl
> &newUrlSeeds
);
434 void handleTorrentUrlSeedsRemoved(TorrentImpl
*const torrent
, const QVector
<QUrl
> &urlSeeds
);
435 void handleTorrentResumeDataReady(TorrentImpl
*const torrent
, const LoadTorrentParams
&data
);
436 void handleTorrentInfoHashChanged(TorrentImpl
*torrent
, const InfoHash
&prevInfoHash
);
438 bool addMoveTorrentStorageJob(TorrentImpl
*torrent
, const Path
&newPath
, MoveStorageMode mode
);
440 void findIncompleteFiles(const TorrentInfo
&torrentInfo
, const Path
&savePath
441 , const Path
&downloadPath
, const PathList
&filePaths
= {}) const;
443 void enablePortMapping();
444 void disablePortMapping();
445 void addMappedPorts(const QSet
<quint16
> &ports
);
446 void removeMappedPorts(const QSet
<quint16
> &ports
);
448 template <typename Func
>
449 void invoke(Func
&&func
)
451 QMetaObject::invokeMethod(this, std::forward
<Func
>(func
), Qt::QueuedConnection
);
454 void invokeAsync(std::function
<void ()> func
);
457 void configureDeferred();
459 void enqueueRefresh();
460 void processShareLimits();
461 void generateResumeData();
462 void handleIPFilterParsed(int ruleCount
);
463 void handleIPFilterError();
464 void handleDownloadFinished(const Net::DownloadResult
&result
);
465 void fileSearchFinished(const TorrentID
&id
, const Path
&savePath
, const PathList
&fileNames
);
467 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
468 // Session reconfiguration triggers
469 void networkOnlineStateChanged(bool online
);
470 void networkConfigurationChange(const QNetworkConfiguration
&);
474 struct ResumeSessionContext
;
476 struct MoveStorageJob
478 lt::torrent_handle torrentHandle
;
480 MoveStorageMode mode
;
483 struct RemovingTorrentData
487 DeleteOption deleteOption
;
490 explicit SessionImpl(QObject
*parent
= nullptr);
493 bool hasPerTorrentRatioLimit() const;
494 bool hasPerTorrentSeedingTimeLimit() const;
496 // Session configuration
497 Q_INVOKABLE
void configure();
498 void configureComponents();
499 void initializeNativeSession();
500 lt::settings_pack
loadLTSettings() const;
501 void applyNetworkInterfacesSettings(lt::settings_pack
&settingsPack
) const;
502 void configurePeerClasses();
504 void applyBandwidthLimits();
505 void processBannedIPs(lt::ip_filter
&filter
);
506 QStringList
getListeningIPs() const;
507 void configureListeningInterface();
508 void enableTracker(bool enable
);
509 void enableBandwidthScheduler();
510 void populateAdditionalTrackers();
511 void enableIPFilter();
512 void disableIPFilter();
513 void processTrackerStatuses();
514 void populateExcludedFileNamesRegExpList();
515 void prepareStartup();
516 void handleLoadedResumeData(ResumeSessionContext
*context
);
517 void processNextResumeData(ResumeSessionContext
*context
);
518 void endStartup(ResumeSessionContext
*context
);
520 LoadTorrentParams
initLoadTorrentParams(const AddTorrentParams
&addTorrentParams
);
521 bool addTorrent_impl(const std::variant
<MagnetUri
, TorrentInfo
> &source
, const AddTorrentParams
&addTorrentParams
);
523 void updateSeedingLimitTimer();
524 void exportTorrentFile(const Torrent
*torrent
, const Path
&folderPath
);
526 void handleAlert(const lt::alert
*a
);
527 void handleAddTorrentAlerts(const std::vector
<lt::alert
*> &alerts
);
528 void dispatchTorrentAlert(const lt::torrent_alert
*a
);
529 void handleStateUpdateAlert(const lt::state_update_alert
*p
);
530 void handleMetadataReceivedAlert(const lt::metadata_received_alert
*p
);
531 void handleFileErrorAlert(const lt::file_error_alert
*p
);
532 void handleTorrentRemovedAlert(const lt::torrent_removed_alert
*p
);
533 void handleTorrentDeletedAlert(const lt::torrent_deleted_alert
*p
);
534 void handleTorrentDeleteFailedAlert(const lt::torrent_delete_failed_alert
*p
);
535 void handlePortmapWarningAlert(const lt::portmap_error_alert
*p
);
536 void handlePortmapAlert(const lt::portmap_alert
*p
);
537 void handlePeerBlockedAlert(const lt::peer_blocked_alert
*p
);
538 void handlePeerBanAlert(const lt::peer_ban_alert
*p
);
539 void handleUrlSeedAlert(const lt::url_seed_alert
*p
);
540 void handleListenSucceededAlert(const lt::listen_succeeded_alert
*p
);
541 void handleListenFailedAlert(const lt::listen_failed_alert
*p
);
542 void handleExternalIPAlert(const lt::external_ip_alert
*p
);
543 void handleSessionStatsAlert(const lt::session_stats_alert
*p
);
544 void handleAlertsDroppedAlert(const lt::alerts_dropped_alert
*p
) const;
545 void handleStorageMovedAlert(const lt::storage_moved_alert
*p
);
546 void handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert
*p
);
547 void handleSocks5Alert(const lt::socks5_alert
*p
) const;
548 void handleTrackerAlert(const lt::tracker_alert
*a
);
549 #ifdef QBT_USES_LIBTORRENT2
550 void handleTorrentConflictAlert(const lt::torrent_conflict_alert
*a
);
553 TorrentImpl
*createTorrent(const lt::torrent_handle
&nativeHandle
, const LoadTorrentParams
¶ms
);
555 void saveResumeData();
556 void saveTorrentsQueue();
557 void removeTorrentsQueue();
559 std::vector
<lt::alert
*> getPendingAlerts(lt::time_duration time
= lt::time_duration::zero()) const;
561 void moveTorrentStorage(const MoveStorageJob
&job
) const;
562 void handleMoveTorrentStorageJobFinished(const Path
&newPath
);
564 void loadCategories();
565 void storeCategories() const;
566 void upgradeCategories();
568 void saveStatistics() const;
569 void loadStatistics();
572 lt::session
*m_nativeSession
= nullptr;
573 NativeSessionExtension
*m_nativeSessionExtension
= nullptr;
575 bool m_deferredConfigureScheduled
= false;
576 bool m_IPFilteringConfigured
= false;
577 mutable bool m_listenInterfaceConfigured
= false;
579 CachedSettingValue
<bool> m_isDHTEnabled
;
580 CachedSettingValue
<bool> m_isLSDEnabled
;
581 CachedSettingValue
<bool> m_isPeXEnabled
;
582 CachedSettingValue
<bool> m_isIPFilteringEnabled
;
583 CachedSettingValue
<bool> m_isTrackerFilteringEnabled
;
584 CachedSettingValue
<Path
> m_IPFilterFile
;
585 CachedSettingValue
<bool> m_announceToAllTrackers
;
586 CachedSettingValue
<bool> m_announceToAllTiers
;
587 CachedSettingValue
<int> m_asyncIOThreads
;
588 CachedSettingValue
<int> m_hashingThreads
;
589 CachedSettingValue
<int> m_filePoolSize
;
590 CachedSettingValue
<int> m_checkingMemUsage
;
591 CachedSettingValue
<int> m_diskCacheSize
;
592 CachedSettingValue
<int> m_diskCacheTTL
;
593 CachedSettingValue
<qint64
> m_diskQueueSize
;
594 CachedSettingValue
<DiskIOType
> m_diskIOType
;
595 CachedSettingValue
<DiskIOReadMode
> m_diskIOReadMode
;
596 CachedSettingValue
<DiskIOWriteMode
> m_diskIOWriteMode
;
597 CachedSettingValue
<bool> m_coalesceReadWriteEnabled
;
598 CachedSettingValue
<bool> m_usePieceExtentAffinity
;
599 CachedSettingValue
<bool> m_isSuggestMode
;
600 CachedSettingValue
<int> m_sendBufferWatermark
;
601 CachedSettingValue
<int> m_sendBufferLowWatermark
;
602 CachedSettingValue
<int> m_sendBufferWatermarkFactor
;
603 CachedSettingValue
<int> m_connectionSpeed
;
604 CachedSettingValue
<int> m_socketBacklogSize
;
605 CachedSettingValue
<bool> m_isAnonymousModeEnabled
;
606 CachedSettingValue
<bool> m_isQueueingEnabled
;
607 CachedSettingValue
<int> m_maxActiveDownloads
;
608 CachedSettingValue
<int> m_maxActiveUploads
;
609 CachedSettingValue
<int> m_maxActiveTorrents
;
610 CachedSettingValue
<bool> m_ignoreSlowTorrentsForQueueing
;
611 CachedSettingValue
<int> m_downloadRateForSlowTorrents
;
612 CachedSettingValue
<int> m_uploadRateForSlowTorrents
;
613 CachedSettingValue
<int> m_slowTorrentsInactivityTimer
;
614 CachedSettingValue
<int> m_outgoingPortsMin
;
615 CachedSettingValue
<int> m_outgoingPortsMax
;
616 CachedSettingValue
<int> m_UPnPLeaseDuration
;
617 CachedSettingValue
<int> m_peerToS
;
618 CachedSettingValue
<bool> m_ignoreLimitsOnLAN
;
619 CachedSettingValue
<bool> m_includeOverheadInLimits
;
620 CachedSettingValue
<QString
> m_announceIP
;
621 CachedSettingValue
<int> m_maxConcurrentHTTPAnnounces
;
622 CachedSettingValue
<bool> m_isReannounceWhenAddressChangedEnabled
;
623 CachedSettingValue
<int> m_stopTrackerTimeout
;
624 CachedSettingValue
<int> m_maxConnections
;
625 CachedSettingValue
<int> m_maxUploads
;
626 CachedSettingValue
<int> m_maxConnectionsPerTorrent
;
627 CachedSettingValue
<int> m_maxUploadsPerTorrent
;
628 CachedSettingValue
<BTProtocol
> m_btProtocol
;
629 CachedSettingValue
<bool> m_isUTPRateLimited
;
630 CachedSettingValue
<MixedModeAlgorithm
> m_utpMixedMode
;
631 CachedSettingValue
<bool> m_IDNSupportEnabled
;
632 CachedSettingValue
<bool> m_multiConnectionsPerIpEnabled
;
633 CachedSettingValue
<bool> m_validateHTTPSTrackerCertificate
;
634 CachedSettingValue
<bool> m_SSRFMitigationEnabled
;
635 CachedSettingValue
<bool> m_blockPeersOnPrivilegedPorts
;
636 CachedSettingValue
<bool> m_isAddTrackersEnabled
;
637 CachedSettingValue
<QString
> m_additionalTrackers
;
638 CachedSettingValue
<qreal
> m_globalMaxRatio
;
639 CachedSettingValue
<int> m_globalMaxSeedingMinutes
;
640 CachedSettingValue
<bool> m_isAddTorrentToQueueTop
;
641 CachedSettingValue
<bool> m_isAddTorrentPaused
;
642 CachedSettingValue
<Torrent::StopCondition
> m_torrentStopCondition
;
643 CachedSettingValue
<TorrentContentLayout
> m_torrentContentLayout
;
644 CachedSettingValue
<bool> m_isAppendExtensionEnabled
;
645 CachedSettingValue
<int> m_refreshInterval
;
646 CachedSettingValue
<bool> m_isPreallocationEnabled
;
647 CachedSettingValue
<Path
> m_torrentExportDirectory
;
648 CachedSettingValue
<Path
> m_finishedTorrentExportDirectory
;
649 CachedSettingValue
<int> m_globalDownloadSpeedLimit
;
650 CachedSettingValue
<int> m_globalUploadSpeedLimit
;
651 CachedSettingValue
<int> m_altGlobalDownloadSpeedLimit
;
652 CachedSettingValue
<int> m_altGlobalUploadSpeedLimit
;
653 CachedSettingValue
<bool> m_isAltGlobalSpeedLimitEnabled
;
654 CachedSettingValue
<bool> m_isBandwidthSchedulerEnabled
;
655 CachedSettingValue
<bool> m_isPerformanceWarningEnabled
;
656 CachedSettingValue
<int> m_saveResumeDataInterval
;
657 CachedSettingValue
<int> m_port
;
658 CachedSettingValue
<QString
> m_networkInterface
;
659 CachedSettingValue
<QString
> m_networkInterfaceName
;
660 CachedSettingValue
<QString
> m_networkInterfaceAddress
;
661 CachedSettingValue
<int> m_encryption
;
662 CachedSettingValue
<int> m_maxActiveCheckingTorrents
;
663 CachedSettingValue
<bool> m_isProxyPeerConnectionsEnabled
;
664 CachedSettingValue
<ChokingAlgorithm
> m_chokingAlgorithm
;
665 CachedSettingValue
<SeedChokingAlgorithm
> m_seedChokingAlgorithm
;
666 CachedSettingValue
<QStringList
> m_storedTags
;
667 CachedSettingValue
<int> m_maxRatioAction
;
668 CachedSettingValue
<Path
> m_savePath
;
669 CachedSettingValue
<Path
> m_downloadPath
;
670 CachedSettingValue
<bool> m_isDownloadPathEnabled
;
671 CachedSettingValue
<bool> m_isSubcategoriesEnabled
;
672 CachedSettingValue
<bool> m_useCategoryPathsInManualMode
;
673 CachedSettingValue
<bool> m_isAutoTMMDisabledByDefault
;
674 CachedSettingValue
<bool> m_isDisableAutoTMMWhenCategoryChanged
;
675 CachedSettingValue
<bool> m_isDisableAutoTMMWhenDefaultSavePathChanged
;
676 CachedSettingValue
<bool> m_isDisableAutoTMMWhenCategorySavePathChanged
;
677 CachedSettingValue
<bool> m_isTrackerEnabled
;
678 CachedSettingValue
<int> m_peerTurnover
;
679 CachedSettingValue
<int> m_peerTurnoverCutoff
;
680 CachedSettingValue
<int> m_peerTurnoverInterval
;
681 CachedSettingValue
<int> m_requestQueueSize
;
682 CachedSettingValue
<bool> m_isExcludedFileNamesEnabled
;
683 CachedSettingValue
<QStringList
> m_excludedFileNames
;
684 CachedSettingValue
<QStringList
> m_bannedIPs
;
685 CachedSettingValue
<ResumeDataStorageType
> m_resumeDataStorageType
;
686 CachedSettingValue
<bool> m_isI2PEnabled
;
687 CachedSettingValue
<QString
> m_I2PAddress
;
688 CachedSettingValue
<int> m_I2PPort
;
689 CachedSettingValue
<bool> m_I2PMixedMode
;
691 bool m_isRestored
= false;
693 // Order is important. This needs to be declared after its CachedSettingsValue
694 // counterpart, because it uses it for initialization in the constructor
695 // initialization list.
696 const bool m_wasPexEnabled
= m_isPeXEnabled
;
698 int m_numResumeData
= 0;
699 QVector
<TrackerEntry
> m_additionalTrackerList
;
700 QVector
<QRegularExpression
> m_excludedFileNamesRegExpList
;
703 mutable QElapsedTimer m_statisticsLastUpdateTimer
;
704 mutable bool m_isStatisticsDirty
= false;
705 qint64 m_previouslyUploaded
= 0;
706 qint64 m_previouslyDownloaded
= 0;
708 bool m_torrentsQueueChanged
= false;
709 bool m_needSaveTorrentsQueue
= false;
710 bool m_refreshEnqueued
= false;
711 QTimer
*m_seedingLimitTimer
= nullptr;
712 QTimer
*m_resumeDataTimer
= nullptr;
714 QPointer
<FilterParserThread
> m_filterParser
;
715 QPointer
<BandwidthScheduler
> m_bwScheduler
;
717 QPointer
<Tracker
> m_tracker
;
719 Utils::Thread::UniquePtr m_ioThread
;
720 QThreadPool
*m_asyncWorker
= nullptr;
721 ResumeDataStorage
*m_resumeDataStorage
= nullptr;
722 FileSearcher
*m_fileSearcher
= nullptr;
724 QHash
<TorrentID
, lt::torrent_handle
> m_downloadedMetadata
;
726 QHash
<TorrentID
, TorrentImpl
*> m_torrents
;
727 QHash
<TorrentID
, TorrentImpl
*> m_hybridTorrentsByAltID
;
728 QHash
<TorrentID
, LoadTorrentParams
> m_loadingTorrents
;
729 QHash
<QString
, AddTorrentParams
> m_downloadedTorrents
;
730 QHash
<TorrentID
, RemovingTorrentData
> m_removingTorrents
;
731 QSet
<TorrentID
> m_needSaveResumeDataTorrents
;
732 QHash
<TorrentID
, TorrentID
> m_changedTorrentIDs
;
733 QMap
<QString
, CategoryOptions
> m_categories
;
734 QSet
<QString
> m_tags
;
736 // This field holds amounts of peers reported by trackers in their responses to announces
737 // (torrent.tracker_name.tracker_local_endpoint.num_peers)
738 QHash
<lt::torrent_handle
, QHash
<std::string
, QMap
<TrackerEntry::Endpoint
, int>>> m_updatedTrackerEntries
;
740 // I/O errored torrents
741 QSet
<TorrentID
> m_recentErroredTorrents
;
742 QTimer
*m_recentErroredTorrentsTimer
= nullptr;
744 SessionMetricIndices m_metricIndices
;
745 lt::time_point m_statsLastTimestamp
= lt::clock_type::now();
747 SessionStatus m_status
;
748 CacheStatus m_cacheStatus
;
749 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
750 QNetworkConfigurationManager
*m_networkManager
= nullptr;
753 QList
<MoveStorageJob
> m_moveStorageQueue
;
755 QString m_lastExternalIP
;
757 bool m_needUpgradeDownloadPath
= false;
759 // All port mapping related routines are invoked from working thread
760 // so there are no synchronization used. If multithreaded access is
761 // ever required, synchronization should also be provided.
762 bool m_isPortMappingEnabled
= false;
763 QHash
<quint16
, std::vector
<lt::port_mapping_t
>> m_mappedPorts
;
765 friend void Session::initInstance();
766 friend void Session::freeInstance();
767 friend Session
*Session::instance();
768 static Session
*m_instance
;