4#include <Kanoop/torrent/kanooptorrent.h>
5#include <Kanoop/torrent/magnetlink.h>
6#include <Kanoop/torrent/peerinfo.h>
7#include <Kanoop/utility/loggingbaseclass.h>
20class LIBKANOOPTORRENT_EXPORT
Torrent :
public QObject,
21 public LoggingBaseClass
39 Torrent(QObject* parent =
nullptr);
67 QByteArray
infoHash()
const {
return _infoHash; }
69 QString
infoHashHex()
const {
return QString::fromLatin1(_infoHash.toHex()); }
317 void setHandle(
void* handle);
319 void* handle()
const {
return _handle; }
321 void setMagnetLink(
const MagnetLink& link) { _magnetLink = link; }
323 void setInfoHash(
const QByteArray& hash) { _infoHash = hash; }
325 void setDownloadDirectory(
const QString& dir) { _downloadDirectory = dir; }
327 void updateFromStatus();
329 void checkSeedRatio();
361 void setState(
State newState);
365 QByteArray _infoHash;
366 QString _downloadDirectory;
367 bool _hasMetadata =
false;
368 bool _downloadEmitted =
false;
369 double _seedRatioLimit = 0.0;
370 void* _handle =
nullptr;
Parses and constructs BitTorrent magnet URIs.
Represents a single torrent within a TorrentClient session.
int filePriority(int index) const
Get the current download priority for a file.
qint64 uploadRate() const
Current upload rate in bytes/sec.
void storageMoved(const QString &newPath)
Emitted when moveStorage() completes successfully.
void setUploadLimit(int bytesPerSecond)
Set the per-torrent upload rate limit.
void forceReannounce()
Force an immediate re-announce to all trackers.
int eta() const
Estimated seconds remaining until download completes.
QByteArray infoHash() const
Raw 20-byte SHA-1 info hash.
int maxUploads() const
Maximum number of upload slots for this torrent.
void setMaxConnections(int value)
Set the maximum peer connections for this torrent.
bool isAutoManaged() const
Whether libtorrent auto-manages this torrent's queue position.
QString outputPath() const
Full output path (save_path + torrent name).
bool hasMetadata() const
Whether torrent metadata has been received.
QString infoHashHex() const
Info hash as a lowercase hex string (40 characters).
void setDownloadLimit(int bytesPerSecond)
Set the per-torrent download rate limit.
void removeTracker(const QString &url)
Remove a tracker by URL.
State state() const
Current lifecycle state.
void downloadComplete()
Emitted once when the entire torrent download completes.
void progressUpdated(double ratio)
Emitted periodically during download with the current progress ratio (0.0–1.0).
QList< PeerInfo > peers() const
Snapshot of all currently connected peers.
QString name() const
Human-readable torrent name.
void resume()
Resume a paused torrent.
qint64 bytesDownloaded() const
Total bytes downloaded so far.
int findFileByName(const QString &partialName) const
Find a file by partial name (case-insensitive substring match).
int totalPieces() const
Total number of pieces in this torrent.
int connectedPeers() const
Number of currently connected peers.
void banPeer(const QHostAddress &address)
Ban a peer by IP address.
void stateChanged(Torrent::State state)
Emitted when the torrent transitions to a new State.
qint64 fileSize(int index) const
Size of a file in bytes.
void stop()
Stop the torrent and reset state to Idle.
int fileCount() const
Number of files in the torrent.
int maxConnections() const
Maximum number of peer connections for this torrent.
QList< qint64 > fileProgress() const
Get per-file download progress as a list of byte counts.
void trackerAnnounced(const QString &url)
Emitted when a tracker announce succeeds.
void setAutoManaged(bool enabled)
Enable or disable libtorrent's auto-managed mode.
void setFilePriority(int index, int priority)
Set the download priority for a single file.
void fileRenamed(int fileIndex, const QString &newName)
Emitted when renameFile() completes successfully.
void start()
Resume downloading/seeding.
void saveResumeData()
Request an asynchronous resume-data save.
int downloadedPieces() const
Number of pieces that have been downloaded and verified.
void setAllFilePriorities(int priority)
Set the same download priority for every file.
void setSeedRatioLimit(double ratio)
Set a share-ratio target; the torrent pauses when it is reached.
qint64 totalUploaded() const
Total bytes uploaded over the lifetime of this torrent.
int downloadLimit() const
Per-torrent download rate limit in bytes/sec.
void metadataReceived()
Emitted when metadata is received (magnet links only).
void storageMoveError(const QString &error)
Emitted when moveStorage() fails.
void fileRenameError(int fileIndex, const QString &error)
Emitted when renameFile() fails.
void setMaxUploads(int value)
Set the maximum upload slots for this torrent.
QString downloadDirectory() const
The directory where this torrent's data is being saved.
bool isSequentialDownload() const
Whether pieces are requested in sequential order.
void trackerError(const QString &url, const QString &message)
Emitted when a tracker announce fails.
void renameFile(int index, const QString &newName)
Rename a file within the torrent.
int pieceSize() const
Size of each piece in bytes.
int uploadLimit() const
Per-torrent upload rate limit in bytes/sec.
QString fileName(int index) const
Relative path of a file within the torrent.
qint64 downloadRate() const
Current download rate in bytes/sec.
double seedRatioLimit() const
Target share ratio after which the torrent is auto-paused.
QStringList trackers() const
List of tracker URLs currently attached to this torrent.
double ratio() const
Share ratio (uploaded / downloaded).
void fileCompleted(int fileIndex, const QString &filePath)
Emitted when an individual file finishes downloading.
void error(const QString &message)
Emitted on torrent errors (tracker failures, I/O errors, etc.).
State
Lifecycle state of a torrent.
@ Idle
Torrent is stopped or not yet started.
@ Checking
Verifying existing data on disk.
@ Downloading
Actively downloading pieces.
@ Error
An unrecoverable error occurred.
@ FetchingMetadata
Downloading torrent metadata (magnet link resolution).
@ Paused
Explicitly paused by the user.
@ Seeding
Download complete; uploading to peers.
double progress() const
Download progress as a ratio from 0.0 to 1.0.
qint64 totalSize() const
Total size of all selected files in bytes.
void moveStorage(const QString &newPath)
Move the torrent's data to a new directory.
void pause()
Pause the torrent, keeping its state recoverable via resume().
void setSequentialDownload(bool enabled)
Enable or disable sequential piece downloading.
QStringList fileNames() const
List of all file paths in the torrent.
void addTracker(const QString &url)
Append a tracker URL.