2006-08-01 17:27:08 +02:00
|
|
|
/*
|
|
|
|
|
2015-06-03 07:18:48 +02:00
|
|
|
Copyright (c) 2006-2015, Arvid Norberg
|
2006-08-01 17:27:08 +02: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 RPC_MANAGER_HPP
|
|
|
|
#define RPC_MANAGER_HPP
|
|
|
|
|
2015-04-21 03:16:28 +02:00
|
|
|
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
2015-04-18 04:33:39 +02:00
|
|
|
|
2006-08-01 17:27:08 +02:00
|
|
|
#include <vector>
|
2014-01-03 09:02:53 +01:00
|
|
|
#include <deque>
|
2006-08-01 17:27:08 +02:00
|
|
|
#include <map>
|
|
|
|
#include <boost/cstdint.hpp>
|
2007-05-23 10:45:12 +02:00
|
|
|
#include <boost/pool/pool.hpp>
|
2011-01-19 06:57:44 +01:00
|
|
|
#include <boost/function/function3.hpp>
|
2006-08-01 17:27:08 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
#if TORRENT_HAS_BOOST_UNORDERED
|
|
|
|
#include <boost/unordered_map.hpp>
|
|
|
|
#else
|
|
|
|
#include <multimap>
|
|
|
|
#endif
|
|
|
|
|
2015-04-21 03:16:28 +02:00
|
|
|
#include "libtorrent/aux_/disable_warnings_pop.hpp"
|
2015-04-18 04:33:39 +02:00
|
|
|
|
2006-08-01 17:27:08 +02:00
|
|
|
#include <libtorrent/socket.hpp>
|
|
|
|
#include <libtorrent/entry.hpp>
|
|
|
|
#include <libtorrent/kademlia/node_id.hpp>
|
2007-05-23 10:45:12 +02:00
|
|
|
#include <libtorrent/kademlia/observer.hpp>
|
2006-08-01 17:27:08 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
#include "libtorrent/time.hpp"
|
2007-04-05 00:27:36 +02:00
|
|
|
|
2010-12-11 10:38:07 +01:00
|
|
|
namespace libtorrent { namespace aux { struct session_impl; } }
|
|
|
|
|
2013-10-14 03:03:43 +02:00
|
|
|
namespace libtorrent { struct dht_settings; }
|
|
|
|
|
2006-08-01 17:27:08 +02:00
|
|
|
namespace libtorrent { namespace dht
|
|
|
|
{
|
|
|
|
|
2015-05-10 06:54:02 +02:00
|
|
|
struct dht_logger;
|
2012-04-30 07:39:35 +02:00
|
|
|
struct udp_socket_interface;
|
|
|
|
|
2015-12-03 13:51:53 +01:00
|
|
|
struct TORRENT_EXTRA_EXPORT null_observer : public observer
|
2006-08-01 17:27:08 +02:00
|
|
|
{
|
2010-11-05 20:06:50 +01:00
|
|
|
null_observer(boost::intrusive_ptr<traversal_algorithm> const& a
|
|
|
|
, udp::endpoint const& ep, node_id const& id): observer(a, ep, id) {}
|
2010-12-12 04:17:08 +01:00
|
|
|
virtual void reply(msg const&) { flags |= flag_done; }
|
2006-08-01 17:27:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class routing_table;
|
|
|
|
|
2012-03-20 04:53:07 +01:00
|
|
|
class TORRENT_EXTRA_EXPORT rpc_manager
|
2006-08-01 17:27:08 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2009-09-20 02:23:36 +02:00
|
|
|
rpc_manager(node_id const& our_id
|
2015-09-03 00:09:49 +02:00
|
|
|
, dht_settings const& settings
|
2015-05-10 06:54:02 +02:00
|
|
|
, routing_table& table
|
|
|
|
, udp_socket_interface* sock
|
2015-09-03 00:09:49 +02:00
|
|
|
, dht_logger* log);
|
2006-08-01 17:27:08 +02:00
|
|
|
~rpc_manager();
|
|
|
|
|
2008-05-08 02:22:17 +02:00
|
|
|
void unreachable(udp::endpoint const& ep);
|
|
|
|
|
2006-08-01 17:27:08 +02:00
|
|
|
// returns true if the node needs a refresh
|
2010-01-03 12:08:39 +01:00
|
|
|
// if so, id is assigned the node id to refresh
|
2015-09-03 00:09:49 +02:00
|
|
|
bool incoming(msg const&, node_id* id);
|
2007-04-05 00:27:36 +02:00
|
|
|
time_duration tick();
|
2006-08-01 17:27:08 +02:00
|
|
|
|
2009-10-07 22:51:02 +02:00
|
|
|
bool invoke(entry& e, udp::endpoint target
|
2007-05-23 10:45:12 +02:00
|
|
|
, observer_ptr o);
|
2006-08-01 17:27:08 +02:00
|
|
|
|
2009-09-20 02:23:36 +02:00
|
|
|
void add_our_id(entry& e);
|
2006-08-01 17:27:08 +02:00
|
|
|
|
2014-01-19 20:45:50 +01:00
|
|
|
#if TORRENT_USE_ASSERTS
|
2008-01-13 05:24:10 +01:00
|
|
|
size_t allocation_size() const;
|
2011-05-08 11:04:59 +02:00
|
|
|
#endif
|
2014-01-21 20:26:09 +01:00
|
|
|
#if TORRENT_USE_INVARIANT_CHECKS
|
2006-08-01 17:27:08 +02:00
|
|
|
void check_invariant() const;
|
|
|
|
#endif
|
|
|
|
|
2010-11-06 08:12:57 +01:00
|
|
|
void* allocate_observer();
|
|
|
|
void free_observer(void* ptr);
|
|
|
|
|
|
|
|
int num_allocated_observers() const { return m_allocated_observers; }
|
2007-05-23 10:45:12 +02:00
|
|
|
|
2006-08-01 17:27:08 +02:00
|
|
|
private:
|
|
|
|
|
|
|
|
boost::uint32_t calc_connection_id(udp::endpoint addr);
|
|
|
|
|
2007-05-23 10:45:12 +02:00
|
|
|
mutable boost::pool<> m_pool_allocator;
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
#if TORRENT_HAS_BOOST_UNORDERED
|
|
|
|
typedef boost::unordered_multimap<int, observer_ptr> transactions_t;
|
|
|
|
#else
|
|
|
|
typedef std::multimap<int, observer_ptr> transactions_t;
|
|
|
|
#endif
|
2006-08-01 17:27:08 +02:00
|
|
|
transactions_t m_transactions;
|
2015-12-01 01:07:35 +01:00
|
|
|
|
2012-04-30 07:39:35 +02:00
|
|
|
udp_socket_interface* m_sock;
|
2015-05-10 06:54:02 +02:00
|
|
|
dht_logger* m_log;
|
2015-09-03 00:09:49 +02:00
|
|
|
dht_settings const& m_settings;
|
2006-08-01 17:27:08 +02:00
|
|
|
routing_table& m_table;
|
2015-03-12 05:34:54 +01:00
|
|
|
time_point m_timer;
|
2013-11-26 03:23:33 +01:00
|
|
|
node_id m_our_id;
|
2014-07-06 21:18:00 +02:00
|
|
|
boost::uint32_t m_allocated_observers:31;
|
|
|
|
boost::uint32_t m_destructing:1;
|
2006-08-01 17:27:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} } // namespace libtorrent::dht
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|