From a06a8fe19e923f63bbdbc7e82f90198f2de1ce7b Mon Sep 17 00:00:00 2001 From: Thomas Yuan Date: Tue, 8 Sep 2015 15:15:51 -0400 Subject: [PATCH] load_state should restart dht/proxy if there is dht state/proxy. --- src/session_impl.cpp | 52 ++++++++++++++++++++++--------------------- src/settings_pack.cpp | 4 ++-- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/session_impl.cpp b/src/session_impl.cpp index c3d6448e5..7f1cb137b 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -750,6 +750,7 @@ namespace aux { if (e->type() != bdecode_node::dict_t) return; #ifndef TORRENT_DISABLE_DHT + bool need_update_dht = false; // load from the old settings names settings = e->dict_find_dict("dht"); if (settings) @@ -772,9 +773,17 @@ namespace aux { val = settings.dict_find_int("extended_routing_table"); if (val) m_dht_settings.extended_routing_table = val.int_value(); } + + settings = e->dict_find_dict("dht state"); + if (settings) + { + m_dht_state = settings; + need_update_dht = true; + } #endif #ifndef TORRENT_NO_DEPRECATE + bool need_update_proxy = false; settings = e->dict_find_dict("proxy"); if (settings) { @@ -793,6 +802,7 @@ namespace aux { if (val) m_settings.set_str(settings_pack::proxy_password, val.string_value()); val = settings.dict_find_string("username"); if (val) m_settings.set_str(settings_pack::proxy_username, val.string_value()); + need_update_proxy = true; } settings = e->dict_find_dict("encryption"); @@ -808,32 +818,7 @@ namespace aux { val = settings.dict_find_int("allowed_enc_level"); if (val) m_settings.set_int(settings_pack::allowed_enc_level, val.int_value()); } -#endif - settings = e->dict_find_dict("settings"); - if (settings) - { - boost::shared_ptr pack = load_pack_from_dict(settings); - apply_settings_pack(pack); - } - - // in case we just set a socks proxy, we might have to - // open the socks incoming connection - if (!m_socks_listen_socket) open_new_incoming_socks_connection(); - m_udp_socket.set_proxy_settings(proxy()); - -#ifndef TORRENT_DISABLE_DHT - settings = e->dict_find_dict("dht state"); - if (settings) - { - // TODO: 2 if the DHT is enabled, it should probably be restarted here. - // maybe it should even be deferred to not be started until the client - // has had a chance to pass in the dht state - m_dht_state = settings; - } -#endif - -#ifndef TORRENT_NO_DEPRECATE settings = e->dict_find_list("feeds"); if (settings) { @@ -850,6 +835,23 @@ namespace aux { } #endif + settings = e->dict_find_dict("settings"); + if (settings) + { + // apply_settings_pack will update dht and proxy + boost::shared_ptr pack = load_pack_from_dict(settings); + apply_settings_pack(pack); + } + else + { +#ifndef TORRENT_DISABLE_DHT + if (need_update_dht) update_dht(); +#endif +#ifndef TORRENT_NO_DEPRECATE + if (need_update_proxy) update_proxy(); +#endif + } + #ifndef TORRENT_DISABLE_EXTENSIONS for (ses_extension_list_t::iterator i = m_ses_extensions.begin() , end(m_ses_extensions.end()); i != end; ++i) diff --git a/src/settings_pack.cpp b/src/settings_pack.cpp index 071998343..fa6beb3ec 100644 --- a/src/settings_pack.cpp +++ b/src/settings_pack.cpp @@ -606,7 +606,7 @@ namespace libtorrent for (std::vector >::const_iterator i = pack->m_ints.begin() , end(pack->m_ints.end()); i != end; ++i) { - // disregard setting indices that are not string types + // disregard setting indices that are not int types if ((i->first & settings_pack::type_mask) != settings_pack::int_type_base) continue; @@ -625,7 +625,7 @@ namespace libtorrent for (std::vector >::const_iterator i = pack->m_bools.begin() , end(pack->m_bools.end()); i != end; ++i) { - // disregard setting indices that are not string types + // disregard setting indices that are not bool types if ((i->first & settings_pack::type_mask) != settings_pack::bool_type_base) continue;