2006-08-01 17:27:08 +02:00
|
|
|
/*
|
|
|
|
|
2018-04-09 09:04:33 +02:00
|
|
|
Copyright (c) 2006-2018, 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>
|
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-19 00:00:27 +02:00
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
|
2017-04-12 19:00:57 +02:00
|
|
|
namespace libtorrent { namespace dht {
|
2006-08-01 17:27:08 +02:00
|
|
|
|
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
|
|
|
{
|
2018-03-22 17:01:38 +01:00
|
|
|
using nodes_callback = std::function<void(std::vector<std::pair<node_entry, std::string>> const&)>;
|
2006-08-01 17:27:08 +02:00
|
|
|
|
2016-09-12 02:49:15 +02:00
|
|
|
find_data(node& dht_node, node_id const& 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
|
|
|
|
2017-09-12 23:10:11 +02:00
|
|
|
void start() override;
|
2013-09-09 09:08:02 +02:00
|
|
|
|
2017-09-12 23:10:11 +02:00
|
|
|
char const* name() const override;
|
2009-09-20 02:23:36 +02:00
|
|
|
|
|
|
|
protected:
|
2008-09-20 19:42:25 +02:00
|
|
|
|
2017-09-12 23:10:11 +02:00
|
|
|
void done() override;
|
|
|
|
observer_ptr new_observer(udp::endpoint const& ep
|
|
|
|
, node_id const& id) override;
|
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(
|
2017-11-06 02:17:56 +01:00
|
|
|
std::shared_ptr<traversal_algorithm> algorithm
|
2010-11-05 20:06:50 +01:00
|
|
|
, udp::endpoint const& ep, node_id const& id)
|
2017-11-06 02:17:56 +01:00
|
|
|
: traversal_observer(std::move(algorithm), ep, id)
|
2013-12-15 00:25:38 +01:00
|
|
|
{}
|
|
|
|
|
2017-09-12 23:10:11 +02:00
|
|
|
void reply(msg const&) override;
|
2007-05-23 10:45:12 +02:00
|
|
|
};
|
|
|
|
|
2006-08-01 17:27:08 +02:00
|
|
|
} } // namespace libtorrent::dht
|
|
|
|
|
|
|
|
#endif // FIND_DATA_050323_HPP
|