2004-01-31 11:46:15 +01:00
|
|
|
/*
|
|
|
|
|
2018-04-09 09:04:33 +02:00
|
|
|
Copyright (c) 2003-2018, 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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TORRENT_TRACKER_MANAGER_HPP_INCLUDED
|
|
|
|
#define TORRENT_TRACKER_MANAGER_HPP_INCLUDED
|
|
|
|
|
2015-04-19 15:45:13 +02:00
|
|
|
#include "libtorrent/config.hpp"
|
|
|
|
|
2004-01-31 11:46:15 +01:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2014-07-06 21:18:00 +02:00
|
|
|
#include <list>
|
2004-01-31 11:46:15 +01:00
|
|
|
#include <utility>
|
2016-06-20 17:32:06 +02:00
|
|
|
#include <cstdint>
|
|
|
|
#include <tuple>
|
2016-08-13 03:31:55 +02:00
|
|
|
#include <functional>
|
2016-09-01 03:42:18 +02:00
|
|
|
#include <memory>
|
2016-09-07 05:37:36 +02:00
|
|
|
#include <unordered_map>
|
2004-01-31 11:46:15 +01:00
|
|
|
|
2015-04-18 04:33:39 +02:00
|
|
|
#ifdef TORRENT_USE_OPENSSL
|
2017-10-09 01:21:19 +02:00
|
|
|
// there is no forward declaration header for asio
|
|
|
|
namespace boost {
|
|
|
|
namespace asio {
|
|
|
|
namespace ssl {
|
2017-10-10 14:25:12 +02:00
|
|
|
class context;
|
2017-10-09 01:21:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-07 05:37:36 +02:00
|
|
|
#endif
|
2015-04-18 04:33:39 +02:00
|
|
|
|
2004-01-31 11:46:15 +01:00
|
|
|
#include "libtorrent/socket.hpp"
|
2018-04-26 09:01:14 +02:00
|
|
|
#include "libtorrent/fwd.hpp"
|
2009-11-23 09:38:50 +01:00
|
|
|
#include "libtorrent/address.hpp"
|
2004-01-31 11:46:15 +01:00
|
|
|
#include "libtorrent/peer_id.hpp"
|
2009-11-23 09:38:50 +01:00
|
|
|
#include "libtorrent/peer.hpp" // peer_entry
|
2009-09-16 05:46:36 +02:00
|
|
|
#include "libtorrent/deadline_timer.hpp"
|
2010-02-14 02:39:55 +01:00
|
|
|
#include "libtorrent/union_endpoint.hpp"
|
2015-06-06 07:22:53 +02:00
|
|
|
#include "libtorrent/io_service.hpp"
|
2016-07-22 18:31:42 +02:00
|
|
|
#include "libtorrent/span.hpp"
|
2016-05-01 00:54:23 +02:00
|
|
|
#include "libtorrent/time.hpp"
|
2016-05-03 04:22:13 +02:00
|
|
|
#include "libtorrent/debug.hpp"
|
2016-05-23 14:15:39 +02:00
|
|
|
#include "libtorrent/error_code.hpp"
|
2017-07-21 05:19:28 +02:00
|
|
|
#include "libtorrent/aux_/listen_socket_handle.hpp"
|
2017-07-26 19:38:40 +02:00
|
|
|
#include "libtorrent/udp_socket.hpp"
|
2004-01-31 11:46:15 +01:00
|
|
|
|
2017-04-12 19:00:57 +02:00
|
|
|
namespace libtorrent {
|
|
|
|
|
2004-01-31 11:46:15 +01:00
|
|
|
class tracker_manager;
|
2006-04-25 23:04:48 +02:00
|
|
|
struct timeout_handler;
|
2014-10-20 22:44:05 +02:00
|
|
|
class udp_tracker_connection;
|
|
|
|
class http_tracker_connection;
|
2014-10-21 02:28:51 +02:00
|
|
|
struct resolver_interface;
|
2014-10-21 23:24:15 +02:00
|
|
|
struct counters;
|
2015-02-01 15:30:43 +01:00
|
|
|
#if TORRENT_USE_I2P
|
|
|
|
class i2p_connection;
|
|
|
|
#endif
|
2017-07-21 05:19:28 +02:00
|
|
|
namespace aux { struct session_logger; struct session_settings; }
|
2004-10-11 23:50:04 +02:00
|
|
|
|
2012-03-19 00:31:04 +01:00
|
|
|
struct TORRENT_EXTRA_EXPORT tracker_request
|
2004-01-31 11:46:15 +01:00
|
|
|
{
|
2005-03-11 18:21:56 +01:00
|
|
|
tracker_request()
|
2014-07-06 21:18:00 +02:00
|
|
|
: downloaded(-1)
|
2010-10-18 02:10:33 +02:00
|
|
|
, uploaded(-1)
|
|
|
|
, left(-1)
|
|
|
|
, corrupt(0)
|
|
|
|
, redundant(0)
|
2011-02-21 06:24:41 +01:00
|
|
|
, listen_port(0)
|
2005-03-11 18:21:56 +01:00
|
|
|
, event(none)
|
2014-07-06 21:18:00 +02:00
|
|
|
, kind(announce_request)
|
2005-03-11 18:21:56 +01:00
|
|
|
, key(0)
|
|
|
|
, num_want(0)
|
2017-03-12 17:49:41 +01:00
|
|
|
, private_torrent(false)
|
2016-01-17 03:24:04 +01:00
|
|
|
, triggered_manually(false)
|
2005-03-11 18:21:56 +01:00
|
|
|
{}
|
|
|
|
|
2004-01-31 11:46:15 +01:00
|
|
|
enum event_t
|
|
|
|
{
|
|
|
|
none,
|
|
|
|
completed,
|
|
|
|
started,
|
2010-09-06 06:02:15 +02:00
|
|
|
stopped,
|
|
|
|
paused
|
2004-01-31 11:46:15 +01:00
|
|
|
};
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
enum kind_t
|
|
|
|
{
|
2015-06-27 23:30:00 +02:00
|
|
|
// do not compare against announce_request ! check if not scrape instead
|
|
|
|
announce_request = 0,
|
|
|
|
scrape_request = 1,
|
|
|
|
// affects interpretation of peers string in HTTP response
|
|
|
|
// see parse_tracker_response()
|
|
|
|
i2p = 2
|
2014-07-06 21:18:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
std::string url;
|
|
|
|
std::string trackerid;
|
2018-04-26 09:01:14 +02:00
|
|
|
#if TORRENT_ABI_VERSION == 1
|
2015-02-01 15:30:43 +01:00
|
|
|
std::string auth;
|
2015-12-13 21:14:19 +01:00
|
|
|
#endif
|
2014-07-06 21:18:00 +02:00
|
|
|
|
2016-09-01 03:42:18 +02:00
|
|
|
std::shared_ptr<const ip_filter> filter;
|
2015-05-16 08:33:37 +02:00
|
|
|
|
2016-06-18 20:01:38 +02:00
|
|
|
std::int64_t downloaded;
|
|
|
|
std::int64_t uploaded;
|
|
|
|
std::int64_t left;
|
|
|
|
std::int64_t corrupt;
|
|
|
|
std::int64_t redundant;
|
|
|
|
std::uint16_t listen_port;
|
2014-07-06 21:18:00 +02:00
|
|
|
|
|
|
|
// values from event_t
|
2016-06-18 20:01:38 +02:00
|
|
|
std::uint8_t event;
|
2014-07-06 21:18:00 +02:00
|
|
|
|
|
|
|
// values from kind_t
|
2016-06-18 20:01:38 +02:00
|
|
|
std::uint8_t kind;
|
2014-07-06 21:18:00 +02:00
|
|
|
|
2016-06-18 20:01:38 +02:00
|
|
|
std::uint32_t key;
|
2004-03-21 03:03:37 +01:00
|
|
|
int num_want;
|
2017-08-23 08:45:48 +02:00
|
|
|
std::vector<address_v6> ipv6;
|
2018-11-19 01:56:30 +01:00
|
|
|
std::vector<address_v4> ipv4;
|
2014-07-06 21:18:00 +02:00
|
|
|
sha1_hash info_hash;
|
|
|
|
peer_id pid;
|
2017-11-20 23:42:22 +01:00
|
|
|
|
2017-07-21 05:19:28 +02:00
|
|
|
aux::listen_socket_handle outgoing_socket;
|
2014-07-06 21:18:00 +02:00
|
|
|
|
2017-03-12 17:49:41 +01:00
|
|
|
// set to true if the .torrent file this tracker announce is for is marked
|
|
|
|
// as private (i.e. has the "priv": 1 key)
|
|
|
|
bool private_torrent;
|
|
|
|
|
2016-01-17 03:24:04 +01:00
|
|
|
// this is set to true if this request was triggered by a "manual" call to
|
|
|
|
// scrape_tracker() or force_reannounce()
|
|
|
|
bool triggered_manually;
|
|
|
|
|
2011-08-28 23:06:15 +02:00
|
|
|
#ifdef TORRENT_USE_OPENSSL
|
2018-02-12 23:13:50 +01:00
|
|
|
boost::asio::ssl::context* ssl_ctx = nullptr;
|
2015-02-01 15:30:43 +01:00
|
|
|
#endif
|
|
|
|
#if TORRENT_USE_I2P
|
2017-09-28 10:11:20 +02:00
|
|
|
i2p_connection* i2pconn = nullptr;
|
2011-08-28 23:06:15 +02:00
|
|
|
#endif
|
2004-01-31 11:46:15 +01:00
|
|
|
};
|
|
|
|
|
2014-09-28 08:36:03 +02:00
|
|
|
struct tracker_response
|
|
|
|
{
|
|
|
|
tracker_response()
|
|
|
|
: interval(1800)
|
2018-08-18 23:25:02 +02:00
|
|
|
, min_interval(1)
|
2014-09-28 08:36:03 +02:00
|
|
|
, complete(-1)
|
|
|
|
, incomplete(-1)
|
2014-09-29 08:10:22 +02:00
|
|
|
, downloaders(-1)
|
2014-09-28 08:36:03 +02:00
|
|
|
, downloaded(-1)
|
|
|
|
{}
|
|
|
|
|
2014-09-29 08:10:22 +02:00
|
|
|
// peers from the tracker, in various forms
|
2014-09-28 08:36:03 +02:00
|
|
|
std::vector<peer_entry> peers;
|
|
|
|
std::vector<ipv4_peer_entry> peers4;
|
|
|
|
std::vector<ipv6_peer_entry> peers6;
|
2014-09-29 08:10:22 +02:00
|
|
|
// our external IP address (if the tracker responded with ti, otherwise
|
|
|
|
// INADDR_ANY)
|
2014-09-28 08:36:03 +02:00
|
|
|
address external_ip;
|
2014-09-29 08:10:22 +02:00
|
|
|
|
|
|
|
// the tracker id, if it was included in the response, otherwise
|
|
|
|
// an empty string
|
2014-09-28 08:36:03 +02:00
|
|
|
std::string trackerid;
|
2014-09-29 08:10:22 +02:00
|
|
|
|
|
|
|
// if the tracker returned an error, this is set to that error
|
|
|
|
std::string failure_reason;
|
|
|
|
|
|
|
|
// contains a warning message from the tracker, if included in
|
|
|
|
// the response
|
|
|
|
std::string warning_message;
|
|
|
|
|
|
|
|
// re-announce interval, in seconds
|
2017-02-06 01:18:06 +01:00
|
|
|
seconds32 interval;
|
2014-09-29 08:10:22 +02:00
|
|
|
|
|
|
|
// the lowest force-announce interval
|
2017-02-06 01:18:06 +01:00
|
|
|
seconds32 min_interval;
|
2014-09-29 08:10:22 +02:00
|
|
|
|
|
|
|
// the number of seeds in the swarm
|
2014-09-28 08:36:03 +02:00
|
|
|
int complete;
|
2014-09-29 08:10:22 +02:00
|
|
|
|
|
|
|
// the number of downloaders in the swarm
|
2014-09-28 08:36:03 +02:00
|
|
|
int incomplete;
|
2014-09-29 08:10:22 +02:00
|
|
|
|
|
|
|
// if supported by the tracker, the number of actively downloading peers.
|
2016-08-29 14:31:23 +02:00
|
|
|
// i.e. partial seeds. If not supported, -1
|
2014-09-29 08:10:22 +02:00
|
|
|
int downloaders;
|
|
|
|
|
|
|
|
// the number of times the torrent has been downloaded
|
2014-09-28 08:36:03 +02:00
|
|
|
int downloaded;
|
|
|
|
};
|
|
|
|
|
2012-03-19 00:31:04 +01:00
|
|
|
struct TORRENT_EXTRA_EXPORT request_callback
|
2004-01-31 11:46:15 +01:00
|
|
|
{
|
|
|
|
friend class tracker_manager;
|
2014-07-06 21:18:00 +02:00
|
|
|
request_callback() {}
|
2004-09-16 03:14:16 +02:00
|
|
|
virtual ~request_callback() {}
|
2008-04-23 03:54:21 +02:00
|
|
|
virtual void tracker_warning(tracker_request const& req
|
|
|
|
, std::string const& msg) = 0;
|
2009-11-11 06:22:57 +01:00
|
|
|
virtual void tracker_scrape_response(tracker_request const& /*req*/
|
2010-09-06 06:02:15 +02:00
|
|
|
, int /*complete*/, int /*incomplete*/, int /*downloads*/
|
|
|
|
, int /*downloaders*/) {}
|
2004-01-31 11:46:15 +01:00
|
|
|
virtual void tracker_response(
|
2008-04-23 03:54:21 +02:00
|
|
|
tracker_request const& req
|
2008-12-01 09:48:54 +01:00
|
|
|
, address const& tracker_ip
|
2009-05-15 23:23:41 +02:00
|
|
|
, std::list<address> const& ip_list
|
2014-09-28 08:36:03 +02:00
|
|
|
, struct tracker_response const& response) = 0;
|
2004-01-31 11:46:15 +01:00
|
|
|
virtual void tracker_request_error(
|
2008-04-23 03:54:21 +02:00
|
|
|
tracker_request const& req
|
2010-02-23 22:53:45 +01:00
|
|
|
, error_code const& ec
|
|
|
|
, const std::string& msg
|
2017-02-06 01:18:06 +01:00
|
|
|
, seconds32 retry_interval) = 0;
|
2004-01-31 11:46:15 +01:00
|
|
|
|
2015-04-17 03:15:33 +02:00
|
|
|
#ifndef TORRENT_DISABLE_LOGGING
|
2016-09-14 04:46:07 +02:00
|
|
|
virtual bool should_log() const = 0;
|
2017-12-28 21:41:46 +01:00
|
|
|
virtual void debug_log(const char* fmt, ...) const noexcept TORRENT_FORMAT(2,3) = 0;
|
2011-09-21 11:27:07 +02:00
|
|
|
#endif
|
2004-01-31 11:46:15 +01:00
|
|
|
};
|
|
|
|
|
2012-03-19 00:31:04 +01:00
|
|
|
struct TORRENT_EXTRA_EXPORT timeout_handler
|
2016-08-29 14:31:23 +02:00
|
|
|
: std::enable_shared_from_this<timeout_handler>
|
2004-01-31 11:46:15 +01:00
|
|
|
{
|
2016-10-08 20:07:11 +02:00
|
|
|
explicit timeout_handler(io_service& str);
|
2006-04-25 23:04:48 +02:00
|
|
|
|
2017-09-12 23:10:11 +02:00
|
|
|
timeout_handler(timeout_handler const&) = delete;
|
|
|
|
timeout_handler& operator=(timeout_handler const&) = delete;
|
|
|
|
|
2006-04-25 23:04:48 +02:00
|
|
|
void set_timeout(int completion_timeout, int read_timeout);
|
|
|
|
void restart_read_timeout();
|
|
|
|
void cancel();
|
2010-03-02 10:04:27 +01:00
|
|
|
bool cancelled() const { return m_abort; }
|
2006-04-25 23:04:48 +02:00
|
|
|
|
2010-11-18 02:06:33 +01:00
|
|
|
virtual void on_timeout(error_code const& ec) = 0;
|
2016-10-19 07:18:05 +02:00
|
|
|
virtual ~timeout_handler();
|
2006-04-25 23:04:48 +02:00
|
|
|
|
2019-04-19 20:56:19 +02:00
|
|
|
io_service& get_io_service() { return lt::get_io_service(m_timeout); }
|
2013-11-03 00:08:26 +01:00
|
|
|
|
2006-04-25 23:04:48 +02:00
|
|
|
private:
|
2015-05-16 09:21:23 +02:00
|
|
|
|
2008-05-03 18:05:42 +02:00
|
|
|
void timeout_callback(error_code const&);
|
2006-04-25 23:04:48 +02:00
|
|
|
|
2016-10-19 07:18:05 +02:00
|
|
|
int m_completion_timeout = 0;
|
2014-07-06 21:18:00 +02:00
|
|
|
|
2006-04-25 23:04:48 +02:00
|
|
|
// used for timeouts
|
|
|
|
// this is set when the request has been sent
|
2015-03-12 05:34:54 +01:00
|
|
|
time_point m_start_time;
|
2014-07-06 21:18:00 +02:00
|
|
|
|
2006-04-25 23:04:48 +02:00
|
|
|
// this is set every time something is received
|
2015-03-12 05:34:54 +01:00
|
|
|
time_point m_read_time;
|
2014-07-06 21:18:00 +02:00
|
|
|
|
2006-04-25 23:04:48 +02:00
|
|
|
// the asio async operation
|
2007-04-05 00:27:36 +02:00
|
|
|
deadline_timer m_timeout;
|
2015-05-16 09:21:23 +02:00
|
|
|
|
2016-10-19 07:18:05 +02:00
|
|
|
int m_read_timeout = 0;
|
2006-04-25 23:04:48 +02:00
|
|
|
|
2016-10-19 07:18:05 +02:00
|
|
|
bool m_abort = false;
|
|
|
|
#if TORRENT_USE_ASSERTS
|
|
|
|
int m_outstanding_timer_wait = 0;
|
|
|
|
#endif
|
2006-04-25 23:04:48 +02:00
|
|
|
};
|
|
|
|
|
2012-03-19 00:31:04 +01:00
|
|
|
struct TORRENT_EXTRA_EXPORT tracker_connection
|
2006-04-25 23:04:48 +02:00
|
|
|
: timeout_handler
|
|
|
|
{
|
|
|
|
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
|
2016-08-31 14:27:36 +02:00
|
|
|
, std::weak_ptr<request_callback> r);
|
2004-01-31 11:46:15 +01:00
|
|
|
|
2016-08-31 14:27:36 +02:00
|
|
|
std::shared_ptr<request_callback> requester() const;
|
2017-09-12 23:10:11 +02:00
|
|
|
~tracker_connection() override {}
|
2004-01-31 11:46:15 +01:00
|
|
|
|
2006-04-25 23:04:48 +02:00
|
|
|
tracker_request const& tracker_req() const { return m_req; }
|
2004-01-31 11:46:15 +01:00
|
|
|
|
2017-12-18 22:21:08 +01:00
|
|
|
void fail(error_code const& ec, char const* msg = ""
|
2017-02-06 01:18:06 +01:00
|
|
|
, seconds32 interval = seconds32(0), seconds32 min_interval = seconds32(0));
|
2008-09-07 12:03:59 +02:00
|
|
|
virtual void start() = 0;
|
2016-12-11 16:56:44 +01:00
|
|
|
virtual void close() = 0;
|
2017-04-28 05:34:39 +02:00
|
|
|
address bind_interface() const;
|
2017-07-21 05:19:28 +02:00
|
|
|
aux::listen_socket_handle const& bind_socket() const { return m_req.outgoing_socket; }
|
2008-09-22 02:15:05 +02:00
|
|
|
void sent_bytes(int bytes);
|
|
|
|
void received_bytes(int bytes);
|
2004-01-31 11:46:15 +01:00
|
|
|
|
2016-08-29 14:31:23 +02:00
|
|
|
std::shared_ptr<tracker_connection> shared_from_this()
|
2014-10-20 22:44:05 +02:00
|
|
|
{
|
2016-08-29 14:31:23 +02:00
|
|
|
return std::static_pointer_cast<tracker_connection>(
|
2014-10-20 22:44:05 +02:00
|
|
|
timeout_handler::shared_from_this());
|
|
|
|
}
|
2013-11-03 00:08:26 +01:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
private:
|
|
|
|
|
|
|
|
const tracker_request m_req;
|
|
|
|
|
2006-04-25 23:04:48 +02:00
|
|
|
protected:
|
2011-09-21 11:27:07 +02:00
|
|
|
|
2017-12-18 22:21:08 +01:00
|
|
|
void fail_impl(error_code const& ec, std::string msg = std::string()
|
2017-02-06 01:18:06 +01:00
|
|
|
, seconds32 interval = seconds32(0), seconds32 min_interval = seconds32(0));
|
2013-11-03 00:08:26 +01:00
|
|
|
|
2016-08-31 14:27:36 +02:00
|
|
|
std::weak_ptr<request_callback> m_requester;
|
2011-09-21 11:27:07 +02:00
|
|
|
|
2006-04-25 23:04:48 +02:00
|
|
|
tracker_manager& m_man;
|
2004-01-31 11:46:15 +01:00
|
|
|
};
|
|
|
|
|
2016-04-30 17:05:54 +02:00
|
|
|
class TORRENT_EXTRA_EXPORT tracker_manager final
|
2017-09-12 23:10:11 +02:00
|
|
|
: single_threaded
|
2004-01-31 11:46:15 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2018-03-22 17:01:38 +01:00
|
|
|
using send_fun_t = std::function<void(aux::listen_socket_handle const&
|
2017-04-28 05:34:39 +02:00
|
|
|
, udp::endpoint const&
|
2016-07-22 18:31:42 +02:00
|
|
|
, span<char const>
|
2018-03-22 17:01:38 +01:00
|
|
|
, error_code&, udp_send_flags_t)>;
|
|
|
|
using send_fun_hostname_t = std::function<void(aux::listen_socket_handle const&
|
2017-04-28 05:34:39 +02:00
|
|
|
, char const*, int
|
2016-07-22 18:31:42 +02:00
|
|
|
, span<char const>
|
2018-03-22 17:01:38 +01:00
|
|
|
, error_code&, udp_send_flags_t)>;
|
2016-04-24 21:26:28 +02:00
|
|
|
|
|
|
|
tracker_manager(send_fun_t const& send_fun
|
|
|
|
, send_fun_hostname_t const& send_fun_hostname
|
2015-02-01 15:30:43 +01:00
|
|
|
, counters& stats_counters
|
|
|
|
, resolver_interface& resolver
|
|
|
|
, aux::session_settings const& sett
|
2015-04-17 03:15:33 +02:00
|
|
|
#if !defined TORRENT_DISABLE_LOGGING || TORRENT_USE_ASSERTS
|
2015-02-01 15:30:43 +01:00
|
|
|
, aux::session_logger& ses
|
|
|
|
#endif
|
|
|
|
);
|
2017-09-12 23:10:11 +02:00
|
|
|
|
|
|
|
~tracker_manager();
|
|
|
|
|
|
|
|
tracker_manager(tracker_manager const&) = delete;
|
|
|
|
tracker_manager& operator=(tracker_manager const&) = delete;
|
2006-04-25 23:04:48 +02:00
|
|
|
|
2004-02-22 23:40:45 +01:00
|
|
|
void queue_request(
|
2008-01-08 06:47:43 +01:00
|
|
|
io_service& ios
|
2018-11-11 20:33:41 +01:00
|
|
|
, tracker_request&& r
|
2016-08-31 14:27:36 +02:00
|
|
|
, std::weak_ptr<request_callback> c
|
|
|
|
= std::weak_ptr<request_callback>());
|
2018-11-11 20:33:41 +01:00
|
|
|
void queue_request(
|
|
|
|
io_service& ios
|
|
|
|
, tracker_request const& r
|
|
|
|
, std::weak_ptr<request_callback> c
|
|
|
|
= std::weak_ptr<request_callback>()) = delete;
|
2008-12-25 03:05:23 +01:00
|
|
|
void abort_all_requests(bool all = false);
|
2004-01-31 11:46:15 +01:00
|
|
|
|
2016-12-11 16:56:44 +01:00
|
|
|
void remove_request(http_tracker_connection const* c);
|
|
|
|
void remove_request(udp_tracker_connection const* c);
|
2006-08-01 17:27:08 +02:00
|
|
|
bool empty() const;
|
2007-10-07 20:06:56 +02:00
|
|
|
int num_requests() const;
|
2008-09-22 02:15:05 +02:00
|
|
|
|
|
|
|
void sent_bytes(int bytes);
|
|
|
|
void received_bytes(int bytes);
|
2010-05-30 03:33:03 +02:00
|
|
|
|
2016-04-24 21:26:28 +02:00
|
|
|
void incoming_error(error_code const& ec, udp::endpoint const& ep);
|
2016-07-22 18:31:42 +02:00
|
|
|
bool incoming_packet(udp::endpoint const& ep, span<char const> buf);
|
2010-08-03 11:08:37 +02:00
|
|
|
|
|
|
|
// this is only used for SOCKS packets, since
|
|
|
|
// they may be addressed to hostname
|
2016-04-24 21:26:28 +02:00
|
|
|
// TODO: 3 make sure the udp_socket supports passing on string-hostnames
|
|
|
|
// too, and that this function is used
|
2016-07-22 18:31:42 +02:00
|
|
|
bool incoming_packet(char const* hostname, span<char const> buf);
|
2015-05-16 09:21:23 +02:00
|
|
|
|
2014-10-20 22:44:05 +02:00
|
|
|
void update_transaction_id(
|
2016-08-29 14:31:23 +02:00
|
|
|
std::shared_ptr<udp_tracker_connection> c
|
2016-12-05 02:15:49 +01:00
|
|
|
, std::uint32_t tid);
|
2014-10-20 22:44:05 +02:00
|
|
|
|
2014-10-21 02:28:51 +02:00
|
|
|
aux::session_settings const& settings() const { return m_settings; }
|
|
|
|
resolver_interface& host_resolver() { return m_host_resolver; }
|
|
|
|
|
2017-07-21 05:19:28 +02:00
|
|
|
void send_hostname(aux::listen_socket_handle const& sock
|
2017-04-28 05:34:39 +02:00
|
|
|
, char const* hostname, int port, span<char const> p
|
2017-07-26 19:38:40 +02:00
|
|
|
, error_code& ec, udp_send_flags_t flags = {});
|
2016-04-24 21:26:28 +02:00
|
|
|
|
2017-07-21 05:19:28 +02:00
|
|
|
void send(aux::listen_socket_handle const& sock
|
2017-04-28 05:34:39 +02:00
|
|
|
, udp::endpoint const& ep, span<char const> p
|
2017-07-26 19:38:40 +02:00
|
|
|
, error_code& ec, udp_send_flags_t flags = {});
|
2016-04-24 21:26:28 +02:00
|
|
|
|
2004-01-31 11:46:15 +01:00
|
|
|
private:
|
|
|
|
|
2014-10-20 22:44:05 +02:00
|
|
|
// maps transactionid to the udp_tracker_connection
|
2016-04-30 19:50:42 +02:00
|
|
|
// These must use shared_ptr to avoid a dangling reference
|
|
|
|
// if a connection is erased while a timeout event is in the queue
|
2016-12-12 02:50:30 +01:00
|
|
|
std::unordered_map<std::uint32_t, std::shared_ptr<udp_tracker_connection>> m_udp_conns;
|
2014-10-20 22:44:05 +02:00
|
|
|
|
2016-12-12 02:50:30 +01:00
|
|
|
std::vector<std::shared_ptr<http_tracker_connection>> m_http_conns;
|
2014-10-20 22:44:05 +02:00
|
|
|
|
2016-04-24 21:26:28 +02:00
|
|
|
send_fun_t m_send_fun;
|
|
|
|
send_fun_hostname_t m_send_fun_hostname;
|
2014-10-21 02:28:51 +02:00
|
|
|
resolver_interface& m_host_resolver;
|
|
|
|
aux::session_settings const& m_settings;
|
2014-10-21 23:24:15 +02:00
|
|
|
counters& m_stats_counters;
|
2016-10-19 07:18:05 +02:00
|
|
|
bool m_abort = false;
|
2015-04-17 03:15:33 +02:00
|
|
|
#if !defined TORRENT_DISABLE_LOGGING || TORRENT_USE_ASSERTS
|
2015-02-01 15:30:43 +01:00
|
|
|
aux::session_logger& m_ses;
|
|
|
|
#endif
|
2004-01-31 11:46:15 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // TORRENT_TRACKER_MANAGER_HPP_INCLUDED
|