Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracker is errored only if all local endpoints fail #11733

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/base/bittorrent/torrenthandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,17 @@ void TorrentHandle::handleTrackerErrorAlert(const lt::tracker_error_alert *p)

m_trackerInfos[trackerUrl].lastMessage = message;

m_session->handleTorrentTrackerError(this, trackerUrl);
// Starting with libtorrent 1.2.x each tracker has multiple local endpoints from which
// an announce is attempted. Some endpoints might succeed while others might fail.
// Emit the signal only if all endpoints have failed. TrackerEntry::isWorking() returns
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment of how TrackerEntry::isWorking() works should be documented at trackerentry.cpp, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. I did it here to help any reader on why I seem to check only once but I say "multiple endpoints" (in the comment).

// true if at least one endpoint works.
const QVector<TrackerEntry> trackerList = trackers();
const auto iter = std::find_if(trackerList.cbegin(), trackerList.cend(), [&trackerUrl](const TrackerEntry &entry)
{
return (entry.url() == trackerUrl);
});
if ((iter != trackerList.cend()) && !iter->isWorking())
m_session->handleTorrentTrackerError(this, trackerUrl);
}

void TorrentHandle::handleTorrentCheckedAlert(const lt::torrent_checked_alert *p)
Expand Down
10 changes: 6 additions & 4 deletions src/base/bittorrent/trackerentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ QString TrackerEntry::url() const

bool TrackerEntry::isWorking() const
{
// lt::announce_entry::is_working() returns
// true when the tracker hasn't been tried yet.
#if (LIBTORRENT_VERSION_NUM < 10200)
return nativeEntry().is_working();
return nativeEntry().verified && nativeEntry().is_working();
#else
if (!nativeEntry().verified)
return false;
const auto &endpoints = nativeEntry().endpoints;
return std::any_of(endpoints.begin(), endpoints.end()
, [](const lt::announce_endpoint &endpoint)
Expand All @@ -73,9 +77,7 @@ int TrackerEntry::tier() const

TrackerEntry::Status TrackerEntry::status() const
{
// lt::announce_entry::is_working() returns
// true when the tracker hasn't been tried yet.
if (nativeEntry().verified && isWorking())
if (isWorking())
return Working;

#if (LIBTORRENT_VERSION_NUM < 10200)
Expand Down