diff --git a/ChangeLog b/ChangeLog index 2899f7cf6..9123c362f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,6 @@ * fix tail-padding for last file in create_torrent + * don't send user-agent in metadata http downloads or UPnP requests when + in anonymous mode * fix internal resolve links lookup for mutable torrents * hint DHT bootstrap nodes of actual bootstrap request diff --git a/include/libtorrent/upnp.hpp b/include/libtorrent/upnp.hpp index 691d27515..ec1614429 100644 --- a/include/libtorrent/upnp.hpp +++ b/include/libtorrent/upnp.hpp @@ -138,6 +138,8 @@ public: , bool ignore_nonrouters); ~upnp(); + void set_user_agent(std::string const& v) { m_user_agent = v; } + void start(); enum protocol_type { none = 0, udp = 1, tcp = 2 }; @@ -357,7 +359,7 @@ private: std::vector m_mappings; - std::string const& m_user_agent; + std::string m_user_agent; // the set of devices we've found std::set m_devices; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 49c40fd11..4117879c8 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -6501,8 +6501,15 @@ retry: void session_impl::update_anonymous_mode() { - if (!m_settings.get_bool(settings_pack::anonymous_mode)) return; + if (!m_settings.get_bool(settings_pack::anonymous_mode)) + { + if (m_upnp) + m_upnp->set_user_agent(m_settings.get_str(settings_pack::user_agent)); + return; + } + if (m_upnp) + m_upnp->set_user_agent(""); m_settings.set_str(settings_pack::user_agent, ""); url_random(m_peer_id.data(), m_peer_id.data() + 20); } @@ -6825,7 +6832,8 @@ retry: // the upnp constructor may fail and call the callbacks m_upnp = boost::make_shared(boost::ref(m_io_service) , m_listen_interface.address() - , m_settings.get_str(settings_pack::user_agent) + , m_settings.get_bool(settings_pack::anonymous_mode) + ? "" : m_settings.get_str(settings_pack::user_agent) , boost::bind(&session_impl::on_port_mapping , this, _1, _2, _3, _4, _5, 1) , boost::bind(&session_impl::on_port_map_log diff --git a/src/torrent.cpp b/src/torrent.cpp index fe8ebf04e..37d68feba 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -882,7 +882,9 @@ namespace libtorrent )); aux::proxy_settings ps = m_ses.proxy(); conn->get(m_url, seconds(30), 0, &ps - , 5, settings().get_str(settings_pack::user_agent)); + , 5 + , settings().get_bool(settings_pack::anonymous_mode) + ? "" : settings().get_str(settings_pack::user_agent)); set_state(torrent_status::downloading_metadata); } diff --git a/src/web_connection_base.cpp b/src/web_connection_base.cpp index b531cc411..9391db38e 100644 --- a/src/web_connection_base.cpp +++ b/src/web_connection_base.cpp @@ -140,7 +140,8 @@ namespace libtorrent { request += "Host: "; request += m_host; - if (m_first_request || m_settings.get_bool(settings_pack::always_send_user_agent)) { + if ((m_first_request || m_settings.get_bool(settings_pack::always_send_user_agent)) + && !m_settings.get_bool(settings_pack::anonymous_mode)) { request += "\r\nUser-Agent: "; request += m_settings.get_str(settings_pack::user_agent); }