2015-04-19 18:17:47 +03:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2020-04-12 18:08:19 +03:00
|
|
|
#pragma once
|
2015-04-19 18:17:47 +03:00
|
|
|
|
2020-04-12 18:08:19 +03:00
|
|
|
#include <QMetaType>
|
2017-06-05 03:22:17 +03:00
|
|
|
#include <QString>
|
2020-12-09 08:48:59 +03:00
|
|
|
#include <QtContainerFwd>
|
2015-04-19 18:17:47 +03:00
|
|
|
|
2021-04-02 08:45:50 +03:00
|
|
|
#include "base/tagset.h"
|
2020-12-17 11:57:06 +03:00
|
|
|
#include "abstractfilestorage.h"
|
|
|
|
|
2015-04-19 18:17:47 +03:00
|
|
|
class QBitArray;
|
2019-03-02 08:22:13 +03:00
|
|
|
class QDateTime;
|
|
|
|
class QUrl;
|
2016-04-19 09:54:48 +03:00
|
|
|
|
2015-04-19 18:17:47 +03:00
|
|
|
namespace BitTorrent
|
|
|
|
{
|
2019-06-02 12:13:34 +03:00
|
|
|
enum class DownloadPriority;
|
2020-04-12 18:08:19 +03:00
|
|
|
class InfoHash;
|
2015-04-19 18:17:47 +03:00
|
|
|
class PeerInfo;
|
2021-03-05 12:43:58 +03:00
|
|
|
class TorrentID;
|
2020-04-12 18:08:19 +03:00
|
|
|
class TorrentInfo;
|
2019-03-02 08:22:13 +03:00
|
|
|
struct PeerAddress;
|
2021-03-01 16:06:08 +03:00
|
|
|
struct TrackerEntry;
|
2015-04-19 18:17:47 +03:00
|
|
|
|
2021-03-24 11:53:47 +03:00
|
|
|
// 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
|
|
|
|
inline namespace TorrentOperatingModeNS
|
2020-04-19 16:12:50 +03:00
|
|
|
{
|
2021-03-24 11:53:47 +03:00
|
|
|
Q_NAMESPACE
|
|
|
|
|
|
|
|
enum class TorrentOperatingMode
|
|
|
|
{
|
|
|
|
AutoManaged = 0,
|
|
|
|
Forced = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
Q_ENUM_NS(TorrentOperatingMode)
|
|
|
|
}
|
2020-04-19 16:12:50 +03:00
|
|
|
|
2017-02-18 03:38:40 +03:00
|
|
|
enum class TorrentState
|
2015-04-19 18:17:47 +03:00
|
|
|
{
|
2017-02-18 03:38:40 +03:00
|
|
|
Unknown = -1,
|
2015-04-19 18:17:47 +03:00
|
|
|
|
2017-02-18 03:38:40 +03:00
|
|
|
ForcedDownloading,
|
|
|
|
Downloading,
|
2021-07-17 21:33:14 +03:00
|
|
|
ForcedDownloadingMetadata,
|
2017-02-18 03:38:40 +03:00
|
|
|
DownloadingMetadata,
|
|
|
|
StalledDownloading,
|
2015-06-20 09:05:53 +03:00
|
|
|
|
2017-02-18 03:38:40 +03:00
|
|
|
ForcedUploading,
|
|
|
|
Uploading,
|
|
|
|
StalledUploading,
|
2015-06-20 09:05:53 +03:00
|
|
|
|
2017-02-18 03:38:40 +03:00
|
|
|
CheckingResumeData,
|
|
|
|
QueuedDownloading,
|
|
|
|
QueuedUploading,
|
2015-06-30 11:03:46 +03:00
|
|
|
|
2017-02-18 03:38:40 +03:00
|
|
|
CheckingUploading,
|
|
|
|
CheckingDownloading,
|
2015-06-20 09:05:53 +03:00
|
|
|
|
2017-02-18 03:38:40 +03:00
|
|
|
PausedDownloading,
|
|
|
|
PausedUploading,
|
2015-04-19 18:17:47 +03:00
|
|
|
|
2018-04-09 18:19:33 +03:00
|
|
|
Moving,
|
|
|
|
|
2017-02-18 03:38:40 +03:00
|
|
|
MissingFiles,
|
|
|
|
Error
|
2015-04-19 18:17:47 +03:00
|
|
|
};
|
|
|
|
|
2019-12-16 19:45:08 +03:00
|
|
|
uint qHash(TorrentState key, uint seed);
|
|
|
|
|
2021-01-06 15:12:40 +03:00
|
|
|
class Torrent : public AbstractFileStorage
|
2015-04-19 18:17:47 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static const qreal USE_GLOBAL_RATIO;
|
|
|
|
static const qreal NO_RATIO_LIMIT;
|
|
|
|
|
2016-02-07 20:31:50 +03:00
|
|
|
static const int USE_GLOBAL_SEEDING_TIME;
|
|
|
|
static const int NO_SEEDING_TIME_LIMIT;
|
|
|
|
|
2015-04-19 18:17:47 +03:00
|
|
|
static const qreal MAX_RATIO;
|
2016-02-07 20:31:50 +03:00
|
|
|
static const int MAX_SEEDING_TIME;
|
2015-04-19 18:17:47 +03:00
|
|
|
|
2021-01-06 15:12:40 +03:00
|
|
|
virtual ~Torrent() = default;
|
2020-04-12 18:08:19 +03:00
|
|
|
|
2021-03-05 12:43:58 +03:00
|
|
|
virtual InfoHash infoHash() const = 0;
|
2020-04-12 18:08:19 +03:00
|
|
|
virtual QString name() const = 0;
|
|
|
|
virtual QDateTime creationDate() const = 0;
|
|
|
|
virtual QString creator() const = 0;
|
|
|
|
virtual QString comment() const = 0;
|
|
|
|
virtual bool isPrivate() const = 0;
|
|
|
|
virtual qlonglong totalSize() const = 0;
|
|
|
|
virtual qlonglong wantedSize() const = 0;
|
|
|
|
virtual qlonglong completedSize() const = 0;
|
|
|
|
virtual qlonglong pieceLength() const = 0;
|
|
|
|
virtual qlonglong wastedSize() const = 0;
|
|
|
|
virtual QString currentTracker() const = 0;
|
2015-10-24 15:28:29 +03:00
|
|
|
|
2021-12-09 06:12:47 +03:00
|
|
|
// 1. savePath() - the path where all the files and subfolders of torrent are stored.
|
2021-05-20 10:36:44 +03:00
|
|
|
// 1.1 downloadPath() - the path where all the files and subfolders of torrent are stored until torrent has finished downloading.
|
2021-12-09 06:12:47 +03:00
|
|
|
// 2. rootPath() - absolute path of torrent file tree (first common subfolder of torrent files); empty string if torrent has no root folder.
|
2015-10-24 15:28:29 +03:00
|
|
|
// 3. contentPath() - absolute path of torrent content (root path for multifile torrents, absolute file path for singlefile torrents).
|
|
|
|
//
|
|
|
|
// Examples.
|
|
|
|
// Suppose we have three torrent with following structures and save path `/home/user/torrents`:
|
|
|
|
//
|
|
|
|
// Torrent A (multifile)
|
|
|
|
//
|
|
|
|
// torrentA/
|
|
|
|
// subdir1/
|
|
|
|
// subdir2/
|
|
|
|
// file1
|
|
|
|
// file2
|
|
|
|
// file3
|
|
|
|
// file4
|
|
|
|
//
|
|
|
|
//
|
2016-01-06 10:26:57 +03:00
|
|
|
// Torrent A* (Torrent A in "strip root folder" mode)
|
|
|
|
//
|
|
|
|
//
|
2015-10-24 15:28:29 +03:00
|
|
|
// Torrent B (singlefile)
|
|
|
|
//
|
|
|
|
// torrentB/
|
|
|
|
// subdir1/
|
|
|
|
// file1
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Torrent C (singlefile)
|
|
|
|
//
|
|
|
|
// file1
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Results:
|
|
|
|
// | | rootPath | contentPath |
|
|
|
|
// |---|------------------------------|--------------------------------------------|
|
|
|
|
// | A | /home/user/torrents/torrentA | /home/user/torrents/torrentA |
|
2016-01-06 10:26:57 +03:00
|
|
|
// | A*| <empty> | /home/user/torrents |
|
2015-10-24 15:28:29 +03:00
|
|
|
// | B | /home/user/torrents/torrentB | /home/user/torrents/torrentB/subdir1/file1 |
|
2021-12-09 06:12:47 +03:00
|
|
|
// | C | <empty> | /home/user/torrents/file1 |
|
2015-10-24 15:28:29 +03:00
|
|
|
|
2020-04-12 18:08:19 +03:00
|
|
|
virtual bool isAutoTMMEnabled() const = 0;
|
|
|
|
virtual void setAutoTMMEnabled(bool enabled) = 0;
|
2021-05-20 10:36:44 +03:00
|
|
|
virtual QString savePath() const = 0;
|
|
|
|
virtual void setSavePath(const QString &savePath) = 0;
|
|
|
|
virtual QString downloadPath() const = 0;
|
|
|
|
virtual void setDownloadPath(const QString &downloadPath) = 0;
|
|
|
|
virtual QString actualStorageLocation() const = 0;
|
|
|
|
virtual QString rootPath() const = 0;
|
|
|
|
virtual QString contentPath() const = 0;
|
2020-04-12 18:08:19 +03:00
|
|
|
virtual QString category() const = 0;
|
|
|
|
virtual bool belongsToCategory(const QString &category) const = 0;
|
|
|
|
virtual bool setCategory(const QString &category) = 0;
|
|
|
|
|
2021-04-02 08:45:50 +03:00
|
|
|
virtual TagSet tags() const = 0;
|
2020-04-12 18:08:19 +03:00
|
|
|
virtual bool hasTag(const QString &tag) const = 0;
|
|
|
|
virtual bool addTag(const QString &tag) = 0;
|
|
|
|
virtual bool removeTag(const QString &tag) = 0;
|
|
|
|
virtual void removeAllTags() = 0;
|
|
|
|
|
|
|
|
virtual int piecesCount() const = 0;
|
|
|
|
virtual int piecesHave() const = 0;
|
|
|
|
virtual qreal progress() const = 0;
|
|
|
|
virtual QDateTime addedTime() const = 0;
|
|
|
|
virtual qreal ratioLimit() const = 0;
|
|
|
|
virtual int seedingTimeLimit() const = 0;
|
|
|
|
|
2022-01-08 08:45:50 +03:00
|
|
|
virtual QString actualFilePath(int index) const = 0;
|
2021-10-02 21:42:58 +03:00
|
|
|
virtual QStringList filePaths() const = 0;
|
2020-04-12 18:08:19 +03:00
|
|
|
virtual QVector<DownloadPriority> filePriorities() const = 0;
|
|
|
|
|
|
|
|
virtual TorrentInfo info() const = 0;
|
|
|
|
virtual bool isSeed() const = 0;
|
|
|
|
virtual bool isPaused() const = 0;
|
|
|
|
virtual bool isQueued() const = 0;
|
|
|
|
virtual bool isForced() const = 0;
|
|
|
|
virtual bool isChecking() const = 0;
|
|
|
|
virtual bool isDownloading() const = 0;
|
|
|
|
virtual bool isUploading() const = 0;
|
|
|
|
virtual bool isCompleted() const = 0;
|
|
|
|
virtual bool isActive() const = 0;
|
|
|
|
virtual bool isInactive() const = 0;
|
|
|
|
virtual bool isErrored() const = 0;
|
|
|
|
virtual bool isSequentialDownload() const = 0;
|
|
|
|
virtual bool hasFirstLastPiecePriority() const = 0;
|
|
|
|
virtual TorrentState state() const = 0;
|
|
|
|
virtual bool hasMetadata() const = 0;
|
|
|
|
virtual bool hasMissingFiles() const = 0;
|
|
|
|
virtual bool hasError() const = 0;
|
|
|
|
virtual int queuePosition() const = 0;
|
|
|
|
virtual QVector<TrackerEntry> trackers() const = 0;
|
|
|
|
virtual QVector<QUrl> urlSeeds() const = 0;
|
|
|
|
virtual QString error() const = 0;
|
|
|
|
virtual qlonglong totalDownload() const = 0;
|
|
|
|
virtual qlonglong totalUpload() const = 0;
|
|
|
|
virtual qlonglong activeTime() const = 0;
|
|
|
|
virtual qlonglong finishedTime() const = 0;
|
|
|
|
virtual qlonglong eta() const = 0;
|
|
|
|
virtual QVector<qreal> filesProgress() const = 0;
|
|
|
|
virtual int seedsCount() const = 0;
|
|
|
|
virtual int peersCount() const = 0;
|
|
|
|
virtual int leechsCount() const = 0;
|
|
|
|
virtual int totalSeedsCount() const = 0;
|
|
|
|
virtual int totalPeersCount() const = 0;
|
|
|
|
virtual int totalLeechersCount() const = 0;
|
|
|
|
virtual int completeCount() const = 0;
|
|
|
|
virtual int incompleteCount() const = 0;
|
|
|
|
virtual QDateTime lastSeenComplete() const = 0;
|
|
|
|
virtual QDateTime completedTime() const = 0;
|
|
|
|
virtual qlonglong timeSinceUpload() const = 0;
|
|
|
|
virtual qlonglong timeSinceDownload() const = 0;
|
|
|
|
virtual qlonglong timeSinceActivity() const = 0;
|
|
|
|
virtual int downloadLimit() const = 0;
|
|
|
|
virtual int uploadLimit() const = 0;
|
|
|
|
virtual bool superSeeding() const = 0;
|
2020-11-29 17:36:07 +03:00
|
|
|
virtual bool isDHTDisabled() const = 0;
|
|
|
|
virtual bool isPEXDisabled() const = 0;
|
|
|
|
virtual bool isLSDDisabled() const = 0;
|
2020-04-12 18:08:19 +03:00
|
|
|
virtual QVector<PeerInfo> peers() const = 0;
|
|
|
|
virtual QBitArray pieces() const = 0;
|
|
|
|
virtual QBitArray downloadingPieces() const = 0;
|
|
|
|
virtual QVector<int> pieceAvailability() const = 0;
|
|
|
|
virtual qreal distributedCopies() const = 0;
|
|
|
|
virtual qreal maxRatio() const = 0;
|
|
|
|
virtual int maxSeedingTime() const = 0;
|
|
|
|
virtual qreal realRatio() const = 0;
|
|
|
|
virtual int uploadPayloadRate() const = 0;
|
|
|
|
virtual int downloadPayloadRate() const = 0;
|
|
|
|
virtual qlonglong totalPayloadUpload() const = 0;
|
|
|
|
virtual qlonglong totalPayloadDownload() const = 0;
|
|
|
|
virtual int connectionsCount() const = 0;
|
|
|
|
virtual int connectionsLimit() const = 0;
|
|
|
|
virtual qlonglong nextAnnounce() const = 0;
|
2016-03-22 20:10:12 +03:00
|
|
|
/**
|
|
|
|
* @brief fraction of file pieces that are available at least from one peer
|
|
|
|
*
|
|
|
|
* This is not the same as torrrent availability, it is just a fraction of pieces
|
|
|
|
* that can be downloaded right now. It varies between 0 to 1.
|
|
|
|
*/
|
2020-04-12 18:08:19 +03:00
|
|
|
virtual QVector<qreal> availableFileFractions() const = 0;
|
|
|
|
|
|
|
|
virtual void setName(const QString &name) = 0;
|
|
|
|
virtual void setSequentialDownload(bool enable) = 0;
|
|
|
|
virtual void setFirstLastPiecePriority(bool enabled) = 0;
|
|
|
|
virtual void pause() = 0;
|
2020-04-19 16:12:50 +03:00
|
|
|
virtual void resume(TorrentOperatingMode mode = TorrentOperatingMode::AutoManaged) = 0;
|
2020-04-12 18:08:19 +03:00
|
|
|
virtual void forceReannounce(int index = -1) = 0;
|
|
|
|
virtual void forceDHTAnnounce() = 0;
|
|
|
|
virtual void forceRecheck() = 0;
|
|
|
|
virtual void prioritizeFiles(const QVector<DownloadPriority> &priorities) = 0;
|
|
|
|
virtual void setRatioLimit(qreal limit) = 0;
|
|
|
|
virtual void setSeedingTimeLimit(int limit) = 0;
|
|
|
|
virtual void setUploadLimit(int limit) = 0;
|
|
|
|
virtual void setDownloadLimit(int limit) = 0;
|
|
|
|
virtual void setSuperSeeding(bool enable) = 0;
|
2020-11-29 17:36:07 +03:00
|
|
|
virtual void setDHTDisabled(bool disable) = 0;
|
|
|
|
virtual void setPEXDisabled(bool disable) = 0;
|
|
|
|
virtual void setLSDDisabled(bool disable) = 0;
|
2020-04-12 18:08:19 +03:00
|
|
|
virtual void flushCache() const = 0;
|
|
|
|
virtual void addTrackers(const QVector<TrackerEntry> &trackers) = 0;
|
|
|
|
virtual void replaceTrackers(const QVector<TrackerEntry> &trackers) = 0;
|
|
|
|
virtual void addUrlSeeds(const QVector<QUrl> &urlSeeds) = 0;
|
|
|
|
virtual void removeUrlSeeds(const QVector<QUrl> &urlSeeds) = 0;
|
|
|
|
virtual bool connectPeer(const PeerAddress &peerAddress) = 0;
|
2020-05-21 10:21:00 +03:00
|
|
|
virtual void clearPeers() = 0;
|
2020-04-12 18:08:19 +03:00
|
|
|
|
|
|
|
virtual QString createMagnetURI() const = 0;
|
|
|
|
|
2021-03-05 12:43:58 +03:00
|
|
|
TorrentID id() const;
|
2020-04-19 16:12:50 +03:00
|
|
|
bool isResumed() const;
|
|
|
|
qlonglong remainingSize() const;
|
|
|
|
|
2020-04-12 18:08:19 +03:00
|
|
|
void toggleSequentialDownload();
|
|
|
|
void toggleFirstLastPiecePriority();
|
2015-04-19 18:17:47 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-02-18 03:38:40 +03:00
|
|
|
Q_DECLARE_METATYPE(BitTorrent::TorrentState)
|