From 48ca20968e66d73464e85cc0dca8b1fa8cebc7f5 Mon Sep 17 00:00:00 2001 From: terry zhao Date: Tue, 26 Jul 2016 13:13:28 +0800 Subject: [PATCH] fix value of current_tracker when all tracker failed (#932) fix torrent_status::current_tracker when all trackers fail. --- ChangeLog | 1 + src/torrent.cpp | 3 ++- test/test_tracker.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 4f524c201..fcdc10f54 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 1.1.1 release + * fix value of current_tracker when all tracker failed * deprecate lt_trackers extension * remove load_asnum_db and load_country_db from python bindings * fix crash in session::get_ip_filter when not having set one diff --git a/src/torrent.cpp b/src/torrent.cpp index 7218ddb5c..ffb611da4 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -12099,7 +12099,8 @@ namespace libtorrent std::vector::const_iterator i; for (i = m_trackers.begin(); i != m_trackers.end(); ++i) { - if (!i->updating) continue; + if (i->updating) continue; + if (!i->verified) continue; st->current_tracker = i->url; break; } diff --git a/test/test_tracker.cpp b/test/test_tracker.cpp index eead9c622..fb4f7fdc5 100644 --- a/test/test_tracker.cpp +++ b/test/test_tracker.cpp @@ -421,9 +421,16 @@ TORRENT_TEST(http_peers) addp.save_path = "tmp2_tracker"; torrent_handle h = s->add_torrent(addp); + libtorrent::torrent_status status = h.status(); + TEST_CHECK(status.current_tracker.empty()); + // wait to hit the tracker wait_for_alert(*s, tracker_reply_alert::alert_type, "s"); + status = h.status(); + TEST_CHECK(!status.current_tracker.empty()); + TEST_CHECK(status.current_tracker == tracker_url); + // we expect to have certain peers in our peer list now // these peers are hard coded in web_server.py std::vector peers; @@ -455,6 +462,61 @@ TORRENT_TEST(http_peers) fprintf(stderr, "done\n"); } +TORRENT_TEST(current_tracker) +{ + // use a invalid tracker port + int http_port = 39527; + + settings_pack pack = settings(); + pack.set_bool(settings_pack::announce_to_all_trackers, true); + pack.set_bool(settings_pack::announce_to_all_tiers, false); + pack.set_int(settings_pack::tracker_completion_timeout, 2); + pack.set_int(settings_pack::tracker_receive_timeout, 1); + pack.set_str(settings_pack::listen_interfaces, "0.0.0.0:39775"); + //pack.set_int(settings_pack::alert_mask, alert::tracker_notification); + + boost::scoped_ptr s(new lt::session(pack)); + + error_code ec; + remove_all("tmp3_tracker", ec); + create_directory("tmp3_tracker", ec); + std::ofstream file(combine_path("tmp3_tracker", "temporary").c_str()); + boost::shared_ptr t = ::create_torrent(&file, "temporary", 16 * 1024, 13, false); + file.close(); + + char tracker_url[200]; + snprintf(tracker_url, sizeof(tracker_url), "http://127.0.0.1:%d/announce" + , http_port); + t->add_tracker(tracker_url, 0); + + add_torrent_params addp; + addp.flags &= ~add_torrent_params::flag_paused; + addp.flags &= ~add_torrent_params::flag_auto_managed; + addp.flags |= add_torrent_params::flag_seed_mode; + addp.ti = t; + addp.save_path = "tmp3_tracker"; + torrent_handle h = s->add_torrent(addp); + + libtorrent::torrent_status status = h.status(); + TEST_CHECK(status.current_tracker.empty()); + + // wait to hit the tracker announce + wait_for_alert(*s, tracker_announce_alert::alert_type, "s"); + + status = h.status(); + TEST_CHECK(status.current_tracker.empty()); + + // wait to hit the tracker error + wait_for_alert(*s, tracker_error_alert::alert_type, "s"); + + status = h.status(); + TEST_CHECK(status.current_tracker.empty()); + + fprintf(stderr, "destructing session\n"); + s.reset(); + fprintf(stderr, "done\n"); +} + void test_proxy(bool proxy_trackers) { int http_port = start_web_server();