commit
39f62fe3d9
|
@ -156,6 +156,10 @@ private:
|
||||||
|
|
||||||
std::vector<tcp::endpoint> m_endpoints;
|
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;
|
socket_type m_sock;
|
||||||
|
|
||||||
#ifdef TORRENT_USE_OPENSSL
|
#ifdef TORRENT_USE_OPENSSL
|
||||||
|
|
|
@ -66,7 +66,8 @@ http_connection::http_connection(io_service& ios
|
||||||
, ssl::context* ssl_ctx
|
, ssl::context* ssl_ctx
|
||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
: m_sock(ios)
|
: m_next_ep(0)
|
||||||
|
, m_sock(ios)
|
||||||
#ifdef TORRENT_USE_OPENSSL
|
#ifdef TORRENT_USE_OPENSSL
|
||||||
, m_ssl_ctx(ssl_ctx)
|
, m_ssl_ctx(ssl_ctx)
|
||||||
, m_own_ssl_context(false)
|
, 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");
|
add_outstanding_async("http_connection::on_resolve");
|
||||||
#endif
|
#endif
|
||||||
m_endpoints.clear();
|
m_endpoints.clear();
|
||||||
|
m_next_ep = 0;
|
||||||
m_resolver.async_resolve(hostname, m_resolve_flags
|
m_resolver.async_resolve(hostname, m_resolve_flags
|
||||||
, boost::bind(&http_connection::on_resolve
|
, boost::bind(&http_connection::on_resolve
|
||||||
, me, _1, _2));
|
, 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
|
// the connection timed out. If we have more endpoints to try, just
|
||||||
// close this connection. The on_connect handler will try the next
|
// close this connection. The on_connect handler will try the next
|
||||||
// endpoint in the list.
|
// endpoint in the list.
|
||||||
if (!c->m_endpoints.empty())
|
if (c->m_next_ep < c->m_endpoints.size())
|
||||||
{
|
{
|
||||||
error_code ec;
|
error_code ec;
|
||||||
c->m_sock.close(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->callback(boost::asio::error::timed_out);
|
||||||
c->close(true);
|
c->close(true);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -570,7 +572,7 @@ void http_connection::on_resolve(error_code const& e
|
||||||
|
|
||||||
void http_connection::connect()
|
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());
|
boost::shared_ptr<http_connection> me(shared_from_this());
|
||||||
|
|
||||||
|
@ -594,11 +596,11 @@ void http_connection::connect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TORRENT_ASSERT(!m_endpoints.empty());
|
TORRENT_ASSERT(m_next_ep < m_endpoints.size());
|
||||||
if (m_endpoints.empty()) return;
|
if (m_next_ep >= m_endpoints.size()) return;
|
||||||
|
|
||||||
tcp::endpoint target_address = m_endpoints.front();
|
tcp::endpoint target_address = m_endpoints[m_next_ep];
|
||||||
m_endpoints.erase(m_endpoints.begin());
|
++m_next_ep;
|
||||||
|
|
||||||
#if defined TORRENT_ASIO_DEBUGGING
|
#if defined TORRENT_ASIO_DEBUGGING
|
||||||
add_outstanding_async("http_connection::on_connect");
|
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)
|
async_write(m_sock, boost::asio::buffer(m_sendbuffer)
|
||||||
, boost::bind(&http_connection::on_write, shared_from_this(), _1));
|
, 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.
|
// The connection failed. Try the next endpoint in the list.
|
||||||
error_code ec;
|
error_code ec;
|
||||||
|
|
|
@ -366,8 +366,6 @@ namespace libtorrent
|
||||||
if (m_tracker_connection)
|
if (m_tracker_connection)
|
||||||
{
|
{
|
||||||
error_code ignore;
|
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();
|
std::vector<tcp::endpoint> const& epts = m_tracker_connection->endpoints();
|
||||||
for (std::vector<tcp::endpoint>::const_iterator i = epts.begin()
|
for (std::vector<tcp::endpoint>::const_iterator i = epts.begin()
|
||||||
, end(epts.end()); i != end; ++i)
|
, end(epts.end()); i != end; ++i)
|
||||||
|
|
|
@ -3363,12 +3363,12 @@ namespace libtorrent
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
TORRENT_ASSERT(0 == (r.kind & tracker_request::scrape_request));
|
TORRENT_ASSERT(0 == (r.kind & tracker_request::scrape_request));
|
||||||
|
|
||||||
// TODO: 2 this looks suspicious. Figure out why it makes sense to use the
|
// if the tracker told us what our external IP address is, record it with
|
||||||
// first IP in this list and leave a comment here
|
// out external IP counter (and pass along the IP of the tracker to know
|
||||||
if (resp.external_ip != address() && !tracker_ips.empty())
|
// who to attribute this vote to)
|
||||||
|
if (resp.external_ip != address() && !is_any(tracker_ip))
|
||||||
m_ses.set_external_address(resp.external_ip
|
m_ses.set_external_address(resp.external_ip
|
||||||
, aux::session_interface::source_tracker
|
, aux::session_interface::source_tracker, tracker_ip);
|
||||||
, *tracker_ips.begin());
|
|
||||||
|
|
||||||
time_point now = aux::time_now();
|
time_point now = aux::time_now();
|
||||||
|
|
||||||
|
@ -3410,13 +3410,22 @@ namespace libtorrent
|
||||||
m_last_scrape = m_ses.session_time();
|
m_last_scrape = m_ses.session_time();
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_LOGGING
|
#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"
|
debug_log("TRACKER RESPONSE\n"
|
||||||
"interval: %d\n"
|
"interval: %d\n"
|
||||||
"external ip: %s\n"
|
"external ip: %s\n"
|
||||||
|
"resolved to: %s\n"
|
||||||
"we connected to: %s\n"
|
"we connected to: %s\n"
|
||||||
"peers:"
|
"peers:"
|
||||||
, interval
|
, interval
|
||||||
, print_address(resp.external_ip).c_str()
|
, print_address(resp.external_ip).c_str()
|
||||||
|
, resolved_to.c_str()
|
||||||
, print_address(tracker_ip).c_str());
|
, print_address(tracker_ip).c_str());
|
||||||
|
|
||||||
for (std::vector<peer_entry>::const_iterator i = resp.peers.begin();
|
for (std::vector<peer_entry>::const_iterator i = resp.peers.begin();
|
||||||
|
|
Loading…
Reference in New Issue