Merge pull request #251 from arvidn/ipv6-fix

fix IPv6 tracker announce
This commit is contained in:
Arvid Norberg 2015-11-11 19:13:31 -05:00
commit 39f62fe3d9
4 changed files with 29 additions and 16 deletions

View File

@ -156,6 +156,10 @@ private:
std::vector<tcp::endpoint> m_endpoints;
// if the current connection attempt fails, we'll connect to the
// endpoint with this index (in m_endpoints) next
int m_next_ep;
socket_type m_sock;
#ifdef TORRENT_USE_OPENSSL

View File

@ -66,7 +66,8 @@ http_connection::http_connection(io_service& ios
, ssl::context* ssl_ctx
#endif
)
: m_sock(ios)
: m_next_ep(0)
, m_sock(ios)
#ifdef TORRENT_USE_OPENSSL
, m_ssl_ctx(ssl_ctx)
, m_own_ssl_context(false)
@ -408,6 +409,7 @@ void http_connection::start(std::string const& hostname, int port
add_outstanding_async("http_connection::on_resolve");
#endif
m_endpoints.clear();
m_next_ep = 0;
m_resolver.async_resolve(hostname, m_resolve_flags
, boost::bind(&http_connection::on_resolve
, me, _1, _2));
@ -438,7 +440,7 @@ void http_connection::on_timeout(boost::weak_ptr<http_connection> p
// the connection timed out. If we have more endpoints to try, just
// close this connection. The on_connect handler will try the next
// endpoint in the list.
if (!c->m_endpoints.empty())
if (c->m_next_ep < c->m_endpoints.size())
{
error_code ec;
c->m_sock.close(ec);
@ -448,8 +450,8 @@ void http_connection::on_timeout(boost::weak_ptr<http_connection> p
{
c->callback(boost::asio::error::timed_out);
c->close(true);
return;
}
return;
}
else
{
@ -570,7 +572,7 @@ void http_connection::on_resolve(error_code const& e
void http_connection::connect()
{
TORRENT_ASSERT(!m_endpoints.empty());
TORRENT_ASSERT(m_next_ep < m_endpoints.size());
boost::shared_ptr<http_connection> me(shared_from_this());
@ -594,11 +596,11 @@ void http_connection::connect()
}
}
TORRENT_ASSERT(!m_endpoints.empty());
if (m_endpoints.empty()) return;
TORRENT_ASSERT(m_next_ep < m_endpoints.size());
if (m_next_ep >= m_endpoints.size()) return;
tcp::endpoint target_address = m_endpoints.front();
m_endpoints.erase(m_endpoints.begin());
tcp::endpoint target_address = m_endpoints[m_next_ep];
++m_next_ep;
#if defined TORRENT_ASIO_DEBUGGING
add_outstanding_async("http_connection::on_connect");
@ -628,7 +630,7 @@ void http_connection::on_connect(error_code const& e)
async_write(m_sock, boost::asio::buffer(m_sendbuffer)
, boost::bind(&http_connection::on_write, shared_from_this(), _1));
}
else if (!m_endpoints.empty() && !m_abort)
else if (m_next_ep < m_endpoints.size() && !m_abort)
{
// The connection failed. Try the next endpoint in the list.
error_code ec;

View File

@ -366,8 +366,6 @@ namespace libtorrent
if (m_tracker_connection)
{
error_code ignore;
ip_list.push_back(
m_tracker_connection->socket().remote_endpoint(ignore).address());
std::vector<tcp::endpoint> const& epts = m_tracker_connection->endpoints();
for (std::vector<tcp::endpoint>::const_iterator i = epts.begin()
, end(epts.end()); i != end; ++i)

View File

@ -3363,12 +3363,12 @@ namespace libtorrent
INVARIANT_CHECK;
TORRENT_ASSERT(0 == (r.kind & tracker_request::scrape_request));
// TODO: 2 this looks suspicious. Figure out why it makes sense to use the
// first IP in this list and leave a comment here
if (resp.external_ip != address() && !tracker_ips.empty())
// if the tracker told us what our external IP address is, record it with
// out external IP counter (and pass along the IP of the tracker to know
// who to attribute this vote to)
if (resp.external_ip != address() && !is_any(tracker_ip))
m_ses.set_external_address(resp.external_ip
, aux::session_interface::source_tracker
, *tracker_ips.begin());
, aux::session_interface::source_tracker, tracker_ip);
time_point now = aux::time_now();
@ -3410,13 +3410,22 @@ namespace libtorrent
m_last_scrape = m_ses.session_time();
#ifndef TORRENT_DISABLE_LOGGING
std::string resolved_to;
for (std::list<address>::const_iterator i = tracker_ips.begin()
, end(tracker_ips.end()); i != end; ++i)
{
resolved_to += i->to_string();
resolved_to += ", ";
}
debug_log("TRACKER RESPONSE\n"
"interval: %d\n"
"external ip: %s\n"
"resolved to: %s\n"
"we connected to: %s\n"
"peers:"
, interval
, print_address(resp.external_ip).c_str()
, resolved_to.c_str()
, print_address(tracker_ip).c_str());
for (std::vector<peer_entry>::const_iterator i = resp.peers.begin();