qBittorrent
torrent.h
Go to the documentation of this file.
1 /*
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>
5  *
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.
10  *
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.
15  *
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.
19  *
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.
28  */
29 
30 #pragma once
31 
32 #include <QMetaType>
33 #include <QString>
34 #include <QtContainerFwd>
35 
36 #include "base/tagset.h"
37 #include "abstractfilestorage.h"
38 
39 class QBitArray;
40 class QDateTime;
41 class QUrl;
42 
43 namespace BitTorrent
44 {
45  enum class DownloadPriority;
46  class InfoHash;
47  class PeerInfo;
48  class TorrentID;
49  class TorrentInfo;
50  struct PeerAddress;
51  struct TrackerEntry;
52 
53  // Using `Q_ENUM_NS()` without a wrapper namespace in our case is not advised
54  // since `Q_NAMESPACE` cannot be used when the same namespace resides at different files.
55  // https://www.kdab.com/new-qt-5-8-meta-object-support-namespaces/#comment-143779
56  inline namespace TorrentOperatingModeNS
57  {
58  Q_NAMESPACE
59 
61  {
62  AutoManaged = 0,
63  Forced = 1
64  };
65 
66  Q_ENUM_NS(TorrentOperatingMode)
67  }
68 
69  enum class TorrentState
70  {
71  Unknown = -1,
72 
78 
80  Uploading,
82 
86 
89 
92 
93  Moving,
94 
96  Error
97  };
98 
99  uint qHash(TorrentState key, uint seed);
100 
102  {
103  public:
104  static const qreal USE_GLOBAL_RATIO;
105  static const qreal NO_RATIO_LIMIT;
106 
107  static const int USE_GLOBAL_SEEDING_TIME;
108  static const int NO_SEEDING_TIME_LIMIT;
109 
110  static const qreal MAX_RATIO;
111  static const int MAX_SEEDING_TIME;
112 
113  virtual ~Torrent() = default;
114 
115  virtual InfoHash infoHash() const = 0;
116  virtual QString name() const = 0;
117  virtual QDateTime creationDate() const = 0;
118  virtual QString creator() const = 0;
119  virtual QString comment() const = 0;
120  virtual bool isPrivate() const = 0;
121  virtual qlonglong totalSize() const = 0;
122  virtual qlonglong wantedSize() const = 0;
123  virtual qlonglong completedSize() const = 0;
124  virtual qlonglong pieceLength() const = 0;
125  virtual qlonglong wastedSize() const = 0;
126  virtual QString currentTracker() const = 0;
127 
128  // 1. savePath() - the path where all the files and subfolders of torrent are stored.
129  // 1.1 downloadPath() - the path where all the files and subfolders of torrent are stored until torrent has finished downloading.
130  // 2. rootPath() - absolute path of torrent file tree (first common subfolder of torrent files); empty string if torrent has no root folder.
131  // 3. contentPath() - absolute path of torrent content (root path for multifile torrents, absolute file path for singlefile torrents).
132  //
133  // Examples.
134  // Suppose we have three torrent with following structures and save path `/home/user/torrents`:
135  //
136  // Torrent A (multifile)
137  //
138  // torrentA/
139  // subdir1/
140  // subdir2/
141  // file1
142  // file2
143  // file3
144  // file4
145  //
146  //
147  // Torrent A* (Torrent A in "strip root folder" mode)
148  //
149  //
150  // Torrent B (singlefile)
151  //
152  // torrentB/
153  // subdir1/
154  // file1
155  //
156  //
157  // Torrent C (singlefile)
158  //
159  // file1
160  //
161  //
162  // Results:
163  // | | rootPath | contentPath |
164  // |---|------------------------------|--------------------------------------------|
165  // | A | /home/user/torrents/torrentA | /home/user/torrents/torrentA |
166  // | A*| <empty> | /home/user/torrents |
167  // | B | /home/user/torrents/torrentB | /home/user/torrents/torrentB/subdir1/file1 |
168  // | C | <empty> | /home/user/torrents/file1 |
169 
170  virtual bool isAutoTMMEnabled() const = 0;
171  virtual void setAutoTMMEnabled(bool enabled) = 0;
172  virtual QString savePath() const = 0;
173  virtual void setSavePath(const QString &savePath) = 0;
174  virtual QString downloadPath() const = 0;
175  virtual void setDownloadPath(const QString &downloadPath) = 0;
176  virtual QString actualStorageLocation() const = 0;
177  virtual QString rootPath() const = 0;
178  virtual QString contentPath() const = 0;
179  virtual QString category() const = 0;
180  virtual bool belongsToCategory(const QString &category) const = 0;
181  virtual bool setCategory(const QString &category) = 0;
182 
183  virtual TagSet tags() const = 0;
184  virtual bool hasTag(const QString &tag) const = 0;
185  virtual bool addTag(const QString &tag) = 0;
186  virtual bool removeTag(const QString &tag) = 0;
187  virtual void removeAllTags() = 0;
188 
189  virtual int piecesCount() const = 0;
190  virtual int piecesHave() const = 0;
191  virtual qreal progress() const = 0;
192  virtual QDateTime addedTime() const = 0;
193  virtual qreal ratioLimit() const = 0;
194  virtual int seedingTimeLimit() const = 0;
195 
196  virtual QString actualFilePath(int index) const = 0;
197  virtual QStringList filePaths() const = 0;
198  virtual QVector<DownloadPriority> filePriorities() const = 0;
199 
200  virtual TorrentInfo info() const = 0;
201  virtual bool isSeed() const = 0;
202  virtual bool isPaused() const = 0;
203  virtual bool isQueued() const = 0;
204  virtual bool isForced() const = 0;
205  virtual bool isChecking() const = 0;
206  virtual bool isDownloading() const = 0;
207  virtual bool isUploading() const = 0;
208  virtual bool isCompleted() const = 0;
209  virtual bool isActive() const = 0;
210  virtual bool isInactive() const = 0;
211  virtual bool isErrored() const = 0;
212  virtual bool isSequentialDownload() const = 0;
213  virtual bool hasFirstLastPiecePriority() const = 0;
214  virtual TorrentState state() const = 0;
215  virtual bool hasMetadata() const = 0;
216  virtual bool hasMissingFiles() const = 0;
217  virtual bool hasError() const = 0;
218  virtual int queuePosition() const = 0;
219  virtual QVector<TrackerEntry> trackers() const = 0;
220  virtual QVector<QUrl> urlSeeds() const = 0;
221  virtual QString error() const = 0;
222  virtual qlonglong totalDownload() const = 0;
223  virtual qlonglong totalUpload() const = 0;
224  virtual qlonglong activeTime() const = 0;
225  virtual qlonglong finishedTime() const = 0;
226  virtual qlonglong eta() const = 0;
227  virtual QVector<qreal> filesProgress() const = 0;
228  virtual int seedsCount() const = 0;
229  virtual int peersCount() const = 0;
230  virtual int leechsCount() const = 0;
231  virtual int totalSeedsCount() const = 0;
232  virtual int totalPeersCount() const = 0;
233  virtual int totalLeechersCount() const = 0;
234  virtual int completeCount() const = 0;
235  virtual int incompleteCount() const = 0;
236  virtual QDateTime lastSeenComplete() const = 0;
237  virtual QDateTime completedTime() const = 0;
238  virtual qlonglong timeSinceUpload() const = 0;
239  virtual qlonglong timeSinceDownload() const = 0;
240  virtual qlonglong timeSinceActivity() const = 0;
241  virtual int downloadLimit() const = 0;
242  virtual int uploadLimit() const = 0;
243  virtual bool superSeeding() const = 0;
244  virtual bool isDHTDisabled() const = 0;
245  virtual bool isPEXDisabled() const = 0;
246  virtual bool isLSDDisabled() const = 0;
247  virtual QVector<PeerInfo> peers() const = 0;
248  virtual QBitArray pieces() const = 0;
249  virtual QBitArray downloadingPieces() const = 0;
250  virtual QVector<int> pieceAvailability() const = 0;
251  virtual qreal distributedCopies() const = 0;
252  virtual qreal maxRatio() const = 0;
253  virtual int maxSeedingTime() const = 0;
254  virtual qreal realRatio() const = 0;
255  virtual int uploadPayloadRate() const = 0;
256  virtual int downloadPayloadRate() const = 0;
257  virtual qlonglong totalPayloadUpload() const = 0;
258  virtual qlonglong totalPayloadDownload() const = 0;
259  virtual int connectionsCount() const = 0;
260  virtual int connectionsLimit() const = 0;
261  virtual qlonglong nextAnnounce() const = 0;
268  virtual QVector<qreal> availableFileFractions() const = 0;
269 
270  virtual void setName(const QString &name) = 0;
271  virtual void setSequentialDownload(bool enable) = 0;
272  virtual void setFirstLastPiecePriority(bool enabled) = 0;
273  virtual void pause() = 0;
274  virtual void resume(TorrentOperatingMode mode = TorrentOperatingMode::AutoManaged) = 0;
275  virtual void forceReannounce(int index = -1) = 0;
276  virtual void forceDHTAnnounce() = 0;
277  virtual void forceRecheck() = 0;
278  virtual void prioritizeFiles(const QVector<DownloadPriority> &priorities) = 0;
279  virtual void setRatioLimit(qreal limit) = 0;
280  virtual void setSeedingTimeLimit(int limit) = 0;
281  virtual void setUploadLimit(int limit) = 0;
282  virtual void setDownloadLimit(int limit) = 0;
283  virtual void setSuperSeeding(bool enable) = 0;
284  virtual void setDHTDisabled(bool disable) = 0;
285  virtual void setPEXDisabled(bool disable) = 0;
286  virtual void setLSDDisabled(bool disable) = 0;
287  virtual void flushCache() const = 0;
288  virtual void addTrackers(const QVector<TrackerEntry> &trackers) = 0;
289  virtual void replaceTrackers(const QVector<TrackerEntry> &trackers) = 0;
290  virtual void addUrlSeeds(const QVector<QUrl> &urlSeeds) = 0;
291  virtual void removeUrlSeeds(const QVector<QUrl> &urlSeeds) = 0;
292  virtual bool connectPeer(const PeerAddress &peerAddress) = 0;
293  virtual void clearPeers() = 0;
294 
295  virtual QString createMagnetURI() const = 0;
296 
297  TorrentID id() const;
298  bool isResumed() const;
299  qlonglong remainingSize() const;
300 
303  };
304 }
305 
306 Q_DECLARE_METATYPE(BitTorrent::TorrentState)
virtual qlonglong totalSize() const =0
static const int NO_SEEDING_TIME_LIMIT
Definition: torrent.h:108
virtual QVector< PeerInfo > peers() const =0
virtual qreal distributedCopies() const =0
virtual int uploadPayloadRate() const =0
virtual void forceRecheck()=0
virtual QVector< int > pieceAvailability() const =0
virtual int seedsCount() const =0
virtual int downloadLimit() const =0
virtual void flushCache() const =0
virtual int incompleteCount() const =0
virtual bool isErrored() const =0
virtual int peersCount() const =0
virtual void setSuperSeeding(bool enable)=0
TorrentID id() const
Definition: torrent.cpp:54
virtual void setDHTDisabled(bool disable)=0
virtual TagSet tags() const =0
virtual qlonglong nextAnnounce() const =0
virtual bool connectPeer(const PeerAddress &peerAddress)=0
virtual bool isDownloading() const =0
virtual int totalPeersCount() const =0
virtual qreal ratioLimit() const =0
virtual void setSequentialDownload(bool enable)=0
virtual bool removeTag(const QString &tag)=0
virtual bool hasError() const =0
virtual bool isDHTDisabled() const =0
virtual QVector< DownloadPriority > filePriorities() const =0
virtual void setAutoTMMEnabled(bool enabled)=0
virtual bool hasFirstLastPiecePriority() const =0
virtual bool isChecking() const =0
virtual void forceReannounce(int index=-1)=0
virtual bool isCompleted() const =0
virtual void setDownloadPath(const QString &downloadPath)=0
virtual QString createMagnetURI() const =0
static const int USE_GLOBAL_SEEDING_TIME
Definition: torrent.h:107
virtual void setFirstLastPiecePriority(bool enabled)=0
virtual QVector< qreal > filesProgress() const =0
virtual qlonglong totalUpload() const =0
virtual QString currentTracker() const =0
virtual int piecesHave() const =0
virtual int maxSeedingTime() const =0
virtual bool isInactive() const =0
virtual QString category() const =0
virtual QDateTime creationDate() const =0
void toggleFirstLastPiecePriority()
Definition: torrent.cpp:74
virtual bool hasTag(const QString &tag) const =0
virtual QString comment() const =0
virtual qlonglong pieceLength() const =0
static const qreal NO_RATIO_LIMIT
Definition: torrent.h:105
virtual void setUploadLimit(int limit)=0
virtual qlonglong activeTime() const =0
virtual qlonglong totalPayloadDownload() const =0
virtual void setSeedingTimeLimit(int limit)=0
virtual bool hasMissingFiles() const =0
virtual QString error() const =0
virtual bool belongsToCategory(const QString &category) const =0
virtual InfoHash infoHash() const =0
virtual void prioritizeFiles(const QVector< DownloadPriority > &priorities)=0
virtual qlonglong finishedTime() const =0
virtual QStringList filePaths() const =0
virtual int piecesCount() const =0
virtual int uploadLimit() const =0
qlonglong remainingSize() const
Definition: torrent.cpp:64
void toggleSequentialDownload()
Definition: torrent.cpp:69
virtual void forceDHTAnnounce()=0
virtual bool superSeeding() const =0
virtual qlonglong completedSize() const =0
virtual int connectionsLimit() const =0
virtual int totalSeedsCount() const =0
virtual TorrentState state() const =0
bool isResumed() const
Definition: torrent.cpp:59
virtual bool isQueued() const =0
virtual qlonglong totalDownload() const =0
virtual void resume(TorrentOperatingMode mode=TorrentOperatingMode::AutoManaged)=0
virtual void setSavePath(const QString &savePath)=0
virtual QString creator() const =0
virtual QString savePath() const =0
virtual qreal realRatio() const =0
virtual qreal maxRatio() const =0
virtual bool isPEXDisabled() const =0
virtual bool isLSDDisabled() const =0
virtual void removeAllTags()=0
virtual void addUrlSeeds(const QVector< QUrl > &urlSeeds)=0
virtual QString downloadPath() const =0
virtual QString actualStorageLocation() const =0
virtual int seedingTimeLimit() const =0
virtual QBitArray downloadingPieces() const =0
virtual bool isActive() const =0
virtual bool isPaused() const =0
virtual int queuePosition() const =0
virtual QVector< TrackerEntry > trackers() const =0
virtual bool setCategory(const QString &category)=0
virtual QDateTime addedTime() const =0
virtual QString rootPath() const =0
virtual bool isAutoTMMEnabled() const =0
virtual void setName(const QString &name)=0
virtual qlonglong totalPayloadUpload() const =0
virtual void addTrackers(const QVector< TrackerEntry > &trackers)=0
virtual qlonglong timeSinceDownload() const =0
virtual void replaceTrackers(const QVector< TrackerEntry > &trackers)=0
virtual QBitArray pieces() const =0
virtual QVector< qreal > availableFileFractions() const =0
fraction of file pieces that are available at least from one peer
virtual int connectionsCount() const =0
virtual bool isUploading() const =0
virtual QDateTime completedTime() const =0
virtual bool isPrivate() const =0
static const int MAX_SEEDING_TIME
Definition: torrent.h:111
virtual QVector< QUrl > urlSeeds() const =0
virtual TorrentInfo info() const =0
static const qreal USE_GLOBAL_RATIO
Definition: torrent.h:104
virtual qlonglong wastedSize() const =0
virtual bool addTag(const QString &tag)=0
virtual int completeCount() const =0
virtual QDateTime lastSeenComplete() const =0
virtual bool isForced() const =0
virtual void setDownloadLimit(int limit)=0
virtual QString actualFilePath(int index) const =0
virtual int leechsCount() const =0
virtual qreal progress() const =0
virtual void setLSDDisabled(bool disable)=0
virtual ~Torrent()=default
virtual bool isSeed() const =0
virtual qlonglong timeSinceActivity() const =0
virtual qlonglong eta() const =0
virtual bool isSequentialDownload() const =0
static const qreal MAX_RATIO
Definition: torrent.h:110
virtual void removeUrlSeeds(const QVector< QUrl > &urlSeeds)=0
virtual void pause()=0
virtual qlonglong wantedSize() const =0
virtual void setPEXDisabled(bool disable)=0
virtual int downloadPayloadRate() const =0
virtual int totalLeechersCount() const =0
virtual qlonglong timeSinceUpload() const =0
virtual void setRatioLimit(qreal limit)=0
virtual void clearPeers()=0
virtual bool hasMetadata() const =0
virtual QString name() const =0
virtual QString contentPath() const =0
uint qHash(const TorrentID &key, uint seed)
Definition: infohash.cpp:86
TorrentState
Definition: torrent.h:70