Browse Source

Merge pull request #13637 from Chocobo1/libt

Improve compatibility with libtorrent 2.0
adaptive-webui-19844
Mike Tzou 4 years ago committed by GitHub
parent
commit
73e9dce143
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      src/base/bittorrent/peerinfo.cpp
  2. 6
      src/base/bittorrent/torrentinfo.cpp
  3. 42
      src/base/bittorrent/trackerentry.cpp

14
src/base/bittorrent/peerinfo.cpp

@ -220,17 +220,9 @@ QString PeerInfo::connectionType() const
if (m_nativeInfo.flags & lt::peer_info::utp_socket) if (m_nativeInfo.flags & lt::peer_info::utp_socket)
return QString::fromUtf8(C_UTP); return QString::fromUtf8(C_UTP);
QString connection; return (m_nativeInfo.connection_type == lt::peer_info::standard_bittorrent)
switch (m_nativeInfo.connection_type) { ? QLatin1String {"BT"}
case lt::peer_info::http_seed: : QLatin1String {"Web"};
case lt::peer_info::web_seed:
connection = "Web";
break;
default:
connection = "BT";
}
return connection;
} }
void PeerInfo::calcRelevance(const TorrentHandle *torrent) void PeerInfo::calcRelevance(const TorrentHandle *torrent)

6
src/base/bittorrent/torrentinfo.cpp

@ -31,6 +31,7 @@
#include <libtorrent/bencode.hpp> #include <libtorrent/bencode.hpp>
#include <libtorrent/create_torrent.hpp> #include <libtorrent/create_torrent.hpp>
#include <libtorrent/error_code.hpp> #include <libtorrent/error_code.hpp>
#include <libtorrent/version.hpp>
#include <QByteArray> #include <QByteArray>
#include <QDateTime> #include <QDateTime>
@ -294,7 +295,12 @@ QVector<QUrl> TorrentInfo::urlSeeds() const
QByteArray TorrentInfo::metadata() const QByteArray TorrentInfo::metadata() const
{ {
if (!isValid()) return {}; if (!isValid()) return {};
#if (LIBTORRENT_VERSION_NUM >= 20000)
const lt::span<const char> infoSection {m_nativeInfo->info_section()};
return {infoSection.data(), static_cast<int>(infoSection.size())};
#else
return {m_nativeInfo->metadata().get(), m_nativeInfo->metadata_size()}; return {m_nativeInfo->metadata().get(), m_nativeInfo->metadata_size()};
#endif
} }
QStringList TorrentInfo::filesForPiece(const int pieceIndex) const QStringList TorrentInfo::filesForPiece(const int pieceIndex) const

42
src/base/bittorrent/trackerentry.cpp

@ -30,6 +30,8 @@
#include <algorithm> #include <algorithm>
#include <libtorrent/version.hpp>
#include <QString> #include <QString>
#include <QUrl> #include <QUrl>
@ -62,7 +64,15 @@ TrackerEntry::Status TrackerEntry::status() const
const bool allFailed = !endpoints.empty() && std::all_of(endpoints.begin(), endpoints.end() const bool allFailed = !endpoints.empty() && std::all_of(endpoints.begin(), endpoints.end()
, [](const lt::announce_endpoint &endpoint) , [](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); return (endpoint.fails > 0);
#endif
}); });
if (allFailed) if (allFailed)
return NotWorking; return NotWorking;
@ -70,7 +80,15 @@ TrackerEntry::Status TrackerEntry::status() const
const bool isUpdating = std::any_of(endpoints.begin(), endpoints.end() const bool isUpdating = std::any_of(endpoints.begin(), endpoints.end()
, [](const lt::announce_endpoint &endpoint) , [](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; return endpoint.updating;
#endif
}); });
if (isUpdating) if (isUpdating)
return Updating; return Updating;
@ -89,24 +107,42 @@ void TrackerEntry::setTier(const int value)
int TrackerEntry::numSeeds() const int TrackerEntry::numSeeds() const
{ {
int value = -1; 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); value = std::max(value, endpoint.scrape_complete);
#endif
}
return value; return value;
} }
int TrackerEntry::numLeeches() const int TrackerEntry::numLeeches() const
{ {
int value = -1; 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); value = std::max(value, endpoint.scrape_incomplete);
#endif
}
return value; return value;
} }
int TrackerEntry::numDownloaded() const int TrackerEntry::numDownloaded() const
{ {
int value = -1; 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); value = std::max(value, endpoint.scrape_downloaded);
#endif
}
return value; return value;
} }

Loading…
Cancel
Save