Browse Source

separate getData and putData

miguelfreitas
Miguel Freitas 11 years ago
parent
commit
e46256a2f5
  1. 4
      libtorrent/include/libtorrent/kademlia/node.hpp
  2. 21
      libtorrent/src/kademlia/node.cpp

4
libtorrent/include/libtorrent/kademlia/node.hpp

@ -247,7 +247,9 @@ public:
void putData(std::string const &username, std::string const &resource, bool multi, void putData(std::string const &username, std::string const &resource, bool multi,
entry const &value, std::string const &sig_user, entry const &value, std::string const &sig_user,
int timeutc, int seq, int timeutc, int seq);
void getData(std::string const &username, std::string const &resource, bool multi,
boost::function<void(entry::list_type const&)> f); boost::function<void(entry::list_type const&)> f);
bool verify_token(std::string const& token, char const* info_hash bool verify_token(std::string const& token, char const* info_hash

21
libtorrent/src/kademlia/node.cpp

@ -403,21 +403,34 @@ void node_impl::announce(sha1_hash const& info_hash, int listen_port, bool seed
void node_impl::putData(std::string const &username, std::string const &resource, bool multi, void node_impl::putData(std::string const &username, std::string const &resource, bool multi,
entry const &value, std::string const &sig_user, entry const &value, std::string const &sig_user,
int timeutc, int seq, int timeutc, int seq)
boost::function<void(entry::list_type const&)> f)
{ {
#ifdef TORRENT_DHT_VERBOSE_LOGGING #ifdef TORRENT_DHT_VERBOSE_LOGGING
TORRENT_LOG(node) << "putData [ username: " << info_hash << " res: " << resource << " ]" ; TORRENT_LOG(node) << "putData [ username: " << info_hash << " res: " << resource << " ]" ;
#endif #endif
// search for nodes with ids close to id or with peers // search for nodes with ids close to id or with peers
// for info-hash id. then send announce_peer to them. // for info-hash id. then send putData to them.
boost::intrusive_ptr<dht_get> ta(new dht_get(*this, username, resource, multi, f, boost::intrusive_ptr<dht_get> ta(new dht_get(*this, username, resource, multi,
boost::bind(&nop),
boost::bind(&putData_fun, _1, boost::ref(*this), boost::bind(&putData_fun, _1, boost::ref(*this),
username, resource, multi, username, resource, multi,
value, sig_user, timeutc, seq), true)); value, sig_user, timeutc, seq), true));
ta->start(); ta->start();
} }
void node_impl::getData(std::string const &username, std::string const &resource, bool multi,
boost::function<void(entry::list_type const&)> f)
{
#ifdef TORRENT_DHT_VERBOSE_LOGGING
TORRENT_LOG(node) << "getData [ username: " << info_hash << " res: " << resource << " ]" ;
#endif
// search for nodes with ids close to id or with peers
// for info-hash id. callback is used to return data.
boost::intrusive_ptr<dht_get> ta(new dht_get(*this, username, resource, multi, f,
boost::bind(&nop), false));
ta->start();
}
void node_impl::tick() void node_impl::tick()
{ {
node_id target; node_id target;

Loading…
Cancel
Save