mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-02 01:44:26 +00:00
parent
c805606524
commit
9ab8203c8a
@ -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()
|
||||
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));
|
||||
|
@ -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
|
||||
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;
|
||||
|
@ -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
|
||||
|
||||
#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,50 +113,52 @@ 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];
|
||||
|
||||
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 = endpointUpdateInfo.value(protocolVersionNum, trackerEndpoint.numPeers);
|
||||
trackerEndpoint.numSeeds = infoHash.scrape_complete;
|
||||
trackerEndpoint.numLeeches = infoHash.scrape_incomplete;
|
||||
trackerEndpoint.numDownloaded = infoHash.scrape_downloaded;
|
||||
|
||||
if (infoHash.updating)
|
||||
{
|
||||
const lt::announce_infohash &infoHash = endpoint.info_hashes[protocolVersion];
|
||||
trackerEndpoint.status = TrackerEntry::Updating;
|
||||
++numUpdating;
|
||||
}
|
||||
else if (infoHash.fails > 0)
|
||||
{
|
||||
trackerEndpoint.status = TrackerEntry::NotWorking;
|
||||
++numNotWorking;
|
||||
}
|
||||
else if (nativeEntry.verified)
|
||||
{
|
||||
trackerEndpoint.status = TrackerEntry::Working;
|
||||
++numWorking;
|
||||
}
|
||||
else
|
||||
{
|
||||
trackerEndpoint.status = TrackerEntry::NotContacted;
|
||||
}
|
||||
|
||||
TrackerEntry::EndpointStats &trackerEndpoint = trackerEntry.stats[endpoint.local_endpoint][(protocolVersion == lt::protocol_version::V1) ? 1 : 2];
|
||||
|
||||
trackerEndpoint.name = endpointName;
|
||||
trackerEndpoint.numPeers = updateInfo.value(endpoint.local_endpoint, trackerEndpoint.numPeers);
|
||||
trackerEndpoint.numSeeds = infoHash.scrape_complete;
|
||||
trackerEndpoint.numLeeches = infoHash.scrape_incomplete;
|
||||
trackerEndpoint.numDownloaded = infoHash.scrape_downloaded;
|
||||
|
||||
if (infoHash.updating)
|
||||
{
|
||||
trackerEndpoint.status = TrackerEntry::Updating;
|
||||
++numUpdating;
|
||||
}
|
||||
else if (infoHash.fails > 0)
|
||||
{
|
||||
trackerEndpoint.status = TrackerEntry::NotWorking;
|
||||
++numNotWorking;
|
||||
}
|
||||
else if (nativeEntry.verified)
|
||||
{
|
||||
trackerEndpoint.status = TrackerEntry::Working;
|
||||
++numWorking;
|
||||
}
|
||||
else
|
||||
{
|
||||
trackerEndpoint.status = TrackerEntry::NotContacted;
|
||||
}
|
||||
|
||||
if (!infoHash.message.empty())
|
||||
{
|
||||
trackerEndpoint.message = QString::fromStdString(infoHash.message);
|
||||
if (firstTrackerMessage.isEmpty())
|
||||
firstTrackerMessage = trackerEndpoint.message;
|
||||
}
|
||||
else if (infoHash.last_error)
|
||||
{
|
||||
trackerEndpoint.message = QString::fromLocal8Bit(infoHash.last_error.message());
|
||||
if (firstErrorMessage.isEmpty())
|
||||
firstErrorMessage = trackerEndpoint.message;
|
||||
}
|
||||
if (!infoHash.message.empty())
|
||||
{
|
||||
trackerEndpoint.message = QString::fromStdString(infoHash.message);
|
||||
if (firstTrackerMessage.isEmpty())
|
||||
firstTrackerMessage = trackerEndpoint.message;
|
||||
}
|
||||
else if (infoHash.last_error)
|
||||
{
|
||||
trackerEndpoint.message = QString::fromLocal8Bit(infoHash.last_error.message());
|
||||
if (firstErrorMessage.isEmpty())
|
||||
firstErrorMessage = trackerEndpoint.message;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -164,10 +166,12 @@ namespace
|
||||
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
|
||||
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)
|
||||
|
@ -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…
x
Reference in New Issue
Block a user