diff --git a/ChangeLog b/ChangeLog index 3eb4f2c35..e2c55567e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * added resolver_cache_timeout setting for internal host name resolver * make parse_magnet_uri take a string_view instead of std::string * deprecate add_torrent_params::url field. use parse_magnet_uri instead * optimize download queue management diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 9e1f40a23..23e09f2f4 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -704,6 +704,7 @@ namespace libtorrent void update_auto_sequential(); void update_max_failcount(); void update_close_file_interval(); + void update_resolver_cache_timeout(); void update_upnp(); void update_natpmp(); diff --git a/include/libtorrent/resolver.hpp b/include/libtorrent/resolver.hpp index ced6d48b1..5b70bf4a7 100644 --- a/include/libtorrent/resolver.hpp +++ b/include/libtorrent/resolver.hpp @@ -45,7 +45,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/socket.hpp" #include "libtorrent/resolver_interface.hpp" #include "libtorrent/address.hpp" -#include "libtorrent/time.hpp" namespace libtorrent { @@ -59,6 +58,8 @@ struct TORRENT_EXTRA_EXPORT resolver final : resolver_interface virtual void abort() override; + virtual void set_cache_timeout(seconds timeout) override; + private: void on_lookup(error_code const& ec, tcp::resolver::iterator i diff --git a/include/libtorrent/resolver_interface.hpp b/include/libtorrent/resolver_interface.hpp index 65f1f26a0..2910741bb 100644 --- a/include/libtorrent/resolver_interface.hpp +++ b/include/libtorrent/resolver_interface.hpp @@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/error_code.hpp" #include "libtorrent/address.hpp" +#include "libtorrent/time.hpp" namespace libtorrent { @@ -62,6 +63,9 @@ struct TORRENT_EXTRA_EXPORT resolver_interface , callback_t const& h) = 0; virtual void abort() = 0; + + virtual void set_cache_timeout(seconds timeout) = 0; + protected: ~resolver_interface() {} }; diff --git a/include/libtorrent/settings_pack.hpp b/include/libtorrent/settings_pack.hpp index 8e87b4ec4..d287f738f 100644 --- a/include/libtorrent/settings_pack.hpp +++ b/include/libtorrent/settings_pack.hpp @@ -1632,6 +1632,11 @@ namespace libtorrent // given time. max_web_seed_connections, + // the number of seconds before the internal host name resolver + // considers a cache value timed out, negative values are interpreted + // as zero. + resolver_cache_timeout, + max_int_setting_internal }; diff --git a/src/resolver.cpp b/src/resolver.cpp index 99de9e3c6..f7d88db41 100644 --- a/src/resolver.cpp +++ b/src/resolver.cpp @@ -132,4 +132,12 @@ namespace libtorrent { m_resolver.cancel(); } + + void resolver::set_cache_timeout(seconds timeout) + { + if (timeout >= seconds(0)) + m_timeout = timeout; + else + m_timeout = seconds(0); + } } diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 4ca42889b..648ef273a 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -625,6 +625,7 @@ namespace aux { update_connections_limit(); update_unchoke_limit(); update_disk_threads(); + update_resolver_cache_timeout(); update_upnp(); update_natpmp(); update_lsd(); @@ -5087,6 +5088,12 @@ namespace aux { m_close_file_timer.async_wait(make_tick_handler(std::bind(&session_impl::on_close_file, this, _1))); } + void session_impl::update_resolver_cache_timeout() + { + int const timeout = m_settings.get_int(settings_pack::resolver_cache_timeout); + m_host_resolver.set_cache_timeout(seconds(timeout)); + } + void session_impl::update_proxy() { for (auto& i : m_listen_sockets) diff --git a/src/settings_pack.cpp b/src/settings_pack.cpp index 1a83b100f..9be67d92a 100644 --- a/src/settings_pack.cpp +++ b/src/settings_pack.cpp @@ -335,6 +335,7 @@ namespace libtorrent SET(web_seed_name_lookup_retry, 1800, nullptr), SET(close_file_interval, CLOSE_FILE_INTERVAL, &session_impl::update_close_file_interval), SET(max_web_seed_connections, 3, nullptr), + SET(resolver_cache_timeout, 1200, &session_impl::update_resolver_cache_timeout), }}); #undef SET diff --git a/test/test_session.cpp b/test/test_session.cpp index ef253ae18..96a919117 100644 --- a/test/test_session.cpp +++ b/test/test_session.cpp @@ -58,6 +58,7 @@ TORRENT_TEST(session) settings_pack sett = settings(); sett.set_int(settings_pack::num_optimistic_unchoke_slots, 10); sett.set_int(settings_pack::unchoke_slots_limit, 10); + sett.set_int(settings_pack::resolver_cache_timeout, 1000); ses.apply_settings(sett); @@ -90,6 +91,11 @@ TORRENT_TEST(session) ses.apply_settings(sett); TEST_CHECK(ses.get_settings().get_int(settings_pack::unchoke_slots_limit) == 8); + TEST_EQUAL(ses.get_settings().get_int(settings_pack::resolver_cache_timeout), 1000); + sett.set_int(settings_pack::resolver_cache_timeout, 1001); + ses.apply_settings(sett); + TEST_EQUAL(ses.get_settings().get_int(settings_pack::resolver_cache_timeout), 1001); + // make sure the destructor waits properly // for the asynchronous call to set the alert // mask completes, before it goes on to destruct diff --git a/test/test_settings_pack.cpp b/test/test_settings_pack.cpp index 476ce32d9..e5939072f 100644 --- a/test/test_settings_pack.cpp +++ b/test/test_settings_pack.cpp @@ -253,5 +253,7 @@ TORRENT_TEST(settings_pack_abi) TEST_EQUAL(settings_pack::aio_threads, settings_pack::int_type_base + 104); TEST_EQUAL(settings_pack::max_http_recv_buffer_size, settings_pack::int_type_base + 115); TEST_EQUAL(settings_pack::web_seed_name_lookup_retry, settings_pack::int_type_base + 128); + TEST_EQUAL(settings_pack::close_file_interval, settings_pack::int_type_base + 129); + TEST_EQUAL(settings_pack::max_web_seed_connections, settings_pack::int_type_base + 130); + TEST_EQUAL(settings_pack::resolver_cache_timeout, settings_pack::int_type_base + 131); } -