From c95e450b8dbb937570d0b820c28f7790464a4b69 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 25 Oct 2020 12:22:48 +0800 Subject: [PATCH 1/3] Improve compatibility with libtorrent 2.0 In libtorrent 2.0, the `connection_type` was changed to a flag type and hence it cannot be used in a switch statement directly. Also our use of `connection_type` is limited so that a single equality comparison would cover all of our use cases. --- src/base/bittorrent/peerinfo.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/base/bittorrent/peerinfo.cpp b/src/base/bittorrent/peerinfo.cpp index 445380bf7..f3eec84d4 100644 --- a/src/base/bittorrent/peerinfo.cpp +++ b/src/base/bittorrent/peerinfo.cpp @@ -220,17 +220,9 @@ QString PeerInfo::connectionType() const if (m_nativeInfo.flags & lt::peer_info::utp_socket) return QString::fromUtf8(C_UTP); - QString connection; - switch (m_nativeInfo.connection_type) { - case lt::peer_info::http_seed: - case lt::peer_info::web_seed: - connection = "Web"; - break; - default: - connection = "BT"; - } - - return connection; + return (m_nativeInfo.connection_type == lt::peer_info::standard_bittorrent) + ? QLatin1String {"BT"} + : QLatin1String {"Web"}; } void PeerInfo::calcRelevance(const TorrentHandle *torrent) From 7a3e397949791307b40c4481dcd98fd8632dc423 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 25 Oct 2020 13:44:02 +0800 Subject: [PATCH 2/3] Migrate away from deprecated functions in libtorrent 2.0 --- src/base/bittorrent/torrentinfo.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/base/bittorrent/torrentinfo.cpp b/src/base/bittorrent/torrentinfo.cpp index 716b25983..a6f44c873 100644 --- a/src/base/bittorrent/torrentinfo.cpp +++ b/src/base/bittorrent/torrentinfo.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -294,7 +295,12 @@ QVector TorrentInfo::urlSeeds() const QByteArray TorrentInfo::metadata() const { if (!isValid()) return {}; +#if (LIBTORRENT_VERSION_NUM >= 20000) + const lt::span infoSection {m_nativeInfo->info_section()}; + return {infoSection.data(), static_cast(infoSection.size())}; +#else return {m_nativeInfo->metadata().get(), m_nativeInfo->metadata_size()}; +#endif } QStringList TorrentInfo::filesForPiece(const int pieceIndex) const From 480832318c77f72c126a30189ea6b14a749d8418 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 25 Oct 2020 14:36:18 +0800 Subject: [PATCH 3/3] Add support for tracker scrape in libtorrent 2.0 --- src/base/bittorrent/trackerentry.cpp | 42 ++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/base/bittorrent/trackerentry.cpp b/src/base/bittorrent/trackerentry.cpp index e20be6589..61b359012 100644 --- a/src/base/bittorrent/trackerentry.cpp +++ b/src/base/bittorrent/trackerentry.cpp @@ -30,6 +30,8 @@ #include +#include + #include #include @@ -62,7 +64,15 @@ TrackerEntry::Status TrackerEntry::status() const const bool allFailed = !endpoints.empty() && std::all_of(endpoints.begin(), endpoints.end() , [](const lt::announce_endpoint &endpoint) { +#if (LIBTORRENT_VERSION_NUM >= 20000) + return std::all_of(endpoint.info_hashes.begin(), endpoint.info_hashes.end() + , [](const lt::announce_infohash &infohash) + { + return (infohash.fails > 0); + }); +#else return (endpoint.fails > 0); +#endif }); if (allFailed) return NotWorking; @@ -70,7 +80,15 @@ TrackerEntry::Status TrackerEntry::status() const const bool isUpdating = std::any_of(endpoints.begin(), endpoints.end() , [](const lt::announce_endpoint &endpoint) { +#if (LIBTORRENT_VERSION_NUM >= 20000) + return std::any_of(endpoint.info_hashes.begin(), endpoint.info_hashes.end() + , [](const lt::announce_infohash &infohash) + { + return infohash.updating; + }); +#else return endpoint.updating; +#endif }); if (isUpdating) return Updating; @@ -89,24 +107,42 @@ void TrackerEntry::setTier(const int value) int TrackerEntry::numSeeds() const { int value = -1; - for (const lt::announce_endpoint &endpoint : nativeEntry().endpoints) + for (const lt::announce_endpoint &endpoint : nativeEntry().endpoints) { +#if (LIBTORRENT_VERSION_NUM >= 20000) + for (const lt::announce_infohash &infoHash : endpoint.info_hashes) + value = std::max(value, infoHash.scrape_complete); +#else value = std::max(value, endpoint.scrape_complete); +#endif + } return value; } int TrackerEntry::numLeeches() const { int value = -1; - for (const lt::announce_endpoint &endpoint : nativeEntry().endpoints) + for (const lt::announce_endpoint &endpoint : nativeEntry().endpoints) { +#if (LIBTORRENT_VERSION_NUM >= 20000) + for (const lt::announce_infohash &infoHash : endpoint.info_hashes) + value = std::max(value, infoHash.scrape_incomplete); +#else value = std::max(value, endpoint.scrape_incomplete); +#endif + } return value; } int TrackerEntry::numDownloaded() const { int value = -1; - for (const lt::announce_endpoint &endpoint : nativeEntry().endpoints) + for (const lt::announce_endpoint &endpoint : nativeEntry().endpoints) { +#if (LIBTORRENT_VERSION_NUM >= 20000) + for (const lt::announce_infohash &infoHash : endpoint.info_hashes) + value = std::max(value, infoHash.scrape_downloaded); +#else value = std::max(value, endpoint.scrape_downloaded); +#endif + } return value; }