2006-08-01 17:27:08 +02:00
|
|
|
/*
|
|
|
|
|
2016-01-18 00:57:46 +01:00
|
|
|
Copyright (c) 2006-2016, Arvid Norberg & Daniel Wallin
|
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 FIND_DATA_050323_HPP
|
|
|
|
#define FIND_DATA_050323_HPP
|
|
|
|
|
|
|
|
#include <libtorrent/kademlia/traversal_algorithm.hpp>
|
|
|
|
#include <libtorrent/kademlia/node_id.hpp>
|
|
|
|
#include <libtorrent/kademlia/routing_table.hpp>
|
|
|
|
#include <libtorrent/kademlia/rpc_manager.hpp>
|
2007-05-23 10:45:12 +02:00
|
|
|
#include <libtorrent/kademlia/observer.hpp>
|
|
|
|
#include <libtorrent/kademlia/msg.hpp>
|
2006-08-01 17:27:08 +02:00
|
|
|
|
2015-04-21 03:16:28 +02:00
|
|
|
#include "libtorrent/aux_/disable_warnings_push.hpp"
|
2015-04-19 00:00:27 +02:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
|
2007-05-23 10:45:12 +02:00
|
|
|
#include <boost/optional.hpp>
|
2009-11-23 09:38:50 +01:00
|
|
|
#include <boost/function/function1.hpp>
|
|
|
|
#include <boost/function/function2.hpp>
|
2006-08-01 17:27:08 +02:00
|
|
|
|
2015-04-21 03:16:28 +02:00
|
|
|
#include "libtorrent/aux_/disable_warnings_pop.hpp"
|
2015-04-19 00:00:27 +02:00
|
|
|
|
2006-08-01 17:27:08 +02:00
|
|
|
namespace libtorrent { namespace dht
|
|
|
|
{
|
|
|
|
|
|
|
|
typedef std::vector<char> packet_t;
|
|
|
|
|
|
|
|
class rpc_manager;
|
2015-05-09 21:00:22 +02:00
|
|
|
class node;
|
2006-08-01 17:27:08 +02:00
|
|
|
|
|
|
|
// -------- find data -----------
|
|
|
|
|
2013-12-15 00:25:38 +01:00
|
|
|
struct find_data : traversal_algorithm
|
2006-08-01 17:27:08 +02:00
|
|
|
{
|
2013-12-27 05:28:25 +01:00
|
|
|
typedef boost::function<void(std::vector<std::pair<node_entry, std::string> > const&)> nodes_callback;
|
2006-08-01 17:27:08 +02:00
|
|
|
|
2016-07-24 00:57:04 +02:00
|
|
|
find_data(node& node, node_id target
|
2013-12-27 05:28:25 +01:00
|
|
|
, nodes_callback const& ncallback);
|
2008-09-20 19:42:25 +02:00
|
|
|
|
2016-08-13 13:04:53 +02:00
|
|
|
void got_write_token(node_id const& n, std::string write_token);
|
2014-02-28 05:02:48 +01:00
|
|
|
|
2013-09-09 09:08:02 +02:00
|
|
|
virtual void start();
|
|
|
|
|
|
|
|
virtual char const* name() const;
|
2009-09-20 02:23:36 +02:00
|
|
|
|
2008-12-23 21:04:12 +01:00
|
|
|
node_id const target() const { return m_target; }
|
2008-09-20 19:42:25 +02:00
|
|
|
|
2009-09-20 02:23:36 +02:00
|
|
|
protected:
|
2008-09-20 19:42:25 +02:00
|
|
|
|
2013-09-09 09:08:02 +02:00
|
|
|
virtual void done();
|
2013-12-27 05:28:25 +01:00
|
|
|
virtual observer_ptr new_observer(void* ptr, udp::endpoint const& ep
|
2013-12-15 00:25:38 +01:00
|
|
|
, node_id const& id);
|
2009-09-20 02:23:36 +02:00
|
|
|
|
2008-12-23 21:04:12 +01:00
|
|
|
nodes_callback m_nodes_callback;
|
|
|
|
std::map<node_id, std::string> m_write_tokens;
|
2013-12-27 05:28:25 +01:00
|
|
|
bool m_done;
|
2013-09-09 09:08:02 +02:00
|
|
|
};
|
|
|
|
|
2013-12-15 00:25:38 +01:00
|
|
|
struct find_data_observer : traversal_observer
|
2007-05-23 10:45:12 +02:00
|
|
|
{
|
|
|
|
find_data_observer(
|
2010-11-05 20:06:50 +01:00
|
|
|
boost::intrusive_ptr<traversal_algorithm> const& algorithm
|
|
|
|
, udp::endpoint const& ep, node_id const& id)
|
2013-12-15 00:25:38 +01:00
|
|
|
: traversal_observer(algorithm, ep, id)
|
|
|
|
{}
|
|
|
|
|
2013-12-27 05:28:25 +01:00
|
|
|
virtual void reply(msg const&);
|
2007-05-23 10:45:12 +02:00
|
|
|
};
|
|
|
|
|
2006-08-01 17:27:08 +02:00
|
|
|
} } // namespace libtorrent::dht
|
|
|
|
|
|
|
|
#endif // FIND_DATA_050323_HPP
|
|
|
|
|