Improve tracker entries handling

PR #19496.

* Add torrent entry status to represent tracker error
* Add torrent entry status to represent unreachable endpoint
* Display tracker entry next/min announce time
* Reset tracker entries when torrent is stopped
This commit is contained in:
Vladimir Golovnev 2023-09-07 08:58:13 +03:00 committed by GitHub
parent 2f94c92df9
commit 7cd2445a49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 239 additions and 69 deletions

View file

@ -487,6 +487,9 @@ void TorrentsController::trackersAction()
int numSeeds = -1;
int numLeeches = -1;
int numDownloaded = -1;
QDateTime nextAnnounceTime;
QDateTime minAnnounceTime;
QString message;
for (const auto &endpoint : tracker.stats)
{
for (const auto &protocolStat : endpoint)
@ -495,15 +498,38 @@ void TorrentsController::trackersAction()
numSeeds = std::max(numSeeds, protocolStat.numSeeds);
numLeeches = std::max(numLeeches, protocolStat.numLeeches);
numDownloaded = std::max(numDownloaded, protocolStat.numDownloaded);
if (protocolStat.status == tracker.status)
{
if (!nextAnnounceTime.isValid() || (nextAnnounceTime > protocolStat.nextAnnounceTime))
{
nextAnnounceTime = protocolStat.nextAnnounceTime;
minAnnounceTime = protocolStat.minAnnounceTime;
if ((protocolStat.status != BitTorrent::TrackerEntry::Status::Working)
|| !protocolStat.message.isEmpty())
{
message = protocolStat.message;
}
}
if (protocolStat.status == BitTorrent::TrackerEntry::Status::Working)
{
if (message.isEmpty())
message = protocolStat.message;
}
}
}
}
const bool isNotWorking = (tracker.status == BitTorrent::TrackerEntry::Status::NotWorking)
|| (tracker.status == BitTorrent::TrackerEntry::Status::TrackerError)
|| (tracker.status == BitTorrent::TrackerEntry::Status::Unreachable);
trackerList << QJsonObject
{
{KEY_TRACKER_URL, tracker.url},
{KEY_TRACKER_TIER, tracker.tier},
{KEY_TRACKER_STATUS, static_cast<int>(tracker.status)},
{KEY_TRACKER_MSG, tracker.message},
{KEY_TRACKER_STATUS, static_cast<int>((isNotWorking ? BitTorrent::TrackerEntry::Status::NotWorking : tracker.status))},
{KEY_TRACKER_MSG, message},
{KEY_TRACKER_PEERS_COUNT, numPeers},
{KEY_TRACKER_SEEDS_COUNT, numSeeds},
{KEY_TRACKER_LEECHES_COUNT, numLeeches},