From 752734362981fe125f76c478e6b277c3e9dbf506 Mon Sep 17 00:00:00 2001 From: Vladimir Golovnev Date: Tue, 23 Aug 2022 07:47:20 +0300 Subject: [PATCH] Handle some torrent conflicts PR #17576. --- src/base/bittorrent/infohash.cpp | 21 +++- src/base/bittorrent/infohash.h | 3 + src/base/bittorrent/session.cpp | 146 +++++++++++++++++++++------ src/base/bittorrent/session.h | 20 +++- src/base/bittorrent/torrentimpl.cpp | 7 ++ src/gui/addnewtorrentdialog.cpp | 13 +-- src/gui/torrentoptionsdialog.cpp | 2 +- src/webui/api/synccontroller.cpp | 2 +- src/webui/api/torrentscontroller.cpp | 34 +++---- 9 files changed, 188 insertions(+), 60 deletions(-) diff --git a/src/base/bittorrent/infohash.cpp b/src/base/bittorrent/infohash.cpp index 36e3fa271..dcef97874 100644 --- a/src/base/bittorrent/infohash.cpp +++ b/src/base/bittorrent/infohash.cpp @@ -50,6 +50,15 @@ bool BitTorrent::InfoHash::isValid() const return m_valid; } +bool BitTorrent::InfoHash::isHybrid() const +{ +#ifdef QBT_USES_LIBTORRENT2 + return (m_nativeHash.has_v1() && m_nativeHash.has_v2()); +#else + return false; +#endif +} + SHA1Hash BitTorrent::InfoHash::v1() const { #ifdef QBT_USES_LIBTORRENT2 @@ -84,7 +93,7 @@ BitTorrent::InfoHash::operator WrappedType() const BitTorrent::TorrentID BitTorrent::TorrentID::fromString(const QString &hashString) { - return {BaseType::fromString(hashString)}; + return TorrentID(BaseType::fromString(hashString)); } BitTorrent::TorrentID BitTorrent::TorrentID::fromInfoHash(const BitTorrent::InfoHash &infoHash) @@ -92,6 +101,16 @@ BitTorrent::TorrentID BitTorrent::TorrentID::fromInfoHash(const BitTorrent::Info return infoHash.toTorrentID(); } +BitTorrent::TorrentID BitTorrent::TorrentID::fromSHA1Hash(const SHA1Hash &hash) +{ + return TorrentID(hash); +} + +BitTorrent::TorrentID BitTorrent::TorrentID::fromSHA256Hash(const SHA256Hash &hash) +{ + return BaseType::UnderlyingType(static_cast(hash).data()); +} + #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) std::size_t BitTorrent::qHash(const BitTorrent::TorrentID &key, const std::size_t seed) #else diff --git a/src/base/bittorrent/infohash.h b/src/base/bittorrent/infohash.h index 2953b9fcf..ffaff0c25 100644 --- a/src/base/bittorrent/infohash.h +++ b/src/base/bittorrent/infohash.h @@ -52,6 +52,8 @@ namespace BitTorrent static TorrentID fromString(const QString &hashString); static TorrentID fromInfoHash(const InfoHash &infoHash); + static TorrentID fromSHA1Hash(const SHA1Hash &hash); + static TorrentID fromSHA256Hash(const SHA256Hash &hash); }; class InfoHash @@ -70,6 +72,7 @@ namespace BitTorrent #endif bool isValid() const; + bool isHybrid() const; SHA1Hash v1() const; SHA256Hash v2() const; TorrentID toTorrentID() const; diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 6f98f25e8..d300648c4 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -2116,12 +2116,26 @@ void Session::fileSearchFinished(const TorrentID &id, const Path &savePath, cons } } -// Return the torrent handle, given its hash -Torrent *Session::findTorrent(const TorrentID &id) const +Torrent *Session::getTorrent(const TorrentID &id) const { return m_torrents.value(id); } +Torrent *Session::findTorrent(const InfoHash &infoHash) const +{ + const auto id = TorrentID::fromInfoHash(infoHash); + if (Torrent *torrent = m_torrents.value(id); torrent) + return torrent; + + if (!infoHash.isHybrid()) + return nullptr; + + // alternative ID can be useful to find existing torrent + // in case if hybrid torrent was added by v1 info hash + const auto altID = TorrentID::fromSHA1Hash(infoHash.v1()); + return m_torrents.value(altID); +} + bool Session::hasActiveTorrents() const { return std::any_of(m_torrents.begin(), m_torrents.end(), [](TorrentImpl *torrent) @@ -2502,21 +2516,18 @@ bool Session::addTorrent_impl(const std::variant &source Q_ASSERT(isRestored()); const bool hasMetadata = std::holds_alternative(source); - const auto id = TorrentID::fromInfoHash(hasMetadata ? std::get(source).infoHash() : std::get(source).infoHash()); + const auto infoHash = (hasMetadata ? std::get(source).infoHash() : std::get(source).infoHash()); + const auto id = TorrentID::fromInfoHash(infoHash); - // It looks illogical that we don't just use an existing handle, - // but as previous experience has shown, it actually creates unnecessary - // problems and unwanted behavior due to the fact that it was originally - // added with parameters other than those provided by the user. - cancelDownloadMetadata(id); + // alternative ID can be useful to find existing torrent in case if hybrid torrent was added by v1 info hash + const auto altID = (infoHash.isHybrid() ? TorrentID::fromSHA1Hash(infoHash.v1()) : TorrentID()); // We should not add the torrent if it is already // processed or is pending to add to session - if (m_loadingTorrents.contains(id)) + if (m_loadingTorrents.contains(id) || (infoHash.isHybrid() && m_loadingTorrents.contains(altID))) return false; - TorrentImpl *const torrent = m_torrents.value(id); - if (torrent) + if (Torrent *torrent = findTorrent(infoHash); torrent) { if (hasMetadata) { @@ -2527,6 +2538,14 @@ bool Session::addTorrent_impl(const std::variant &source return false; } + // It looks illogical that we don't just use an existing handle, + // but as previous experience has shown, it actually creates unnecessary + // problems and unwanted behavior due to the fact that it was originally + // added with parameters other than those provided by the user. + cancelDownloadMetadata(id); + if (infoHash.isHybrid()) + cancelDownloadMetadata(altID); + LoadTorrentParams loadTorrentParams = initLoadTorrentParams(addTorrentParams); lt::add_torrent_params &p = loadTorrentParams.ltAddTorrentParams; @@ -2662,6 +2681,8 @@ bool Session::addTorrent_impl(const std::variant &source else p.flags |= lt::torrent_flags::auto_managed; + p.flags |= lt::torrent_flags::duplicate_is_error; + p.added_time = std::time(nullptr); // Limits @@ -2697,20 +2718,13 @@ void Session::findIncompleteFiles(const TorrentInfo &torrentInfo, const Path &sa // and force it to download its metadata bool Session::downloadMetadata(const MagnetUri &magnetUri) { - if (!magnetUri.isValid()) return false; - - const auto id = TorrentID::fromInfoHash(magnetUri.infoHash()); - const QString name = magnetUri.name(); + if (!magnetUri.isValid()) + return false; // We should not add torrent if it's already // processed or adding to session - if (m_torrents.contains(id)) return false; - if (m_loadingTorrents.contains(id)) return false; - if (m_downloadedMetadata.contains(id)) return false; - - qDebug("Adding torrent to preload metadata..."); - qDebug(" -> Torrent ID: %s", qUtf8Printable(id.toString())); - qDebug(" -> Name: %s", qUtf8Printable(name)); + if (isKnownTorrent(magnetUri.infoHash())) + return false; lt::add_torrent_params p = magnetUri.addTorrentParams(); @@ -2725,6 +2739,7 @@ bool Session::downloadMetadata(const MagnetUri &magnetUri) p.max_connections = maxConnectionsPerTorrent(); p.max_uploads = maxUploadsPerTorrent(); + const auto id = TorrentID::fromInfoHash(magnetUri.infoHash()); const Path savePath = Utils::Fs::tempPath() / Path(id.toString()); p.save_path = savePath.toString().toStdString(); @@ -2816,7 +2831,7 @@ void Session::saveResumeData() { case lt::save_resume_data_failed_alert::alert_type: case lt::save_resume_data_alert::alert_type: - dispatchTorrentAlert(a); + dispatchTorrentAlert(static_cast(a)); break; } } @@ -4365,11 +4380,19 @@ void Session::setMaxRatioAction(const MaxRatioAction act) // If this functions returns true, we cannot add torrent to session, // but it is still possible to merge trackers in some cases -bool Session::isKnownTorrent(const TorrentID &id) const +bool Session::isKnownTorrent(const InfoHash &infoHash) const { - return (m_torrents.contains(id) - || m_loadingTorrents.contains(id) - || m_downloadedMetadata.contains(id)); + const bool isHybrid = infoHash.isHybrid(); + const auto id = TorrentID::fromInfoHash(infoHash); + // alternative ID can be useful to find existing torrent + // in case if hybrid torrent was added by v1 info hash + const auto altID = (isHybrid ? TorrentID::fromSHA1Hash(infoHash.v1()) : TorrentID()); + + if (m_loadingTorrents.contains(id) || (isHybrid && m_loadingTorrents.contains(altID))) + return true; + if (m_downloadedMetadata.contains(id) || (isHybrid && m_downloadedMetadata.contains(altID))) + return true; + return findTorrent(infoHash); } void Session::updateSeedingLimitTimer() @@ -4522,6 +4545,18 @@ void Session::handleTorrentResumeDataReady(TorrentImpl *const torrent, const Loa --m_numResumeData; m_resumeDataStorage->store(torrent->id(), data); + const auto iter = m_changedTorrentIDs.find(torrent->id()); + if (iter != m_changedTorrentIDs.end()) + { + m_resumeDataStorage->remove(iter.value()); + m_changedTorrentIDs.erase(iter); + } +} + +void Session::handleTorrentIDChanged(const TorrentImpl *torrent, const TorrentID &prevID) +{ + m_torrents[torrent->id()] = m_torrents.take(prevID); + m_changedTorrentIDs[torrent->id()] = prevID; } bool Session::addMoveTorrentStorageJob(TorrentImpl *torrent, const Path &newPath, const MoveStorageMode mode) @@ -4956,7 +4991,7 @@ void Session::handleAlert(const lt::alert *a) case lt::torrent_checked_alert::alert_type: case lt::metadata_received_alert::alert_type: case lt::performance_alert::alert_type: - dispatchTorrentAlert(a); + dispatchTorrentAlert(static_cast(a)); break; case lt::state_update_alert::alert_type: handleStateUpdateAlert(static_cast(a)); @@ -5021,6 +5056,11 @@ void Session::handleAlert(const lt::alert *a) case lt::socks5_alert::alert_type: handleSocks5Alert(static_cast(a)); break; +#ifdef QBT_USES_LIBTORRENT2 + case lt::torrent_conflict_alert::alert_type: + handleTorrentConflictAlert(static_cast(a)); + break; +#endif } } catch (const std::exception &exc) @@ -5029,9 +5069,19 @@ void Session::handleAlert(const lt::alert *a) } } -void Session::dispatchTorrentAlert(const lt::alert *a) +void Session::dispatchTorrentAlert(const lt::torrent_alert *a) { - TorrentImpl *const torrent = m_torrents.value(static_cast(a)->handle.info_hash()); + const TorrentID torrentID {a->handle.info_hash()}; + TorrentImpl *torrent = m_torrents.value(torrentID); +#ifdef QBT_USES_LIBTORRENT2 + if (!torrent && (a->type() == lt::metadata_received_alert::alert_type)) + { + const InfoHash infoHash {a->handle.info_hashes()}; + if (infoHash.isHybrid()) + torrent = m_torrents.value(TorrentID::fromSHA1Hash(infoHash.v1())); + } +#endif + if (torrent) { torrent->handleAlert(a); @@ -5041,7 +5091,7 @@ void Session::dispatchTorrentAlert(const lt::alert *a) switch (a->type()) { case lt::metadata_received_alert::alert_type: - handleMetadataReceivedAlert(static_cast(a)); + handleMetadataReceivedAlert(static_cast(a)); break; } } @@ -5489,6 +5539,40 @@ void Session::handleTrackerAlert(const lt::tracker_alert *a) } } +#ifdef QBT_USES_LIBTORRENT2 +void Session::handleTorrentConflictAlert(const lt::torrent_conflict_alert *a) +{ + const auto torrentIDv1 = TorrentID::fromSHA1Hash(a->metadata->info_hashes().v1); + const auto torrentIDv2 = TorrentID::fromSHA256Hash(a->metadata->info_hashes().v2); + TorrentImpl *torrent1 = m_torrents.value(torrentIDv1); + TorrentImpl *torrent2 = m_torrents.value(torrentIDv2); + if (torrent2) + { + if (torrent1) + deleteTorrent(torrentIDv1); + else + cancelDownloadMetadata(torrentIDv1); + + torrent2->nativeHandle().set_metadata(a->metadata->info_section()); + } + else if (torrent1) + { + if (!torrent2) + cancelDownloadMetadata(torrentIDv2); + + torrent1->nativeHandle().set_metadata(a->metadata->info_section()); + } + else + { + cancelDownloadMetadata(torrentIDv1); + cancelDownloadMetadata(torrentIDv2); + } + + if (!torrent1 || !torrent2) + emit metadataDownloaded(TorrentInfo(*a->metadata)); +} +#endif + void Session::processTrackerStatuses() { for (auto it = m_updatedTrackerEntries.cbegin(); it != m_updatedTrackerEntries.cend(); ++it) diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 3fc1c3be7..ea369537e 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -52,6 +52,14 @@ #include "torrentinfo.h" #include "trackerentry.h" +#ifdef QBT_USES_LIBTORRENT2 +// TODO: Remove the following forward declaration once v2.0.8 is released +namespace libtorrent +{ + struct torrent_conflict_alert; +} +#endif + #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) class QNetworkConfiguration; class QNetworkConfigurationManager; @@ -473,7 +481,8 @@ namespace BitTorrent bool isRestored() const; - Torrent *findTorrent(const TorrentID &id) const; + Torrent *getTorrent(const TorrentID &id) const; + Torrent *findTorrent(const InfoHash &infoHash) const; QVector torrents() const; qsizetype torrentsCount() const; bool hasActiveTorrents() const; @@ -490,7 +499,7 @@ namespace BitTorrent void banIP(const QString &ip); - bool isKnownTorrent(const TorrentID &id) const; + bool isKnownTorrent(const InfoHash &infoHash) const; bool addTorrent(const QString &source, const AddTorrentParams ¶ms = AddTorrentParams()); bool addTorrent(const MagnetUri &magnetUri, const AddTorrentParams ¶ms = AddTorrentParams()); bool addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams ¶ms = AddTorrentParams()); @@ -525,6 +534,7 @@ namespace BitTorrent void handleTorrentUrlSeedsAdded(TorrentImpl *const torrent, const QVector &newUrlSeeds); void handleTorrentUrlSeedsRemoved(TorrentImpl *const torrent, const QVector &urlSeeds); void handleTorrentResumeDataReady(TorrentImpl *const torrent, const LoadTorrentParams &data); + void handleTorrentIDChanged(const TorrentImpl *torrent, const TorrentID &prevID); bool addMoveTorrentStorageJob(TorrentImpl *torrent, const Path &newPath, MoveStorageMode mode); @@ -647,7 +657,7 @@ namespace BitTorrent void handleAlert(const lt::alert *a); void handleAddTorrentAlerts(const std::vector &alerts); - void dispatchTorrentAlert(const lt::alert *a); + void dispatchTorrentAlert(const lt::torrent_alert *a); void handleStateUpdateAlert(const lt::state_update_alert *p); void handleMetadataReceivedAlert(const lt::metadata_received_alert *p); void handleFileErrorAlert(const lt::file_error_alert *p); @@ -668,6 +678,9 @@ namespace BitTorrent void handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert *p); void handleSocks5Alert(const lt::socks5_alert *p) const; void handleTrackerAlert(const lt::tracker_alert *a); +#ifdef QBT_USES_LIBTORRENT2 + void handleTorrentConflictAlert(const lt::torrent_conflict_alert *a); +#endif TorrentImpl *createTorrent(const lt::torrent_handle &nativeHandle, const LoadTorrentParams ¶ms); @@ -830,6 +843,7 @@ namespace BitTorrent QHash m_downloadedTorrents; QHash m_removingTorrents; QSet m_needSaveResumeDataTorrents; + QHash m_changedTorrentIDs; QMap m_categories; QSet m_tags; diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index 31d0ac322..9936467d0 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -2004,6 +2004,13 @@ void TorrentImpl::handleMetadataReceivedAlert(const lt::metadata_received_alert Q_UNUSED(p); qDebug("Metadata received for torrent %s.", qUtf8Printable(name())); +#ifdef QBT_USES_LIBTORRENT2 + const TorrentID prevTorrentID = id(); + m_infoHash = InfoHash(m_nativeHandle.info_hashes()); + if (prevTorrentID != id()) + m_session->handleTorrentIDChanged(this, prevTorrentID); +#endif + m_maintenanceJob = MaintenanceJob::HandleMetadata; m_session->handleTorrentNeedSaveResumeData(this); } diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index 6039aa70a..9324c7499 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -427,12 +427,12 @@ bool AddNewTorrentDialog::loadTorrentFile(const QString &source) bool AddNewTorrentDialog::loadTorrentImpl() { - const auto torrentID = BitTorrent::TorrentID::fromInfoHash(m_torrentInfo.infoHash()); + const BitTorrent::InfoHash infoHash = m_torrentInfo.infoHash(); // Prevent showing the dialog if download is already present - if (BitTorrent::Session::instance()->isKnownTorrent(torrentID)) + if (BitTorrent::Session::instance()->isKnownTorrent(infoHash)) { - BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(torrentID); + BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(infoHash); if (torrent) { // Trying to set metadata to existing torrent in case if it has none @@ -480,11 +480,12 @@ bool AddNewTorrentDialog::loadMagnet(const BitTorrent::MagnetUri &magnetUri) m_torrentGuard = std::make_unique(); - const auto torrentID = BitTorrent::TorrentID::fromInfoHash(magnetUri.infoHash()); + const BitTorrent::InfoHash infoHash = magnetUri.infoHash(); + // Prevent showing the dialog if download is already present - if (BitTorrent::Session::instance()->isKnownTorrent(torrentID)) + if (BitTorrent::Session::instance()->isKnownTorrent(infoHash)) { - BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(torrentID); + BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(infoHash); if (torrent) { if (torrent->isPrivate()) diff --git a/src/gui/torrentoptionsdialog.cpp b/src/gui/torrentoptionsdialog.cpp index 2aea974f4..f31dbe969 100644 --- a/src/gui/torrentoptionsdialog.cpp +++ b/src/gui/torrentoptionsdialog.cpp @@ -411,7 +411,7 @@ void TorrentOptionsDialog::accept() auto *session = BitTorrent::Session::instance(); for (const BitTorrent::TorrentID &id : asConst(m_torrentIDs)) { - BitTorrent::Torrent *torrent = session->findTorrent(id); + BitTorrent::Torrent *torrent = session->getTorrent(id); if (!torrent) continue; if (m_initialValues.autoTMM != m_ui->checkAutoTMM->checkState()) diff --git a/src/webui/api/synccontroller.cpp b/src/webui/api/synccontroller.cpp index 03e4817af..74d3e83e2 100644 --- a/src/webui/api/synccontroller.cpp +++ b/src/webui/api/synccontroller.cpp @@ -536,7 +536,7 @@ void SyncController::maindataAction() void SyncController::torrentPeersAction() { const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]); - const BitTorrent::Torrent *torrent = BitTorrent::Session::instance()->findTorrent(id); + const BitTorrent::Torrent *torrent = BitTorrent::Session::instance()->getTorrent(id); if (!torrent) throw APIError(APIErrorType::NotFound); diff --git a/src/webui/api/torrentscontroller.cpp b/src/webui/api/torrentscontroller.cpp index 05786343b..58ae26742 100644 --- a/src/webui/api/torrentscontroller.cpp +++ b/src/webui/api/torrentscontroller.cpp @@ -133,7 +133,7 @@ namespace for (const QString &idString : idList) { const auto hash = BitTorrent::TorrentID::fromString(idString); - BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(hash); + BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(hash); if (torrent) func(torrent); } @@ -392,7 +392,7 @@ void TorrentsController::propertiesAction() requireParams({u"hash"_qs}); const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]); - BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id); + BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id); if (!torrent) throw APIError(APIErrorType::NotFound); @@ -466,7 +466,7 @@ void TorrentsController::trackersAction() requireParams({u"hash"_qs}); const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]); - const BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id); + const BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id); if (!torrent) throw APIError(APIErrorType::NotFound); @@ -499,7 +499,7 @@ void TorrentsController::webseedsAction() requireParams({u"hash"_qs}); const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]); - BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id); + BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id); if (!torrent) throw APIError(APIErrorType::NotFound); @@ -531,7 +531,7 @@ void TorrentsController::filesAction() requireParams({u"hash"_qs}); const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]); - const BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id); + const BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id); if (!torrent) throw APIError(APIErrorType::NotFound); @@ -600,7 +600,7 @@ void TorrentsController::pieceHashesAction() requireParams({u"hash"_qs}); const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]); - BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id); + BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id); if (!torrent) throw APIError(APIErrorType::NotFound); @@ -625,7 +625,7 @@ void TorrentsController::pieceStatesAction() requireParams({u"hash"_qs}); const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]); - BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id); + BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id); if (!torrent) throw APIError(APIErrorType::NotFound); @@ -741,7 +741,7 @@ void TorrentsController::addTrackersAction() requireParams({u"hash"_qs, u"urls"_qs}); const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]); - BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id); + BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id); if (!torrent) throw APIError(APIErrorType::NotFound); @@ -763,7 +763,7 @@ void TorrentsController::editTrackerAction() const QString origUrl = params()[u"origUrl"_qs]; const QString newUrl = params()[u"newUrl"_qs]; - BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id); + BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id); if (!torrent) throw APIError(APIErrorType::NotFound); @@ -801,7 +801,7 @@ void TorrentsController::removeTrackersAction() requireParams({u"hash"_qs, u"urls"_qs}); const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]); - BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id); + BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id); if (!torrent) throw APIError(APIErrorType::NotFound); @@ -879,7 +879,7 @@ void TorrentsController::filePrioAction() if (!BitTorrent::isValidDownloadPriority(priority)) throw APIError(APIErrorType::BadParams, tr("Priority is not valid")); - BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id); + BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id); if (!torrent) throw APIError(APIErrorType::NotFound); if (!torrent->hasMetadata()) @@ -916,7 +916,7 @@ void TorrentsController::uploadLimitAction() for (const QString &id : idList) { int limit = -1; - const BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(BitTorrent::TorrentID::fromString(id)); + const BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(BitTorrent::TorrentID::fromString(id)); if (torrent) limit = torrent->uploadLimit(); map[id] = limit; @@ -934,7 +934,7 @@ void TorrentsController::downloadLimitAction() for (const QString &id : idList) { int limit = -1; - const BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(BitTorrent::TorrentID::fromString(id)); + const BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(BitTorrent::TorrentID::fromString(id)); if (torrent) limit = torrent->downloadLimit(); map[id] = limit; @@ -1163,7 +1163,7 @@ void TorrentsController::renameAction() if (name.isEmpty()) throw APIError(APIErrorType::Conflict, tr("Incorrect torrent name")); - BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id); + BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id); if (!torrent) throw APIError(APIErrorType::NotFound); @@ -1363,7 +1363,7 @@ void TorrentsController::renameFileAction() requireParams({u"hash"_qs, u"oldPath"_qs, u"newPath"_qs}); const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]); - BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id); + BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id); if (!torrent) throw APIError(APIErrorType::NotFound); @@ -1385,7 +1385,7 @@ void TorrentsController::renameFolderAction() requireParams({u"hash"_qs, u"oldPath"_qs, u"newPath"_qs}); const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]); - BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id); + BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id); if (!torrent) throw APIError(APIErrorType::NotFound); @@ -1407,7 +1407,7 @@ void TorrentsController::exportAction() requireParams({u"hash"_qs}); const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]); - const BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(id); + const BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id); if (!torrent) throw APIError(APIErrorType::NotFound);