feat: stop announcing on not-registered tracker error (#2708)

Fixes #2051.
This commit is contained in:
Charles Kerr 2022-02-25 00:26:19 -06:00 committed by GitHub
parent e94ddc82fc
commit 4450973d94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 5 deletions

View File

@ -927,6 +927,15 @@ struct announce_data
bool is_running_on_success = false;
};
static bool isUnregistered(char const* errmsg)
{
auto const lower = tr_strlower(errmsg != nullptr ? errmsg : "");
auto constexpr Keys = std::array<std::string_view, 2>{ "unregistered torrent"sv, "torrent not registered"sv };
return std::any_of(std::begin(Keys), std::end(Keys), [&lower](auto const& key) { return tr_strvContains(lower, key); });
}
static void on_announce_error(tr_tier* tier, char const* err, tr_announce_event e)
{
/* increment the error count */
@ -942,12 +951,20 @@ static void on_announce_error(tr_tier* tier, char const* err, tr_announce_event
/* switch to the next tracker */
current_tracker = tier->useNextTracker();
/* schedule a reannounce */
int const interval = current_tracker->getRetryInterval();
auto const* const host_cstr = current_tracker->host.c_str();
dbgmsg(tier, "Tracker '%s' announce error: %s (Retrying in %d seconds)", host_cstr, err, interval);
tr_logAddTorInfo(tier->tor, "Tracker '%s' announce error: %s (Retrying in %d seconds)", host_cstr, err, interval);
tier_announce_event_push(tier, e, tr_time() + interval);
if (isUnregistered(err))
{
dbgmsg(tier, "Tracker '%s' announce error: %s", host_cstr, err);
tr_logAddTorInfo(tier->tor, "Tracker '%s' announce error: %s", host_cstr, err);
}
else
{
/* schedule a reannounce */
int const interval = current_tracker->getRetryInterval();
dbgmsg(tier, "Tracker '%s' announce error: %s (Retrying in %d seconds)", host_cstr, err, interval);
tr_logAddTorInfo(tier->tor, "Tracker '%s' announce error: %s (Retrying in %d seconds)", host_cstr, err, interval);
tier_announce_event_push(tier, e, tr_time() + interval);
}
}
static void on_announce_done(tr_announce_response const* response, void* vdata)