Browse Source

Don't overwrite tracker entry of unrelated protocol

PR #19493.
adaptive-webui-19844
Vladimir Golovnev 1 year ago committed by GitHub
parent
commit
9ab8203c8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      src/base/bittorrent/sessionimpl.cpp
  2. 6
      src/base/bittorrent/sessionimpl.h
  3. 26
      src/base/bittorrent/torrentimpl.cpp
  4. 2
      src/base/bittorrent/torrentimpl.h

11
src/base/bittorrent/sessionimpl.cpp

@ -5920,12 +5920,17 @@ void SessionImpl::handleTrackerAlert(const lt::tracker_alert *a) @@ -5920,12 +5920,17 @@ void SessionImpl::handleTrackerAlert(const lt::tracker_alert *a)
if (!torrent)
return;
QHash<TrackerEntry::Endpoint, int> &updateInfo = m_updatedTrackerEntries[torrent->nativeHandle()][std::string(a->tracker_url())];
QMap<int, int> &updateInfo = m_updatedTrackerEntries[torrent->nativeHandle()][std::string(a->tracker_url())][a->local_endpoint];
if (a->type() == lt::tracker_reply_alert::alert_type)
{
const int numPeers = static_cast<const lt::tracker_reply_alert *>(a)->num_peers;
updateInfo.insert(a->local_endpoint, numPeers);
#ifdef QBT_USES_LIBTORRENT2
const int protocolVersionNum = (static_cast<const lt::tracker_reply_alert *>(a)->version == lt::protocol_version::V1) ? 1 : 2;
#else
const int protocolVersionNum = 1;
#endif
updateInfo.insert(protocolVersionNum, numPeers);
}
}
@ -6004,7 +6009,7 @@ void SessionImpl::processTrackerStatuses() @@ -6004,7 +6009,7 @@ void SessionImpl::processTrackerStatuses()
if (updatedTrackersIter == updatedTrackers.end())
continue;
const QHash<TrackerEntry::Endpoint, int> &updateInfo = updatedTrackersIter.value();
const auto &updateInfo = updatedTrackersIter.value();
TrackerEntry trackerEntry = torrent->updateTrackerEntry(announceEntry, updateInfo);
const QString url = trackerEntry.url;
updatedTrackerEntries.emplace(url, std::move(trackerEntry));

6
src/base/bittorrent/sessionimpl.h

@ -40,13 +40,13 @@ @@ -40,13 +40,13 @@
#include <QDateTime>
#include <QElapsedTimer>
#include <QHash>
#include <QMap>
#include <QPointer>
#include <QSet>
#include <QVector>
#include "base/path.h"
#include "base/settingvalue.h"
#include "base/types.h"
#include "base/utils/thread.h"
#include "addtorrentparams.h"
#include "cachestatus.h"
@ -745,8 +745,8 @@ namespace BitTorrent @@ -745,8 +745,8 @@ namespace BitTorrent
QSet<QString> m_tags;
// This field holds amounts of peers reported by trackers in their responses to announces
// (torrent.tracker_name.tracker_local_endpoint.num_peers)
QHash<lt::torrent_handle, QHash<std::string, QHash<TrackerEntry::Endpoint, int>>> m_updatedTrackerEntries;
// (torrent.tracker_name.tracker_local_endpoint.protocol_version.num_peers)
QHash<lt::torrent_handle, QHash<std::string, QHash<TrackerEntry::Endpoint, QMap<int, int>>>> m_updatedTrackerEntries;
// I/O errored torrents
QSet<TorrentID> m_recentErroredTorrents;

26
src/base/bittorrent/torrentimpl.cpp

@ -54,9 +54,9 @@ @@ -54,9 +54,9 @@
#include "base/global.h"
#include "base/logger.h"
#include "base/preferences.h"
#include "base/types.h"
#include "base/utils/fs.h"
#include "base/utils/io.h"
#include "base/utils/string.h"
#include "common.h"
#include "downloadpriority.h"
#include "extensiondata.h"
@ -80,10 +80,10 @@ namespace @@ -80,10 +80,10 @@ namespace
#ifdef QBT_USES_LIBTORRENT2
void updateTrackerEntry(TrackerEntry &trackerEntry, const lt::announce_entry &nativeEntry
, const lt::info_hash_t &hashes, const QHash<TrackerEntry::Endpoint, int> &updateInfo)
, const lt::info_hash_t &hashes, const QHash<TrackerEntry::Endpoint, QMap<int, int>> &updateInfo)
#else
void updateTrackerEntry(TrackerEntry &trackerEntry, const lt::announce_entry &nativeEntry
, const QHash<TrackerEntry::Endpoint, int> &updateInfo)
, const QHash<TrackerEntry::Endpoint, QMap<int, int>> &updateInfo)
#endif
{
Q_ASSERT(trackerEntry.url == QString::fromStdString(nativeEntry.url));
@ -113,14 +113,17 @@ namespace @@ -113,14 +113,17 @@ namespace
for (const auto protocolVersion : {lt::protocol_version::V1, lt::protocol_version::V2})
{
if (hashes.has(protocolVersion))
{
if (!hashes.has(protocolVersion))
continue;
const lt::announce_infohash &infoHash = endpoint.info_hashes[protocolVersion];
TrackerEntry::EndpointStats &trackerEndpoint = trackerEntry.stats[endpoint.local_endpoint][(protocolVersion == lt::protocol_version::V1) ? 1 : 2];
const int protocolVersionNum = (protocolVersion == lt::protocol_version::V1) ? 1 : 2;
const QMap<int, int> &endpointUpdateInfo = updateInfo[endpoint.local_endpoint];
TrackerEntry::EndpointStats &trackerEndpoint = trackerEntry.stats[endpoint.local_endpoint][protocolVersionNum];
trackerEndpoint.name = endpointName;
trackerEndpoint.numPeers = updateInfo.value(endpoint.local_endpoint, trackerEndpoint.numPeers);
trackerEndpoint.numPeers = endpointUpdateInfo.value(protocolVersionNum, trackerEndpoint.numPeers);
trackerEndpoint.numSeeds = infoHash.scrape_complete;
trackerEndpoint.numLeeches = infoHash.scrape_incomplete;
trackerEndpoint.numDownloaded = infoHash.scrape_downloaded;
@ -159,15 +162,16 @@ namespace @@ -159,15 +162,16 @@ namespace
}
}
}
}
#else
const auto numEndpoints = static_cast<qsizetype>(nativeEntry.endpoints.size());
for (const lt::announce_endpoint &endpoint : nativeEntry.endpoints)
{
TrackerEntry::EndpointStats &trackerEndpoint = trackerEntry.stats[endpoint.local_endpoint][1];
const int protocolVersionNum = 1;
const QMap<int, int> &endpointUpdateInfo = updateInfo[endpoint.local_endpoint];
TrackerEntry::EndpointStats &trackerEndpoint = trackerEntry.stats[endpoint.local_endpoint][protocolVersionNum];
trackerEndpoint.name = QString::fromStdString((std::stringstream() << endpoint.local_endpoint).str());
trackerEndpoint.numPeers = updateInfo.value(endpoint.local_endpoint, trackerEndpoint.numPeers);
trackerEndpoint.numPeers = endpointUpdateInfo.value(protocolVersionNum, trackerEndpoint.numPeers);
trackerEndpoint.numSeeds = endpoint.scrape_complete;
trackerEndpoint.numLeeches = endpoint.scrape_incomplete;
trackerEndpoint.numDownloaded = endpoint.scrape_downloaded;
@ -1615,7 +1619,7 @@ void TorrentImpl::fileSearchFinished(const Path &savePath, const PathList &fileN @@ -1615,7 +1619,7 @@ void TorrentImpl::fileSearchFinished(const Path &savePath, const PathList &fileN
endReceivedMetadataHandling(savePath, fileNames);
}
TrackerEntry TorrentImpl::updateTrackerEntry(const lt::announce_entry &announceEntry, const QHash<TrackerEntry::Endpoint, int> &updateInfo)
TrackerEntry TorrentImpl::updateTrackerEntry(const lt::announce_entry &announceEntry, const QHash<TrackerEntry::Endpoint, QMap<int, int>> &updateInfo)
{
const auto it = std::find_if(m_trackerEntries.begin(), m_trackerEntries.end()
, [&announceEntry](const TrackerEntry &trackerEntry)

2
src/base/bittorrent/torrentimpl.h

@ -264,7 +264,7 @@ namespace BitTorrent @@ -264,7 +264,7 @@ namespace BitTorrent
void saveResumeData(lt::resume_data_flags_t flags = {});
void handleMoveStorageJobFinished(const Path &path, MoveStorageContext context, bool hasOutstandingJob);
void fileSearchFinished(const Path &savePath, const PathList &fileNames);
TrackerEntry updateTrackerEntry(const lt::announce_entry &announceEntry, const QHash<TrackerEntry::Endpoint, int> &updateInfo);
TrackerEntry updateTrackerEntry(const lt::announce_entry &announceEntry, const QHash<TrackerEntry::Endpoint, QMap<int, int> > &updateInfo);
private:
using EventTrigger = std::function<void ()>;

Loading…
Cancel
Save