2004-01-31 11:46:15 +01:00
|
|
|
/*
|
|
|
|
|
2014-02-23 20:12:25 +01:00
|
|
|
Copyright (c) 2003-2014, Arvid Norberg
|
2004-01-31 11:46:15 +01:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in
|
|
|
|
the documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the author nor the names of its
|
|
|
|
contributors may be used to endorse or promote products derived
|
|
|
|
from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <cctype>
|
|
|
|
|
2006-04-25 23:04:48 +02:00
|
|
|
#include <boost/bind.hpp>
|
2014-10-20 22:44:05 +02:00
|
|
|
#include <boost/make_shared.hpp>
|
2006-04-25 23:04:48 +02:00
|
|
|
|
2004-01-31 11:46:15 +01:00
|
|
|
#include "libtorrent/tracker_manager.hpp"
|
|
|
|
#include "libtorrent/http_tracker_connection.hpp"
|
|
|
|
#include "libtorrent/udp_tracker_connection.hpp"
|
2008-09-22 02:15:05 +02:00
|
|
|
#include "libtorrent/aux_/session_impl.hpp"
|
2004-01-31 11:46:15 +01:00
|
|
|
|
2006-01-07 14:48:14 +01:00
|
|
|
using boost::tuples::make_tuple;
|
|
|
|
using boost::tuples::tuple;
|
2004-01-31 11:46:15 +01:00
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
minimum_tracker_response_length = 3,
|
|
|
|
http_buffer_size = 2048
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace libtorrent
|
|
|
|
{
|
2008-01-08 06:47:43 +01:00
|
|
|
timeout_handler::timeout_handler(io_service& ios)
|
2014-07-06 21:18:00 +02:00
|
|
|
: m_completion_timeout(0)
|
|
|
|
, m_start_time(time_now_hires())
|
2009-05-26 01:12:06 +02:00
|
|
|
, m_read_time(m_start_time)
|
2008-01-08 06:47:43 +01:00
|
|
|
, m_timeout(ios)
|
2006-04-25 23:04:48 +02:00
|
|
|
, m_read_timeout(0)
|
2007-11-02 01:27:53 +01:00
|
|
|
, m_abort(false)
|
2006-04-25 23:04:48 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
void timeout_handler::set_timeout(int completion_timeout, int read_timeout)
|
|
|
|
{
|
|
|
|
m_completion_timeout = completion_timeout;
|
|
|
|
m_read_timeout = read_timeout;
|
2009-05-26 01:12:06 +02:00
|
|
|
m_start_time = m_read_time = time_now_hires();
|
2006-04-25 23:04:48 +02:00
|
|
|
|
2010-11-18 02:06:33 +01:00
|
|
|
TORRENT_ASSERT(completion_timeout > 0 || read_timeout > 0);
|
|
|
|
|
2007-11-02 01:27:53 +01:00
|
|
|
if (m_abort) return;
|
|
|
|
|
2010-11-18 02:06:33 +01:00
|
|
|
int timeout = 0;
|
|
|
|
if (m_read_timeout > 0) timeout = m_read_timeout;
|
|
|
|
if (m_completion_timeout > 0)
|
|
|
|
{
|
|
|
|
timeout = timeout == 0
|
|
|
|
? m_completion_timeout
|
|
|
|
: (std::min)(m_completion_timeout, timeout);
|
|
|
|
}
|
|
|
|
|
2010-11-28 02:47:30 +01:00
|
|
|
#if defined TORRENT_ASIO_DEBUGGING
|
|
|
|
add_outstanding_async("timeout_handler::timeout_callback");
|
|
|
|
#endif
|
2008-05-03 18:05:42 +02:00
|
|
|
error_code ec;
|
2007-12-29 07:13:49 +01:00
|
|
|
m_timeout.expires_at(m_read_time + seconds(timeout), ec);
|
2010-04-30 21:08:16 +02:00
|
|
|
m_timeout.async_wait(boost::bind(
|
2014-10-20 22:44:05 +02:00
|
|
|
&timeout_handler::timeout_callback, shared_from_this(), _1));
|
2006-04-25 23:04:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void timeout_handler::restart_read_timeout()
|
|
|
|
{
|
2009-05-26 01:12:06 +02:00
|
|
|
m_read_time = time_now_hires();
|
2006-04-25 23:04:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void timeout_handler::cancel()
|
|
|
|
{
|
2007-11-02 01:27:53 +01:00
|
|
|
m_abort = true;
|
2006-04-25 23:04:48 +02:00
|
|
|
m_completion_timeout = 0;
|
2008-05-03 18:05:42 +02:00
|
|
|
error_code ec;
|
2007-12-29 07:13:49 +01:00
|
|
|
m_timeout.cancel(ec);
|
2006-04-25 23:04:48 +02:00
|
|
|
}
|
|
|
|
|
2008-05-03 18:05:42 +02:00
|
|
|
void timeout_handler::timeout_callback(error_code const& error)
|
2006-04-25 23:04:48 +02:00
|
|
|
{
|
2010-11-28 02:47:30 +01:00
|
|
|
#if defined TORRENT_ASIO_DEBUGGING
|
|
|
|
complete_async("timeout_handler::timeout_callback");
|
|
|
|
#endif
|
2010-11-18 02:06:33 +01:00
|
|
|
if (m_abort) return;
|
|
|
|
|
2009-05-26 01:12:06 +02:00
|
|
|
ptime now = time_now_hires();
|
2006-04-25 23:04:48 +02:00
|
|
|
time_duration receive_timeout = now - m_read_time;
|
|
|
|
time_duration completion_timeout = now - m_start_time;
|
|
|
|
|
2010-11-18 02:06:33 +01:00
|
|
|
if ((m_read_timeout
|
|
|
|
&& m_read_timeout <= total_seconds(receive_timeout))
|
|
|
|
|| (m_completion_timeout
|
|
|
|
&& m_completion_timeout <= total_seconds(completion_timeout))
|
|
|
|
|| error)
|
2006-04-25 23:04:48 +02:00
|
|
|
{
|
2010-11-18 02:06:33 +01:00
|
|
|
on_timeout(error);
|
2006-04-25 23:04:48 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-18 02:06:33 +01:00
|
|
|
int timeout = 0;
|
|
|
|
if (m_read_timeout > 0) timeout = m_read_timeout;
|
|
|
|
if (m_completion_timeout > 0)
|
|
|
|
{
|
|
|
|
timeout = timeout == 0
|
2014-05-10 05:23:05 +02:00
|
|
|
? int(m_completion_timeout - total_seconds(m_read_time - m_start_time))
|
2013-11-02 00:13:53 +01:00
|
|
|
: (std::min)(int(m_completion_timeout - total_seconds(m_read_time - m_start_time)), timeout);
|
2010-11-18 02:06:33 +01:00
|
|
|
}
|
2010-11-28 02:47:30 +01:00
|
|
|
#if defined TORRENT_ASIO_DEBUGGING
|
|
|
|
add_outstanding_async("timeout_handler::timeout_callback");
|
|
|
|
#endif
|
2008-05-03 18:05:42 +02:00
|
|
|
error_code ec;
|
2007-12-29 07:13:49 +01:00
|
|
|
m_timeout.expires_at(m_read_time + seconds(timeout), ec);
|
2008-01-08 06:47:43 +01:00
|
|
|
m_timeout.async_wait(
|
2014-10-20 22:44:05 +02:00
|
|
|
boost::bind(&timeout_handler::timeout_callback, shared_from_this(), _1));
|
2006-04-25 23:04:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
tracker_connection::tracker_connection(
|
|
|
|
tracker_manager& man
|
2007-11-20 23:46:27 +01:00
|
|
|
, tracker_request const& req
|
2008-01-08 06:47:43 +01:00
|
|
|
, io_service& ios
|
2006-04-25 23:04:48 +02:00
|
|
|
, boost::weak_ptr<request_callback> r)
|
2008-01-08 06:47:43 +01:00
|
|
|
: timeout_handler(ios)
|
2014-07-06 21:18:00 +02:00
|
|
|
, m_req(req)
|
2006-04-25 23:04:48 +02:00
|
|
|
, m_requester(r)
|
|
|
|
, m_man(man)
|
|
|
|
{}
|
|
|
|
|
2012-10-01 02:13:58 +02:00
|
|
|
boost::shared_ptr<request_callback> tracker_connection::requester() const
|
2004-09-16 03:14:16 +02:00
|
|
|
{
|
2007-09-14 04:54:15 +02:00
|
|
|
return m_requester.lock();
|
2004-09-16 03:14:16 +02:00
|
|
|
}
|
|
|
|
|
2010-02-23 22:53:45 +01:00
|
|
|
void tracker_connection::fail(error_code const& ec, int code
|
|
|
|
, char const* msg, int interval, int min_interval)
|
2013-11-03 00:08:26 +01:00
|
|
|
{
|
|
|
|
// we need to post the error to avoid deadlock
|
|
|
|
get_io_service().post(boost::bind(&tracker_connection::fail_impl
|
2014-10-20 22:44:05 +02:00
|
|
|
, shared_from_this(), ec, code, std::string(msg), interval, min_interval));
|
2013-11-03 00:08:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void tracker_connection::fail_impl(error_code const& ec, int code
|
|
|
|
, std::string msg, int interval, int min_interval)
|
2006-04-25 23:04:48 +02:00
|
|
|
{
|
2007-09-14 04:54:15 +02:00
|
|
|
boost::shared_ptr<request_callback> cb = requester();
|
2013-11-03 00:08:26 +01:00
|
|
|
if (cb) cb->tracker_request_error(m_req, code, ec, msg.c_str()
|
2009-12-21 10:47:32 +01:00
|
|
|
, interval == 0 ? min_interval : interval);
|
2006-04-25 23:04:48 +02:00
|
|
|
close();
|
|
|
|
}
|
2004-01-31 11:46:15 +01:00
|
|
|
|
2008-09-22 02:15:05 +02:00
|
|
|
void tracker_connection::sent_bytes(int bytes)
|
|
|
|
{
|
|
|
|
m_man.sent_bytes(bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tracker_connection::received_bytes(int bytes)
|
|
|
|
{
|
|
|
|
m_man.received_bytes(bytes);
|
|
|
|
}
|
|
|
|
|
2006-04-25 23:04:48 +02:00
|
|
|
void tracker_connection::close()
|
|
|
|
{
|
|
|
|
cancel();
|
2006-06-17 03:29:36 +02:00
|
|
|
m_man.remove_request(this);
|
2004-01-31 11:46:15 +01:00
|
|
|
}
|
|
|
|
|
2014-10-21 02:28:51 +02:00
|
|
|
tracker_manager::tracker_manager(aux::session_impl& ses)
|
|
|
|
: m_ses(ses)
|
|
|
|
, m_ip_filter(ses.m_ip_filter)
|
|
|
|
, m_udp_socket(ses.m_udp_socket)
|
|
|
|
, m_host_resolver(ses.m_host_resolver)
|
|
|
|
, m_settings(ses.settings())
|
2014-10-21 23:24:15 +02:00
|
|
|
, m_stats_counters(ses.m_stats_counters)
|
2014-10-21 02:28:51 +02:00
|
|
|
, m_abort(false)
|
|
|
|
{}
|
|
|
|
|
2008-12-25 03:05:23 +01:00
|
|
|
tracker_manager::~tracker_manager()
|
|
|
|
{
|
|
|
|
TORRENT_ASSERT(m_abort);
|
|
|
|
abort_all_requests(true);
|
|
|
|
}
|
|
|
|
|
2008-09-22 02:15:05 +02:00
|
|
|
void tracker_manager::sent_bytes(int bytes)
|
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
TORRENT_ASSERT(m_ses.is_single_thread());
|
2014-10-21 23:24:15 +02:00
|
|
|
m_stats_counters.inc_stats_counter(counters::sent_tracker_bytes, bytes);
|
2008-09-22 02:15:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void tracker_manager::received_bytes(int bytes)
|
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
TORRENT_ASSERT(m_ses.is_single_thread());
|
2014-10-21 23:24:15 +02:00
|
|
|
m_stats_counters.inc_stats_counter(counters::recv_tracker_bytes, bytes);
|
2008-09-22 02:15:05 +02:00
|
|
|
}
|
|
|
|
|
2006-04-25 23:04:48 +02:00
|
|
|
void tracker_manager::remove_request(tracker_connection const* c)
|
|
|
|
{
|
|
|
|
mutex_t::scoped_lock l(m_mutex);
|
|
|
|
|
2014-10-20 22:44:05 +02:00
|
|
|
http_conns_t::iterator i = std::find_if(m_http_conns.begin()
|
|
|
|
, m_http_conns.end()
|
|
|
|
, boost::bind(&boost::shared_ptr<http_tracker_connection>::get, _1) == c);
|
|
|
|
if (i != m_http_conns.end())
|
|
|
|
{
|
|
|
|
m_http_conns.erase(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
udp_conns_t::iterator j = std::find_if(m_udp_conns.begin()
|
|
|
|
, m_udp_conns.end()
|
|
|
|
, boost::bind(&boost::shared_ptr<udp_tracker_connection>::get
|
|
|
|
, boost::bind(&udp_conns_t::value_type::second, _1)) == c);
|
|
|
|
if (j != m_udp_conns.end())
|
|
|
|
{
|
|
|
|
m_udp_conns.erase(j);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2006-04-25 23:04:48 +02:00
|
|
|
|
2014-10-20 22:44:05 +02:00
|
|
|
void tracker_manager::update_transaction_id(
|
|
|
|
boost::shared_ptr<udp_tracker_connection> c
|
|
|
|
, boost::uint64_t tid)
|
|
|
|
{
|
|
|
|
m_udp_conns.erase(c->transaction_id());
|
|
|
|
m_udp_conns[tid] = c;
|
2006-04-25 23:04:48 +02:00
|
|
|
}
|
2007-05-22 22:44:18 +02:00
|
|
|
|
2005-03-11 18:21:56 +01:00
|
|
|
void tracker_manager::queue_request(
|
2008-01-08 06:47:43 +01:00
|
|
|
io_service& ios
|
2006-04-25 23:04:48 +02:00
|
|
|
, tracker_request req
|
2005-03-11 18:21:56 +01:00
|
|
|
, std::string const& auth
|
|
|
|
, boost::weak_ptr<request_callback> c)
|
|
|
|
{
|
2006-04-25 23:04:48 +02:00
|
|
|
mutex_t::scoped_lock l(m_mutex);
|
2007-10-05 02:30:00 +02:00
|
|
|
TORRENT_ASSERT(req.num_want >= 0);
|
2011-09-16 10:34:17 +02:00
|
|
|
TORRENT_ASSERT(!m_abort || req.event == tracker_request::stopped);
|
|
|
|
if (m_abort && req.event != tracker_request::stopped) return;
|
2005-03-11 18:21:56 +01:00
|
|
|
if (req.event == tracker_request::stopped)
|
|
|
|
req.num_want = 0;
|
|
|
|
|
2007-10-05 02:30:00 +02:00
|
|
|
TORRENT_ASSERT(!m_abort || req.event == tracker_request::stopped);
|
2007-05-23 03:02:46 +02:00
|
|
|
if (m_abort && req.event != tracker_request::stopped)
|
|
|
|
return;
|
|
|
|
|
2008-02-05 07:32:10 +01:00
|
|
|
std::string protocol = req.url.substr(0, req.url.find(':'));
|
2004-01-31 11:46:15 +01:00
|
|
|
|
2008-01-27 23:39:50 +01:00
|
|
|
#ifdef TORRENT_USE_OPENSSL
|
|
|
|
if (protocol == "http" || protocol == "https")
|
|
|
|
#else
|
2007-12-29 07:13:49 +01:00
|
|
|
if (protocol == "http")
|
2008-01-27 23:39:50 +01:00
|
|
|
#endif
|
2007-12-29 07:13:49 +01:00
|
|
|
{
|
2014-10-20 22:44:05 +02:00
|
|
|
boost::shared_ptr<http_tracker_connection> con
|
|
|
|
= boost::make_shared<http_tracker_connection>(
|
2014-10-21 06:22:10 +02:00
|
|
|
boost::ref(ios), boost::ref(*this), boost::cref(req), c, auth
|
2009-08-20 05:19:12 +02:00
|
|
|
#if TORRENT_USE_I2P
|
|
|
|
, &m_ses.m_i2p_conn
|
|
|
|
#endif
|
|
|
|
);
|
2014-10-20 22:44:05 +02:00
|
|
|
m_http_conns.push_back(con);
|
|
|
|
con->start();
|
|
|
|
return;
|
2007-12-29 07:13:49 +01:00
|
|
|
}
|
|
|
|
else if (protocol == "udp")
|
|
|
|
{
|
2014-10-20 22:44:05 +02:00
|
|
|
boost::shared_ptr<udp_tracker_connection> con
|
|
|
|
= boost::make_shared<udp_tracker_connection>(
|
2014-10-21 06:22:10 +02:00
|
|
|
boost::ref(ios), boost::ref(*this), boost::cref(req) , c);
|
2014-10-20 22:44:05 +02:00
|
|
|
m_udp_conns[con->transaction_id()] = con;
|
|
|
|
con->start();
|
2008-01-27 21:00:56 +01:00
|
|
|
return;
|
2004-01-31 11:46:15 +01:00
|
|
|
}
|
2007-12-29 07:13:49 +01:00
|
|
|
|
2014-10-20 22:44:05 +02:00
|
|
|
// we need to post the error to avoid deadlock
|
|
|
|
if (boost::shared_ptr<request_callback> r = c.lock())
|
|
|
|
ios.post(boost::bind(&request_callback::tracker_request_error, r, req
|
|
|
|
, -1, error_code(errors::unsupported_url_protocol)
|
|
|
|
, "", 0));
|
2004-01-31 11:46:15 +01:00
|
|
|
}
|
2005-03-11 18:21:56 +01:00
|
|
|
|
2012-06-22 06:21:20 +02:00
|
|
|
bool tracker_manager::incoming_packet(error_code const& e
|
2010-05-30 03:33:03 +02:00
|
|
|
, udp::endpoint const& ep, char const* buf, int size)
|
|
|
|
{
|
2014-10-20 22:44:05 +02:00
|
|
|
// ignore packets smaller than 8 bytes
|
|
|
|
if (size < 8) return false;
|
|
|
|
|
|
|
|
const char* ptr = buf + 4;
|
|
|
|
boost::uint32_t transaction = detail::read_uint32(ptr);
|
|
|
|
udp_conns_t::iterator i = m_udp_conns.find(transaction);
|
|
|
|
|
|
|
|
if (i == m_udp_conns.end()) return false;
|
|
|
|
|
|
|
|
boost::shared_ptr<tracker_connection> p = i->second;
|
|
|
|
// on_receive() may remove the tracker connection from the list
|
|
|
|
return p->on_receive(e, ep, buf, size);
|
2010-05-30 03:33:03 +02:00
|
|
|
}
|
|
|
|
|
2012-06-22 06:21:20 +02:00
|
|
|
bool tracker_manager::incoming_packet(error_code const& e
|
2010-08-03 11:08:37 +02:00
|
|
|
, char const* hostname, char const* buf, int size)
|
|
|
|
{
|
2014-10-20 22:44:05 +02:00
|
|
|
// ignore packets smaller than 8 bytes
|
|
|
|
if (size < 8) return false;
|
|
|
|
|
|
|
|
const char* ptr = buf + 4;
|
|
|
|
boost::uint32_t transaction = detail::read_uint32(ptr);
|
|
|
|
udp_conns_t::iterator i = m_udp_conns.find(transaction);
|
|
|
|
|
|
|
|
if (i == m_udp_conns.end()) return false;
|
|
|
|
|
|
|
|
boost::shared_ptr<tracker_connection> p = i->second;
|
|
|
|
// on_receive() may remove the tracker connection from the list
|
|
|
|
return p->on_receive_hostname(e, hostname, buf, size);
|
2010-08-03 11:08:37 +02:00
|
|
|
}
|
|
|
|
|
2008-12-25 03:05:23 +01:00
|
|
|
void tracker_manager::abort_all_requests(bool all)
|
2004-01-31 11:46:15 +01:00
|
|
|
{
|
2014-10-20 22:44:05 +02:00
|
|
|
// removes all connections except 'event=stopped'-requests
|
2006-04-25 23:04:48 +02:00
|
|
|
mutex_t::scoped_lock l(m_mutex);
|
2004-01-31 11:46:15 +01:00
|
|
|
|
2007-05-23 03:02:46 +02:00
|
|
|
m_abort = true;
|
2014-10-20 22:44:05 +02:00
|
|
|
http_conns_t close_http_connections;
|
|
|
|
std::vector<boost::shared_ptr<udp_tracker_connection> > close_udp_connections;
|
|
|
|
|
|
|
|
for (http_conns_t::iterator i = m_http_conns.begin()
|
|
|
|
, end(m_http_conns.end()); i != end; ++i)
|
|
|
|
{
|
|
|
|
http_tracker_connection* c = i->get();
|
|
|
|
tracker_request const& req = c->tracker_req();
|
|
|
|
if (req.event == tracker_request::stopped && !all)
|
|
|
|
continue;
|
2004-01-31 11:46:15 +01:00
|
|
|
|
2014-10-20 22:44:05 +02:00
|
|
|
close_http_connections.push_back(*i);
|
|
|
|
|
|
|
|
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
|
|
|
boost::shared_ptr<request_callback> rc = c->requester();
|
|
|
|
if (rc) rc->debug_log("aborting: %s", req.url.c_str());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
for (udp_conns_t::iterator i = m_udp_conns.begin()
|
|
|
|
, end(m_udp_conns.end()); i != end; ++i)
|
2004-01-31 11:46:15 +01:00
|
|
|
{
|
2014-10-20 22:44:05 +02:00
|
|
|
boost::shared_ptr<udp_tracker_connection> c = i->second;
|
2007-10-28 00:01:32 +02:00
|
|
|
tracker_request const& req = c->tracker_req();
|
2008-12-25 03:05:23 +01:00
|
|
|
if (req.event == tracker_request::stopped && !all)
|
2007-10-28 00:01:32 +02:00
|
|
|
continue;
|
2009-10-20 04:49:56 +02:00
|
|
|
|
2014-10-20 22:44:05 +02:00
|
|
|
close_udp_connections.push_back(c);
|
2008-03-30 21:00:37 +02:00
|
|
|
|
|
|
|
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
|
|
|
boost::shared_ptr<request_callback> rc = c->requester();
|
2012-09-28 01:04:51 +02:00
|
|
|
if (rc) rc->debug_log("aborting: %s", req.url.c_str());
|
2008-03-30 21:00:37 +02:00
|
|
|
#endif
|
2004-01-31 11:46:15 +01:00
|
|
|
}
|
2009-10-20 04:49:56 +02:00
|
|
|
l.unlock();
|
2004-01-31 11:46:15 +01:00
|
|
|
|
2014-10-20 22:44:05 +02:00
|
|
|
for (http_conns_t::iterator i = close_http_connections.begin()
|
|
|
|
, end(close_http_connections.end()); i != end; ++i)
|
|
|
|
{
|
|
|
|
(*i)->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (std::vector<boost::shared_ptr<udp_tracker_connection> >::iterator i
|
|
|
|
= close_udp_connections.begin()
|
|
|
|
, end(close_udp_connections.end()); i != end; ++i)
|
2009-10-20 04:49:56 +02:00
|
|
|
{
|
|
|
|
(*i)->close();
|
|
|
|
}
|
2004-01-31 11:46:15 +01:00
|
|
|
}
|
2006-08-01 17:27:08 +02:00
|
|
|
|
|
|
|
bool tracker_manager::empty() const
|
|
|
|
{
|
|
|
|
mutex_t::scoped_lock l(m_mutex);
|
2014-10-20 22:44:05 +02:00
|
|
|
return m_http_conns.empty() && m_udp_conns.empty();
|
2006-08-01 17:27:08 +02:00
|
|
|
}
|
|
|
|
|
2007-10-07 20:06:56 +02:00
|
|
|
int tracker_manager::num_requests() const
|
|
|
|
{
|
|
|
|
mutex_t::scoped_lock l(m_mutex);
|
2014-10-20 22:44:05 +02:00
|
|
|
return m_http_conns.size() + m_udp_conns.size();
|
2007-10-07 20:06:56 +02:00
|
|
|
}
|
2004-01-31 11:46:15 +01:00
|
|
|
}
|