qBittorrent
BitTorrent::TorrentImpl Class Referencefinal

#include <torrentimpl.h>

Inheritance diagram for BitTorrent::TorrentImpl:
Collaboration diagram for BitTorrent::TorrentImpl:

Public Member Functions

 TorrentImpl (Session *session, lt::session *nativeSession, const lt::torrent_handle &nativeHandle, const LoadTorrentParams &params)
 
 ~TorrentImpl () override
 
bool isValid () const
 
InfoHash infoHash () const override
 
QString name () const override
 
QDateTime creationDate () const override
 
QString creator () const override
 
QString comment () const override
 
bool isPrivate () const override
 
qlonglong totalSize () const override
 
qlonglong wantedSize () const override
 
qlonglong completedSize () const override
 
qlonglong pieceLength () const override
 
qlonglong wastedSize () const override
 
QString currentTracker () const override
 
bool isAutoTMMEnabled () const override
 
void setAutoTMMEnabled (bool enabled) override
 
QString savePath () const override
 
void setSavePath (const QString &path) override
 
QString downloadPath () const override
 
void setDownloadPath (const QString &path) override
 
QString actualStorageLocation () const override
 
QString rootPath () const override
 
QString contentPath () const override
 
QString category () const override
 
bool belongsToCategory (const QString &category) const override
 
bool setCategory (const QString &category) override
 
TagSet tags () const override
 
bool hasTag (const QString &tag) const override
 
bool addTag (const QString &tag) override
 
bool removeTag (const QString &tag) override
 
void removeAllTags () override
 
int filesCount () const override
 
int piecesCount () const override
 
int piecesHave () const override
 
qreal progress () const override
 
QDateTime addedTime () const override
 
qreal ratioLimit () const override
 
int seedingTimeLimit () const override
 
QString filePath (int index) const override
 
QString actualFilePath (int index) const override
 
qlonglong fileSize (int index) const override
 
QStringList filePaths () const override
 
QVector< DownloadPriorityfilePriorities () const override
 
TorrentInfo info () const override
 
bool isSeed () const override
 
bool isPaused () const override
 
bool isQueued () const override
 
bool isForced () const override
 
bool isChecking () const override
 
bool isDownloading () const override
 
bool isUploading () const override
 
bool isCompleted () const override
 
bool isActive () const override
 
bool isInactive () const override
 
bool isErrored () const override
 
bool isSequentialDownload () const override
 
bool hasFirstLastPiecePriority () const override
 
TorrentState state () const override
 
bool hasMetadata () const override
 
bool hasMissingFiles () const override
 
bool hasError () const override
 
int queuePosition () const override
 
QVector< TrackerEntrytrackers () const override
 
QVector< QUrl > urlSeeds () const override
 
QString error () const override
 
qlonglong totalDownload () const override
 
qlonglong totalUpload () const override
 
qlonglong activeTime () const override
 
qlonglong finishedTime () const override
 
qlonglong eta () const override
 
QVector< qreal > filesProgress () const override
 
int seedsCount () const override
 
int peersCount () const override
 
int leechsCount () const override
 
int totalSeedsCount () const override
 
int totalPeersCount () const override
 
int totalLeechersCount () const override
 
int completeCount () const override
 
int incompleteCount () const override
 
QDateTime lastSeenComplete () const override
 
QDateTime completedTime () const override
 
qlonglong timeSinceUpload () const override
 
qlonglong timeSinceDownload () const override
 
qlonglong timeSinceActivity () const override
 
int downloadLimit () const override
 
int uploadLimit () const override
 
bool superSeeding () const override
 
bool isDHTDisabled () const override
 
bool isPEXDisabled () const override
 
bool isLSDDisabled () const override
 
QVector< PeerInfopeers () const override
 
QBitArray pieces () const override
 
QBitArray downloadingPieces () const override
 
QVector< int > pieceAvailability () const override
 
qreal distributedCopies () const override
 
qreal maxRatio () const override
 
int maxSeedingTime () const override
 
qreal realRatio () const override
 
int uploadPayloadRate () const override
 
int downloadPayloadRate () const override
 
qlonglong totalPayloadUpload () const override
 
qlonglong totalPayloadDownload () const override
 
int connectionsCount () const override
 
int connectionsLimit () const override
 
qlonglong nextAnnounce () const override
 
QVector< qreal > availableFileFractions () const override
 fraction of file pieces that are available at least from one peer More...
 
void setName (const QString &name) override
 
void setSequentialDownload (bool enable) override
 
void setFirstLastPiecePriority (bool enabled) override
 
void pause () override
 
void resume (TorrentOperatingMode mode=TorrentOperatingMode::AutoManaged) override
 
void forceReannounce (int index=-1) override
 
void forceDHTAnnounce () override
 
void forceRecheck () override
 
void renameFile (int index, const QString &path) override
 
void prioritizeFiles (const QVector< DownloadPriority > &priorities) override
 
void setRatioLimit (qreal limit) override
 
void setSeedingTimeLimit (int limit) override
 
void setUploadLimit (int limit) override
 
void setDownloadLimit (int limit) override
 
void setSuperSeeding (bool enable) override
 
void setDHTDisabled (bool disable) override
 
void setPEXDisabled (bool disable) override
 
void setLSDDisabled (bool disable) override
 
void flushCache () const override
 
void addTrackers (const QVector< TrackerEntry > &trackers) override
 
void replaceTrackers (const QVector< TrackerEntry > &trackers) override
 
void addUrlSeeds (const QVector< QUrl > &urlSeeds) override
 
void removeUrlSeeds (const QVector< QUrl > &urlSeeds) override
 
bool connectPeer (const PeerAddress &peerAddress) override
 
void clearPeers () override
 
QString createMagnetURI () const override
 
bool needSaveResumeData () const
 
lt::torrent_handle nativeHandle () const
 
void handleAlert (const lt::alert *a)
 
void handleStateUpdate (const lt::torrent_status &nativeStatus)
 
void handleDownloadPathChanged ()
 
void handleCategoryOptionsChanged ()
 
void handleAppendExtensionToggled ()
 
void saveResumeData ()
 
void handleMoveStorageJobFinished (bool hasOutstandingJob)
 
void fileSearchFinished (const QString &savePath, const QStringList &fileNames)
 
- Public Member Functions inherited from BitTorrent::Torrent
virtual ~Torrent ()=default
 
TorrentID id () const
 
bool isResumed () const
 
qlonglong remainingSize () const
 
void toggleSequentialDownload ()
 
void toggleFirstLastPiecePriority ()
 
- Public Member Functions inherited from BitTorrent::AbstractFileStorage
virtual ~AbstractFileStorage ()=default
 
void renameFile (const QString &oldPath, const QString &newPath)
 
void renameFolder (const QString &oldPath, const QString &newPath)
 

Private Types

using EventTrigger = std::function< void()>
 

Private Member Functions

void updateStatus ()
 
void updateStatus (const lt::torrent_status &nativeStatus)
 
void updateState ()
 
void handleFastResumeRejectedAlert (const lt::fastresume_rejected_alert *p)
 
void handleFileCompletedAlert (const lt::file_completed_alert *p)
 
void handleFileErrorAlert (const lt::file_error_alert *p)
 
void handleFileRenamedAlert (const lt::file_renamed_alert *p)
 
void handleFileRenameFailedAlert (const lt::file_rename_failed_alert *p)
 
void handleMetadataReceivedAlert (const lt::metadata_received_alert *p)
 
void handlePerformanceAlert (const lt::performance_alert *p) const
 
void handleSaveResumeDataAlert (const lt::save_resume_data_alert *p)
 
void handleSaveResumeDataFailedAlert (const lt::save_resume_data_failed_alert *p)
 
void handleTorrentCheckedAlert (const lt::torrent_checked_alert *p)
 
void handleTorrentFinishedAlert (const lt::torrent_finished_alert *p)
 
void handleTorrentPausedAlert (const lt::torrent_paused_alert *p)
 
void handleTorrentResumedAlert (const lt::torrent_resumed_alert *p)
 
void handleTrackerErrorAlert (const lt::tracker_error_alert *p)
 
void handleTrackerReplyAlert (const lt::tracker_reply_alert *p)
 
void handleTrackerWarningAlert (const lt::tracker_warning_alert *p)
 
bool isMoveInProgress () const
 
void setAutoManaged (bool enable)
 
void adjustStorageLocation ()
 
void moveStorage (const QString &newPath, MoveStorageMode mode)
 
void manageIncompleteFiles ()
 
void applyFirstLastPiecePriority (bool enabled, const QVector< DownloadPriority > &updatedFilePrio={})
 
void prepareResumeData (const lt::add_torrent_params &params)
 
void endReceivedMetadataHandling (const QString &savePath, const QStringList &fileNames)
 
void reload ()
 

Private Attributes

Session *const m_session
 
lt::session * m_nativeSession
 
lt::torrent_handle m_nativeHandle
 
lt::torrent_status m_nativeStatus
 
TorrentState m_state = TorrentState::Unknown
 
TorrentInfo m_torrentInfo
 
QStringList m_filePaths
 
SpeedMonitor m_speedMonitor
 
InfoHash m_infoHash
 
QQueue< EventTriggerm_moveFinishedTriggers
 
int m_renameCount = 0
 
bool m_storageIsMoving = false
 
MaintenanceJob m_maintenanceJob = MaintenanceJob::None
 
QHash< QString, QMap< lt::tcp::endpoint, int > > m_trackerPeerCounts
 
FileErrorInfo m_lastFileError
 
QString m_name
 
QString m_savePath
 
QString m_downloadPath
 
QString m_category
 
TagSet m_tags
 
qreal m_ratioLimit
 
int m_seedingTimeLimit
 
TorrentOperatingMode m_operatingMode
 
TorrentContentLayout m_contentLayout
 
bool m_hasSeedStatus
 
bool m_fastresumeDataRejected = false
 
bool m_hasMissingFiles = false
 
bool m_hasFirstLastPiecePriority = false
 
bool m_useAutoTMM
 
bool m_isStopped
 
bool m_unchecked = false
 
lt::add_torrent_params m_ltAddTorrentParams
 

Additional Inherited Members

- Static Public Attributes inherited from BitTorrent::Torrent
static const qreal USE_GLOBAL_RATIO = -2
 
static const qreal NO_RATIO_LIMIT = -1
 
static const int USE_GLOBAL_SEEDING_TIME = -2
 
static const int NO_SEEDING_TIME_LIMIT = -1
 
static const qreal MAX_RATIO = 9999
 
static const int MAX_SEEDING_TIME = 525600
 

Detailed Description

Definition at line 77 of file torrentimpl.h.

Member Typedef Documentation

◆ EventTrigger

using BitTorrent::TorrentImpl::EventTrigger = std::function<void ()>
private

Definition at line 242 of file torrentimpl.h.

Constructor & Destructor Documentation

◆ TorrentImpl()

TorrentImpl::TorrentImpl ( Session session,
lt::session *  nativeSession,
const lt::torrent_handle &  nativeHandle,
const LoadTorrentParams params 
)

Definition at line 242 of file torrentimpl.cpp.

244  : QObject(session)
245  , m_session(session)
246  , m_nativeSession(nativeSession)
248 #ifdef QBT_USES_LIBTORRENT2
249  , m_infoHash(m_nativeHandle.info_hashes())
250 #else
251  , m_infoHash(m_nativeHandle.info_hash())
252 #endif
253  , m_name(params.name)
254  , m_savePath(params.savePath)
255  , m_downloadPath(params.downloadPath)
256  , m_category(params.category)
257  , m_tags(params.tags)
258  , m_ratioLimit(params.ratioLimit)
264  , m_useAutoTMM(params.useAutoTMM)
265  , m_isStopped(params.stopped)
267 {
268  if (m_ltAddTorrentParams.ti)
269  {
270  // Initialize it only if torrent is added with metadata.
271  // Otherwise it should be initialized in "Metadata received" handler.
273 
274  Q_ASSERT(m_filePaths.isEmpty());
275  const int filesCount = m_torrentInfo.filesCount();
276  m_filePaths.reserve(filesCount);
277  const std::shared_ptr<const lt::torrent_info> currentInfo = m_nativeHandle.torrent_file();
278  const lt::file_storage &fileStorage = currentInfo->files();
279  for (int i = 0; i < filesCount; ++i)
280  {
281  const lt::file_index_t nativeIndex = m_torrentInfo.nativeIndexes().at(i);
282  const QString filePath = Utils::Fs::toUniformPath(QString::fromStdString(fileStorage.file_path(nativeIndex)));
283  m_filePaths.append(filePath.endsWith(QB_EXT, Qt::CaseInsensitive) ? filePath.chopped(QB_EXT.size()) : filePath);
284  }
285  }
286 
288  updateState();
289 
290  if (hasMetadata())
292 
293  // TODO: Remove the following upgrade code in v4.4
294  // == BEGIN UPGRADE CODE ==
295  const QString spath = actualStorageLocation();
296  for (int i = 0; i < filesCount(); ++i)
297  {
298  const QString filepath = filePath(i);
299  // Move "unwanted" files back to their original folder
300  const QString parentRelPath = Utils::Fs::branchPath(filepath);
301  if (QDir(parentRelPath).dirName() == ".unwanted")
302  {
303  const QString oldName = Utils::Fs::fileName(filepath);
304  const QString newRelPath = Utils::Fs::branchPath(parentRelPath);
305  if (newRelPath.isEmpty())
306  renameFile(i, oldName);
307  else
308  renameFile(i, QDir(newRelPath).filePath(oldName));
309 
310  // Remove .unwanted directory if empty
311  qDebug() << "Attempting to remove \".unwanted\" folder at " << QDir(spath + '/' + newRelPath).absoluteFilePath(".unwanted");
312  QDir(spath + '/' + newRelPath).rmdir(".unwanted");
313  }
314  }
315  // == END UPGRADE CODE ==
316 }
lt::torrent_handle m_nativeHandle
Definition: torrentimpl.h:283
lt::session * m_nativeSession
Definition: torrentimpl.h:282
void renameFile(int index, const QString &path) override
lt::torrent_status m_nativeStatus
Definition: torrentimpl.h:284
lt::add_torrent_params m_ltAddTorrentParams
Definition: torrentimpl.h:322
int filesCount() const override
QString filePath(int index) const override
lt::torrent_handle nativeHandle() const
TorrentInfo m_torrentInfo
Definition: torrentimpl.h:286
TorrentOperatingMode m_operatingMode
Definition: torrentimpl.h:311
TorrentContentLayout m_contentLayout
Definition: torrentimpl.h:312
void applyFirstLastPiecePriority(bool enabled, const QVector< DownloadPriority > &updatedFilePrio={})
Session *const m_session
Definition: torrentimpl.h:281
bool hasMetadata() const override
QString actualStorageLocation() const override
QVector< lt::file_index_t > nativeIndexes() const
const QString QB_EXT
Definition: common.h:33
QString fileName(const QString &filePath)
Definition: fs.cpp:87
QString toUniformPath(const QString &path)
Definition: fs.cpp:69
QString branchPath(const QString &filePath, QString *removed=nullptr)
Definition: fs.cpp:276
void initializeStatus(lt::torrent_status &status, const lt::add_torrent_params &params)
TorrentContentLayout contentLayout
lt::add_torrent_params ltAddTorrentParams
TorrentOperatingMode operatingMode

References actualStorageLocation(), applyFirstLastPiecePriority(), Utils::Fs::branchPath(), Utils::Fs::fileName(), filePath(), BitTorrent::TorrentInfo::filesCount(), filesCount(), hasMetadata(), anonymous_namespace{torrentimpl.cpp}::initializeStatus(), m_filePaths, m_hasFirstLastPiecePriority, m_ltAddTorrentParams, m_nativeHandle, m_nativeStatus, m_torrentInfo, BitTorrent::TorrentInfo::nativeIndexes(), QB_EXT, renameFile(), Utils::Fs::toUniformPath(), and updateState().

Here is the call graph for this function:

◆ ~TorrentImpl()

TorrentImpl::~TorrentImpl ( )
override

Definition at line 318 of file torrentimpl.cpp.

318 {}

Member Function Documentation

◆ activeTime()

qlonglong TorrentImpl::activeTime ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1050 of file torrentimpl.cpp.

1051 {
1052  return lt::total_seconds(m_nativeStatus.active_duration);
1053 }

References m_nativeStatus.

◆ actualFilePath()

QString TorrentImpl::actualFilePath ( int  index) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 801 of file torrentimpl.cpp.

802 {
803  const auto nativeIndex = m_torrentInfo.nativeIndexes().at(index);
804  return QString::fromStdString(m_nativeHandle.torrent_file()->files().file_path(nativeIndex));
805 }

References m_nativeHandle, m_torrentInfo, and BitTorrent::TorrentInfo::nativeIndexes().

Referenced by handleFileCompletedAlert(), and manageIncompleteFiles().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ actualStorageLocation()

QString TorrentImpl::actualStorageLocation ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 488 of file torrentimpl.cpp.

489 {
490  return Utils::Fs::toUniformPath(QString::fromStdString(m_nativeStatus.save_path));
491 }

References m_nativeStatus, and Utils::Fs::toUniformPath().

Referenced by BitTorrent::Session::addMoveTorrentStorageJob(), contentPath(), BitTorrent::Session::handleTorrentFinished(), rootPath(), and TorrentImpl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addedTime()

QDateTime TorrentImpl::addedTime ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 781 of file torrentimpl.cpp.

782 {
783  return QDateTime::fromSecsSinceEpoch(m_nativeStatus.added_time);
784 }

References m_nativeStatus.

◆ addTag()

bool TorrentImpl::addTag ( const QString &  tag)
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 746 of file torrentimpl.cpp.

747 {
748  if (!Session::isValidTag(tag))
749  return false;
750  if (hasTag(tag))
751  return false;
752 
753  if (!m_session->hasTag(tag))
754  {
755  if (!m_session->addTag(tag))
756  return false;
757  }
758  m_tags.insert(tag);
760  m_session->handleTorrentTagAdded(this, tag);
761  return true;
762 }
void handleTorrentTagAdded(TorrentImpl *const torrent, const QString &tag)
Definition: session.cpp:3885
bool hasTag(const QString &tag) const
Definition: session.cpp:834
bool addTag(const QString &tag)
Definition: session.cpp:839
void handleTorrentNeedSaveResumeData(const TorrentImpl *torrent)
Definition: session.cpp:1972
static bool isValidTag(const QString &tag)
Definition: session.cpp:829
bool hasTag(const QString &tag) const override

References BitTorrent::Session::addTag(), BitTorrent::Session::handleTorrentNeedSaveResumeData(), BitTorrent::Session::handleTorrentTagAdded(), BitTorrent::Session::hasTag(), hasTag(), BitTorrent::Session::isValidTag(), m_session, and m_tags.

Here is the call graph for this function:

◆ addTrackers()

void TorrentImpl::addTrackers ( const QVector< TrackerEntry > &  trackers)
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 521 of file torrentimpl.cpp.

522 {
523  QSet<TrackerEntry> currentTrackers;
524  for (const lt::announce_entry &entry : m_nativeHandle.trackers())
525  currentTrackers.insert({QString::fromStdString(entry.url), entry.tier});
526 
527  QVector<TrackerEntry> newTrackers;
528  newTrackers.reserve(trackers.size());
529 
530  for (const TrackerEntry &tracker : trackers)
531  {
532  if (!currentTrackers.contains(tracker))
533  {
534  m_nativeHandle.add_tracker(makeNativeAnnouncerEntry(tracker.url, tracker.tier));
535  newTrackers << tracker;
536  }
537  }
538 
539  if (!newTrackers.isEmpty())
540  {
542  m_session->handleTorrentTrackersAdded(this, newTrackers);
543  }
544 }
void handleTorrentTrackersAdded(TorrentImpl *const torrent, const QVector< TrackerEntry > &newTrackers)
Definition: session.cpp:3900
QVector< TrackerEntry > trackers() const override
lt::announce_entry makeNativeAnnouncerEntry(const QString &url, const int tier)
Definition: torrentimpl.cpp:73
Definition: trackerentry.h:38

References BitTorrent::Session::handleTorrentNeedSaveResumeData(), BitTorrent::Session::handleTorrentTrackersAdded(), m_nativeHandle, m_session, anonymous_namespace{torrentimpl.cpp}::makeNativeAnnouncerEntry(), and trackers().

Referenced by BitTorrent::Session::addTorrent_impl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addUrlSeeds()

void TorrentImpl::addUrlSeeds ( const QVector< QUrl > &  urlSeeds)
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 601 of file torrentimpl.cpp.

602 {
603  const std::set<std::string> currentSeeds = m_nativeHandle.url_seeds();
604 
605  QVector<QUrl> addedUrlSeeds;
606  addedUrlSeeds.reserve(urlSeeds.size());
607 
608  for (const QUrl &url : urlSeeds)
609  {
610  const std::string nativeUrl = url.toString().toStdString();
611  if (currentSeeds.find(nativeUrl) == currentSeeds.end())
612  {
613  m_nativeHandle.add_url_seed(nativeUrl);
614  addedUrlSeeds << url;
615  }
616  }
617 
618  if (!addedUrlSeeds.isEmpty())
619  {
621  m_session->handleTorrentUrlSeedsAdded(this, addedUrlSeeds);
622  }
623 }
void handleTorrentUrlSeedsAdded(TorrentImpl *const torrent, const QVector< QUrl > &newUrlSeeds)
Definition: session.cpp:3925
QVector< QUrl > urlSeeds() const override

References BitTorrent::Session::handleTorrentNeedSaveResumeData(), BitTorrent::Session::handleTorrentUrlSeedsAdded(), m_nativeHandle, m_session, and urlSeeds().

Referenced by BitTorrent::Session::addTorrent_impl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ adjustStorageLocation()

void TorrentImpl::adjustStorageLocation ( )
private

Definition at line 2071 of file torrentimpl.cpp.

2072 {
2073  const QString downloadPath = this->downloadPath();
2074  const bool isFinished = isSeed() || m_hasSeedStatus;
2075  const QDir targetDir {((isFinished || downloadPath.isEmpty()) ? savePath() : downloadPath)};
2076 
2077  moveStorage(targetDir.absolutePath(), MoveStorageMode::Overwrite);
2078 }
QString downloadPath() const override
QString savePath() const override
bool isSeed() const override
void moveStorage(const QString &newPath, MoveStorageMode mode)

References downloadPath(), isSeed(), m_hasSeedStatus, moveStorage(), BitTorrent::Overwrite, and savePath().

Referenced by handleCategoryOptionsChanged(), handleDownloadPathChanged(), handleTorrentCheckedAlert(), handleTorrentFinishedAlert(), setAutoTMMEnabled(), and setCategory().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ applyFirstLastPiecePriority()

void TorrentImpl::applyFirstLastPiecePriority ( bool  enabled,
const QVector< DownloadPriority > &  updatedFilePrio = {} 
)
private

Definition at line 1447 of file torrentimpl.cpp.

1448 {
1449  Q_ASSERT(hasMetadata());
1450 
1451  // Download first and last pieces first for every file in the torrent
1452 
1453  const QVector<DownloadPriority> filePriorities =
1454  !updatedFilePrio.isEmpty() ? updatedFilePrio : this->filePriorities();
1455  std::vector<lt::download_priority_t> piecePriorities = nativeHandle().get_piece_priorities();
1456 
1457  // Updating file priorities is an async operation in libtorrent, when we just updated it and immediately query it
1458  // we might get the old/wrong values, so we rely on `updatedFilePrio` in this case.
1459  for (int index = 0; index < filePriorities.size(); ++index)
1460  {
1461  const DownloadPriority filePrio = filePriorities[index];
1462  if (filePrio <= DownloadPriority::Ignored)
1463  continue;
1464 
1465  // Determine the priority to set
1466  const DownloadPriority newPrio = enabled ? DownloadPriority::Maximum : filePrio;
1467  const auto piecePrio = static_cast<lt::download_priority_t>(static_cast<int>(newPrio));
1468  const TorrentInfo::PieceRange extremities = m_torrentInfo.filePieces(index);
1469 
1470  // worst case: AVI index = 1% of total file size (at the end of the file)
1471  const int nNumPieces = std::ceil(fileSize(index) * 0.01 / pieceLength());
1472  for (int i = 0; i < nNumPieces; ++i)
1473  {
1474  piecePriorities[extremities.first() + i] = piecePrio;
1475  piecePriorities[extremities.last() - i] = piecePrio;
1476  }
1477  }
1478 
1479  m_nativeHandle.prioritize_pieces(piecePriorities);
1480 }
qlonglong fileSize(int index) const override
qlonglong pieceLength() const override
QVector< DownloadPriority > filePriorities() const override
PieceRange filePieces(const QString &file) const
constexpr IndexType last() const
Definition: indexrange.h:156
constexpr IndexType first() const
Definition: indexrange.h:151

References BitTorrent::TorrentInfo::filePieces(), filePriorities(), fileSize(), IndexRange< Index, IndexDiff >::first(), hasMetadata(), BitTorrent::Ignored, IndexRange< Index, IndexDiff >::last(), m_nativeHandle, m_torrentInfo, BitTorrent::Maximum, nativeHandle(), and pieceLength().

Referenced by endReceivedMetadataHandling(), prioritizeFiles(), setFirstLastPiecePriority(), and TorrentImpl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ availableFileFractions()

QVector< qreal > TorrentImpl::availableFileFractions ( ) const
overridevirtual

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.

Implements BitTorrent::Torrent.

Definition at line 2259 of file torrentimpl.cpp.

2260 {
2261  Q_ASSERT(hasMetadata());
2262 
2263  const int filesCount = this->filesCount();
2264  if (filesCount <= 0) return {};
2265 
2266  const QVector<int> piecesAvailability = pieceAvailability();
2267  // libtorrent returns empty array for seeding only torrents
2268  if (piecesAvailability.empty()) return QVector<qreal>(filesCount, -1);
2269 
2270  QVector<qreal> res;
2271  res.reserve(filesCount);
2272  for (int i = 0; i < filesCount; ++i)
2273  {
2274  const TorrentInfo::PieceRange filePieces = m_torrentInfo.filePieces(i);
2275 
2276  int availablePieces = 0;
2277  for (const int piece : filePieces)
2278  availablePieces += (piecesAvailability[piece] > 0) ? 1 : 0;
2279 
2280  const qreal availability = filePieces.isEmpty()
2281  ? 1 // the file has no pieces, so it is available by default
2282  : static_cast<qreal>(availablePieces) / filePieces.size();
2283  res.push_back(availability);
2284  }
2285  return res;
2286 }
QVector< int > pieceAvailability() const override
constexpr bool isEmpty() const
Definition: indexrange.h:161

References BitTorrent::TorrentInfo::filePieces(), filesCount(), hasMetadata(), IndexRange< Index, IndexDiff >::isEmpty(), m_torrentInfo, pieceAvailability(), and IndexRange< Index, IndexDiff >::size().

Here is the call graph for this function:

◆ belongsToCategory()

bool TorrentImpl::belongsToCategory ( const QString &  category) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 723 of file torrentimpl.cpp.

724 {
725  if (m_category.isEmpty()) return category.isEmpty();
726  if (!Session::isValidCategoryName(category)) return false;
727 
728  if (m_category == category) return true;
729 
730  if (m_session->isSubcategoriesEnabled() && m_category.startsWith(category + '/'))
731  return true;
732 
733  return false;
734 }
static bool isValidCategoryName(const QString &name)
Definition: session.cpp:630
bool isSubcategoriesEnabled() const
Definition: session.cpp:798
QString category() const override

References category(), BitTorrent::Session::isSubcategoriesEnabled(), BitTorrent::Session::isValidCategoryName(), m_category, and m_session.

Here is the call graph for this function:

◆ category()

QString TorrentImpl::category ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 718 of file torrentimpl.cpp.

719 {
720  return m_category;
721 }

References m_category.

Referenced by belongsToCategory(), downloadPath(), savePath(), setAutoTMMEnabled(), and setCategory().

Here is the caller graph for this function:

◆ clearPeers()

void TorrentImpl::clearPeers ( )
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 649 of file torrentimpl.cpp.

650 {
651  m_nativeHandle.clear_peers();
652 }

References m_nativeHandle.

Referenced by replaceTrackers().

Here is the caller graph for this function:

◆ comment()

QString TorrentImpl::comment ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 355 of file torrentimpl.cpp.

356 {
357  return m_torrentInfo.comment();
358 }
QString comment() const

References BitTorrent::TorrentInfo::comment(), and m_torrentInfo.

Here is the call graph for this function:

◆ completeCount()

int TorrentImpl::completeCount ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1157 of file torrentimpl.cpp.

1158 {
1159  // additional info: https://github.com/qbittorrent/qBittorrent/pull/5300#issuecomment-267783646
1160  return m_nativeStatus.num_complete;
1161 }

References m_nativeStatus.

◆ completedSize()

qlonglong TorrentImpl::completedSize ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 376 of file torrentimpl.cpp.

377 {
378  return m_nativeStatus.total_wanted_done;
379 }

References m_nativeStatus.

Referenced by eta().

Here is the caller graph for this function:

◆ completedTime()

QDateTime TorrentImpl::completedTime ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1177 of file torrentimpl.cpp.

1178 {
1179  if (m_nativeStatus.completed_time > 0)
1180  return QDateTime::fromSecsSinceEpoch(m_nativeStatus.completed_time);
1181  else
1182  return {};
1183 }

References m_nativeStatus.

◆ connectionsCount()

int TorrentImpl::connectionsCount ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1341 of file torrentimpl.cpp.

1342 {
1343  return m_nativeStatus.num_connections;
1344 }

References m_nativeStatus.

◆ connectionsLimit()

int TorrentImpl::connectionsLimit ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1346 of file torrentimpl.cpp.

1347 {
1348  return m_nativeStatus.connections_limit;
1349 }

References m_nativeStatus.

◆ connectPeer()

bool TorrentImpl::connectPeer ( const PeerAddress peerAddress)
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 654 of file torrentimpl.cpp.

655 {
656  lt::error_code ec;
657  const lt::address addr = lt::make_address(peerAddress.ip.toString().toStdString(), ec);
658  if (ec) return false;
659 
660  const lt::tcp::endpoint endpoint(addr, peerAddress.port);
661  try
662  {
663  m_nativeHandle.connect_peer(endpoint);
664  }
665  catch (const lt::system_error &err)
666  {
667  LogMsg(tr("Failed to add peer \"%1\" to torrent \"%2\". Reason: %3")
668  .arg(peerAddress.toString(), name(), QString::fromLocal8Bit(err.what())), Log::WARNING);
669  return false;
670  }
671 
672  LogMsg(tr("Peer \"%1\" is added to torrent \"%2\"").arg(peerAddress.toString(), name()));
673  return true;
674 }
QString name() const override
void LogMsg(const QString &message, const Log::MsgType &type)
Definition: logger.cpp:125
@ WARNING
Definition: logger.h:47
QString toString() const
Definition: peeraddress.cpp:64

References BitTorrent::PeerAddress::ip, LogMsg(), m_nativeHandle, name(), BitTorrent::PeerAddress::port, BitTorrent::PeerAddress::toString(), and Log::WARNING.

Here is the call graph for this function:

◆ contentPath()

QString TorrentImpl::contentPath ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 453 of file torrentimpl.cpp.

454 {
455  if (!hasMetadata())
456  return {};
457 
458  if (filesCount() == 1)
459  return QDir(actualStorageLocation()).absoluteFilePath(filePath(0));
460 
461  const QString rootPath = this->rootPath();
462  return (rootPath.isEmpty() ? actualStorageLocation() : rootPath);
463 }
QString rootPath() const override

References actualStorageLocation(), filePath(), filesCount(), hasMetadata(), and rootPath().

Here is the call graph for this function:

◆ createMagnetURI()

QString TorrentImpl::createMagnetURI ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 2219 of file torrentimpl.cpp.

2220 {
2221  return QString::fromStdString(lt::make_magnet_uri(m_nativeHandle));
2222 }

References m_nativeHandle.

◆ creationDate()

QDateTime TorrentImpl::creationDate ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 345 of file torrentimpl.cpp.

346 {
347  return m_torrentInfo.creationDate();
348 }
QDateTime creationDate() const

References BitTorrent::TorrentInfo::creationDate(), and m_torrentInfo.

Here is the call graph for this function:

◆ creator()

QString TorrentImpl::creator ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 350 of file torrentimpl.cpp.

351 {
352  return m_torrentInfo.creator();
353 }
QString creator() const

References BitTorrent::TorrentInfo::creator(), and m_torrentInfo.

Here is the call graph for this function:

◆ currentTracker()

QString TorrentImpl::currentTracker ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 391 of file torrentimpl.cpp.

392 {
393  return QString::fromStdString(m_nativeStatus.current_tracker);
394 }

References m_nativeStatus.

◆ distributedCopies()

qreal TorrentImpl::distributedCopies ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1284 of file torrentimpl.cpp.

1285 {
1286  return m_nativeStatus.distributed_copies;
1287 }

References m_nativeStatus.

◆ downloadingPieces()

QBitArray TorrentImpl::downloadingPieces ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1263 of file torrentimpl.cpp.

1264 {
1265  QBitArray result(piecesCount());
1266 
1267  std::vector<lt::partial_piece_info> queue;
1268  m_nativeHandle.get_download_queue(queue);
1269 
1270  for (const lt::partial_piece_info &info : queue)
1271  result.setBit(LT::toUnderlyingType(info.piece_index));
1272 
1273  return result;
1274 }
int piecesCount() const override
TorrentInfo info() const override
constexpr T::underlying_type toUnderlyingType(const T &t) noexcept
Definition: lttypecast.h:38

References info(), m_nativeHandle, piecesCount(), and BitTorrent::LT::toUnderlyingType().

Here is the call graph for this function:

◆ downloadLimit()

int TorrentImpl::downloadLimit ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1208 of file torrentimpl.cpp.

1209 {
1210  return m_nativeHandle.download_limit();
1211 }

References m_nativeHandle.

Referenced by setDownloadLimit().

Here is the caller graph for this function:

◆ downloadPath()

QString TorrentImpl::downloadPath ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 418 of file torrentimpl.cpp.

419 {
421 }
QString categoryDownloadPath(const QString &categoryName) const
Definition: session.cpp:682
bool isAutoTMMEnabled() const override

References category(), BitTorrent::Session::categoryDownloadPath(), isAutoTMMEnabled(), m_downloadPath, and m_session.

Referenced by adjustStorageLocation(), and handleSaveResumeDataAlert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ downloadPayloadRate()

int TorrentImpl::downloadPayloadRate ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1326 of file torrentimpl.cpp.

1327 {
1328  return m_nativeStatus.download_payload_rate;
1329 }

References m_nativeStatus.

◆ endReceivedMetadataHandling()

void TorrentImpl::endReceivedMetadataHandling ( const QString &  savePath,
const QStringList &  fileNames 
)
private

Definition at line 1487 of file torrentimpl.cpp.

1488 {
1489  Q_ASSERT(m_filePaths.isEmpty());
1490 
1491  lt::add_torrent_params &p = m_ltAddTorrentParams;
1492 
1493  const std::shared_ptr<lt::torrent_info> metadata = std::const_pointer_cast<lt::torrent_info>(m_nativeHandle.torrent_file());
1494  m_torrentInfo = TorrentInfo(*metadata);
1495  const auto nativeIndexes = m_torrentInfo.nativeIndexes();
1496  for (int i = 0; i < fileNames.size(); ++i)
1497  {
1498  const QString filePath = fileNames.at(i);
1499  m_filePaths.append(filePath.endsWith(QB_EXT, Qt::CaseInsensitive) ? filePath.chopped(QB_EXT.size()) : filePath);
1500  p.renamed_files[nativeIndexes[i]] = filePath.toStdString();
1501  }
1502  p.save_path = Utils::Fs::toNativePath(savePath).toStdString();
1503  p.ti = metadata;
1504 
1505  const int internalFilesCount = p.ti->files().num_files(); // including .pad files
1506  // Use qBittorrent default priority rather than libtorrent's (4)
1507  p.file_priorities = std::vector(internalFilesCount, LT::toNative(DownloadPriority::Normal));
1508 
1509  reload();
1510 
1511  // If first/last piece priority was specified when adding this torrent,
1512  // we should apply it now that we have metadata:
1515 
1517  updateStatus();
1518  prepareResumeData(p);
1519 
1521 }
void handleTorrentMetadataReceived(TorrentImpl *const torrent)
Definition: session.cpp:3937
void prepareResumeData(const lt::add_torrent_params &params)
MaintenanceJob m_maintenanceJob
Definition: torrentimpl.h:298
constexpr lt::download_priority_t toNative(const DownloadPriority priority) noexcept
Definition: lttypecast.h:43
QString toNativePath(const QString &path)
Definition: fs.cpp:64

References applyFirstLastPiecePriority(), filePath(), BitTorrent::Session::handleTorrentMetadataReceived(), m_filePaths, m_hasFirstLastPiecePriority, m_ltAddTorrentParams, m_maintenanceJob, m_nativeHandle, m_session, m_torrentInfo, BitTorrent::TorrentInfo::nativeIndexes(), BitTorrent::None, BitTorrent::Normal, prepareResumeData(), QB_EXT, reload(), savePath(), BitTorrent::LT::toNative(), Utils::Fs::toNativePath(), and updateStatus().

Referenced by fileSearchFinished().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ error()

QString TorrentImpl::error ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1023 of file torrentimpl.cpp.

1024 {
1025  if (m_nativeStatus.errc)
1026  return QString::fromLocal8Bit(m_nativeStatus.errc.message().c_str());
1027 
1028  if (m_nativeStatus.flags & lt::torrent_flags::upload_mode)
1029  {
1030  const QString writeErrorStr = tr("Couldn't write to file.");
1031  const QString uploadModeStr = tr("Torrent is currently in \"upload only\" mode.");
1032  const QString errorMessage = QString::fromLocal8Bit(m_lastFileError.error.message().c_str());
1033 
1034  return writeErrorStr + QLatin1Char(' ') + errorMessage + QLatin1String(". ") + uploadModeStr;
1035  }
1036 
1037  return {};
1038 }
FileErrorInfo m_lastFileError
Definition: torrentimpl.h:301
lt::error_code error
Definition: torrentimpl.h:73

References BitTorrent::FileErrorInfo::error, m_lastFileError, and m_nativeStatus.

Referenced by nova3.sgmllib3.SGMLParser::goahead(), nova3.sgmllib3.SGMLParser::parse_pi(), and nova3.sgmllib3.SGMLParser::parse_starttag().

Here is the caller graph for this function:

◆ eta()

qlonglong TorrentImpl::eta ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1060 of file torrentimpl.cpp.

1061 {
1062  if (isPaused()) return MAX_ETA;
1063 
1064  const SpeedSampleAvg speedAverage = m_speedMonitor.average();
1065 
1066  if (isSeed())
1067  {
1068  const qreal maxRatioValue = maxRatio();
1069  const int maxSeedingTimeValue = maxSeedingTime();
1070  if ((maxRatioValue < 0) && (maxSeedingTimeValue < 0)) return MAX_ETA;
1071 
1072  qlonglong ratioEta = MAX_ETA;
1073 
1074  if ((speedAverage.upload > 0) && (maxRatioValue >= 0))
1075  {
1076 
1077  qlonglong realDL = totalDownload();
1078  if (realDL <= 0)
1079  realDL = wantedSize();
1080 
1081  ratioEta = ((realDL * maxRatioValue) - totalUpload()) / speedAverage.upload;
1082  }
1083 
1084  qlonglong seedingTimeEta = MAX_ETA;
1085 
1086  if (maxSeedingTimeValue >= 0)
1087  {
1088  seedingTimeEta = (maxSeedingTimeValue * 60) - finishedTime();
1089  if (seedingTimeEta < 0)
1090  seedingTimeEta = 0;
1091  }
1092 
1093  return std::min(ratioEta, seedingTimeEta);
1094  }
1095 
1096  if (!speedAverage.download) return MAX_ETA;
1097 
1098  return (wantedSize() - completedSize()) / speedAverage.download;
1099 }
qlonglong finishedTime() const override
qlonglong wantedSize() const override
qlonglong totalUpload() const override
qreal maxRatio() const override
qlonglong totalDownload() const override
SpeedMonitor m_speedMonitor
Definition: torrentimpl.h:288
int maxSeedingTime() const override
qlonglong completedSize() const override
bool isPaused() const override
SpeedSampleAvg average() const
T download
Definition: speedmonitor.h:63
const qlonglong MAX_ETA
Definition: types.h:33

References SpeedMonitor::average(), completedSize(), Sample< T >::download, finishedTime(), isPaused(), isSeed(), m_speedMonitor, MAX_ETA, maxRatio(), maxSeedingTime(), totalDownload(), totalUpload(), Sample< T >::upload, and wantedSize().

Here is the call graph for this function:

◆ filePath()

QString TorrentImpl::filePath ( int  index) const
overridevirtual

Implements BitTorrent::AbstractFileStorage.

Definition at line 796 of file torrentimpl.cpp.

797 {
798  return m_filePaths.at(index);
799 }

References m_filePaths.

Referenced by contentPath(), endReceivedMetadataHandling(), handleFileCompletedAlert(), handleFileRenameFailedAlert(), manageIncompleteFiles(), and TorrentImpl().

Here is the caller graph for this function:

◆ filePaths()

QStringList TorrentImpl::filePaths ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 812 of file torrentimpl.cpp.

813 {
814  return m_filePaths;
815 }

References m_filePaths.

Referenced by handleSaveResumeDataAlert(), BitTorrent::Session::handleTorrentFinished(), and BitTorrent::Session::recursiveTorrentDownload().

Here is the caller graph for this function:

◆ filePriorities()

QVector< DownloadPriority > TorrentImpl::filePriorities ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 817 of file torrentimpl.cpp.

818 {
819  if (!hasMetadata())
820  return {};
821 
822  const std::vector<lt::download_priority_t> fp = m_nativeHandle.get_file_priorities();
823 
824  QVector<DownloadPriority> ret;
825  ret.reserve(filesCount());
826  for (const lt::file_index_t nativeIndex : asConst(m_torrentInfo.nativeIndexes()))
827  {
828  const auto priority = LT::fromNative(fp[LT::toUnderlyingType(nativeIndex)]);
829  ret.append(priority);
830  }
831 
832  return ret;
833 }
constexpr std::add_const_t< T > & asConst(T &t) noexcept
Definition: global.h:42
constexpr DownloadPriority fromNative(const lt::download_priority_t priority) noexcept
Definition: lttypecast.h:48

References asConst(), filesCount(), BitTorrent::LT::fromNative(), hasMetadata(), m_nativeHandle, m_torrentInfo, BitTorrent::TorrentInfo::nativeIndexes(), and BitTorrent::LT::toUnderlyingType().

Referenced by applyFirstLastPiecePriority(), and prioritizeFiles().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ filesCount()

int TorrentImpl::filesCount ( ) const
overridevirtual

Implements BitTorrent::AbstractFileStorage.

Definition at line 687 of file torrentimpl.cpp.

688 {
689  return m_torrentInfo.filesCount();
690 }

References BitTorrent::TorrentInfo::filesCount(), and m_torrentInfo.

Referenced by availableFileFractions(), contentPath(), filePriorities(), filesProgress(), manageIncompleteFiles(), prioritizeFiles(), and TorrentImpl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fileSearchFinished()

void TorrentImpl::fileSearchFinished ( const QString &  savePath,
const QStringList &  fileNames 
)

Definition at line 1482 of file torrentimpl.cpp.

1483 {
1485 }
void endReceivedMetadataHandling(const QString &savePath, const QStringList &fileNames)

References endReceivedMetadataHandling(), and savePath().

Referenced by BitTorrent::Session::fileSearchFinished().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fileSize()

qlonglong TorrentImpl::fileSize ( int  index) const
overridevirtual

Implements BitTorrent::AbstractFileStorage.

Definition at line 807 of file torrentimpl.cpp.

808 {
809  return m_torrentInfo.fileSize(index);
810 }
qlonglong fileSize(int index) const

References BitTorrent::TorrentInfo::fileSize(), and m_torrentInfo.

Referenced by applyFirstLastPiecePriority(), filesProgress(), and manageIncompleteFiles().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ filesProgress()

QVector< qreal > TorrentImpl::filesProgress ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1101 of file torrentimpl.cpp.

1102 {
1103  if (!hasMetadata())
1104  return {};
1105 
1106  std::vector<int64_t> fp;
1107  m_nativeHandle.file_progress(fp, lt::torrent_handle::piece_granularity);
1108 
1109  const int count = filesCount();
1110  const auto nativeIndexes = m_torrentInfo.nativeIndexes();
1111  QVector<qreal> result;
1112  result.reserve(count);
1113  for (int i = 0; i < count; ++i)
1114  {
1115  const int64_t progress = fp[LT::toUnderlyingType(nativeIndexes[i])];
1116  const qlonglong size = fileSize(i);
1117  if ((size <= 0) || (progress == size))
1118  result << 1;
1119  else
1120  result << (progress / static_cast<qreal>(size));
1121  }
1122 
1123  return result;
1124 }
qreal progress() const override

References filesCount(), fileSize(), hasMetadata(), m_nativeHandle, m_torrentInfo, BitTorrent::TorrentInfo::nativeIndexes(), progress(), and BitTorrent::LT::toUnderlyingType().

Referenced by manageIncompleteFiles(), and prioritizeFiles().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ finishedTime()

qlonglong TorrentImpl::finishedTime ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1055 of file torrentimpl.cpp.

1056 {
1057  return lt::total_seconds(m_nativeStatus.finished_duration);
1058 }

References m_nativeStatus.

Referenced by eta().

Here is the caller graph for this function:

◆ flushCache()

void TorrentImpl::flushCache ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 2214 of file torrentimpl.cpp.

2215 {
2216  m_nativeHandle.flush_cache();
2217 }

References m_nativeHandle.

◆ forceDHTAnnounce()

void TorrentImpl::forceDHTAnnounce ( )
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1395 of file torrentimpl.cpp.

1396 {
1397  m_nativeHandle.force_dht_announce();
1398 }

References m_nativeHandle.

◆ forceReannounce()

void TorrentImpl::forceReannounce ( int  index = -1)
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1390 of file torrentimpl.cpp.

1391 {
1392  m_nativeHandle.force_reannounce(0, index);
1393 }

References m_nativeHandle.

◆ forceRecheck()

void TorrentImpl::forceRecheck ( )
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1400 of file torrentimpl.cpp.

1401 {
1402  if (!hasMetadata()) return;
1403 
1404  m_nativeHandle.force_recheck();
1405  m_hasMissingFiles = false;
1406  m_unchecked = false;
1407 
1408  if (isPaused())
1409  {
1410  // When "force recheck" is applied on paused torrent, we temporarily resume it
1411  // (really we just allow libtorrent to resume it by enabling auto management for it).
1412  m_nativeHandle.set_flags(lt::torrent_flags::stop_when_ready | lt::torrent_flags::auto_managed);
1413  }
1414 }

References hasMetadata(), isPaused(), m_hasMissingFiles, m_nativeHandle, and m_unchecked.

Referenced by handleTorrentFinishedAlert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleAlert()

void TorrentImpl::handleAlert ( const lt::alert *  a)

Definition at line 1977 of file torrentimpl.cpp.

1978 {
1979  switch (a->type())
1980  {
1981 #ifdef QBT_USES_LIBTORRENT2
1982  case lt::file_prio_alert::alert_type:
1983  handleFilePrioAlert(static_cast<const lt::file_prio_alert*>(a));
1984  break;
1985 #endif
1986  case lt::file_renamed_alert::alert_type:
1987  handleFileRenamedAlert(static_cast<const lt::file_renamed_alert*>(a));
1988  break;
1989  case lt::file_rename_failed_alert::alert_type:
1990  handleFileRenameFailedAlert(static_cast<const lt::file_rename_failed_alert*>(a));
1991  break;
1992  case lt::file_completed_alert::alert_type:
1993  handleFileCompletedAlert(static_cast<const lt::file_completed_alert*>(a));
1994  break;
1995  case lt::file_error_alert::alert_type:
1996  handleFileErrorAlert(static_cast<const lt::file_error_alert*>(a));
1997  break;
1998  case lt::torrent_finished_alert::alert_type:
1999  handleTorrentFinishedAlert(static_cast<const lt::torrent_finished_alert*>(a));
2000  break;
2001  case lt::save_resume_data_alert::alert_type:
2002  handleSaveResumeDataAlert(static_cast<const lt::save_resume_data_alert*>(a));
2003  break;
2004  case lt::save_resume_data_failed_alert::alert_type:
2005  handleSaveResumeDataFailedAlert(static_cast<const lt::save_resume_data_failed_alert*>(a));
2006  break;
2007  case lt::torrent_paused_alert::alert_type:
2008  handleTorrentPausedAlert(static_cast<const lt::torrent_paused_alert*>(a));
2009  break;
2010  case lt::torrent_resumed_alert::alert_type:
2011  handleTorrentResumedAlert(static_cast<const lt::torrent_resumed_alert*>(a));
2012  break;
2013  case lt::tracker_error_alert::alert_type:
2014  handleTrackerErrorAlert(static_cast<const lt::tracker_error_alert*>(a));
2015  break;
2016  case lt::tracker_reply_alert::alert_type:
2017  handleTrackerReplyAlert(static_cast<const lt::tracker_reply_alert*>(a));
2018  break;
2019  case lt::tracker_warning_alert::alert_type:
2020  handleTrackerWarningAlert(static_cast<const lt::tracker_warning_alert*>(a));
2021  break;
2022  case lt::metadata_received_alert::alert_type:
2023  handleMetadataReceivedAlert(static_cast<const lt::metadata_received_alert*>(a));
2024  break;
2025  case lt::fastresume_rejected_alert::alert_type:
2026  handleFastResumeRejectedAlert(static_cast<const lt::fastresume_rejected_alert*>(a));
2027  break;
2028  case lt::torrent_checked_alert::alert_type:
2029  handleTorrentCheckedAlert(static_cast<const lt::torrent_checked_alert*>(a));
2030  break;
2031  case lt::performance_alert::alert_type:
2032  handlePerformanceAlert(static_cast<const lt::performance_alert*>(a));
2033  break;
2034  }
2035 }
void handleFastResumeRejectedAlert(const lt::fastresume_rejected_alert *p)
void handleTrackerReplyAlert(const lt::tracker_reply_alert *p)
void handleSaveResumeDataAlert(const lt::save_resume_data_alert *p)
void handleFileCompletedAlert(const lt::file_completed_alert *p)
void handleTorrentCheckedAlert(const lt::torrent_checked_alert *p)
void handleTorrentPausedAlert(const lt::torrent_paused_alert *p)
void handleFileErrorAlert(const lt::file_error_alert *p)
void handleSaveResumeDataFailedAlert(const lt::save_resume_data_failed_alert *p)
void handleTorrentResumedAlert(const lt::torrent_resumed_alert *p)
void handleFileRenameFailedAlert(const lt::file_rename_failed_alert *p)
void handleTrackerErrorAlert(const lt::tracker_error_alert *p)
void handleFileRenamedAlert(const lt::file_renamed_alert *p)
void handlePerformanceAlert(const lt::performance_alert *p) const
void handleMetadataReceivedAlert(const lt::metadata_received_alert *p)
void handleTrackerWarningAlert(const lt::tracker_warning_alert *p)
void handleTorrentFinishedAlert(const lt::torrent_finished_alert *p)

References handleFastResumeRejectedAlert(), handleFileCompletedAlert(), handleFileErrorAlert(), handleFileRenamedAlert(), handleFileRenameFailedAlert(), handleMetadataReceivedAlert(), handlePerformanceAlert(), handleSaveResumeDataAlert(), handleSaveResumeDataFailedAlert(), handleTorrentCheckedAlert(), handleTorrentFinishedAlert(), handleTorrentPausedAlert(), handleTorrentResumedAlert(), handleTrackerErrorAlert(), handleTrackerReplyAlert(), and handleTrackerWarningAlert().

Referenced by BitTorrent::Session::dispatchTorrentAlert(), and BitTorrent::Session::handleFileErrorAlert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleAppendExtensionToggled()

void TorrentImpl::handleAppendExtensionToggled ( )

Definition at line 1970 of file torrentimpl.cpp.

1971 {
1972  if (!hasMetadata()) return;
1973 
1975 }

References hasMetadata(), and manageIncompleteFiles().

Here is the call graph for this function:

◆ handleCategoryOptionsChanged()

void TorrentImpl::handleCategoryOptionsChanged ( )

Definition at line 1964 of file torrentimpl.cpp.

1965 {
1966  if (m_useAutoTMM)
1968 }

References adjustStorageLocation(), and m_useAutoTMM.

Here is the call graph for this function:

◆ handleDownloadPathChanged()

void TorrentImpl::handleDownloadPathChanged ( )

Definition at line 1629 of file torrentimpl.cpp.

1630 {
1632 }

References adjustStorageLocation().

Here is the call graph for this function:

◆ handleFastResumeRejectedAlert()

void TorrentImpl::handleFastResumeRejectedAlert ( const lt::fastresume_rejected_alert *  p)
private

Definition at line 1837 of file torrentimpl.cpp.

1838 {
1839  m_fastresumeDataRejected = true;
1840 
1841  if (p->error.value() == lt::errors::mismatching_file_size)
1842  {
1843  // Mismatching file size (files were probably moved)
1844  m_hasMissingFiles = true;
1845  LogMsg(tr("File sizes mismatch for torrent '%1'. Cannot proceed further.").arg(name()), Log::CRITICAL);
1846  }
1847  else
1848  {
1849  LogMsg(tr("Fast resume data was rejected for torrent '%1'. Reason: %2. Checking again...")
1850  .arg(name(), QString::fromStdString(p->message())), Log::WARNING);
1851  }
1852 }
@ CRITICAL
Definition: logger.h:48

References Log::CRITICAL, LogMsg(), m_fastresumeDataRejected, m_hasMissingFiles, name(), and Log::WARNING.

Referenced by handleAlert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleFileCompletedAlert()

void TorrentImpl::handleFileCompletedAlert ( const lt::file_completed_alert *  p)
private

Definition at line 1918 of file torrentimpl.cpp.

1919 {
1920  const int fileIndex = m_torrentInfo.nativeIndexes().indexOf(p->index);
1921  Q_ASSERT(fileIndex >= 0);
1922 
1923  qDebug("A file completed download in torrent \"%s\"", qUtf8Printable(name()));
1925  {
1926  const QString path = filePath(fileIndex);
1927  const QString actualPath = actualFilePath(fileIndex);
1928  if (actualPath != path)
1929  {
1930  qDebug("Renaming %s to %s", qUtf8Printable(actualPath), qUtf8Printable(path));
1931  renameFile(fileIndex, path);
1932  }
1933  }
1934 }
bool isAppendExtensionEnabled() const
Definition: session.cpp:556
QString actualFilePath(int index) const override

References actualFilePath(), filePath(), BitTorrent::Session::isAppendExtensionEnabled(), m_session, m_torrentInfo, name(), BitTorrent::TorrentInfo::nativeIndexes(), and renameFile().

Referenced by handleAlert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleFileErrorAlert()

void TorrentImpl::handleFileErrorAlert ( const lt::file_error_alert *  p)
private

Definition at line 1936 of file torrentimpl.cpp.

1937 {
1938  m_lastFileError = {p->error, p->op};
1939 }

References BitTorrent::FileErrorInfo::error, and m_lastFileError.

Referenced by handleAlert().

Here is the caller graph for this function:

◆ handleFileRenamedAlert()

void TorrentImpl::handleFileRenamedAlert ( const lt::file_renamed_alert *  p)
private

Definition at line 1854 of file torrentimpl.cpp.

1855 {
1856  const int fileIndex = m_torrentInfo.nativeIndexes().indexOf(p->index);
1857  Q_ASSERT(fileIndex >= 0);
1858 
1859  // Remove empty leftover folders
1860  // For example renaming "a/b/c" to "d/b/c", then folders "a/b" and "a" will
1861  // be removed if they are empty
1862  const QString oldFilePath = m_filePaths.at(fileIndex);
1863  const QString newFilePath = Utils::Fs::toUniformPath(p->new_name());
1864 
1865  // Check if ".!qB" extension was just added or removed
1866  if ((oldFilePath != newFilePath) && (oldFilePath != newFilePath.chopped(QB_EXT.size())))
1867  {
1868  m_filePaths[fileIndex] = newFilePath;
1869 
1870  QList<QStringView> oldPathParts = QStringView(oldFilePath).split('/', Qt::SkipEmptyParts);
1871  oldPathParts.removeLast(); // drop file name part
1872  QList<QStringView> newPathParts = QStringView(newFilePath).split('/', Qt::SkipEmptyParts);
1873  newPathParts.removeLast(); // drop file name part
1874 
1875 #if defined(Q_OS_WIN)
1876  const Qt::CaseSensitivity caseSensitivity = Qt::CaseInsensitive;
1877 #else
1878  const Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive;
1879 #endif
1880 
1881  int pathIdx = 0;
1882  while ((pathIdx < oldPathParts.size()) && (pathIdx < newPathParts.size()))
1883  {
1884  if (oldPathParts[pathIdx].compare(newPathParts[pathIdx], caseSensitivity) != 0)
1885  break;
1886  ++pathIdx;
1887  }
1888 
1889  for (int i = (oldPathParts.size() - 1); i >= pathIdx; --i)
1890  {
1891  QDir().rmdir(savePath() + Utils::String::join(oldPathParts, QString::fromLatin1("/")));
1892  oldPathParts.removeLast();
1893  }
1894  }
1895 
1896  --m_renameCount;
1897  while (!isMoveInProgress() && (m_renameCount == 0) && !m_moveFinishedTriggers.isEmpty())
1898  m_moveFinishedTriggers.takeFirst()();
1899 
1901 }
QQueue< EventTrigger > m_moveFinishedTriggers
Definition: torrentimpl.h:294
bool isMoveInProgress() const
QString join(const QList< QStringView > &strings, QStringView separator)
Definition: string.cpp:102

References BitTorrent::Session::handleTorrentNeedSaveResumeData(), isMoveInProgress(), Utils::String::join(), m_filePaths, m_moveFinishedTriggers, m_renameCount, m_session, m_torrentInfo, BitTorrent::TorrentInfo::nativeIndexes(), QB_EXT, savePath(), and Utils::Fs::toUniformPath().

Referenced by handleAlert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleFileRenameFailedAlert()

void TorrentImpl::handleFileRenameFailedAlert ( const lt::file_rename_failed_alert *  p)
private

Definition at line 1903 of file torrentimpl.cpp.

1904 {
1905  const int fileIndex = m_torrentInfo.nativeIndexes().indexOf(p->index);
1906  Q_ASSERT(fileIndex >= 0);
1907 
1908  LogMsg(tr("File rename failed. Torrent: \"%1\", file: \"%2\", reason: \"%3\"")
1909  .arg(name(), filePath(fileIndex), QString::fromLocal8Bit(p->error.message().c_str())), Log::WARNING);
1910 
1911  --m_renameCount;
1912  while (!isMoveInProgress() && (m_renameCount == 0) && !m_moveFinishedTriggers.isEmpty())
1913  m_moveFinishedTriggers.takeFirst()();
1914 
1916 }

References filePath(), BitTorrent::Session::handleTorrentNeedSaveResumeData(), isMoveInProgress(), LogMsg(), m_moveFinishedTriggers, m_renameCount, m_session, m_torrentInfo, name(), BitTorrent::TorrentInfo::nativeIndexes(), and Log::WARNING.

Referenced by handleAlert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleMetadataReceivedAlert()

void TorrentImpl::handleMetadataReceivedAlert ( const lt::metadata_received_alert *  p)
private

Definition at line 1949 of file torrentimpl.cpp.

1950 {
1951  Q_UNUSED(p);
1952  qDebug("Metadata received for torrent %s.", qUtf8Printable(name()));
1953 
1956 }

References BitTorrent::HandleMetadata, BitTorrent::Session::handleTorrentNeedSaveResumeData(), m_maintenanceJob, m_session, and name().

Referenced by handleAlert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleMoveStorageJobFinished()

void TorrentImpl::handleMoveStorageJobFinished ( bool  hasOutstandingJob)

Definition at line 1634 of file torrentimpl.cpp.

1635 {
1637  m_storageIsMoving = hasOutstandingJob;
1638 
1639  updateStatus();
1641 
1642  if (!m_storageIsMoving)
1643  {
1644  if (m_hasMissingFiles)
1645  {
1646  // it can be moved to the proper location
1647  m_hasMissingFiles = false;
1648  m_ltAddTorrentParams.save_path = m_nativeStatus.save_path;
1649  m_ltAddTorrentParams.ti = std::const_pointer_cast<lt::torrent_info>(m_nativeHandle.torrent_file());
1650  reload();
1651  updateStatus();
1652  }
1653 
1654  while ((m_renameCount == 0) && !m_moveFinishedTriggers.isEmpty())
1655  m_moveFinishedTriggers.takeFirst()();
1656  }
1657 }
void handleTorrentSavePathChanged(TorrentImpl *const torrent)
Definition: session.cpp:3875

References BitTorrent::Session::handleTorrentNeedSaveResumeData(), BitTorrent::Session::handleTorrentSavePathChanged(), m_hasMissingFiles, m_ltAddTorrentParams, m_moveFinishedTriggers, m_nativeHandle, m_nativeStatus, m_renameCount, m_session, m_storageIsMoving, reload(), and updateStatus().

Referenced by BitTorrent::Session::handleMoveTorrentStorageJobFinished().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handlePerformanceAlert()

void TorrentImpl::handlePerformanceAlert ( const lt::performance_alert *  p) const
private

Definition at line 1958 of file torrentimpl.cpp.

1959 {
1960  LogMsg((tr("Performance alert: ") + QString::fromStdString(p->message()))
1961  , Log::INFO);
1962 }
@ INFO
Definition: logger.h:46

References Log::INFO, and LogMsg().

Referenced by handleAlert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleSaveResumeDataAlert()

void TorrentImpl::handleSaveResumeDataAlert ( const lt::save_resume_data_alert *  p)
private

Definition at line 1765 of file torrentimpl.cpp.

1766 {
1768  {
1769  m_ltAddTorrentParams = p->params;
1770 
1771  m_ltAddTorrentParams.have_pieces.clear();
1772  m_ltAddTorrentParams.verified_pieces.clear();
1773 
1774  TorrentInfo metadata = TorrentInfo(*m_nativeHandle.torrent_file());
1775 
1776  QStringList filePaths = metadata.filePaths();
1779  }
1780  else
1781  {
1782  prepareResumeData(p->params);
1783  }
1784 }
void findIncompleteFiles(const TorrentInfo &torrentInfo, const QString &savePath, const QString &downloadPath, const QStringList &filePaths={}) const
Definition: session.cpp:2268
QStringList filePaths() const override
QStringList filePaths() const
void applyContentLayout(QStringList &filePaths, TorrentContentLayout contentLayout, const QString &rootFolder={})

References BitTorrent::applyContentLayout(), downloadPath(), BitTorrent::TorrentInfo::filePaths(), filePaths(), BitTorrent::Session::findIncompleteFiles(), BitTorrent::HandleMetadata, m_contentLayout, m_ltAddTorrentParams, m_maintenanceJob, m_nativeHandle, m_session, prepareResumeData(), and savePath().

Referenced by handleAlert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleSaveResumeDataFailedAlert()

void TorrentImpl::handleSaveResumeDataFailedAlert ( const lt::save_resume_data_failed_alert *  p)
private

Definition at line 1831 of file torrentimpl.cpp.

1832 {
1833  Q_UNUSED(p);
1834  Q_ASSERT_X(false, Q_FUNC_INFO, "This point should be unreachable since libtorrent 1.2.11");
1835 }

Referenced by handleAlert().

Here is the caller graph for this function:

◆ handleStateUpdate()

void TorrentImpl::handleStateUpdate ( const lt::torrent_status &  nativeStatus)

Definition at line 1624 of file torrentimpl.cpp.

1625 {
1626  updateStatus(nativeStatus);
1627 }

References updateStatus().

Referenced by BitTorrent::Session::handleStateUpdateAlert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleTorrentCheckedAlert()

void TorrentImpl::handleTorrentCheckedAlert ( const lt::torrent_checked_alert *  p)
private

Definition at line 1689 of file torrentimpl.cpp.

1690 {
1691  Q_UNUSED(p);
1692  qDebug("\"%s\" have just finished checking.", qUtf8Printable(name()));
1693 
1694 
1695  if (!hasMetadata())
1696  {
1697  // The torrent is checked due to metadata received, but we should not process
1698  // this event until the torrent is reloaded using the received metadata.
1699  return;
1700  }
1701 
1702  if (m_nativeHandle.need_save_resume_data())
1704 
1706  m_fastresumeDataRejected = false;
1707 
1708  updateStatus();
1709 
1710  if (!m_hasMissingFiles)
1711  {
1712  if ((progress() < 1.0) && (wantedSize() > 0))
1713  m_hasSeedStatus = false;
1714  else if (progress() == 1.0)
1715  m_hasSeedStatus = true;
1716 
1719  }
1720 
1722 }
void handleTorrentChecked(TorrentImpl *const torrent)
Definition: session.cpp:3963

References adjustStorageLocation(), BitTorrent::Session::handleTorrentChecked(), BitTorrent::Session::handleTorrentNeedSaveResumeData(), hasMetadata(), m_fastresumeDataRejected, m_hasMissingFiles, m_hasSeedStatus, m_nativeHandle, m_session, manageIncompleteFiles(), name(), progress(), updateStatus(), and wantedSize().

Referenced by handleAlert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleTorrentFinishedAlert()

void TorrentImpl::handleTorrentFinishedAlert ( const lt::torrent_finished_alert *  p)
private

Definition at line 1724 of file torrentimpl.cpp.

1725 {
1726  Q_UNUSED(p);
1727  qDebug("Got a torrent finished alert for \"%s\"", qUtf8Printable(name()));
1728  qDebug("Torrent has seed status: %s", m_hasSeedStatus ? "yes" : "no");
1729  m_hasMissingFiles = false;
1730  if (m_hasSeedStatus) return;
1731 
1732  updateStatus();
1733  m_hasSeedStatus = true;
1734 
1737 
1739 
1740  const bool recheckTorrentsOnCompletion = Preferences::instance()->recheckTorrentsOnCompletion();
1741  if (isMoveInProgress() || (m_renameCount > 0))
1742  {
1743  if (recheckTorrentsOnCompletion)
1744  m_moveFinishedTriggers.append([this]() { forceRecheck(); });
1745  m_moveFinishedTriggers.append([this]() { m_session->handleTorrentFinished(this); });
1746  }
1747  else
1748  {
1749  if (recheckTorrentsOnCompletion && m_unchecked)
1750  forceRecheck();
1752  }
1753 }
void handleTorrentFinished(TorrentImpl *const torrent)
Definition: session.cpp:3968
void forceRecheck() override
static Preferences * instance()
bool recheckTorrentsOnCompletion() const

References adjustStorageLocation(), forceRecheck(), BitTorrent::Session::handleTorrentFinished(), BitTorrent::Session::handleTorrentNeedSaveResumeData(), Preferences::instance(), isMoveInProgress(), m_hasMissingFiles, m_hasSeedStatus, m_moveFinishedTriggers, m_renameCount, m_session, m_unchecked, manageIncompleteFiles(), name(), Preferences::recheckTorrentsOnCompletion(), and updateStatus().

Referenced by handleAlert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleTorrentPausedAlert()

void TorrentImpl::handleTorrentPausedAlert ( const lt::torrent_paused_alert *  p)
private

Definition at line 1755 of file torrentimpl.cpp.

1756 {
1757  Q_UNUSED(p);
1758 }

Referenced by handleAlert().

Here is the caller graph for this function:

◆ handleTorrentResumedAlert()

void TorrentImpl::handleTorrentResumedAlert ( const lt::torrent_resumed_alert *  p)
private

Definition at line 1760 of file torrentimpl.cpp.

1761 {
1762  Q_UNUSED(p);
1763 }

Referenced by handleAlert().

Here is the caller graph for this function:

◆ handleTrackerErrorAlert()

void TorrentImpl::handleTrackerErrorAlert ( const lt::tracker_error_alert *  p)
private

Definition at line 1673 of file torrentimpl.cpp.

1674 {
1675  const QString trackerUrl = p->tracker_url();
1676 
1677  // Starting with libtorrent 1.2.x each tracker has multiple local endpoints from which
1678  // an announce is attempted. Some endpoints might succeed while others might fail.
1679  // Emit the signal only if all endpoints have failed.
1680  const QVector<TrackerEntry> trackerList = trackers();
1681  const auto iter = std::find_if(trackerList.cbegin(), trackerList.cend(), [&trackerUrl](const TrackerEntry &entry)
1682  {
1683  return (entry.url == trackerUrl);
1684  });
1685  if ((iter != trackerList.cend()) && (iter->status == TrackerEntry::NotWorking))
1686  m_session->handleTorrentTrackerError(this, trackerUrl);
1687 }
void handleTorrentTrackerError(TorrentImpl *const torrent, const QString &trackerUrl)
Definition: session.cpp:4022
@ NotWorking
Definition: trackerentry.h:44

References BitTorrent::Session::handleTorrentTrackerError(), m_session, BitTorrent::TrackerEntry::NotWorking, and trackers().

Referenced by handleAlert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleTrackerReplyAlert()

void TorrentImpl::handleTrackerReplyAlert ( const lt::tracker_reply_alert *  p)
private

Definition at line 1659 of file torrentimpl.cpp.

1660 {
1661  const QString trackerUrl = p->tracker_url();
1662  m_trackerPeerCounts[trackerUrl][p->local_endpoint] = p->num_peers;
1663 
1664  m_session->handleTorrentTrackerReply(this, trackerUrl);
1665 }
void handleTorrentTrackerReply(TorrentImpl *const torrent, const QString &trackerUrl)
Definition: session.cpp:4017
QHash< QString, QMap< lt::tcp::endpoint, int > > m_trackerPeerCounts
Definition: torrentimpl.h:300

References BitTorrent::Session::handleTorrentTrackerReply(), m_session, and m_trackerPeerCounts.

Referenced by handleAlert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleTrackerWarningAlert()

void TorrentImpl::handleTrackerWarningAlert ( const lt::tracker_warning_alert *  p)
private

Definition at line 1667 of file torrentimpl.cpp.

1668 {
1669  const QString trackerUrl = p->tracker_url();
1670  m_session->handleTorrentTrackerWarning(this, trackerUrl);
1671 }
void handleTorrentTrackerWarning(TorrentImpl *const torrent, const QString &trackerUrl)
Definition: session.cpp:4209

References BitTorrent::Session::handleTorrentTrackerWarning(), and m_session.

Referenced by handleAlert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasError()

bool TorrentImpl::hasError ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1013 of file torrentimpl.cpp.

1014 {
1015  return (m_nativeStatus.errc || (m_nativeStatus.flags & lt::torrent_flags::upload_mode));
1016 }

References m_nativeStatus.

Referenced by resume(), and updateState().

Here is the caller graph for this function:

◆ hasFirstLastPiecePriority()

bool TorrentImpl::hasFirstLastPiecePriority ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 931 of file torrentimpl.cpp.

932 {
934 }

References m_hasFirstLastPiecePriority.

◆ hasMetadata()

bool TorrentImpl::hasMetadata ( ) const
overridevirtual

◆ hasMissingFiles()

bool TorrentImpl::hasMissingFiles ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1008 of file torrentimpl.cpp.

1009 {
1010  return m_hasMissingFiles;
1011 }

References m_hasMissingFiles.

Referenced by updateState().

Here is the caller graph for this function:

◆ hasTag()

bool TorrentImpl::hasTag ( const QString &  tag) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 741 of file torrentimpl.cpp.

742 {
743  return m_tags.contains(tag);
744 }
bool contains(const key_type &value) const
Definition: orderedset.h:54

References OrderedSet< T, Compare >::contains(), and m_tags.

Referenced by addTag().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ incompleteCount()

int TorrentImpl::incompleteCount ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1163 of file torrentimpl.cpp.

1164 {
1165  // additional info: https://github.com/qbittorrent/qBittorrent/pull/5300#issuecomment-267783646
1166  return m_nativeStatus.num_incomplete;
1167 }

References m_nativeStatus.

◆ info()

TorrentInfo TorrentImpl::info ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 835 of file torrentimpl.cpp.

836 {
837  return m_torrentInfo;
838 }

References m_torrentInfo.

Referenced by downloadingPieces().

Here is the caller graph for this function:

◆ infoHash()

InfoHash TorrentImpl::infoHash ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 325 of file torrentimpl.cpp.

326 {
327  return m_infoHash;
328 }

References m_infoHash.

◆ isActive()

bool TorrentImpl::isActive ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 890 of file torrentimpl.cpp.

References BitTorrent::Downloading, BitTorrent::DownloadingMetadata, BitTorrent::ForcedDownloading, BitTorrent::ForcedDownloadingMetadata, BitTorrent::ForcedUploading, m_state, BitTorrent::Moving, BitTorrent::StalledDownloading, BitTorrent::Uploading, and uploadPayloadRate().

Referenced by isInactive().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isAutoTMMEnabled()

bool TorrentImpl::isAutoTMMEnabled ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 465 of file torrentimpl.cpp.

466 {
467  return m_useAutoTMM;
468 }

References m_useAutoTMM.

Referenced by downloadPath(), savePath(), setDownloadPath(), and setSavePath().

Here is the caller graph for this function:

◆ isChecking()

bool TorrentImpl::isChecking ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 853 of file torrentimpl.cpp.

854 {
855  return ((m_nativeStatus.state == lt::torrent_status::checking_files)
856  || (m_nativeStatus.state == lt::torrent_status::checking_resume_data));
857 }

References m_nativeStatus.

Referenced by progress(), and updateStatus().

Here is the caller graph for this function:

◆ isCompleted()

◆ isDHTDisabled()

bool TorrentImpl::isDHTDisabled ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1223 of file torrentimpl.cpp.

1224 {
1225  return static_cast<bool>(m_nativeStatus.flags & lt::torrent_flags::disable_dht);
1226 }

References m_nativeStatus.

Referenced by setDHTDisabled().

Here is the caller graph for this function:

◆ isDownloading()

◆ isErrored()

bool TorrentImpl::isErrored ( ) const
overridevirtual

◆ isForced()

bool TorrentImpl::isForced ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 921 of file torrentimpl.cpp.

922 {
923  return (!isPaused() && (m_operatingMode == TorrentOperatingMode::Forced));
924 }

References isPaused(), and m_operatingMode.

Referenced by updateState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isInactive()

bool TorrentImpl::isInactive ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 904 of file torrentimpl.cpp.

905 {
906  return !isActive();
907 }
bool isActive() const override

References isActive().

Here is the call graph for this function:

◆ isLSDDisabled()

bool TorrentImpl::isLSDDisabled ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1233 of file torrentimpl.cpp.

1234 {
1235  return static_cast<bool>(m_nativeStatus.flags & lt::torrent_flags::disable_lsd);
1236 }

References m_nativeStatus.

Referenced by setLSDDisabled().

Here is the caller graph for this function:

◆ isMoveInProgress()

bool TorrentImpl::isMoveInProgress ( ) const
private

Definition at line 2085 of file torrentimpl.cpp.

2086 {
2087  return m_storageIsMoving;
2088 }

References m_storageIsMoving.

Referenced by handleFileRenamedAlert(), handleFileRenameFailedAlert(), handleTorrentFinishedAlert(), and updateState().

Here is the caller graph for this function:

◆ isPaused()

bool TorrentImpl::isPaused ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 840 of file torrentimpl.cpp.

841 {
842  return m_isStopped;
843 }

References m_isStopped.

Referenced by eta(), forceRecheck(), isForced(), isQueued(), and updateState().

Here is the caller graph for this function:

◆ isPEXDisabled()

bool TorrentImpl::isPEXDisabled ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1228 of file torrentimpl.cpp.

1229 {
1230  return static_cast<bool>(m_nativeStatus.flags & lt::torrent_flags::disable_pex);
1231 }

References m_nativeStatus.

Referenced by setPEXDisabled().

Here is the caller graph for this function:

◆ isPrivate()

bool TorrentImpl::isPrivate ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 360 of file torrentimpl.cpp.

361 {
362  return m_torrentInfo.isPrivate();
363 }

References BitTorrent::TorrentInfo::isPrivate(), and m_torrentInfo.

Referenced by BitTorrent::Session::addTorrent_impl(), and replaceTrackers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isQueued()

bool TorrentImpl::isQueued ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 845 of file torrentimpl.cpp.

846 {
847  // Torrent is Queued if it isn't in Paused state but paused internally
848  return (!isPaused()
849  && (m_nativeStatus.flags & lt::torrent_flags::auto_managed)
850  && (m_nativeStatus.flags & lt::torrent_flags::paused));
851 }

References isPaused(), and m_nativeStatus.

Referenced by updateState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isSeed()

bool TorrentImpl::isSeed ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 915 of file torrentimpl.cpp.

916 {
917  return ((m_nativeStatus.state == lt::torrent_status::finished)
918  || (m_nativeStatus.state == lt::torrent_status::seeding));
919 }

References m_nativeStatus.

Referenced by adjustStorageLocation(), eta(), setDownloadPath(), setSavePath(), and updateState().

Here is the caller graph for this function:

◆ isSequentialDownload()

bool TorrentImpl::isSequentialDownload ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 926 of file torrentimpl.cpp.

927 {
928  return static_cast<bool>(m_nativeStatus.flags & lt::torrent_flags::sequential_download);
929 }

References m_nativeStatus.

◆ isUploading()

◆ isValid()

bool TorrentImpl::isValid ( ) const

Definition at line 320 of file torrentimpl.cpp.

321 {
322  return m_nativeHandle.is_valid();
323 }

References m_nativeHandle.

◆ lastSeenComplete()

QDateTime TorrentImpl::lastSeenComplete ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1169 of file torrentimpl.cpp.

1170 {
1171  if (m_nativeStatus.last_seen_complete > 0)
1172  return QDateTime::fromSecsSinceEpoch(m_nativeStatus.last_seen_complete);
1173  else
1174  return {};
1175 }

References m_nativeStatus.

◆ leechsCount()

int TorrentImpl::leechsCount ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1136 of file torrentimpl.cpp.

1137 {
1138  return (m_nativeStatus.num_peers - m_nativeStatus.num_seeds);
1139 }

References m_nativeStatus.

◆ manageIncompleteFiles()

void TorrentImpl::manageIncompleteFiles ( )
private

Definition at line 2037 of file torrentimpl.cpp.

2038 {
2039  const bool isAppendExtensionEnabled = m_session->isAppendExtensionEnabled();
2040  const QVector<qreal> fp = filesProgress();
2041  if (fp.size() != filesCount())
2042  {
2043  qDebug() << "skip manageIncompleteFiles because of invalid torrent meta-data or empty file-progress";
2044  return;
2045  }
2046 
2047  for (int i = 0; i < filesCount(); ++i)
2048  {
2049  const QString path = filePath(i);
2050  const QString actualPath = actualFilePath(i);
2051  if (isAppendExtensionEnabled && (fileSize(i) > 0) && (fp[i] < 1))
2052  {
2053  const QString wantedPath = path + QB_EXT;
2054  if (actualPath != wantedPath)
2055  {
2056  qDebug() << "Renaming" << actualPath << "to" << wantedPath;
2057  renameFile(i, wantedPath);
2058  }
2059  }
2060  else
2061  {
2062  if (actualPath != path)
2063  {
2064  qDebug() << "Renaming" << actualPath << "to" << path;
2065  renameFile(i, path);
2066  }
2067  }
2068  }
2069 }
QVector< qreal > filesProgress() const override

References actualFilePath(), filePath(), filesCount(), fileSize(), filesProgress(), BitTorrent::Session::isAppendExtensionEnabled(), m_session, QB_EXT, and renameFile().

Referenced by handleAppendExtensionToggled(), handleTorrentCheckedAlert(), and handleTorrentFinishedAlert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ maxRatio()

qreal TorrentImpl::maxRatio ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1289 of file torrentimpl.cpp.

1290 {
1292  return m_session->globalMaxRatio();
1293 
1294  return m_ratioLimit;
1295 }
qreal globalMaxRatio() const
Definition: session.cpp:928
static const qreal USE_GLOBAL_RATIO
Definition: torrent.h:104

References BitTorrent::Session::globalMaxRatio(), m_ratioLimit, m_session, and BitTorrent::Torrent::USE_GLOBAL_RATIO.

Referenced by eta().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ maxSeedingTime()

int TorrentImpl::maxSeedingTime ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1297 of file torrentimpl.cpp.

1298 {
1301 
1302  return m_seedingTimeLimit;
1303 }
int globalMaxSeedingMinutes() const
Definition: session.cpp:947
static const int USE_GLOBAL_SEEDING_TIME
Definition: torrent.h:107

References BitTorrent::Session::globalMaxSeedingMinutes(), m_seedingTimeLimit, m_session, and BitTorrent::Torrent::USE_GLOBAL_SEEDING_TIME.

Referenced by eta().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ moveStorage()

void TorrentImpl::moveStorage ( const QString &  newPath,
MoveStorageMode  mode 
)
private

Definition at line 1609 of file torrentimpl.cpp.

1610 {
1611  if (m_session->addMoveTorrentStorageJob(this, Utils::Fs::toNativePath(newPath), mode))
1612  {
1613  m_storageIsMoving = true;
1614  updateStatus();
1615  }
1616 }
bool addMoveTorrentStorageJob(TorrentImpl *torrent, const QString &newPath, MoveStorageMode mode)
Definition: session.cpp:4027

References BitTorrent::Session::addMoveTorrentStorageJob(), m_session, m_storageIsMoving, Utils::Fs::toNativePath(), and updateStatus().

Referenced by adjustStorageLocation(), setDownloadPath(), and setSavePath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ name()

QString TorrentImpl::name ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 330 of file torrentimpl.cpp.

331 {
332  if (!m_name.isEmpty())
333  return m_name;
334 
335  if (hasMetadata())
336  return m_torrentInfo.name();
337 
338  const QString name = QString::fromStdString(m_nativeStatus.name);
339  if (!name.isEmpty())
340  return name;
341 
342  return id().toString();
343 }
TorrentID id() const
Definition: torrent.cpp:54
QString name() const
QString toString() const
Definition: digest32.h:85

References hasMetadata(), BitTorrent::Torrent::id(), m_name, m_nativeStatus, m_torrentInfo, BitTorrent::TorrentInfo::name(), and Digest32< N >::toString().

Referenced by BitTorrent::Session::addMoveTorrentStorageJob(), connectPeer(), BitTorrent::Session::deleteTorrent(), handleFastResumeRejectedAlert(), handleFileCompletedAlert(), BitTorrent::Session::handleFileErrorAlert(), handleFileRenameFailedAlert(), handleMetadataReceivedAlert(), BitTorrent::Session::handleStorageMovedAlert(), BitTorrent::Session::handleStorageMovedFailedAlert(), handleTorrentCheckedAlert(), BitTorrent::Session::handleTorrentFinished(), handleTorrentFinishedAlert(), BitTorrent::Session::handleTorrentMetadataReceived(), BitTorrent::Session::handleTorrentSaveResumeDataRequested(), BitTorrent::Session::handleTorrentTrackersAdded(), BitTorrent::Session::handleTorrentTrackersRemoved(), BitTorrent::Session::handleTorrentUrlSeedsAdded(), BitTorrent::Session::handleTorrentUrlSeedsRemoved(), BitTorrent::Session::handleUrlSeedAlert(), BitTorrent::Session::moveTorrentStorage(), BitTorrent::Session::recursiveTorrentDownload(), setFirstLastPiecePriority(), and setName().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nativeHandle()

◆ needSaveResumeData()

bool TorrentImpl::needSaveResumeData ( ) const

Definition at line 676 of file torrentimpl.cpp.

677 {
678  return m_nativeHandle.need_save_resume_data();
679 }

References m_nativeHandle.

◆ nextAnnounce()

qlonglong TorrentImpl::nextAnnounce ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1351 of file torrentimpl.cpp.

1352 {
1353  return lt::total_seconds(m_nativeStatus.next_announce);
1354 }

References m_nativeStatus.

◆ pause()

void TorrentImpl::pause ( )
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1552 of file torrentimpl.cpp.

1553 {
1554  if (!m_isStopped)
1555  {
1556  m_isStopped = true;
1559  }
1560 
1562  {
1563  setAutoManaged(false);
1564  m_nativeHandle.pause();
1565 
1567  }
1568 }
void handleTorrentPaused(TorrentImpl *const torrent)
Definition: session.cpp:3953
void setAutoManaged(bool enable)

References BitTorrent::Session::handleTorrentNeedSaveResumeData(), BitTorrent::Session::handleTorrentPaused(), m_isStopped, m_maintenanceJob, m_nativeHandle, m_session, m_speedMonitor, BitTorrent::None, SpeedMonitor::reset(), and setAutoManaged().

Here is the call graph for this function:

◆ peers()

QVector< PeerInfo > TorrentImpl::peers ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1238 of file torrentimpl.cpp.

1239 {
1240  std::vector<lt::peer_info> nativePeers;
1241  m_nativeHandle.get_peer_info(nativePeers);
1242 
1243  QVector<PeerInfo> peers;
1244  peers.reserve(static_cast<decltype(peers)::size_type>(nativePeers.size()));
1245 
1246  for (const lt::peer_info &peer : nativePeers)
1247  peers << PeerInfo(this, peer);
1248 
1249  return peers;
1250 }
QVector< PeerInfo > peers() const override

References m_nativeHandle.

Referenced by totalPeersCount().

Here is the caller graph for this function:

◆ peersCount()

int TorrentImpl::peersCount ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1131 of file torrentimpl.cpp.

1132 {
1133  return m_nativeStatus.num_peers;
1134 }

References m_nativeStatus.

◆ pieceAvailability()

QVector< int > TorrentImpl::pieceAvailability ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1276 of file torrentimpl.cpp.

1277 {
1278  std::vector<int> avail;
1279  m_nativeHandle.piece_availability(avail);
1280 
1281  return {avail.cbegin(), avail.cend()};
1282 }

References m_nativeHandle.

Referenced by availableFileFractions().

Here is the caller graph for this function:

◆ pieceLength()

qlonglong TorrentImpl::pieceLength ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 381 of file torrentimpl.cpp.

382 {
383  return m_torrentInfo.pieceLength();
384 }

References m_torrentInfo, and BitTorrent::TorrentInfo::pieceLength().

Referenced by applyFirstLastPiecePriority().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pieces()

QBitArray TorrentImpl::pieces ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1252 of file torrentimpl.cpp.

1253 {
1254  QBitArray result(m_nativeStatus.pieces.size());
1255  for (int i = 0; i < result.size(); ++i)
1256  {
1257  if (m_nativeStatus.pieces[lt::piece_index_t {i}])
1258  result.setBit(i, true);
1259  }
1260  return result;
1261 }

References m_nativeStatus.

◆ piecesCount()

int TorrentImpl::piecesCount ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 692 of file torrentimpl.cpp.

693 {
694  return m_torrentInfo.piecesCount();
695 }

References m_torrentInfo, and BitTorrent::TorrentInfo::piecesCount().

Referenced by downloadingPieces().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ piecesHave()

int TorrentImpl::piecesHave ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 697 of file torrentimpl.cpp.

698 {
699  return m_nativeStatus.num_pieces;
700 }

References m_nativeStatus.

◆ prepareResumeData()

void TorrentImpl::prepareResumeData ( const lt::add_torrent_params &  params)
private

Definition at line 1786 of file torrentimpl.cpp.

1787 {
1788  if (m_hasMissingFiles)
1789  {
1790  const auto havePieces = m_ltAddTorrentParams.have_pieces;
1791  const auto unfinishedPieces = m_ltAddTorrentParams.unfinished_pieces;
1792  const auto verifiedPieces = m_ltAddTorrentParams.verified_pieces;
1793 
1794  // Update recent resume data but preserve existing progress
1795  m_ltAddTorrentParams = params;
1796  m_ltAddTorrentParams.have_pieces = havePieces;
1797  m_ltAddTorrentParams.unfinished_pieces = unfinishedPieces;
1798  m_ltAddTorrentParams.verified_pieces = verifiedPieces;
1799  }
1800  else
1801  {
1802  // Update recent resume data
1803  m_ltAddTorrentParams = params;
1804  }
1805 
1806  // We shouldn't save upload_mode flag to allow torrent operate normally on next run
1807  m_ltAddTorrentParams.flags &= ~lt::torrent_flags::upload_mode;
1808 
1809  LoadTorrentParams resumeData;
1810  resumeData.name = m_name;
1811  resumeData.category = m_category;
1812  resumeData.tags = m_tags;
1813  resumeData.contentLayout = m_contentLayout;
1814  resumeData.ratioLimit = m_ratioLimit;
1815  resumeData.seedingTimeLimit = m_seedingTimeLimit;
1817  resumeData.hasSeedStatus = m_hasSeedStatus;
1818  resumeData.stopped = m_isStopped;
1819  resumeData.operatingMode = m_operatingMode;
1821  resumeData.useAutoTMM = m_useAutoTMM;
1822  if (!resumeData.useAutoTMM)
1823  {
1824  resumeData.savePath = m_savePath;
1825  resumeData.downloadPath = m_downloadPath;
1826  }
1827 
1828  m_session->handleTorrentResumeDataReady(this, resumeData);
1829 }
void handleTorrentResumeDataReady(TorrentImpl *const torrent, const LoadTorrentParams &data)
Definition: session.cpp:4010

References BitTorrent::LoadTorrentParams::category, BitTorrent::LoadTorrentParams::contentLayout, BitTorrent::LoadTorrentParams::downloadPath, BitTorrent::LoadTorrentParams::firstLastPiecePriority, BitTorrent::Session::handleTorrentResumeDataReady(), BitTorrent::LoadTorrentParams::hasSeedStatus, BitTorrent::LoadTorrentParams::ltAddTorrentParams, m_category, m_contentLayout, m_downloadPath, m_hasFirstLastPiecePriority, m_hasMissingFiles, m_hasSeedStatus, m_isStopped, m_ltAddTorrentParams, m_name, m_operatingMode, m_ratioLimit, m_savePath, m_seedingTimeLimit, m_session, m_tags, m_useAutoTMM, BitTorrent::LoadTorrentParams::name, BitTorrent::LoadTorrentParams::operatingMode, BitTorrent::LoadTorrentParams::ratioLimit, BitTorrent::LoadTorrentParams::savePath, BitTorrent::LoadTorrentParams::seedingTimeLimit, BitTorrent::LoadTorrentParams::stopped, BitTorrent::LoadTorrentParams::tags, and BitTorrent::LoadTorrentParams::useAutoTMM.

Referenced by endReceivedMetadataHandling(), and handleSaveResumeDataAlert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prioritizeFiles()

void TorrentImpl::prioritizeFiles ( const QVector< DownloadPriority > &  priorities)
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 2224 of file torrentimpl.cpp.

2225 {
2226  if (!hasMetadata()) return;
2227 
2228  Q_ASSERT(priorities.size() == filesCount());
2229 
2230  // Reset 'm_hasSeedStatus' if needed in order to react again to
2231  // 'torrent_finished_alert' and eg show tray notifications
2232  const QVector<qreal> progress = filesProgress();
2233  const QVector<DownloadPriority> oldPriorities = filePriorities();
2234  for (int i = 0; i < oldPriorities.size(); ++i)
2235  {
2236  if ((oldPriorities[i] == DownloadPriority::Ignored)
2237  && (priorities[i] > DownloadPriority::Ignored)
2238  && (progress[i] < 1.0))
2239  {
2240  m_hasSeedStatus = false;
2241  break;
2242  }
2243  }
2244 
2245  const int internalFilesCount = m_torrentInfo.nativeInfo()->files().num_files(); // including .pad files
2246  auto nativePriorities = std::vector<lt::download_priority_t>(internalFilesCount, LT::toNative(DownloadPriority::Normal));
2247  const auto nativeIndexes = m_torrentInfo.nativeIndexes();
2248  for (int i = 0; i < priorities.size(); ++i)
2249  nativePriorities[LT::toUnderlyingType(nativeIndexes[i])] = LT::toNative(priorities[i]);
2250 
2251  qDebug() << Q_FUNC_INFO << "Changing files priorities...";
2252  m_nativeHandle.prioritize_files(nativePriorities);
2253 
2254  // Restore first/last piece first option if necessary
2256  applyFirstLastPiecePriority(true, priorities);
2257 }
std::shared_ptr< lt::torrent_info > nativeInfo() const

References applyFirstLastPiecePriority(), filePriorities(), filesCount(), filesProgress(), hasMetadata(), BitTorrent::Ignored, m_hasFirstLastPiecePriority, m_hasSeedStatus, m_nativeHandle, m_torrentInfo, BitTorrent::TorrentInfo::nativeIndexes(), BitTorrent::TorrentInfo::nativeInfo(), BitTorrent::Normal, progress(), BitTorrent::LT::toNative(), and BitTorrent::LT::toUnderlyingType().

Here is the call graph for this function:

◆ progress()

qreal TorrentImpl::progress ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 702 of file torrentimpl.cpp.

703 {
704  if (isChecking())
705  return m_nativeStatus.progress;
706 
707  if (m_nativeStatus.total_wanted == 0)
708  return 0.;
709 
710  if (m_nativeStatus.total_wanted_done == m_nativeStatus.total_wanted)
711  return 1.;
712 
713  const qreal progress = static_cast<qreal>(m_nativeStatus.total_wanted_done) / m_nativeStatus.total_wanted;
714  Q_ASSERT((progress >= 0.f) && (progress <= 1.f));
715  return progress;
716 }
bool isChecking() const override

References isChecking(), and m_nativeStatus.

Referenced by filesProgress(), handleTorrentCheckedAlert(), and prioritizeFiles().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ queuePosition()

int TorrentImpl::queuePosition ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1018 of file torrentimpl.cpp.

1019 {
1020  return static_cast<int>(m_nativeStatus.queue_position);
1021 }

References m_nativeStatus.

Referenced by BitTorrent::Session::bottomTorrentsQueuePos(), BitTorrent::Session::decreaseTorrentsQueuePos(), BitTorrent::Session::increaseTorrentsQueuePos(), and BitTorrent::Session::topTorrentsQueuePos().

Here is the caller graph for this function:

◆ ratioLimit()

qreal TorrentImpl::ratioLimit ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 786 of file torrentimpl.cpp.

787 {
788  return m_ratioLimit;
789 }

References m_ratioLimit.

◆ realRatio()

qreal TorrentImpl::realRatio ( ) const
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1305 of file torrentimpl.cpp.

1306 {
1307  const int64_t upload = m_nativeStatus.all_time_upload;
1308  // special case for a seeder who lost its stats, also assume nobody will import a 99% done torrent
1309  const int64_t download = (m_nativeStatus.all_time_download < (m_nativeStatus.total_done * 0.01))
1310  ? m_nativeStatus.total_done
1311  : m_nativeStatus.all_time_download;
1312 
1313  if (download == 0)
1314  return (upload == 0) ? 0 : MAX_RATIO;
1315 
1316  const qreal ratio = upload / static_cast<qreal>(download);
1317  Q_ASSERT(ratio >= 0);
1318  return (ratio > MAX_RATIO) ? MAX_RATIO : ratio;
1319 }
static const qreal MAX_RATIO
Definition: torrent.h:110

References m_nativeStatus, and BitTorrent::Torrent::MAX_RATIO.

◆ reload()

void TorrentImpl::reload ( )
private

Definition at line 1523 of file torrentimpl.cpp.

1524 {
1525  const auto queuePos = m_nativeHandle.queue_position();
1526 
1527  m_nativeSession->remove_torrent(m_nativeHandle, lt::session::delete_partfile);
1528 
1529  lt::add_torrent_params p = m_ltAddTorrentParams;
1530  p.flags |= lt::torrent_flags::update_subscribe
1531  | lt::torrent_flags::override_trackers
1532  | lt::torrent_flags::override_web_seeds;
1533 
1534  if (m_isStopped)
1535  {
1536  p.flags |= lt::torrent_flags::paused;
1537  p.flags &= ~lt::torrent_flags::auto_managed;
1538  }
1539  else if (m_operatingMode == TorrentOperatingMode::AutoManaged)
1540  {
1541  p.flags |= (lt::torrent_flags::auto_managed | lt::torrent_flags::paused);
1542  }
1543  else
1544  {
1545  p.flags &= ~(lt::torrent_flags::auto_managed | lt::torrent_flags::paused);
1546  }
1547 
1548  m_nativeHandle = m_nativeSession->add_torrent(p);
1549  m_nativeHandle.queue_position_set(queuePos);
1550 }

References m_isStopped, m_ltAddTorrentParams, m_nativeHandle, m_nativeSession, and m_operatingMode.

Referenced by endReceivedMetadataHandling(), handleMoveStorageJobFinished(), and resume().

Here is the caller graph for this function:

◆ removeAllTags()

void TorrentImpl::removeAllTags ( )
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 775 of file torrentimpl.cpp.

776 {
777  for (const QString &tag : asConst(tags()))
778  removeTag(tag);
779 }
TagSet tags() const override
bool removeTag(const QString &tag) override

References asConst(), removeTag(), and tags().

Here is the call graph for this function:

◆ removeTag()

bool TorrentImpl::removeTag ( const QString &  tag)
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 764 of file torrentimpl.cpp.

765 {
766  if (m_tags.remove(tag))
767  {
770  return true;
771  }
772  return false;
773 }
void handleTorrentTagRemoved(TorrentImpl *const torrent, const QString &tag)
Definition: session.cpp:3890
bool remove(const key_type &value)
Definition: orderedset.h:98

References BitTorrent::Session::handleTorrentNeedSaveResumeData(), BitTorrent::Session::handleTorrentTagRemoved(), m_session, m_tags, and OrderedSet< T, Compare >::remove().

Referenced by removeAllTags().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeUrlSeeds()

void TorrentImpl::removeUrlSeeds ( const QVector< QUrl > &  urlSeeds)
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 625 of file torrentimpl.cpp.

626 {
627  const std::set<std::string> currentSeeds = m_nativeHandle.url_seeds();
628 
629  QVector<QUrl> removedUrlSeeds;
630  removedUrlSeeds.reserve(urlSeeds.size());
631 
632  for (const QUrl &url : urlSeeds)
633  {
634  const std::string nativeUrl = url.toString().toStdString();
635  if (currentSeeds.find(nativeUrl) != currentSeeds.end())
636  {
637  m_nativeHandle.remove_url_seed(nativeUrl);
638  removedUrlSeeds << url;
639  }
640  }
641 
642  if (!removedUrlSeeds.isEmpty())
643  {
645  m_session->handleTorrentUrlSeedsRemoved(this, removedUrlSeeds);
646  }
647 }
void handleTorrentUrlSeedsRemoved(TorrentImpl *const torrent, const QVector< QUrl > &urlSeeds)
Definition: session.cpp:3931

References BitTorrent::Session::handleTorrentNeedSaveResumeData(), BitTorrent::Session::handleTorrentUrlSeedsRemoved(), m_nativeHandle, m_session, and urlSeeds().

Here is the call graph for this function:

◆ renameFile()

void TorrentImpl::renameFile ( int  index,
const QString &  path 
)
overridevirtual

Implements BitTorrent::AbstractFileStorage.

Definition at line 1618 of file torrentimpl.cpp.

1619 {
1620  ++m_renameCount;
1621  m_nativeHandle.rename_file(m_torrentInfo.nativeIndexes().at(index), Utils::Fs::toNativePath(path).toStdString());
1622 }

References m_nativeHandle, m_renameCount, m_torrentInfo, BitTorrent::TorrentInfo::nativeIndexes(), and Utils::Fs::toNativePath().

Referenced by handleFileCompletedAlert(), manageIncompleteFiles(), and TorrentImpl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ replaceTrackers()

void TorrentImpl::replaceTrackers ( const QVector< TrackerEntry > &  trackers)
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 546 of file torrentimpl.cpp.

547 {
548  QVector<TrackerEntry> currentTrackers = this->trackers();
549 
550  QVector<TrackerEntry> newTrackers;
551  newTrackers.reserve(trackers.size());
552 
553  std::vector<lt::announce_entry> nativeTrackers;
554  nativeTrackers.reserve(trackers.size());
555 
556  for (const TrackerEntry &tracker : trackers)
557  {
558  nativeTrackers.emplace_back(makeNativeAnnouncerEntry(tracker.url, tracker.tier));
559 
560  if (!currentTrackers.removeOne(tracker))
561  newTrackers << tracker;
562  }
563 
564  m_nativeHandle.replace_trackers(nativeTrackers);
565 
567 
568  if (newTrackers.isEmpty() && currentTrackers.isEmpty())
569  {
570  // when existing tracker reorders
572  }
573  else
574  {
575  if (!currentTrackers.isEmpty())
576  m_session->handleTorrentTrackersRemoved(this, currentTrackers);
577 
578  if (!newTrackers.isEmpty())
579  m_session->handleTorrentTrackersAdded(this, newTrackers);
580 
581  // Clear the peer list if it's a private torrent since
582  // we do not want to keep connecting with peers from old tracker.
583  if (isPrivate())
584  clearPeers();
585  }
586 }
void handleTorrentTrackersRemoved(TorrentImpl *const torrent, const QVector< TrackerEntry > &deletedTrackers)
Definition: session.cpp:3910
void handleTorrentTrackersChanged(TorrentImpl *const torrent)
Definition: session.cpp:3920
void clearPeers() override
bool isPrivate() const override

References clearPeers(), BitTorrent::Session::handleTorrentNeedSaveResumeData(), BitTorrent::Session::handleTorrentTrackersAdded(), BitTorrent::Session::handleTorrentTrackersChanged(), BitTorrent::Session::handleTorrentTrackersRemoved(), isPrivate(), m_nativeHandle, m_session, anonymous_namespace{torrentimpl.cpp}::makeNativeAnnouncerEntry(), and trackers().

Here is the call graph for this function:

◆ resume()

void TorrentImpl::resume ( TorrentOperatingMode  mode = TorrentOperatingMode::AutoManaged)
overridevirtual

Implements BitTorrent::Torrent.

Definition at line 1570 of file torrentimpl.cpp.

1571 {
1572  if (hasError())
1573  {
1574  m_nativeHandle.clear_error();
1575  m_nativeHandle.unset_flags(lt::torrent_flags::upload_mode);
1576  }
1577 
1578  m_operatingMode = mode;
1579 
1580  if (m_hasMissingFiles)
1581  {
1582  m_hasMissingFiles = false;
1583  m_isStopped = false;
1584  m_ltAddTorrentParams.ti = std::const_pointer_cast<lt::torrent_info>(m_nativeHandle.torrent_file());
1585  reload();
1586  updateStatus();
1587  return;
1588  }
1589 
1590  if (m_isStopped)
1591  {
1592  // Torrent may have been temporarily resumed to perform checking files
1593  // so we have to ensure it will not pause after checking is done.
1594  m_nativeHandle.unset_flags(lt::torrent_flags::stop_when_ready);
1595 
1596  m_isStopped = false;
1599  }
1600 
1602  {
1603  setAutoManaged(m_operatingMode == TorrentOperatingMode::AutoManaged);
1604  if (m_operatingMode == TorrentOperatingMode::Forced)
1605  m_nativeHandle.resume();
1606  }
1607 }
void handleTorrentResumed(TorrentImpl *const torrent)
Definition: session.cpp:3958
bool hasError() const override

References BitTorrent::Session::handleTorrentNeedSaveResumeData(), BitTorrent::Session::handleTorrentResumed(), hasError(), m_hasMissingFiles, m_isStopped, m_ltAddTorrentParams, m_maintenanceJob, m_nativeHandle, m_operatingMode, m_session, BitTorrent::None, reload(), setAutoManaged(), and updateStatus().

Here is the call graph for this function: