00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef REFRESH_050324_HPP
00034 #define REFRESH_050324_HPP
00035
00036 #include <vector>
00037
00038 #include <libtorrent/kademlia/traversal_algorithm.hpp>
00039 #include <libtorrent/kademlia/node_id.hpp>
00040
00041 #include <boost/function.hpp>
00042
00043 namespace libtorrent { namespace dht
00044 {
00045
00046 #ifdef TORRENT_DHT_VERBOSE_LOGGING
00047 TORRENT_DECLARE_LOG(refresh);
00048 #endif
00049
00050 class routing_table;
00051 class rpc_manager;
00052
00053 class refresh : public traversal_algorithm
00054 {
00055 public:
00056 typedef boost::function<void()> done_callback;
00057
00058 template<class InIt>
00059 static void initiate(
00060 node_id target
00061 , int branch_factor
00062 , int max_active_pings
00063 , int max_results
00064 , routing_table& table
00065 , InIt first
00066 , InIt last
00067 , rpc_manager& rpc
00068 , done_callback const& callback
00069 );
00070
00071 void ping_reply(node_id id);
00072 void ping_timeout(node_id id, bool prevent_request = false);
00073
00074 private:
00075 template<class InIt>
00076 refresh(
00077 node_id target
00078 , int branch_factor
00079 , int max_active_pings
00080 , int max_results
00081 , routing_table& table
00082 , InIt first
00083 , InIt last
00084 , rpc_manager& rpc
00085 , done_callback const& callback
00086 );
00087
00088 void done();
00089 void invoke(node_id const& id, udp::endpoint addr);
00090
00091 void invoke_pings_or_finish(bool prevent_request = false);
00092
00093 int m_max_active_pings;
00094 int m_active_pings;
00095
00096 done_callback m_done_callback;
00097
00098 std::vector<result>::iterator m_leftover_nodes_iterator;
00099 };
00100
00101 template<class InIt>
00102 inline refresh::refresh(
00103 node_id target
00104 , int branch_factor
00105 , int max_active_pings
00106 , int max_results
00107 , routing_table& table
00108 , InIt first
00109 , InIt last
00110 , rpc_manager& rpc
00111 , done_callback const& callback
00112 )
00113 : traversal_algorithm(
00114 target
00115 , branch_factor
00116 , max_results
00117 , table
00118 , rpc
00119 , first
00120 , last
00121 )
00122 , m_max_active_pings(max_active_pings)
00123 , m_active_pings(0)
00124 , m_done_callback(callback)
00125 {
00126 boost::intrusive_ptr<refresh> self(this);
00127 add_requests();
00128 }
00129
00130 template<class InIt>
00131 inline void refresh::initiate(
00132 node_id target
00133 , int branch_factor
00134 , int max_active_pings
00135 , int max_results
00136 , routing_table& table
00137 , InIt first
00138 , InIt last
00139 , rpc_manager& rpc
00140 , done_callback const& callback
00141 )
00142 {
00143 new refresh(
00144 target
00145 , branch_factor
00146 , max_active_pings
00147 , max_results
00148 , table
00149 , first
00150 , last
00151 , rpc
00152 , callback
00153 );
00154 }
00155
00156 } }
00157
00158 #endif // REFRESH_050324_HPP
00159