mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-07 13:41:26 -07:00
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:
parent
2f94c92df9
commit
7cd2445a49
11 changed files with 239 additions and 69 deletions
|
@ -4841,6 +4841,15 @@ void SessionImpl::handleTorrentMetadataReceived(TorrentImpl *const torrent)
|
|||
|
||||
void SessionImpl::handleTorrentPaused(TorrentImpl *const torrent)
|
||||
{
|
||||
torrent->resetTrackerEntries();
|
||||
|
||||
const auto &trackerEntries = torrent->trackers();
|
||||
QHash<QString, TrackerEntry> updatedTrackerEntries;
|
||||
updatedTrackerEntries.reserve(trackerEntries.size());
|
||||
for (const auto &trackerEntry : trackerEntries)
|
||||
updatedTrackerEntries.emplace(trackerEntry.url, trackerEntry);
|
||||
emit trackerEntriesUpdated(torrent, updatedTrackerEntries);
|
||||
|
||||
LogMsg(tr("Torrent paused. Torrent: \"%1\"").arg(torrent->name()));
|
||||
emit torrentPaused(torrent);
|
||||
}
|
||||
|
@ -5985,39 +5994,7 @@ void SessionImpl::processTrackerStatuses()
|
|||
|
||||
for (auto it = m_updatedTrackerEntries.cbegin(); it != m_updatedTrackerEntries.cend(); ++it)
|
||||
{
|
||||
invokeAsync([this, torrentHandle = it.key(), updatedTrackers = it.value()]() mutable
|
||||
{
|
||||
try
|
||||
{
|
||||
std::vector<lt::announce_entry> nativeTrackers = torrentHandle.trackers();
|
||||
invoke([this, torrentHandle, nativeTrackers = std::move(nativeTrackers)
|
||||
, updatedTrackers = std::move(updatedTrackers)]
|
||||
{
|
||||
TorrentImpl *torrent = m_torrents.value(torrentHandle.info_hash());
|
||||
if (!torrent)
|
||||
return;
|
||||
|
||||
QHash<QString, TrackerEntry> updatedTrackerEntries;
|
||||
updatedTrackerEntries.reserve(updatedTrackers.size());
|
||||
for (const lt::announce_entry &announceEntry : nativeTrackers)
|
||||
{
|
||||
const auto updatedTrackersIter = updatedTrackers.find(announceEntry.url);
|
||||
if (updatedTrackersIter == updatedTrackers.end())
|
||||
continue;
|
||||
|
||||
const auto &updateInfo = updatedTrackersIter.value();
|
||||
TrackerEntry trackerEntry = torrent->updateTrackerEntry(announceEntry, updateInfo);
|
||||
const QString url = trackerEntry.url;
|
||||
updatedTrackerEntries.emplace(url, std::move(trackerEntry));
|
||||
}
|
||||
|
||||
emit trackerEntriesUpdated(torrent, updatedTrackerEntries);
|
||||
});
|
||||
}
|
||||
catch (const std::exception &)
|
||||
{
|
||||
}
|
||||
});
|
||||
updateTrackerEntries(it.key(), it.value());
|
||||
}
|
||||
|
||||
m_updatedTrackerEntries.clear();
|
||||
|
@ -6046,3 +6023,40 @@ void SessionImpl::loadStatistics()
|
|||
m_previouslyDownloaded = value[u"AlltimeDL"_s].toLongLong();
|
||||
m_previouslyUploaded = value[u"AlltimeUL"_s].toLongLong();
|
||||
}
|
||||
|
||||
void SessionImpl::updateTrackerEntries(lt::torrent_handle torrentHandle, QHash<std::string, QHash<TrackerEntry::Endpoint, QMap<int, int>>> updatedTrackers)
|
||||
{
|
||||
invokeAsync([this, torrentHandle = std::move(torrentHandle), updatedTrackers = std::move(updatedTrackers)]() mutable
|
||||
{
|
||||
try
|
||||
{
|
||||
std::vector<lt::announce_entry> nativeTrackers = torrentHandle.trackers();
|
||||
invoke([this, torrentHandle, nativeTrackers = std::move(nativeTrackers)
|
||||
, updatedTrackers = std::move(updatedTrackers)]
|
||||
{
|
||||
TorrentImpl *torrent = m_torrents.value(torrentHandle.info_hash());
|
||||
if (!torrent || torrent->isPaused())
|
||||
return;
|
||||
|
||||
QHash<QString, TrackerEntry> updatedTrackerEntries;
|
||||
updatedTrackerEntries.reserve(updatedTrackers.size());
|
||||
for (const lt::announce_entry &announceEntry : nativeTrackers)
|
||||
{
|
||||
const auto updatedTrackersIter = updatedTrackers.find(announceEntry.url);
|
||||
if (updatedTrackersIter == updatedTrackers.end())
|
||||
continue;
|
||||
|
||||
const auto &updateInfo = updatedTrackersIter.value();
|
||||
TrackerEntry trackerEntry = torrent->updateTrackerEntry(announceEntry, updateInfo);
|
||||
const QString url = trackerEntry.url;
|
||||
updatedTrackerEntries.emplace(url, std::move(trackerEntry));
|
||||
}
|
||||
|
||||
emit trackerEntriesUpdated(torrent, updatedTrackerEntries);
|
||||
});
|
||||
}
|
||||
catch (const std::exception &)
|
||||
{
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue