From d657c872433aea21a2762880599e9dbee40db9a0 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 21 Aug 2019 15:41:04 +0800 Subject: [PATCH 1/2] Fix unable to remove web seeds As suggested in post [1] we don't need to assign the `ti` field anymore when fastresme already contains the `info` dict. [1]: https://github.com/arvidn/libtorrent/issues/3946#issuecomment-523300003 --- src/base/bittorrent/session.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 12c96fa77..df0d1036a 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -1929,6 +1929,10 @@ bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magne , (patchedFastresumeData.constData() + patchedFastresumeData.size())}; p.flags |= lt::add_torrent_params::flag_use_resume_save_path; + // load from .torrent file when fastresume doesn't contain the required `info` dict + if (!patchedFastresumeData.contains("4:infod")) + p.ti = torrentInfo.nativeInfo(); + // Still setup the default parameters and let libtorrent handle // the parameter merging hasCompleteFastresume = false; @@ -1936,6 +1940,10 @@ bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magne lt::error_code ec; p = lt::read_resume_data(fastresumeData, ec); + // load from .torrent file when fastresume doesn't contain the required `info` dict + if (!p.ti->is_valid()) + p.ti = torrentInfo.nativeInfo(); + // libtorrent will always apply `file_priorities` to torrents, // if the field is present then the fastresume is considered to // be correctly generated and should be complete. @@ -1972,9 +1980,9 @@ bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magne static_cast(priority)); #endif }); - } - p.ti = torrentInfo.nativeInfo(); + p.ti = torrentInfo.nativeInfo(); + } } // Common From 4aab44e779833039be7d17ae541203918dbb18fd Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 21 Aug 2019 15:37:39 +0800 Subject: [PATCH 2/2] Always save info dict when saving fastresume Otherwise torrents loaded from fastresume won't have it and needs to redownload it from elsewhere and slowing down the startup process. This is also required for the future where we will drop loading the `info` dict from .torrent files. --- src/base/bittorrent/session.cpp | 5 +++++ src/base/bittorrent/torrenthandle.cpp | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index df0d1036a..904e6a206 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -3661,6 +3661,11 @@ void Session::startUpTorrents() int resumedTorrentsCount = 0; const auto startupTorrent = [this, &resumeDataDir, &resumedTorrentsCount](const TorrentResumeData ¶ms) { + // TODO: Remove loading of .torrent files when starting up existing torrents + // Starting from v4.2.0, the required `info` dict will be stored in fastresume too + // (besides .torrent file), that means we can remove loading of .torrent files in + // a later release, such as v4.3.0. + const QString filePath = resumeDataDir.filePath(QString("%1.torrent").arg(params.hash)); qDebug() << "Starting up torrent" << params.hash << "..."; if (!addTorrent_impl(params.addTorrentData, params.magnetUri, TorrentInfo::loadFromFile(filePath), params.data)) diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index 455ae6435..d02abd3fe 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -552,7 +552,7 @@ bool TorrentHandle::needSaveResumeData() const void TorrentHandle::saveResumeData() { - m_nativeHandle.save_resume_data(); + m_nativeHandle.save_resume_data(lt::torrent_handle::save_info_dict); m_session->handleTorrentSaveResumeDataRequested(this); }