Browse Source

Handle some torrent conflicts

PR #17576.
adaptive-webui-19844
Vladimir Golovnev 2 years ago committed by GitHub
parent
commit
7527343629
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      src/base/bittorrent/infohash.cpp
  2. 3
      src/base/bittorrent/infohash.h
  3. 144
      src/base/bittorrent/session.cpp
  4. 20
      src/base/bittorrent/session.h
  5. 7
      src/base/bittorrent/torrentimpl.cpp
  6. 13
      src/gui/addnewtorrentdialog.cpp
  7. 2
      src/gui/torrentoptionsdialog.cpp
  8. 2
      src/webui/api/synccontroller.cpp
  9. 34
      src/webui/api/torrentscontroller.cpp

21
src/base/bittorrent/infohash.cpp

@ -50,6 +50,15 @@ bool BitTorrent::InfoHash::isValid() const
return m_valid; 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 SHA1Hash BitTorrent::InfoHash::v1() const
{ {
#ifdef QBT_USES_LIBTORRENT2 #ifdef QBT_USES_LIBTORRENT2
@ -84,7 +93,7 @@ BitTorrent::InfoHash::operator WrappedType() const
BitTorrent::TorrentID BitTorrent::TorrentID::fromString(const QString &hashString) 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) BitTorrent::TorrentID BitTorrent::TorrentID::fromInfoHash(const BitTorrent::InfoHash &infoHash)
@ -92,6 +101,16 @@ BitTorrent::TorrentID BitTorrent::TorrentID::fromInfoHash(const BitTorrent::Info
return infoHash.toTorrentID(); 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<typename SHA256Hash::UnderlyingType>(hash).data());
}
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
std::size_t BitTorrent::qHash(const BitTorrent::TorrentID &key, const std::size_t seed) std::size_t BitTorrent::qHash(const BitTorrent::TorrentID &key, const std::size_t seed)
#else #else

3
src/base/bittorrent/infohash.h

@ -52,6 +52,8 @@ namespace BitTorrent
static TorrentID fromString(const QString &hashString); static TorrentID fromString(const QString &hashString);
static TorrentID fromInfoHash(const InfoHash &infoHash); static TorrentID fromInfoHash(const InfoHash &infoHash);
static TorrentID fromSHA1Hash(const SHA1Hash &hash);
static TorrentID fromSHA256Hash(const SHA256Hash &hash);
}; };
class InfoHash class InfoHash
@ -70,6 +72,7 @@ namespace BitTorrent
#endif #endif
bool isValid() const; bool isValid() const;
bool isHybrid() const;
SHA1Hash v1() const; SHA1Hash v1() const;
SHA256Hash v2() const; SHA256Hash v2() const;
TorrentID toTorrentID() const; TorrentID toTorrentID() const;

144
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::getTorrent(const TorrentID &id) const
Torrent *Session::findTorrent(const TorrentID &id) const
{ {
return m_torrents.value(id); 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 bool Session::hasActiveTorrents() const
{ {
return std::any_of(m_torrents.begin(), m_torrents.end(), [](TorrentImpl *torrent) return std::any_of(m_torrents.begin(), m_torrents.end(), [](TorrentImpl *torrent)
@ -2502,21 +2516,18 @@ bool Session::addTorrent_impl(const std::variant<MagnetUri, TorrentInfo> &source
Q_ASSERT(isRestored()); Q_ASSERT(isRestored());
const bool hasMetadata = std::holds_alternative<TorrentInfo>(source); const bool hasMetadata = std::holds_alternative<TorrentInfo>(source);
const auto id = TorrentID::fromInfoHash(hasMetadata ? std::get<TorrentInfo>(source).infoHash() : std::get<MagnetUri>(source).infoHash()); const auto infoHash = (hasMetadata ? std::get<TorrentInfo>(source).infoHash() : std::get<MagnetUri>(source).infoHash());
const auto id = TorrentID::fromInfoHash(infoHash);
// It looks illogical that we don't just use an existing handle, // alternative ID can be useful to find existing torrent in case if hybrid torrent was added by v1 info hash
// but as previous experience has shown, it actually creates unnecessary const auto altID = (infoHash.isHybrid() ? TorrentID::fromSHA1Hash(infoHash.v1()) : TorrentID());
// problems and unwanted behavior due to the fact that it was originally
// added with parameters other than those provided by the user.
cancelDownloadMetadata(id);
// We should not add the torrent if it is already // We should not add the torrent if it is already
// processed or is pending to add to session // 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; return false;
TorrentImpl *const torrent = m_torrents.value(id); if (Torrent *torrent = findTorrent(infoHash); torrent)
if (torrent)
{ {
if (hasMetadata) if (hasMetadata)
{ {
@ -2527,6 +2538,14 @@ bool Session::addTorrent_impl(const std::variant<MagnetUri, TorrentInfo> &source
return false; 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); LoadTorrentParams loadTorrentParams = initLoadTorrentParams(addTorrentParams);
lt::add_torrent_params &p = loadTorrentParams.ltAddTorrentParams; lt::add_torrent_params &p = loadTorrentParams.ltAddTorrentParams;
@ -2662,6 +2681,8 @@ bool Session::addTorrent_impl(const std::variant<MagnetUri, TorrentInfo> &source
else else
p.flags |= lt::torrent_flags::auto_managed; p.flags |= lt::torrent_flags::auto_managed;
p.flags |= lt::torrent_flags::duplicate_is_error;
p.added_time = std::time(nullptr); p.added_time = std::time(nullptr);
// Limits // Limits
@ -2697,20 +2718,13 @@ void Session::findIncompleteFiles(const TorrentInfo &torrentInfo, const Path &sa
// and force it to download its metadata // and force it to download its metadata
bool Session::downloadMetadata(const MagnetUri &magnetUri) bool Session::downloadMetadata(const MagnetUri &magnetUri)
{ {
if (!magnetUri.isValid()) return false; if (!magnetUri.isValid())
return false;
const auto id = TorrentID::fromInfoHash(magnetUri.infoHash());
const QString name = magnetUri.name();
// We should not add torrent if it's already // We should not add torrent if it's already
// processed or adding to session // processed or adding to session
if (m_torrents.contains(id)) return false; if (isKnownTorrent(magnetUri.infoHash()))
if (m_loadingTorrents.contains(id)) return false; 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));
lt::add_torrent_params p = magnetUri.addTorrentParams(); lt::add_torrent_params p = magnetUri.addTorrentParams();
@ -2725,6 +2739,7 @@ bool Session::downloadMetadata(const MagnetUri &magnetUri)
p.max_connections = maxConnectionsPerTorrent(); p.max_connections = maxConnectionsPerTorrent();
p.max_uploads = maxUploadsPerTorrent(); p.max_uploads = maxUploadsPerTorrent();
const auto id = TorrentID::fromInfoHash(magnetUri.infoHash());
const Path savePath = Utils::Fs::tempPath() / Path(id.toString()); const Path savePath = Utils::Fs::tempPath() / Path(id.toString());
p.save_path = savePath.toString().toStdString(); 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_failed_alert::alert_type:
case lt::save_resume_data_alert::alert_type: case lt::save_resume_data_alert::alert_type:
dispatchTorrentAlert(a); dispatchTorrentAlert(static_cast<const lt::torrent_alert *>(a));
break; break;
} }
} }
@ -4365,11 +4380,19 @@ void Session::setMaxRatioAction(const MaxRatioAction act)
// If this functions returns true, we cannot add torrent to session, // If this functions returns true, we cannot add torrent to session,
// but it is still possible to merge trackers in some cases // 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) const bool isHybrid = infoHash.isHybrid();
|| m_loadingTorrents.contains(id) const auto id = TorrentID::fromInfoHash(infoHash);
|| m_downloadedMetadata.contains(id)); // 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() void Session::updateSeedingLimitTimer()
@ -4522,6 +4545,18 @@ void Session::handleTorrentResumeDataReady(TorrentImpl *const torrent, const Loa
--m_numResumeData; --m_numResumeData;
m_resumeDataStorage->store(torrent->id(), data); 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) 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::torrent_checked_alert::alert_type:
case lt::metadata_received_alert::alert_type: case lt::metadata_received_alert::alert_type:
case lt::performance_alert::alert_type: case lt::performance_alert::alert_type:
dispatchTorrentAlert(a); dispatchTorrentAlert(static_cast<const lt::torrent_alert *>(a));
break; break;
case lt::state_update_alert::alert_type: case lt::state_update_alert::alert_type:
handleStateUpdateAlert(static_cast<const lt::state_update_alert*>(a)); handleStateUpdateAlert(static_cast<const lt::state_update_alert*>(a));
@ -5021,6 +5056,11 @@ void Session::handleAlert(const lt::alert *a)
case lt::socks5_alert::alert_type: case lt::socks5_alert::alert_type:
handleSocks5Alert(static_cast<const lt::socks5_alert *>(a)); handleSocks5Alert(static_cast<const lt::socks5_alert *>(a));
break; break;
#ifdef QBT_USES_LIBTORRENT2
case lt::torrent_conflict_alert::alert_type:
handleTorrentConflictAlert(static_cast<const lt::torrent_conflict_alert *>(a));
break;
#endif
} }
} }
catch (const std::exception &exc) 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<const lt::torrent_alert*>(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) if (torrent)
{ {
torrent->handleAlert(a); torrent->handleAlert(a);
@ -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() void Session::processTrackerStatuses()
{ {
for (auto it = m_updatedTrackerEntries.cbegin(); it != m_updatedTrackerEntries.cend(); ++it) for (auto it = m_updatedTrackerEntries.cbegin(); it != m_updatedTrackerEntries.cend(); ++it)

20
src/base/bittorrent/session.h

@ -52,6 +52,14 @@
#include "torrentinfo.h" #include "torrentinfo.h"
#include "trackerentry.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)) #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
class QNetworkConfiguration; class QNetworkConfiguration;
class QNetworkConfigurationManager; class QNetworkConfigurationManager;
@ -473,7 +481,8 @@ namespace BitTorrent
bool isRestored() const; bool isRestored() const;
Torrent *findTorrent(const TorrentID &id) const; Torrent *getTorrent(const TorrentID &id) const;
Torrent *findTorrent(const InfoHash &infoHash) const;
QVector<Torrent *> torrents() const; QVector<Torrent *> torrents() const;
qsizetype torrentsCount() const; qsizetype torrentsCount() const;
bool hasActiveTorrents() const; bool hasActiveTorrents() const;
@ -490,7 +499,7 @@ namespace BitTorrent
void banIP(const QString &ip); void banIP(const QString &ip);
bool isKnownTorrent(const TorrentID &id) const; bool isKnownTorrent(const InfoHash &infoHash) const;
bool addTorrent(const QString &source, const AddTorrentParams &params = AddTorrentParams()); bool addTorrent(const QString &source, const AddTorrentParams &params = AddTorrentParams());
bool addTorrent(const MagnetUri &magnetUri, const AddTorrentParams &params = AddTorrentParams()); bool addTorrent(const MagnetUri &magnetUri, const AddTorrentParams &params = AddTorrentParams());
bool addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams &params = AddTorrentParams()); bool addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams &params = AddTorrentParams());
@ -525,6 +534,7 @@ namespace BitTorrent
void handleTorrentUrlSeedsAdded(TorrentImpl *const torrent, const QVector<QUrl> &newUrlSeeds); void handleTorrentUrlSeedsAdded(TorrentImpl *const torrent, const QVector<QUrl> &newUrlSeeds);
void handleTorrentUrlSeedsRemoved(TorrentImpl *const torrent, const QVector<QUrl> &urlSeeds); void handleTorrentUrlSeedsRemoved(TorrentImpl *const torrent, const QVector<QUrl> &urlSeeds);
void handleTorrentResumeDataReady(TorrentImpl *const torrent, const LoadTorrentParams &data); 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); bool addMoveTorrentStorageJob(TorrentImpl *torrent, const Path &newPath, MoveStorageMode mode);
@ -647,7 +657,7 @@ namespace BitTorrent
void handleAlert(const lt::alert *a); void handleAlert(const lt::alert *a);
void handleAddTorrentAlerts(const std::vector<lt::alert *> &alerts); void handleAddTorrentAlerts(const std::vector<lt::alert *> &alerts);
void dispatchTorrentAlert(const lt::alert *a); void dispatchTorrentAlert(const lt::torrent_alert *a);
void handleStateUpdateAlert(const lt::state_update_alert *p); void handleStateUpdateAlert(const lt::state_update_alert *p);
void handleMetadataReceivedAlert(const lt::metadata_received_alert *p); void handleMetadataReceivedAlert(const lt::metadata_received_alert *p);
void handleFileErrorAlert(const lt::file_error_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 handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert *p);
void handleSocks5Alert(const lt::socks5_alert *p) const; void handleSocks5Alert(const lt::socks5_alert *p) const;
void handleTrackerAlert(const lt::tracker_alert *a); 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 &params); TorrentImpl *createTorrent(const lt::torrent_handle &nativeHandle, const LoadTorrentParams &params);
@ -830,6 +843,7 @@ namespace BitTorrent
QHash<QString, AddTorrentParams> m_downloadedTorrents; QHash<QString, AddTorrentParams> m_downloadedTorrents;
QHash<TorrentID, RemovingTorrentData> m_removingTorrents; QHash<TorrentID, RemovingTorrentData> m_removingTorrents;
QSet<TorrentID> m_needSaveResumeDataTorrents; QSet<TorrentID> m_needSaveResumeDataTorrents;
QHash<TorrentID, TorrentID> m_changedTorrentIDs;
QMap<QString, CategoryOptions> m_categories; QMap<QString, CategoryOptions> m_categories;
QSet<QString> m_tags; QSet<QString> m_tags;

7
src/base/bittorrent/torrentimpl.cpp

@ -2004,6 +2004,13 @@ void TorrentImpl::handleMetadataReceivedAlert(const lt::metadata_received_alert
Q_UNUSED(p); Q_UNUSED(p);
qDebug("Metadata received for torrent %s.", qUtf8Printable(name())); 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_maintenanceJob = MaintenanceJob::HandleMetadata;
m_session->handleTorrentNeedSaveResumeData(this); m_session->handleTorrentNeedSaveResumeData(this);
} }

13
src/gui/addnewtorrentdialog.cpp

@ -427,12 +427,12 @@ bool AddNewTorrentDialog::loadTorrentFile(const QString &source)
bool AddNewTorrentDialog::loadTorrentImpl() 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 // 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)
{ {
// Trying to set metadata to existing torrent in case if it has none // 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<TorrentFileGuard>(); m_torrentGuard = std::make_unique<TorrentFileGuard>();
const auto torrentID = BitTorrent::TorrentID::fromInfoHash(magnetUri.infoHash()); const BitTorrent::InfoHash infoHash = magnetUri.infoHash();
// Prevent showing the dialog if download is already present // 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)
{ {
if (torrent->isPrivate()) if (torrent->isPrivate())

2
src/gui/torrentoptionsdialog.cpp

@ -411,7 +411,7 @@ void TorrentOptionsDialog::accept()
auto *session = BitTorrent::Session::instance(); auto *session = BitTorrent::Session::instance();
for (const BitTorrent::TorrentID &id : asConst(m_torrentIDs)) for (const BitTorrent::TorrentID &id : asConst(m_torrentIDs))
{ {
BitTorrent::Torrent *torrent = session->findTorrent(id); BitTorrent::Torrent *torrent = session->getTorrent(id);
if (!torrent) continue; if (!torrent) continue;
if (m_initialValues.autoTMM != m_ui->checkAutoTMM->checkState()) if (m_initialValues.autoTMM != m_ui->checkAutoTMM->checkState())

2
src/webui/api/synccontroller.cpp

@ -536,7 +536,7 @@ void SyncController::maindataAction()
void SyncController::torrentPeersAction() void SyncController::torrentPeersAction()
{ {
const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_qs]); 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) if (!torrent)
throw APIError(APIErrorType::NotFound); throw APIError(APIErrorType::NotFound);

34
src/webui/api/torrentscontroller.cpp

@ -133,7 +133,7 @@ namespace
for (const QString &idString : idList) for (const QString &idString : idList)
{ {
const auto hash = BitTorrent::TorrentID::fromString(idString); 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) if (torrent)
func(torrent); func(torrent);
} }
@ -392,7 +392,7 @@ void TorrentsController::propertiesAction()
requireParams({u"hash"_qs}); requireParams({u"hash"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()[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) if (!torrent)
throw APIError(APIErrorType::NotFound); throw APIError(APIErrorType::NotFound);
@ -466,7 +466,7 @@ void TorrentsController::trackersAction()
requireParams({u"hash"_qs}); requireParams({u"hash"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()[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) if (!torrent)
throw APIError(APIErrorType::NotFound); throw APIError(APIErrorType::NotFound);
@ -499,7 +499,7 @@ void TorrentsController::webseedsAction()
requireParams({u"hash"_qs}); requireParams({u"hash"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()[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) if (!torrent)
throw APIError(APIErrorType::NotFound); throw APIError(APIErrorType::NotFound);
@ -531,7 +531,7 @@ void TorrentsController::filesAction()
requireParams({u"hash"_qs}); requireParams({u"hash"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()[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) if (!torrent)
throw APIError(APIErrorType::NotFound); throw APIError(APIErrorType::NotFound);
@ -600,7 +600,7 @@ void TorrentsController::pieceHashesAction()
requireParams({u"hash"_qs}); requireParams({u"hash"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()[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) if (!torrent)
throw APIError(APIErrorType::NotFound); throw APIError(APIErrorType::NotFound);
@ -625,7 +625,7 @@ void TorrentsController::pieceStatesAction()
requireParams({u"hash"_qs}); requireParams({u"hash"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()[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) if (!torrent)
throw APIError(APIErrorType::NotFound); throw APIError(APIErrorType::NotFound);
@ -741,7 +741,7 @@ void TorrentsController::addTrackersAction()
requireParams({u"hash"_qs, u"urls"_qs}); requireParams({u"hash"_qs, u"urls"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()[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) if (!torrent)
throw APIError(APIErrorType::NotFound); throw APIError(APIErrorType::NotFound);
@ -763,7 +763,7 @@ void TorrentsController::editTrackerAction()
const QString origUrl = params()[u"origUrl"_qs]; const QString origUrl = params()[u"origUrl"_qs];
const QString newUrl = params()[u"newUrl"_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) if (!torrent)
throw APIError(APIErrorType::NotFound); throw APIError(APIErrorType::NotFound);
@ -801,7 +801,7 @@ void TorrentsController::removeTrackersAction()
requireParams({u"hash"_qs, u"urls"_qs}); requireParams({u"hash"_qs, u"urls"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()[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) if (!torrent)
throw APIError(APIErrorType::NotFound); throw APIError(APIErrorType::NotFound);
@ -879,7 +879,7 @@ void TorrentsController::filePrioAction()
if (!BitTorrent::isValidDownloadPriority(priority)) if (!BitTorrent::isValidDownloadPriority(priority))
throw APIError(APIErrorType::BadParams, tr("Priority is not valid")); 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) if (!torrent)
throw APIError(APIErrorType::NotFound); throw APIError(APIErrorType::NotFound);
if (!torrent->hasMetadata()) if (!torrent->hasMetadata())
@ -916,7 +916,7 @@ void TorrentsController::uploadLimitAction()
for (const QString &id : idList) for (const QString &id : idList)
{ {
int limit = -1; 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) if (torrent)
limit = torrent->uploadLimit(); limit = torrent->uploadLimit();
map[id] = limit; map[id] = limit;
@ -934,7 +934,7 @@ void TorrentsController::downloadLimitAction()
for (const QString &id : idList) for (const QString &id : idList)
{ {
int limit = -1; 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) if (torrent)
limit = torrent->downloadLimit(); limit = torrent->downloadLimit();
map[id] = limit; map[id] = limit;
@ -1163,7 +1163,7 @@ void TorrentsController::renameAction()
if (name.isEmpty()) if (name.isEmpty())
throw APIError(APIErrorType::Conflict, tr("Incorrect torrent name")); 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) if (!torrent)
throw APIError(APIErrorType::NotFound); throw APIError(APIErrorType::NotFound);
@ -1363,7 +1363,7 @@ void TorrentsController::renameFileAction()
requireParams({u"hash"_qs, u"oldPath"_qs, u"newPath"_qs}); requireParams({u"hash"_qs, u"oldPath"_qs, u"newPath"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()[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) if (!torrent)
throw APIError(APIErrorType::NotFound); throw APIError(APIErrorType::NotFound);
@ -1385,7 +1385,7 @@ void TorrentsController::renameFolderAction()
requireParams({u"hash"_qs, u"oldPath"_qs, u"newPath"_qs}); requireParams({u"hash"_qs, u"oldPath"_qs, u"newPath"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()[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) if (!torrent)
throw APIError(APIErrorType::NotFound); throw APIError(APIErrorType::NotFound);
@ -1407,7 +1407,7 @@ void TorrentsController::exportAction()
requireParams({u"hash"_qs}); requireParams({u"hash"_qs});
const auto id = BitTorrent::TorrentID::fromString(params()[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) if (!torrent)
throw APIError(APIErrorType::NotFound); throw APIError(APIErrorType::NotFound);

Loading…
Cancel
Save