-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
session.h
739 lines (674 loc) · 31.1 KB
/
session.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*/
#ifndef BITTORRENT_SESSION_H
#define BITTORRENT_SESSION_H
#include <vector>
#include <libtorrent/fwd.hpp>
#include <QHash>
#include <QPointer>
#include <QSet>
#include <QVector>
#include "base/settingvalue.h"
#include "base/types.h"
#include "addtorrentparams.h"
#include "cachestatus.h"
#include "sessionstatus.h"
#include "torrentinfo.h"
class QFile;
class QNetworkConfiguration;
class QNetworkConfigurationManager;
class QString;
class QStringList;
class QThread;
class QTimer;
class QUrl;
class BandwidthScheduler;
class FilterParserThread;
class ResumeDataSavingManager;
class Statistics;
// These values should remain unchanged when adding new items
// so as not to break the existing user settings.
enum MaxRatioAction
{
Pause = 0,
Remove = 1,
DeleteFiles = 3,
EnableSuperSeeding = 2
};
enum DeleteOption
{
Torrent,
TorrentAndFiles
};
enum TorrentExportFolder
{
Regular,
Finished
};
namespace Net
{
struct DownloadResult;
}
namespace BitTorrent
{
class InfoHash;
class MagnetUri;
class TorrentHandle;
class Tracker;
class TrackerEntry;
struct CreateTorrentParams;
// Using `Q_ENUM_NS()` without a wrapper namespace in our case is not advised
// since `Q_NAMESPACE` cannot be used when the same namespace resides at different files.
// https://www.kdab.com/new-qt-5-8-meta-object-support-namespaces/#comment-143779
namespace SessionSettingsEnums
{
Q_NAMESPACE
enum class BTProtocol : int
{
Both = 0,
TCP = 1,
UTP = 2
};
Q_ENUM_NS(BTProtocol)
enum class ChokingAlgorithm : int
{
FixedSlots = 0,
RateBased = 1
};
Q_ENUM_NS(ChokingAlgorithm)
enum class MixedModeAlgorithm : int
{
TCP = 0,
Proportional = 1
};
Q_ENUM_NS(MixedModeAlgorithm)
enum class SeedChokingAlgorithm : int
{
RoundRobin = 0,
FastestUpload = 1,
AntiLeech = 2
};
Q_ENUM_NS(SeedChokingAlgorithm)
#if defined(Q_OS_WIN)
enum class OSMemoryPriority : int
{
Normal = 0,
BelowNormal = 1,
Medium = 2,
Low = 3,
VeryLow = 4
};
Q_ENUM_NS(OSMemoryPriority)
#endif
}
using namespace SessionSettingsEnums;
struct SessionMetricIndices
{
struct
{
int hasIncomingConnections = 0;
int sentPayloadBytes = 0;
int recvPayloadBytes = 0;
int sentBytes = 0;
int recvBytes = 0;
int sentIPOverheadBytes = 0;
int recvIPOverheadBytes = 0;
int sentTrackerBytes = 0;
int recvTrackerBytes = 0;
int recvRedundantBytes = 0;
int recvFailedBytes = 0;
} net;
struct
{
int numPeersConnected = 0;
int numPeersUpDisk = 0;
int numPeersDownDisk = 0;
} peer;
struct
{
int dhtBytesIn = 0;
int dhtBytesOut = 0;
int dhtNodes = 0;
} dht;
struct
{
int diskBlocksInUse = 0;
int numBlocksRead = 0;
int numBlocksCacheHits = 0;
int writeJobs = 0;
int readJobs = 0;
int hashJobs = 0;
int queuedDiskJobs = 0;
int diskJobTime = 0;
} disk;
};
class Session : public QObject
{
Q_OBJECT
Q_DISABLE_COPY(Session)
public:
static void initInstance();
static void freeInstance();
static Session *instance();
QString defaultSavePath() const;
void setDefaultSavePath(QString path);
QString tempPath() const;
void setTempPath(QString path);
bool isTempPathEnabled() const;
void setTempPathEnabled(bool enabled);
QString torrentTempPath(const TorrentInfo &torrentInfo) const;
static bool isValidCategoryName(const QString &name);
// returns category itself and all top level categories
static QStringList expandCategory(const QString &category);
QStringMap categories() const;
QString categorySavePath(const QString &categoryName) const;
bool addCategory(const QString &name, const QString &savePath = "");
bool editCategory(const QString &name, const QString &savePath);
bool removeCategory(const QString &name);
bool isSubcategoriesEnabled() const;
void setSubcategoriesEnabled(bool value);
static bool isValidTag(const QString &tag);
QSet<QString> tags() const;
bool hasTag(const QString &tag) const;
bool addTag(const QString &tag);
bool removeTag(const QString &tag);
// Torrent Management Mode subsystem (TMM)
//
// Each torrent can be either in Manual mode or in Automatic mode
// In Manual Mode various torrent properties are set explicitly(eg save path)
// In Automatic Mode various torrent properties are set implicitly(eg save path)
// based on the associated category.
// In Automatic Mode torrent save path can be changed in following cases:
// 1. Default save path changed
// 2. Torrent category save path changed
// 3. Torrent category changed
// (unless otherwise is specified)
bool isAutoTMMDisabledByDefault() const;
void setAutoTMMDisabledByDefault(bool value);
bool isDisableAutoTMMWhenCategoryChanged() const;
void setDisableAutoTMMWhenCategoryChanged(bool value);
bool isDisableAutoTMMWhenDefaultSavePathChanged() const;
void setDisableAutoTMMWhenDefaultSavePathChanged(bool value);
bool isDisableAutoTMMWhenCategorySavePathChanged() const;
void setDisableAutoTMMWhenCategorySavePathChanged(bool value);
qreal globalMaxRatio() const;
void setGlobalMaxRatio(qreal ratio);
int globalMaxSeedingMinutes() const;
void setGlobalMaxSeedingMinutes(int minutes);
bool isDHTEnabled() const;
void setDHTEnabled(bool enabled);
bool isLSDEnabled() const;
void setLSDEnabled(bool enabled);
bool isPeXEnabled() const;
void setPeXEnabled(bool enabled);
bool isAddTorrentPaused() const;
void setAddTorrentPaused(bool value);
bool isCreateTorrentSubfolder() const;
void setCreateTorrentSubfolder(bool value);
bool isTrackerEnabled() const;
void setTrackerEnabled(bool enabled);
bool isAppendExtensionEnabled() const;
void setAppendExtensionEnabled(bool enabled);
uint refreshInterval() const;
void setRefreshInterval(uint value);
bool isPreallocationEnabled() const;
void setPreallocationEnabled(bool enabled);
QString torrentExportDirectory() const;
void setTorrentExportDirectory(QString path);
QString finishedTorrentExportDirectory() const;
void setFinishedTorrentExportDirectory(QString path);
int globalDownloadSpeedLimit() const;
void setGlobalDownloadSpeedLimit(int limit);
int globalUploadSpeedLimit() const;
void setGlobalUploadSpeedLimit(int limit);
int altGlobalDownloadSpeedLimit() const;
void setAltGlobalDownloadSpeedLimit(int limit);
int altGlobalUploadSpeedLimit() const;
void setAltGlobalUploadSpeedLimit(int limit);
int downloadSpeedLimit() const;
void setDownloadSpeedLimit(int limit);
int uploadSpeedLimit() const;
void setUploadSpeedLimit(int limit);
bool isAltGlobalSpeedLimitEnabled() const;
void setAltGlobalSpeedLimitEnabled(bool enabled);
bool isBandwidthSchedulerEnabled() const;
void setBandwidthSchedulerEnabled(bool enabled);
uint saveResumeDataInterval() const;
void setSaveResumeDataInterval(uint value);
int port() const;
void setPort(int port);
bool useRandomPort() const;
void setUseRandomPort(bool value);
QString networkInterface() const;
void setNetworkInterface(const QString &interface);
QString networkInterfaceName() const;
void setNetworkInterfaceName(const QString &name);
QString networkInterfaceAddress() const;
void setNetworkInterfaceAddress(const QString &address);
int encryption() const;
void setEncryption(int state);
bool isProxyPeerConnectionsEnabled() const;
void setProxyPeerConnectionsEnabled(bool enabled);
ChokingAlgorithm chokingAlgorithm() const;
void setChokingAlgorithm(ChokingAlgorithm mode);
SeedChokingAlgorithm seedChokingAlgorithm() const;
void setSeedChokingAlgorithm(SeedChokingAlgorithm mode);
bool isAddTrackersEnabled() const;
void setAddTrackersEnabled(bool enabled);
QString additionalTrackers() const;
void setAdditionalTrackers(const QString &trackers);
bool isIPFilteringEnabled() const;
void setIPFilteringEnabled(bool enabled);
QString IPFilterFile() const;
void setIPFilterFile(QString path);
bool announceToAllTrackers() const;
void setAnnounceToAllTrackers(bool val);
bool announceToAllTiers() const;
void setAnnounceToAllTiers(bool val);
int asyncIOThreads() const;
void setAsyncIOThreads(int num);
int filePoolSize() const;
void setFilePoolSize(int size);
int checkingMemUsage() const;
void setCheckingMemUsage(int size);
int diskCacheSize() const;
void setDiskCacheSize(int size);
int diskCacheTTL() const;
void setDiskCacheTTL(int ttl);
bool useOSCache() const;
void setUseOSCache(bool use);
bool isCoalesceReadWriteEnabled() const;
void setCoalesceReadWriteEnabled(bool enabled);
bool usePieceExtentAffinity() const;
void setPieceExtentAffinity(bool enabled);
bool isSuggestModeEnabled() const;
void setSuggestMode(bool mode);
int sendBufferWatermark() const;
void setSendBufferWatermark(int value);
int sendBufferLowWatermark() const;
void setSendBufferLowWatermark(int value);
int sendBufferWatermarkFactor() const;
void setSendBufferWatermarkFactor(int value);
int socketBacklogSize() const;
void setSocketBacklogSize(int value);
bool isAnonymousModeEnabled() const;
void setAnonymousModeEnabled(bool enabled);
bool isQueueingSystemEnabled() const;
void setQueueingSystemEnabled(bool enabled);
bool ignoreSlowTorrentsForQueueing() const;
void setIgnoreSlowTorrentsForQueueing(bool ignore);
int downloadRateForSlowTorrents() const;
void setDownloadRateForSlowTorrents(int rateInKibiBytes);
int uploadRateForSlowTorrents() const;
void setUploadRateForSlowTorrents(int rateInKibiBytes);
int slowTorrentsInactivityTimer() const;
void setSlowTorrentsInactivityTimer(int timeInSeconds);
int outgoingPortsMin() const;
void setOutgoingPortsMin(int min);
int outgoingPortsMax() const;
void setOutgoingPortsMax(int max);
bool ignoreLimitsOnLAN() const;
void setIgnoreLimitsOnLAN(bool ignore);
bool includeOverheadInLimits() const;
void setIncludeOverheadInLimits(bool include);
QString announceIP() const;
void setAnnounceIP(const QString &ip);
int stopTrackerTimeout() const;
void setStopTrackerTimeout(int value);
bool isSuperSeedingEnabled() const;
void setSuperSeedingEnabled(bool enabled);
int maxConnections() const;
void setMaxConnections(int max);
int maxConnectionsPerTorrent() const;
void setMaxConnectionsPerTorrent(int max);
int maxUploads() const;
void setMaxUploads(int max);
int maxUploadsPerTorrent() const;
void setMaxUploadsPerTorrent(int max);
int maxActiveDownloads() const;
void setMaxActiveDownloads(int max);
int maxActiveUploads() const;
void setMaxActiveUploads(int max);
int maxActiveTorrents() const;
void setMaxActiveTorrents(int max);
BTProtocol btProtocol() const;
void setBTProtocol(BTProtocol protocol);
bool isUTPRateLimited() const;
void setUTPRateLimited(bool limited);
MixedModeAlgorithm utpMixedMode() const;
void setUtpMixedMode(MixedModeAlgorithm mode);
bool multiConnectionsPerIpEnabled() const;
void setMultiConnectionsPerIpEnabled(bool enabled);
bool isTrackerFilteringEnabled() const;
void setTrackerFilteringEnabled(bool enabled);
QStringList bannedIPs() const;
void setBannedIPs(const QStringList &newList);
#if defined(Q_OS_WIN)
OSMemoryPriority getOSMemoryPriority() const;
void setOSMemoryPriority(OSMemoryPriority priority);
#endif
void startUpTorrents();
TorrentHandle *findTorrent(const InfoHash &hash) const;
QHash<InfoHash, TorrentHandle *> torrents() const;
bool hasActiveTorrents() const;
bool hasUnfinishedTorrents() const;
bool hasRunningSeed() const;
const SessionStatus &status() const;
const CacheStatus &cacheStatus() const;
quint64 getAlltimeDL() const;
quint64 getAlltimeUL() const;
bool isListening() const;
MaxRatioAction maxRatioAction() const;
void setMaxRatioAction(MaxRatioAction act);
void banIP(const QString &ip);
bool isKnownTorrent(const InfoHash &hash) const;
bool addTorrent(const QString &source, const AddTorrentParams ¶ms = AddTorrentParams());
bool addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams ¶ms = AddTorrentParams());
bool deleteTorrent(const InfoHash &hash, DeleteOption deleteOption = Torrent);
bool loadMetadata(const MagnetUri &magnetUri);
bool cancelLoadMetadata(const InfoHash &hash);
void recursiveTorrentDownload(const InfoHash &hash);
void increaseTorrentsQueuePos(const QVector<InfoHash> &hashes);
void decreaseTorrentsQueuePos(const QVector<InfoHash> &hashes);
void topTorrentsQueuePos(const QVector<InfoHash> &hashes);
void bottomTorrentsQueuePos(const QVector<InfoHash> &hashes);
// TorrentHandle interface
void handleTorrentSaveResumeDataRequested(const TorrentHandle *torrent);
void handleTorrentShareLimitChanged(TorrentHandle *const torrent);
void handleTorrentNameChanged(TorrentHandle *const torrent);
void handleTorrentSavePathChanged(TorrentHandle *const torrent);
void handleTorrentCategoryChanged(TorrentHandle *const torrent, const QString &oldCategory);
void handleTorrentTagAdded(TorrentHandle *const torrent, const QString &tag);
void handleTorrentTagRemoved(TorrentHandle *const torrent, const QString &tag);
void handleTorrentSavingModeChanged(TorrentHandle *const torrent);
void handleTorrentMetadataReceived(TorrentHandle *const torrent);
void handleTorrentPaused(TorrentHandle *const torrent);
void handleTorrentResumed(TorrentHandle *const torrent);
void handleTorrentChecked(TorrentHandle *const torrent);
void handleTorrentFinished(TorrentHandle *const torrent);
void handleTorrentTrackersAdded(TorrentHandle *const torrent, const QVector<TrackerEntry> &newTrackers);
void handleTorrentTrackersRemoved(TorrentHandle *const torrent, const QVector<TrackerEntry> &deletedTrackers);
void handleTorrentTrackersChanged(TorrentHandle *const torrent);
void handleTorrentUrlSeedsAdded(TorrentHandle *const torrent, const QVector<QUrl> &newUrlSeeds);
void handleTorrentUrlSeedsRemoved(TorrentHandle *const torrent, const QVector<QUrl> &urlSeeds);
void handleTorrentResumeDataReady(TorrentHandle *const torrent, const lt::entry &data);
void handleTorrentResumeDataFailed(TorrentHandle *const torrent);
void handleTorrentTrackerReply(TorrentHandle *const torrent, const QString &trackerUrl);
void handleTorrentTrackerWarning(TorrentHandle *const torrent, const QString &trackerUrl);
void handleTorrentTrackerError(TorrentHandle *const torrent, const QString &trackerUrl);
signals:
void addTorrentFailed(const QString &error);
void allTorrentsFinished();
void categoryAdded(const QString &categoryName);
void categoryRemoved(const QString &categoryName);
void downloadFromUrlFailed(const QString &url, const QString &reason);
void downloadFromUrlFinished(const QString &url);
void fullDiskError(BitTorrent::TorrentHandle *const torrent, const QString &msg);
void IPFilterParsed(bool error, int ruleCount);
void metadataLoaded(const BitTorrent::TorrentInfo &info);
void recursiveTorrentDownloadPossible(BitTorrent::TorrentHandle *const torrent);
void speedLimitModeChanged(bool alternative);
void statsUpdated();
void subcategoriesSupportChanged();
void tagAdded(const QString &tag);
void tagRemoved(const QString &tag);
void torrentAboutToBeRemoved(BitTorrent::TorrentHandle *const torrent);
void torrentAdded(BitTorrent::TorrentHandle *const torrent);
void torrentCategoryChanged(BitTorrent::TorrentHandle *const torrent, const QString &oldCategory);
void torrentFinished(BitTorrent::TorrentHandle *const torrent);
void torrentFinishedChecking(BitTorrent::TorrentHandle *const torrent);
void torrentMetadataLoaded(BitTorrent::TorrentHandle *const torrent);
void torrentNew(BitTorrent::TorrentHandle *const torrent);
void torrentPaused(BitTorrent::TorrentHandle *const torrent);
void torrentResumed(BitTorrent::TorrentHandle *const torrent);
void torrentSavePathChanged(BitTorrent::TorrentHandle *const torrent);
void torrentSavingModeChanged(BitTorrent::TorrentHandle *const torrent);
void torrentsUpdated(const QVector<BitTorrent::TorrentHandle *> &torrents);
void torrentTagAdded(TorrentHandle *const torrent, const QString &tag);
void torrentTagRemoved(TorrentHandle *const torrent, const QString &tag);
void trackerError(BitTorrent::TorrentHandle *const torrent, const QString &tracker);
void trackerlessStateChanged(BitTorrent::TorrentHandle *const torrent, bool trackerless);
void trackersAdded(BitTorrent::TorrentHandle *const torrent, const QVector<BitTorrent::TrackerEntry> &trackers);
void trackersChanged(BitTorrent::TorrentHandle *const torrent);
void trackersRemoved(BitTorrent::TorrentHandle *const torrent, const QVector<BitTorrent::TrackerEntry> &trackers);
void trackerSuccess(BitTorrent::TorrentHandle *const torrent, const QString &tracker);
void trackerWarning(BitTorrent::TorrentHandle *const torrent, const QString &tracker);
private slots:
void configureDeferred();
void readAlerts();
void refresh();
void processShareLimits();
void generateResumeData(bool final = false);
void handleIPFilterParsed(int ruleCount);
void handleIPFilterError();
void handleDownloadFinished(const Net::DownloadResult &result);
// Session reconfiguration triggers
void networkOnlineStateChanged(bool online);
void networkConfigurationChange(const QNetworkConfiguration &);
private:
struct RemovingTorrentData
{
QString name;
QString savePathToRemove;
DeleteOption deleteOption;
};
explicit Session(QObject *parent = nullptr);
~Session();
bool hasPerTorrentRatioLimit() const;
bool hasPerTorrentSeedingTimeLimit() const;
void initResumeFolder();
// Session configuration
Q_INVOKABLE void configure();
void configureComponents();
void initializeNativeSession();
void loadLTSettings(lt::settings_pack &settingsPack);
void configureNetworkInterfaces(lt::settings_pack &settingsPack);
void configurePeerClasses();
void adjustLimits(lt::settings_pack &settingsPack);
void applyBandwidthLimits(lt::settings_pack &settingsPack) const;
void initMetrics();
void adjustLimits();
void applyBandwidthLimits();
void processBannedIPs(lt::ip_filter &filter);
QStringList getListeningIPs() const;
void configureListeningInterface();
void enableTracker(bool enable);
void enableBandwidthScheduler();
void populateAdditionalTrackers();
void enableIPFilter();
void disableIPFilter();
#if defined(Q_OS_WIN)
void applyOSMemoryPriority() const;
#endif
bool addTorrent_impl(CreateTorrentParams params, const MagnetUri &magnetUri,
TorrentInfo torrentInfo = TorrentInfo(),
const QByteArray &fastresumeData = {});
bool findIncompleteFiles(TorrentInfo &torrentInfo, QString &savePath) const;
void updateSeedingLimitTimer();
void exportTorrentFile(TorrentHandle *const torrent, TorrentExportFolder folder = TorrentExportFolder::Regular);
void handleAlert(const lt::alert *a);
void dispatchTorrentAlert(const lt::alert *a);
void handleAddTorrentAlert(const lt::add_torrent_alert *p);
void handleStateUpdateAlert(const lt::state_update_alert *p);
void handleMetadataReceivedAlert(const lt::metadata_received_alert *p);
void handleTorrentPausedAlert(const lt::torrent_paused_alert *p);
void handleFileErrorAlert(const lt::file_error_alert *p);
void handleTorrentRemovedAlert(const lt::torrent_removed_alert *p);
void handleTorrentDeletedAlert(const lt::torrent_deleted_alert *p);
void handleTorrentDeleteFailedAlert(const lt::torrent_delete_failed_alert *p);
void handlePortmapWarningAlert(const lt::portmap_error_alert *p);
void handlePortmapAlert(const lt::portmap_alert *p);
void handlePeerBlockedAlert(const lt::peer_blocked_alert *p);
void handlePeerBanAlert(const lt::peer_ban_alert *p);
void handleUrlSeedAlert(const lt::url_seed_alert *p);
void handleListenSucceededAlert(const lt::listen_succeeded_alert *p);
void handleListenFailedAlert(const lt::listen_failed_alert *p);
void handleExternalIPAlert(const lt::external_ip_alert *p);
void handleSessionStatsAlert(const lt::session_stats_alert *p);
#if (LIBTORRENT_VERSION_NUM >= 10200)
void handleAlertsDroppedAlert(const lt::alerts_dropped_alert *p) const;
#endif
void createTorrentHandle(const lt::torrent_handle &nativeHandle);
void saveResumeData();
void saveTorrentsQueue();
void removeTorrentsQueue();
std::vector<lt::alert *> getPendingAlerts(lt::time_duration time = lt::time_duration::zero()) const;
// BitTorrent
lt::session *m_nativeSession = nullptr;
bool m_deferredConfigureScheduled = false;
bool m_IPFilteringConfigured = false;
bool m_listenInterfaceConfigured = false;
CachedSettingValue<bool> m_isDHTEnabled;
CachedSettingValue<bool> m_isLSDEnabled;
CachedSettingValue<bool> m_isPeXEnabled;
CachedSettingValue<bool> m_isIPFilteringEnabled;
CachedSettingValue<bool> m_isTrackerFilteringEnabled;
CachedSettingValue<QString> m_IPFilterFile;
CachedSettingValue<bool> m_announceToAllTrackers;
CachedSettingValue<bool> m_announceToAllTiers;
CachedSettingValue<int> m_asyncIOThreads;
CachedSettingValue<int> m_filePoolSize;
CachedSettingValue<int> m_checkingMemUsage;
CachedSettingValue<int> m_diskCacheSize;
CachedSettingValue<int> m_diskCacheTTL;
CachedSettingValue<bool> m_useOSCache;
CachedSettingValue<bool> m_coalesceReadWriteEnabled;
CachedSettingValue<bool> m_usePieceExtentAffinity;
CachedSettingValue<bool> m_isSuggestMode;
CachedSettingValue<int> m_sendBufferWatermark;
CachedSettingValue<int> m_sendBufferLowWatermark;
CachedSettingValue<int> m_sendBufferWatermarkFactor;
CachedSettingValue<int> m_socketBacklogSize;
CachedSettingValue<bool> m_isAnonymousModeEnabled;
CachedSettingValue<bool> m_isQueueingEnabled;
CachedSettingValue<int> m_maxActiveDownloads;
CachedSettingValue<int> m_maxActiveUploads;
CachedSettingValue<int> m_maxActiveTorrents;
CachedSettingValue<bool> m_ignoreSlowTorrentsForQueueing;
CachedSettingValue<int> m_downloadRateForSlowTorrents;
CachedSettingValue<int> m_uploadRateForSlowTorrents;
CachedSettingValue<int> m_slowTorrentsInactivityTimer;
CachedSettingValue<int> m_outgoingPortsMin;
CachedSettingValue<int> m_outgoingPortsMax;
CachedSettingValue<bool> m_ignoreLimitsOnLAN;
CachedSettingValue<bool> m_includeOverheadInLimits;
CachedSettingValue<QString> m_announceIP;
CachedSettingValue<int> m_stopTrackerTimeout;
CachedSettingValue<bool> m_isSuperSeedingEnabled;
CachedSettingValue<int> m_maxConnections;
CachedSettingValue<int> m_maxUploads;
CachedSettingValue<int> m_maxConnectionsPerTorrent;
CachedSettingValue<int> m_maxUploadsPerTorrent;
CachedSettingValue<BTProtocol> m_btProtocol;
CachedSettingValue<bool> m_isUTPRateLimited;
CachedSettingValue<MixedModeAlgorithm> m_utpMixedMode;
CachedSettingValue<bool> m_multiConnectionsPerIpEnabled;
CachedSettingValue<bool> m_isAddTrackersEnabled;
CachedSettingValue<QString> m_additionalTrackers;
CachedSettingValue<qreal> m_globalMaxRatio;
CachedSettingValue<int> m_globalMaxSeedingMinutes;
CachedSettingValue<bool> m_isAddTorrentPaused;
CachedSettingValue<bool> m_isCreateTorrentSubfolder;
CachedSettingValue<bool> m_isAppendExtensionEnabled;
CachedSettingValue<uint> m_refreshInterval;
CachedSettingValue<bool> m_isPreallocationEnabled;
CachedSettingValue<QString> m_torrentExportDirectory;
CachedSettingValue<QString> m_finishedTorrentExportDirectory;
CachedSettingValue<int> m_globalDownloadSpeedLimit;
CachedSettingValue<int> m_globalUploadSpeedLimit;
CachedSettingValue<int> m_altGlobalDownloadSpeedLimit;
CachedSettingValue<int> m_altGlobalUploadSpeedLimit;
CachedSettingValue<bool> m_isAltGlobalSpeedLimitEnabled;
CachedSettingValue<bool> m_isBandwidthSchedulerEnabled;
CachedSettingValue<uint> m_saveResumeDataInterval;
CachedSettingValue<int> m_port;
CachedSettingValue<bool> m_useRandomPort;
CachedSettingValue<QString> m_networkInterface;
CachedSettingValue<QString> m_networkInterfaceName;
CachedSettingValue<QString> m_networkInterfaceAddress;
CachedSettingValue<int> m_encryption;
CachedSettingValue<bool> m_isProxyPeerConnectionsEnabled;
CachedSettingValue<ChokingAlgorithm> m_chokingAlgorithm;
CachedSettingValue<SeedChokingAlgorithm> m_seedChokingAlgorithm;
CachedSettingValue<QVariantMap> m_storedCategories;
CachedSettingValue<QStringList> m_storedTags;
CachedSettingValue<int> m_maxRatioAction;
CachedSettingValue<QString> m_defaultSavePath;
CachedSettingValue<QString> m_tempPath;
CachedSettingValue<bool> m_isSubcategoriesEnabled;
CachedSettingValue<bool> m_isTempPathEnabled;
CachedSettingValue<bool> m_isAutoTMMDisabledByDefault;
CachedSettingValue<bool> m_isDisableAutoTMMWhenCategoryChanged;
CachedSettingValue<bool> m_isDisableAutoTMMWhenDefaultSavePathChanged;
CachedSettingValue<bool> m_isDisableAutoTMMWhenCategorySavePathChanged;
CachedSettingValue<bool> m_isTrackerEnabled;
CachedSettingValue<QStringList> m_bannedIPs;
#if defined(Q_OS_WIN)
CachedSettingValue<OSMemoryPriority> m_OSMemoryPriority;
#endif
// Order is important. This needs to be declared after its CachedSettingsValue
// counterpart, because it uses it for initialization in the constructor
// initialization list.
const bool m_wasPexEnabled = m_isPeXEnabled;
int m_numResumeData = 0;
int m_extraLimit = 0;
QVector<BitTorrent::TrackerEntry> m_additionalTrackerList;
QString m_resumeFolderPath;
QFile *m_resumeFolderLock = nullptr;
QTimer *m_refreshTimer = nullptr;
QTimer *m_seedingLimitTimer = nullptr;
QTimer *m_resumeDataTimer = nullptr;
Statistics *m_statistics = nullptr;
// IP filtering
QPointer<FilterParserThread> m_filterParser;
QPointer<BandwidthScheduler> m_bwScheduler;
// Tracker
QPointer<Tracker> m_tracker;
// fastresume data writing thread
QThread *m_ioThread = nullptr;
ResumeDataSavingManager *m_resumeDataSavingManager = nullptr;
QHash<InfoHash, TorrentInfo> m_loadedMetadata;
QHash<InfoHash, TorrentHandle *> m_torrents;
QHash<InfoHash, CreateTorrentParams> m_addingTorrents;
QHash<QString, AddTorrentParams> m_downloadedTorrents;
QHash<InfoHash, RemovingTorrentData> m_removingTorrents;
QStringMap m_categories;
QSet<QString> m_tags;
// I/O errored torrents
QSet<InfoHash> m_recentErroredTorrents;
QTimer *m_recentErroredTorrentsTimer = nullptr;
SessionMetricIndices m_metricIndices;
lt::time_point m_statsLastTimestamp = lt::clock_type::now();
SessionStatus m_status;
CacheStatus m_cacheStatus;
QNetworkConfigurationManager *m_networkManager = nullptr;
static Session *m_instance;
};
}
#endif // BITTORRENT_SESSION_H