Merge pull request #1108 from arvidn/user-agent-1.1

user agent anonymous mode
This commit is contained in:
Arvid Norberg 2016-09-21 07:25:15 -07:00 committed by GitHub
commit 03068ffa0b
5 changed files with 20 additions and 5 deletions

View File

@ -1,4 +1,6 @@
* fix tail-padding for last file in create_torrent * 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 * fix internal resolve links lookup for mutable torrents
* hint DHT bootstrap nodes of actual bootstrap request * hint DHT bootstrap nodes of actual bootstrap request

View File

@ -138,6 +138,8 @@ public:
, bool ignore_nonrouters); , bool ignore_nonrouters);
~upnp(); ~upnp();
void set_user_agent(std::string const& v) { m_user_agent = v; }
void start(); void start();
enum protocol_type { none = 0, udp = 1, tcp = 2 }; enum protocol_type { none = 0, udp = 1, tcp = 2 };
@ -357,7 +359,7 @@ private:
std::vector<global_mapping_t> m_mappings; std::vector<global_mapping_t> m_mappings;
std::string const& m_user_agent; std::string m_user_agent;
// the set of devices we've found // the set of devices we've found
std::set<rootdevice> m_devices; std::set<rootdevice> m_devices;

View File

@ -6501,8 +6501,15 @@ retry:
void session_impl::update_anonymous_mode() 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, ""); m_settings.set_str(settings_pack::user_agent, "");
url_random(m_peer_id.data(), m_peer_id.data() + 20); 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 // the upnp constructor may fail and call the callbacks
m_upnp = boost::make_shared<upnp>(boost::ref(m_io_service) m_upnp = boost::make_shared<upnp>(boost::ref(m_io_service)
, m_listen_interface.address() , 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 , boost::bind(&session_impl::on_port_mapping
, this, _1, _2, _3, _4, _5, 1) , this, _1, _2, _3, _4, _5, 1)
, boost::bind(&session_impl::on_port_map_log , boost::bind(&session_impl::on_port_map_log

View File

@ -882,7 +882,9 @@ namespace libtorrent
)); ));
aux::proxy_settings ps = m_ses.proxy(); aux::proxy_settings ps = m_ses.proxy();
conn->get(m_url, seconds(30), 0, &ps 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); set_state(torrent_status::downloading_metadata);
} }

View File

@ -140,7 +140,8 @@ namespace libtorrent
{ {
request += "Host: "; request += "Host: ";
request += m_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 += "\r\nUser-Agent: ";
request += m_settings.get_str(settings_pack::user_agent); request += m_settings.get_str(settings_pack::user_agent);
} }