mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-20 07:27:22 -06:00
Provide tracker peers count via TrackerEntry
Don't expose additional accessor in Torrent interface.
This commit is contained in:
@@ -97,9 +97,11 @@ namespace
|
||||
}
|
||||
|
||||
#if (LIBTORRENT_VERSION_NUM >= 20000)
|
||||
TrackerEntry fromNativeAnnouncerEntry(const lt::announce_entry &nativeEntry, const lt::info_hash_t &hashes)
|
||||
TrackerEntry fromNativeAnnouncerEntry(const lt::announce_entry &nativeEntry
|
||||
, const lt::info_hash_t &hashes, const QMap<lt::tcp::endpoint, int> &trackerPeerCounts)
|
||||
#else
|
||||
TrackerEntry fromNativeAnnouncerEntry(const lt::announce_entry &nativeEntry)
|
||||
TrackerEntry fromNativeAnnouncerEntry(const lt::announce_entry &nativeEntry
|
||||
, const QMap<lt::tcp::endpoint, int> &trackerPeerCounts)
|
||||
#endif
|
||||
{
|
||||
TrackerEntry trackerEntry {QString::fromStdString(nativeEntry.url), nativeEntry.tier};
|
||||
@@ -122,6 +124,7 @@ namespace
|
||||
|
||||
TrackerEntry::EndpointStats trackerEndpoint;
|
||||
trackerEndpoint.protocolVersion = (protocolVersion == lt::protocol_version::V1) ? 1 : 2;
|
||||
trackerEndpoint.numPeers = trackerPeerCounts.value(endpoint.local_endpoint, -1);
|
||||
trackerEndpoint.numSeeds = infoHash.scrape_complete;
|
||||
trackerEndpoint.numLeeches = infoHash.scrape_incomplete;
|
||||
trackerEndpoint.numDownloaded = infoHash.scrape_downloaded;
|
||||
@@ -151,6 +154,7 @@ namespace
|
||||
trackerEndpoint.message = (!trackerMessage.isEmpty() ? trackerMessage : errorMessage);
|
||||
|
||||
trackerEntry.endpoints.append(trackerEndpoint);
|
||||
trackerEntry.numPeers = std::max(trackerEntry.numPeers, trackerEndpoint.numPeers);
|
||||
trackerEntry.numSeeds = std::max(trackerEntry.numSeeds, trackerEndpoint.numSeeds);
|
||||
trackerEntry.numLeeches = std::max(trackerEntry.numLeeches, trackerEndpoint.numLeeches);
|
||||
trackerEntry.numDownloaded = std::max(trackerEntry.numDownloaded, trackerEndpoint.numDownloaded);
|
||||
@@ -168,6 +172,7 @@ namespace
|
||||
for (const lt::announce_endpoint &endpoint : nativeEntry.endpoints)
|
||||
{
|
||||
TrackerEntry::EndpointStats trackerEndpoint;
|
||||
trackerEndpoint.numPeers = trackerPeerCounts.value(endpoint.local_endpoint, -1);
|
||||
trackerEndpoint.numSeeds = endpoint.scrape_complete;
|
||||
trackerEndpoint.numLeeches = endpoint.scrape_incomplete;
|
||||
trackerEndpoint.numDownloaded = endpoint.scrape_downloaded;
|
||||
@@ -197,6 +202,7 @@ namespace
|
||||
trackerEndpoint.message = (!trackerMessage.isEmpty() ? trackerMessage : errorMessage);
|
||||
|
||||
trackerEntry.endpoints.append(trackerEndpoint);
|
||||
trackerEntry.numPeers = std::max(trackerEntry.numPeers, trackerEndpoint.numPeers);
|
||||
trackerEntry.numSeeds = std::max(trackerEntry.numSeeds, trackerEndpoint.numSeeds);
|
||||
trackerEntry.numLeeches = std::max(trackerEntry.numLeeches, trackerEndpoint.numLeeches);
|
||||
trackerEntry.numDownloaded = std::max(trackerEntry.numDownloaded, trackerEndpoint.numDownloaded);
|
||||
@@ -471,21 +477,17 @@ QVector<TrackerEntry> TorrentImpl::trackers() const
|
||||
|
||||
for (const lt::announce_entry &tracker : nativeTrackers)
|
||||
{
|
||||
const QString trackerURL = QString::fromStdString(tracker.url);
|
||||
#if (LIBTORRENT_VERSION_NUM >= 20000)
|
||||
entries << fromNativeAnnouncerEntry(tracker, m_nativeHandle.info_hashes());
|
||||
entries << fromNativeAnnouncerEntry(tracker, m_nativeHandle.info_hashes(), m_trackerPeerCounts[trackerURL]);
|
||||
#else
|
||||
entries << fromNativeAnnouncerEntry(tracker);
|
||||
entries << fromNativeAnnouncerEntry(tracker, m_trackerPeerCounts[trackerURL]);
|
||||
#endif
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
QHash<QString, TrackerInfo> TorrentImpl::trackerInfos() const
|
||||
{
|
||||
return m_trackerInfos;
|
||||
}
|
||||
|
||||
void TorrentImpl::addTrackers(const QVector<TrackerEntry> &trackers)
|
||||
{
|
||||
QSet<TrackerEntry> currentTrackers;
|
||||
@@ -1646,10 +1648,8 @@ void TorrentImpl::handleMoveStorageJobFinished(const bool hasOutstandingJob)
|
||||
|
||||
void TorrentImpl::handleTrackerReplyAlert(const lt::tracker_reply_alert *p)
|
||||
{
|
||||
const QString trackerUrl(p->tracker_url());
|
||||
qDebug("Received a tracker reply from %s (Num_peers = %d)", qUtf8Printable(trackerUrl), p->num_peers);
|
||||
// Connection was successful now. Remove possible old errors
|
||||
m_trackerInfos[trackerUrl] = {p->num_peers};
|
||||
const QString trackerUrl = p->tracker_url();
|
||||
m_trackerPeerCounts[trackerUrl][p->local_endpoint] = p->num_peers;
|
||||
|
||||
m_session->handleTorrentTrackerReply(this, trackerUrl);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user