add support for &ipv4= tracker argument

This commit is contained in:
arvidn 2018-11-19 01:56:30 +01:00 committed by Arvid Norberg
parent c1bfd696d4
commit 0d8a5a8a44
5 changed files with 38 additions and 12 deletions

View File

@ -1,5 +1,6 @@
1.2 release 1.2 release
* support &ipv4= tracker argument for private torrents
* renamed debug_notification to connect_notification * renamed debug_notification to connect_notification
* when updating listen sockets, only post alerts for new ones * when updating listen sockets, only post alerts for new ones
* deprecate anonymous_mode_alert * deprecate anonymous_mode_alert

View File

@ -144,6 +144,7 @@ namespace libtorrent {
std::uint32_t key; std::uint32_t key;
int num_want; int num_want;
std::vector<address_v6> ipv6; std::vector<address_v6> ipv6;
std::vector<address_v4> ipv4;
sha1_hash info_hash; sha1_hash info_hash;
peer_id pid; peer_id pid;

View File

@ -970,11 +970,13 @@ TORRENT_TEST(tracker_ipv6_argument)
{ {
bool got_announce = false; bool got_announce = false;
bool got_ipv6 = false; bool got_ipv6 = false;
bool got_ipv4 = false;
tracker_test( tracker_test(
[](lt::add_torrent_params& p, lt::session& ses) [](lt::add_torrent_params& p, lt::session& ses)
{ {
settings_pack pack; settings_pack pack;
pack.set_bool(settings_pack::anonymous_mode, false); pack.set_bool(settings_pack::anonymous_mode, false);
pack.set_str(settings_pack::listen_interfaces, "10.0.0.3:0,[ffff::1337]:0");
ses.apply_settings(pack); ses.apply_settings(pack);
p.ti = make_torrent(true); p.ti = make_torrent(true);
return 60; return 60;
@ -984,13 +986,22 @@ TORRENT_TEST(tracker_ipv6_argument)
{ {
got_announce = true; got_announce = true;
bool const stop_event = req.find("&event=stopped") != std::string::npos; bool const stop_event = req.find("&event=stopped") != std::string::npos;
// stop events don't need to advertise the IPv6 address // stop events don't need to advertise the IPv6/IPv4 address
std::string::size_type pos = req.find("&ipv6="); {
TEST_CHECK(pos != std::string::npos || stop_event); std::string::size_type const pos = req.find("&ipv6=");
got_ipv6 |= pos != std::string::npos; TEST_CHECK(pos != std::string::npos || stop_event);
// make sure the IPv6 argument is url encoded got_ipv6 |= pos != std::string::npos;
TEST_CHECK(req.substr(pos + 6, req.substr(pos + 6).find_first_of('&')) // make sure the IPv6 argument is url encoded
== "ffff%3a%3a1337"); TEST_EQUAL(req.substr(pos + 6, req.substr(pos + 6).find_first_of('&'))
, "ffff%3a%3a1337");
}
{
std::string::size_type const pos = req.find("&ipv4=");
TEST_CHECK(pos != std::string::npos || stop_event);
got_ipv4 |= pos != std::string::npos;
TEST_EQUAL(req.substr(pos + 6, req.substr(pos + 6).find_first_of('&')), "10.0.0.3");
}
return sim::send_response(200, "OK", 11) + "d5:peers0:e"; return sim::send_response(200, "OK", 11) + "d5:peers0:e";
} }
, [](torrent_handle) {} , [](torrent_handle) {}

View File

@ -172,6 +172,17 @@ namespace libtorrent {
} }
} }
if (!tracker_req().ipv4.empty() && !i2p)
{
for (auto const& v4 : tracker_req().ipv4)
{
error_code err;
std::string const ip = v4.to_string(err);
if (err) continue;
url += "&ipv4=";
url += escape_string(ip);
}
}
if (!tracker_req().ipv6.empty() && !i2p) if (!tracker_req().ipv6.empty() && !i2p)
{ {
for (auto const& v6 : tracker_req().ipv6) for (auto const& v6 : tracker_req().ipv6)

View File

@ -2782,11 +2782,13 @@ bool is_downloading_state(int const st)
{ {
m_ses.for_each_listen_socket([&](aux::listen_socket_handle const& s) m_ses.for_each_listen_socket([&](aux::listen_socket_handle const& s)
{ {
if (s.is_ssl() != is_ssl_torrent()) if (s.is_ssl() != is_ssl_torrent()) return;
return; tcp::endpoint const ep = s.get_local_endpoint();
if (!is_v6(s.get_local_endpoint())) if (is_any(ep.address())) return;
return; if (is_v6(ep))
req.ipv6.push_back(s.get_local_endpoint().address().to_v6()); req.ipv6.push_back(ep.address().to_v6());
else
req.ipv4.push_back(ep.address().to_v4());
}); });
} }