From 9bfb108b4f6502b3f2697ca8676be93c11067a9b Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 5 Mar 2020 11:46:04 +0100 Subject: [PATCH] enable all disabled trackers when listen sockets are re-opened --- include/libtorrent/torrent.hpp | 4 ++++ src/session_impl.cpp | 10 ++++++++++ src/torrent.cpp | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 0f2d99af6..794454878 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -1011,6 +1011,10 @@ namespace libtorrent { std::vector const& trackers() const { return m_trackers; } + // this sets all the "enabled" states on all trackers, giving them + // all one more chance of being tried + void enable_all_trackers(); + void replace_trackers(std::vector const& urls); // returns true if the tracker was added, and false if it was already diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 93ab99a94..0f966d143 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2027,6 +2027,16 @@ namespace aux { #if TORRENT_USE_I2P open_new_incoming_i2p_connection(); #endif + + // trackers that were not reachable, may have become reachable now. + // so clear the "disabled" flags to let them be tried one more time + // TODO: it would probably be better to do this by having a + // listen-socket "version" number that gets bumped. And instead of + // setting a bool to disable a tracker, we set the version number that + // it was disabled at. This change would affect the ABI in 1.2, so + // should be done in 2.0 or later + for (auto& t : m_torrents) + t.second->enable_all_trackers(); } void session_impl::reopen_network_sockets(reopen_network_flags_t const options) diff --git a/src/torrent.cpp b/src/torrent.cpp index d75f11798..7fc205e24 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -6201,6 +6201,13 @@ bool is_downloading_state(int const st) return m_torrent_file; } + void torrent::enable_all_trackers() + { + for (announce_entry& ae : m_trackers) + for (announce_endpoint& aep : ae.endpoints) + aep.enabled = true; + } + void torrent::write_resume_data(add_torrent_params& ret) const { ret.version = LIBTORRENT_VERSION_NUM;