~ubuntu-branches/ubuntu/maverick/libtorrent-rasterbar/maverick

« back to all changes in this revision

Viewing changes to include/libtorrent/kademlia/find_data.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Sauthier
  • Date: 2010-08-10 12:59:37 UTC
  • mfrom: (1.3.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100810125937-jbcmmf17y8yo9hgz
Tags: 0.15.0-0ubuntu1
* New upstream version.
* debian/patches/100_fix_html_docs.patch: refreshed.
* debian/control: bump up standards-version to 3.9.1 (no changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
#define FIND_DATA_050323_HPP
35
35
 
36
36
#include <vector>
 
37
#include <map>
37
38
 
38
39
#include <libtorrent/kademlia/traversal_algorithm.hpp>
39
40
#include <libtorrent/kademlia/node_id.hpp>
51
52
typedef std::vector<char> packet_t;
52
53
 
53
54
class rpc_manager;
 
55
class node_impl;
54
56
 
55
57
// -------- find data -----------
56
58
 
57
59
class find_data : public traversal_algorithm
58
60
{
59
61
public:
60
 
        typedef boost::function<void(msg const*)> done_callback;
61
 
 
62
 
        static void initiate(
63
 
                node_id target
64
 
                , int branch_factor
65
 
                , int max_results
66
 
                , routing_table& table
67
 
                , rpc_manager& rpc
68
 
                , done_callback const& callback
69
 
        );
 
62
        typedef boost::function<void(std::vector<tcp::endpoint> const&)> data_callback;
 
63
        typedef boost::function<void(std::vector<std::pair<node_entry, std::string> > const&)> nodes_callback;
70
64
 
71
65
        void got_data(msg const* m);
 
66
        void got_write_token(node_id const& n, std::string const& write_token)
 
67
        { m_write_tokens[n] = write_token; }
 
68
 
 
69
        find_data(node_impl& node, node_id target
 
70
                , data_callback const& dcallback
 
71
                , nodes_callback const& ncallback);
 
72
 
 
73
        virtual char const* name() const { return "get_peers"; }
 
74
        node_id const target() const { return m_target; }
72
75
 
73
76
private:
 
77
 
74
78
        void done();
75
79
        void invoke(node_id const& id, udp::endpoint addr);
76
80
 
77
 
        find_data(
78
 
                node_id target
79
 
                , int branch_factor
80
 
                , int max_results
81
 
                , routing_table& table
82
 
                , rpc_manager& rpc
83
 
                , done_callback const& callback
84
 
        );
85
 
 
86
 
        done_callback m_done_callback;
87
 
        boost::shared_ptr<packet_t> m_packet;
 
81
        data_callback m_data_callback;
 
82
        nodes_callback m_nodes_callback;
 
83
        std::map<node_id, std::string> m_write_tokens;
 
84
        node_id const m_target;
88
85
        bool m_done;
89
86
};
90
87
 
93
90
public:
94
91
        find_data_observer(
95
92
                boost::intrusive_ptr<find_data> const& algorithm
96
 
                , node_id self
97
 
                , node_id target)
 
93
                , node_id self)
98
94
                : observer(algorithm->allocator())
99
95
                , m_algorithm(algorithm)
100
 
                , m_target(target) 
101
96
                , m_self(self)
102
97
        {}
103
98
        ~find_data_observer();
106
101
        {
107
102
                m.reply = false;
108
103
                m.message_id = messages::get_peers;
109
 
                m.info_hash = m_target;
 
104
                m.info_hash = m_algorithm->target();
110
105
        }
111
106
 
112
107
        void timeout();
115
110
 
116
111
private:
117
112
        boost::intrusive_ptr<find_data> m_algorithm;
118
 
        node_id const m_target;
119
113
        node_id const m_self;
120
114
};
121
115