From b329d579e91c284b3a2ae3d785f1058b2a6cf040 Mon Sep 17 00:00:00 2001 From: arvidn Date: Mon, 2 Dec 2019 14:14:41 +0100 Subject: [PATCH] clear tracker errors on success --- ChangeLog | 1 + simulation/test_tracker.cpp | 60 +++++++++++++++++++++++++++++++++++++ src/torrent.cpp | 2 ++ 3 files changed, 63 insertions(+) diff --git a/ChangeLog b/ChangeLog index 609efa38a..5a17e743b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * clear tracker errors on success * optimize setting with unlimited unchoke slots * fixed restoring of trackers, comment, creation date and created-by in resume data * fix handling of torrents with too large pieces diff --git a/simulation/test_tracker.cpp b/simulation/test_tracker.cpp index 450654e49..9d8be0b6e 100644 --- a/simulation/test_tracker.cpp +++ b/simulation/test_tracker.cpp @@ -946,6 +946,66 @@ TORRENT_TEST(try_next) TEST_EQUAL(got_announce, true); } +TORRENT_TEST(clear_error) +{ + // make sure we clear the error from a previous attempt when succeeding + // a tracker announce + + int num_announces = 0; + std::string last_message; + tracker_test( + [](lt::add_torrent_params& p, lt::session& ses) + { + settings_pack pack; + // make sure we just listen on a single listen interface + pack.set_str(settings_pack::listen_interfaces, "123.0.0.3:0"); + pack.set_int(settings_pack::min_announce_interval, 1); + pack.set_int(settings_pack::tracker_backoff, 1); + ses.apply_settings(pack); + p.trackers.push_back("http://tracker.com:8080/announce"); + return 60; + }, + [&](std::string method, std::string req, std::map&) + { + // don't count the stopped event when shutting down + if (req.find("&event=stopped&") != std::string::npos) + { + return sim::send_response(200, "OK", 2) + "de"; + } + if (num_announces++ == 0) + { + // the first announce fails + return std::string{}; + } + + // the second announce succeeds, with an empty peer list + char response[500]; + int const size = std::snprintf(response, sizeof(response), "d8:intervali1800e5:peers0:e"); + return sim::send_response(200, "OK", size) + response; + } + , [](torrent_handle h) { + + } + , [&](torrent_handle h) + { + std::vector const tr = h.trackers(); + TEST_EQUAL(tr.size(), 1); + + std::printf("tracker \"%s\"\n", tr[0].url.c_str()); + TEST_EQUAL(tr[0].url, "http://tracker.com:8080/announce"); + TEST_EQUAL(tr[0].endpoints.size(), 1); + auto const& aep = tr[0].endpoints[0]; + std::printf("message: \"%s\" error: \"%s\"\n" + , aep.message.c_str(), aep.last_error.message().c_str()); + TEST_EQUAL(aep.fails, 0); + TEST_CHECK(!aep.last_error); + TEST_EQUAL(aep.message, ""); + last_message = aep.message; + }); + TEST_EQUAL(num_announces, 2); + TEST_EQUAL(last_message, ""); +} + std::shared_ptr make_torrent(bool priv) { file_storage fs; diff --git a/src/torrent.cpp b/src/torrent.cpp index 43a44615f..eabd52d10 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -3233,6 +3233,8 @@ bool is_downloading_state(int const st) aep->min_announce = now + resp.min_interval; aep->updating = false; aep->fails = 0; + aep->last_error.clear(); + aep->message = !resp.warning_message.empty() ? resp.warning_message : std::string(); int tracker_index = int(ae - m_trackers.data()); m_last_working_tracker = std::int8_t(prioritize_tracker(tracker_index));