mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-30 03:28:41 -07:00
Provide tracker peers count via TrackerEntry
Don't expose additional accessor in Torrent interface.
This commit is contained in:
parent
62a6c725d6
commit
75e0990eb3
6 changed files with 22 additions and 29 deletions
|
@ -84,11 +84,6 @@ namespace BitTorrent
|
||||||
Error
|
Error
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TrackerInfo
|
|
||||||
{
|
|
||||||
int numPeers = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
uint qHash(TorrentState key, uint seed);
|
uint qHash(TorrentState key, uint seed);
|
||||||
|
|
||||||
class Torrent : public AbstractFileStorage
|
class Torrent : public AbstractFileStorage
|
||||||
|
@ -210,7 +205,6 @@ namespace BitTorrent
|
||||||
virtual bool hasFilteredPieces() const = 0;
|
virtual bool hasFilteredPieces() const = 0;
|
||||||
virtual int queuePosition() const = 0;
|
virtual int queuePosition() const = 0;
|
||||||
virtual QVector<TrackerEntry> trackers() const = 0;
|
virtual QVector<TrackerEntry> trackers() const = 0;
|
||||||
virtual QHash<QString, TrackerInfo> trackerInfos() const = 0;
|
|
||||||
virtual QVector<QUrl> urlSeeds() const = 0;
|
virtual QVector<QUrl> urlSeeds() const = 0;
|
||||||
virtual QString error() const = 0;
|
virtual QString error() const = 0;
|
||||||
virtual qlonglong totalDownload() const = 0;
|
virtual qlonglong totalDownload() const = 0;
|
||||||
|
|
|
@ -97,9 +97,11 @@ namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (LIBTORRENT_VERSION_NUM >= 20000)
|
#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
|
#else
|
||||||
TrackerEntry fromNativeAnnouncerEntry(const lt::announce_entry &nativeEntry)
|
TrackerEntry fromNativeAnnouncerEntry(const lt::announce_entry &nativeEntry
|
||||||
|
, const QMap<lt::tcp::endpoint, int> &trackerPeerCounts)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
TrackerEntry trackerEntry {QString::fromStdString(nativeEntry.url), nativeEntry.tier};
|
TrackerEntry trackerEntry {QString::fromStdString(nativeEntry.url), nativeEntry.tier};
|
||||||
|
@ -122,6 +124,7 @@ namespace
|
||||||
|
|
||||||
TrackerEntry::EndpointStats trackerEndpoint;
|
TrackerEntry::EndpointStats trackerEndpoint;
|
||||||
trackerEndpoint.protocolVersion = (protocolVersion == lt::protocol_version::V1) ? 1 : 2;
|
trackerEndpoint.protocolVersion = (protocolVersion == lt::protocol_version::V1) ? 1 : 2;
|
||||||
|
trackerEndpoint.numPeers = trackerPeerCounts.value(endpoint.local_endpoint, -1);
|
||||||
trackerEndpoint.numSeeds = infoHash.scrape_complete;
|
trackerEndpoint.numSeeds = infoHash.scrape_complete;
|
||||||
trackerEndpoint.numLeeches = infoHash.scrape_incomplete;
|
trackerEndpoint.numLeeches = infoHash.scrape_incomplete;
|
||||||
trackerEndpoint.numDownloaded = infoHash.scrape_downloaded;
|
trackerEndpoint.numDownloaded = infoHash.scrape_downloaded;
|
||||||
|
@ -151,6 +154,7 @@ namespace
|
||||||
trackerEndpoint.message = (!trackerMessage.isEmpty() ? trackerMessage : errorMessage);
|
trackerEndpoint.message = (!trackerMessage.isEmpty() ? trackerMessage : errorMessage);
|
||||||
|
|
||||||
trackerEntry.endpoints.append(trackerEndpoint);
|
trackerEntry.endpoints.append(trackerEndpoint);
|
||||||
|
trackerEntry.numPeers = std::max(trackerEntry.numPeers, trackerEndpoint.numPeers);
|
||||||
trackerEntry.numSeeds = std::max(trackerEntry.numSeeds, trackerEndpoint.numSeeds);
|
trackerEntry.numSeeds = std::max(trackerEntry.numSeeds, trackerEndpoint.numSeeds);
|
||||||
trackerEntry.numLeeches = std::max(trackerEntry.numLeeches, trackerEndpoint.numLeeches);
|
trackerEntry.numLeeches = std::max(trackerEntry.numLeeches, trackerEndpoint.numLeeches);
|
||||||
trackerEntry.numDownloaded = std::max(trackerEntry.numDownloaded, trackerEndpoint.numDownloaded);
|
trackerEntry.numDownloaded = std::max(trackerEntry.numDownloaded, trackerEndpoint.numDownloaded);
|
||||||
|
@ -168,6 +172,7 @@ namespace
|
||||||
for (const lt::announce_endpoint &endpoint : nativeEntry.endpoints)
|
for (const lt::announce_endpoint &endpoint : nativeEntry.endpoints)
|
||||||
{
|
{
|
||||||
TrackerEntry::EndpointStats trackerEndpoint;
|
TrackerEntry::EndpointStats trackerEndpoint;
|
||||||
|
trackerEndpoint.numPeers = trackerPeerCounts.value(endpoint.local_endpoint, -1);
|
||||||
trackerEndpoint.numSeeds = endpoint.scrape_complete;
|
trackerEndpoint.numSeeds = endpoint.scrape_complete;
|
||||||
trackerEndpoint.numLeeches = endpoint.scrape_incomplete;
|
trackerEndpoint.numLeeches = endpoint.scrape_incomplete;
|
||||||
trackerEndpoint.numDownloaded = endpoint.scrape_downloaded;
|
trackerEndpoint.numDownloaded = endpoint.scrape_downloaded;
|
||||||
|
@ -197,6 +202,7 @@ namespace
|
||||||
trackerEndpoint.message = (!trackerMessage.isEmpty() ? trackerMessage : errorMessage);
|
trackerEndpoint.message = (!trackerMessage.isEmpty() ? trackerMessage : errorMessage);
|
||||||
|
|
||||||
trackerEntry.endpoints.append(trackerEndpoint);
|
trackerEntry.endpoints.append(trackerEndpoint);
|
||||||
|
trackerEntry.numPeers = std::max(trackerEntry.numPeers, trackerEndpoint.numPeers);
|
||||||
trackerEntry.numSeeds = std::max(trackerEntry.numSeeds, trackerEndpoint.numSeeds);
|
trackerEntry.numSeeds = std::max(trackerEntry.numSeeds, trackerEndpoint.numSeeds);
|
||||||
trackerEntry.numLeeches = std::max(trackerEntry.numLeeches, trackerEndpoint.numLeeches);
|
trackerEntry.numLeeches = std::max(trackerEntry.numLeeches, trackerEndpoint.numLeeches);
|
||||||
trackerEntry.numDownloaded = std::max(trackerEntry.numDownloaded, trackerEndpoint.numDownloaded);
|
trackerEntry.numDownloaded = std::max(trackerEntry.numDownloaded, trackerEndpoint.numDownloaded);
|
||||||
|
@ -471,21 +477,17 @@ QVector<TrackerEntry> TorrentImpl::trackers() const
|
||||||
|
|
||||||
for (const lt::announce_entry &tracker : nativeTrackers)
|
for (const lt::announce_entry &tracker : nativeTrackers)
|
||||||
{
|
{
|
||||||
|
const QString trackerURL = QString::fromStdString(tracker.url);
|
||||||
#if (LIBTORRENT_VERSION_NUM >= 20000)
|
#if (LIBTORRENT_VERSION_NUM >= 20000)
|
||||||
entries << fromNativeAnnouncerEntry(tracker, m_nativeHandle.info_hashes());
|
entries << fromNativeAnnouncerEntry(tracker, m_nativeHandle.info_hashes(), m_trackerPeerCounts[trackerURL]);
|
||||||
#else
|
#else
|
||||||
entries << fromNativeAnnouncerEntry(tracker);
|
entries << fromNativeAnnouncerEntry(tracker, m_trackerPeerCounts[trackerURL]);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<QString, TrackerInfo> TorrentImpl::trackerInfos() const
|
|
||||||
{
|
|
||||||
return m_trackerInfos;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TorrentImpl::addTrackers(const QVector<TrackerEntry> &trackers)
|
void TorrentImpl::addTrackers(const QVector<TrackerEntry> &trackers)
|
||||||
{
|
{
|
||||||
QSet<TrackerEntry> currentTrackers;
|
QSet<TrackerEntry> currentTrackers;
|
||||||
|
@ -1646,10 +1648,8 @@ void TorrentImpl::handleMoveStorageJobFinished(const bool hasOutstandingJob)
|
||||||
|
|
||||||
void TorrentImpl::handleTrackerReplyAlert(const lt::tracker_reply_alert *p)
|
void TorrentImpl::handleTrackerReplyAlert(const lt::tracker_reply_alert *p)
|
||||||
{
|
{
|
||||||
const QString trackerUrl(p->tracker_url());
|
const QString trackerUrl = p->tracker_url();
|
||||||
qDebug("Received a tracker reply from %s (Num_peers = %d)", qUtf8Printable(trackerUrl), p->num_peers);
|
m_trackerPeerCounts[trackerUrl][p->local_endpoint] = p->num_peers;
|
||||||
// Connection was successful now. Remove possible old errors
|
|
||||||
m_trackerInfos[trackerUrl] = {p->num_peers};
|
|
||||||
|
|
||||||
m_session->handleTorrentTrackerReply(this, trackerUrl);
|
m_session->handleTorrentTrackerReply(this, trackerUrl);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,11 +33,13 @@
|
||||||
|
|
||||||
#include <libtorrent/add_torrent_params.hpp>
|
#include <libtorrent/add_torrent_params.hpp>
|
||||||
#include <libtorrent/fwd.hpp>
|
#include <libtorrent/fwd.hpp>
|
||||||
|
#include <libtorrent/socket.hpp>
|
||||||
#include <libtorrent/torrent_handle.hpp>
|
#include <libtorrent/torrent_handle.hpp>
|
||||||
#include <libtorrent/torrent_status.hpp>
|
#include <libtorrent/torrent_status.hpp>
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
#include <QMap>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QQueue>
|
#include <QQueue>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
@ -154,7 +156,6 @@ namespace BitTorrent
|
||||||
bool hasFilteredPieces() const override;
|
bool hasFilteredPieces() const override;
|
||||||
int queuePosition() const override;
|
int queuePosition() const override;
|
||||||
QVector<TrackerEntry> trackers() const override;
|
QVector<TrackerEntry> trackers() const override;
|
||||||
QHash<QString, TrackerInfo> trackerInfos() const override;
|
|
||||||
QVector<QUrl> urlSeeds() const override;
|
QVector<QUrl> urlSeeds() const override;
|
||||||
QString error() const override;
|
QString error() const override;
|
||||||
qlonglong totalDownload() const override;
|
qlonglong totalDownload() const override;
|
||||||
|
@ -308,7 +309,7 @@ namespace BitTorrent
|
||||||
// we will rely on this workaround to remove empty leftover folders
|
// we will rely on this workaround to remove empty leftover folders
|
||||||
QHash<lt::file_index_t, QVector<QString>> m_oldPath;
|
QHash<lt::file_index_t, QVector<QString>> m_oldPath;
|
||||||
|
|
||||||
QHash<QString, TrackerInfo> m_trackerInfos;
|
QHash<QString, QMap<lt::tcp::endpoint, int>> m_trackerPeerCounts;
|
||||||
|
|
||||||
// Persistent data
|
// Persistent data
|
||||||
QString m_name;
|
QString m_name;
|
||||||
|
|
|
@ -49,6 +49,7 @@ namespace BitTorrent
|
||||||
int protocolVersion = 1;
|
int protocolVersion = 1;
|
||||||
|
|
||||||
Status status = NotContacted;
|
Status status = NotContacted;
|
||||||
|
int numPeers = -1;
|
||||||
int numSeeds = -1;
|
int numSeeds = -1;
|
||||||
int numLeeches = -1;
|
int numLeeches = -1;
|
||||||
int numDownloaded = -1;
|
int numDownloaded = -1;
|
||||||
|
@ -62,6 +63,7 @@ namespace BitTorrent
|
||||||
|
|
||||||
// Deprecated fields
|
// Deprecated fields
|
||||||
Status status = NotContacted;
|
Status status = NotContacted;
|
||||||
|
int numPeers = -1;
|
||||||
int numSeeds = -1;
|
int numSeeds = -1;
|
||||||
int numLeeches = -1;
|
int numLeeches = -1;
|
||||||
int numDownloaded = -1;
|
int numDownloaded = -1;
|
||||||
|
|
|
@ -362,7 +362,6 @@ void TrackerListWidget::loadTrackers()
|
||||||
loadStickyItems(torrent);
|
loadStickyItems(torrent);
|
||||||
|
|
||||||
// Load actual trackers information
|
// Load actual trackers information
|
||||||
const QHash<QString, BitTorrent::TrackerInfo> trackerData = torrent->trackerInfos();
|
|
||||||
QStringList oldTrackerURLs = m_trackerItems.keys();
|
QStringList oldTrackerURLs = m_trackerItems.keys();
|
||||||
|
|
||||||
for (const BitTorrent::TrackerEntry &entry : asConst(torrent->trackers()))
|
for (const BitTorrent::TrackerEntry &entry : asConst(torrent->trackers()))
|
||||||
|
@ -384,8 +383,6 @@ void TrackerListWidget::loadTrackers()
|
||||||
|
|
||||||
item->setText(COL_TIER, QString::number(entry.tier));
|
item->setText(COL_TIER, QString::number(entry.tier));
|
||||||
|
|
||||||
const BitTorrent::TrackerInfo data = trackerData.value(trackerURL);
|
|
||||||
|
|
||||||
switch (entry.status)
|
switch (entry.status)
|
||||||
{
|
{
|
||||||
case BitTorrent::TrackerEntry::Working:
|
case BitTorrent::TrackerEntry::Working:
|
||||||
|
@ -403,7 +400,9 @@ void TrackerListWidget::loadTrackers()
|
||||||
}
|
}
|
||||||
|
|
||||||
item->setText(COL_MSG, entry.message);
|
item->setText(COL_MSG, entry.message);
|
||||||
item->setText(COL_PEERS, QString::number(data.numPeers));
|
item->setText(COL_PEERS, ((entry.numPeers > -1)
|
||||||
|
? QString::number(entry.numPeers)
|
||||||
|
: tr("N/A")));
|
||||||
item->setText(COL_SEEDS, ((entry.numSeeds > -1)
|
item->setText(COL_SEEDS, ((entry.numSeeds > -1)
|
||||||
? QString::number(entry.numSeeds)
|
? QString::number(entry.numSeeds)
|
||||||
: tr("N/A")));
|
: tr("N/A")));
|
||||||
|
|
|
@ -453,18 +453,15 @@ void TorrentsController::trackersAction()
|
||||||
|
|
||||||
QJsonArray trackerList = getStickyTrackers(torrent);
|
QJsonArray trackerList = getStickyTrackers(torrent);
|
||||||
|
|
||||||
QHash<QString, BitTorrent::TrackerInfo> trackersData = torrent->trackerInfos();
|
|
||||||
for (const BitTorrent::TrackerEntry &tracker : asConst(torrent->trackers()))
|
for (const BitTorrent::TrackerEntry &tracker : asConst(torrent->trackers()))
|
||||||
{
|
{
|
||||||
const BitTorrent::TrackerInfo data = trackersData.value(tracker.url);
|
|
||||||
|
|
||||||
trackerList << QJsonObject
|
trackerList << QJsonObject
|
||||||
{
|
{
|
||||||
{KEY_TRACKER_URL, tracker.url},
|
{KEY_TRACKER_URL, tracker.url},
|
||||||
{KEY_TRACKER_TIER, tracker.tier},
|
{KEY_TRACKER_TIER, tracker.tier},
|
||||||
{KEY_TRACKER_STATUS, static_cast<int>(tracker.status)},
|
{KEY_TRACKER_STATUS, static_cast<int>(tracker.status)},
|
||||||
{KEY_TRACKER_PEERS_COUNT, data.numPeers},
|
|
||||||
{KEY_TRACKER_MSG, tracker.message},
|
{KEY_TRACKER_MSG, tracker.message},
|
||||||
|
{KEY_TRACKER_PEERS_COUNT, tracker.numPeers},
|
||||||
{KEY_TRACKER_SEEDS_COUNT, tracker.numSeeds},
|
{KEY_TRACKER_SEEDS_COUNT, tracker.numSeeds},
|
||||||
{KEY_TRACKER_LEECHES_COUNT, tracker.numLeeches},
|
{KEY_TRACKER_LEECHES_COUNT, tracker.numLeeches},
|
||||||
{KEY_TRACKER_DOWNLOADED_COUNT, tracker.numDownloaded}
|
{KEY_TRACKER_DOWNLOADED_COUNT, tracker.numDownloaded}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue