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

« back to all changes in this revision

Viewing changes to src/kademlia/closest_nodes.cpp

  • 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:
35
35
#include <libtorrent/kademlia/closest_nodes.hpp>
36
36
#include <libtorrent/kademlia/routing_table.hpp>
37
37
#include <libtorrent/kademlia/rpc_manager.hpp>
 
38
#include <libtorrent/kademlia/node.hpp>
38
39
#include "libtorrent/assert.hpp"
39
40
 
40
41
namespace libtorrent { namespace dht
58
59
                for (msg::nodes_t::const_iterator i = in.nodes.begin()
59
60
                        , end(in.nodes.end()); i != end; ++i)
60
61
                {
61
 
                        m_algorithm->traverse(i->id, i->addr);
 
62
                        m_algorithm->traverse(i->id, i->ep());
62
63
                }
63
64
        }
64
65
        m_algorithm->finished(m_self);
72
73
        m_algorithm = 0;
73
74
}
74
75
 
75
 
 
76
76
closest_nodes::closest_nodes(
77
 
        node_id target
78
 
        , int branch_factor
79
 
        , int max_results
80
 
        , routing_table& table
81
 
        , rpc_manager& rpc
82
 
        , done_callback const& callback
83
 
)
84
 
        : traversal_algorithm(
85
 
                target
86
 
                , branch_factor
87
 
                , max_results
88
 
                , table
89
 
                , rpc
90
 
                , table.begin()
91
 
                , table.end()
92
 
        )
 
77
        node_impl& node
 
78
        , node_id target
 
79
        , done_callback const& callback)
 
80
        : traversal_algorithm(node, target, node.m_table.begin(), node.m_table.end())
93
81
        , m_done_callback(callback)
94
82
{
95
83
        boost::intrusive_ptr<closest_nodes> self(this);
98
86
 
99
87
void closest_nodes::invoke(node_id const& id, udp::endpoint addr)
100
88
{
101
 
        TORRENT_ASSERT(m_rpc.allocation_size() >= sizeof(closest_nodes_observer));
102
 
        observer_ptr o(new (m_rpc.allocator().malloc()) closest_nodes_observer(this, id, m_target));
 
89
        TORRENT_ASSERT(m_node.m_rpc.allocation_size() >= sizeof(closest_nodes_observer));
 
90
        void* ptr = m_node.m_rpc.allocator().malloc();
 
91
        if (ptr == 0)
 
92
        {
 
93
                done();
 
94
                return;
 
95
        }
 
96
        m_node.m_rpc.allocator().set_next_size(10);
 
97
        observer_ptr o(new (ptr) closest_nodes_observer(this, id));
103
98
#ifdef TORRENT_DEBUG
104
99
        o->m_in_constructor = false;
105
100
#endif
106
 
        m_rpc.invoke(messages::find_node, addr, o);
 
101
        m_node.m_rpc.invoke(messages::find_node, addr, o);
107
102
}
108
103
 
109
104
void closest_nodes::done()
110
105
{
111
106
        std::vector<node_entry> results;
112
 
        int num_results = m_max_results;
 
107
        int num_results = m_node.m_table.bucket_size();
113
108
        for (std::vector<result>::iterator i = m_results.begin()
114
109
                , end(m_results.end()); i != end && num_results > 0; ++i)
115
110
        {
121
116
        m_done_callback(results);
122
117
}
123
118
 
124
 
void closest_nodes::initiate(
125
 
        node_id target
126
 
        , int branch_factor
127
 
        , int max_results
128
 
        , routing_table& table
129
 
        , rpc_manager& rpc
130
 
        , done_callback const& callback
131
 
)
132
 
{
133
 
        new closest_nodes(target, branch_factor, max_results, table, rpc, callback);
134
 
}
135
 
 
136
119
} } // namespace libtorrent::dht
137
120