diff --git a/libtorrent/include/libtorrent/alert_types.hpp b/libtorrent/include/libtorrent/alert_types.hpp index e2e61ccb..54af2836 100644 --- a/libtorrent/include/libtorrent/alert_types.hpp +++ b/libtorrent/include/libtorrent/alert_types.hpp @@ -1149,6 +1149,20 @@ namespace libtorrent sha1_hash info_hash; }; + struct TORRENT_EXPORT dht_reply_data_alert: alert + { + dht_reply_data_alert(entry::list_type const& lst) + : m_lst(lst) + {} + + TORRENT_DEFINE_ALERT(dht_reply_data_alert); + + const static int static_category = alert::dht_notification; + virtual std::string message() const; + + entry::list_type const m_lst; + }; + struct TORRENT_EXPORT stats_alert: torrent_alert { stats_alert(torrent_handle const& h, int interval diff --git a/libtorrent/include/libtorrent/aux_/session_impl.hpp b/libtorrent/include/libtorrent/aux_/session_impl.hpp index b8591c32..0242d31a 100644 --- a/libtorrent/include/libtorrent/aux_/session_impl.hpp +++ b/libtorrent/include/libtorrent/aux_/session_impl.hpp @@ -307,6 +307,13 @@ namespace libtorrent // the DHT, to get the initial peers quickly void prioritize_dht(boost::weak_ptr t); + void dht_putData(std::string const &username, std::string const &resource, bool multi, + entry const &value, std::string const &sig_user, + int timeutc, int seq); + + void dht_getData(std::string const &username, std::string const &resource, bool multi); + + #ifndef TORRENT_NO_DEPRECATE entry dht_state() const; #endif diff --git a/libtorrent/include/libtorrent/kademlia/dht_tracker.hpp b/libtorrent/include/libtorrent/kademlia/dht_tracker.hpp index 23d68a77..972f3d42 100644 --- a/libtorrent/include/libtorrent/kademlia/dht_tracker.hpp +++ b/libtorrent/include/libtorrent/kademlia/dht_tracker.hpp @@ -93,6 +93,13 @@ namespace libtorrent { namespace dht void announce(sha1_hash const& ih, int listen_port, bool seed , boost::function const&)> f); + void putData(std::string const &username, std::string const &resource, bool multi, + entry const &value, std::string const &sig_user, + int timeutc, int seq); + + void getData(std::string const &username, std::string const &resource, bool multi, + boost::function f); + void dht_status(session_status& s); void network_stats(int& sent, int& received); diff --git a/libtorrent/include/libtorrent/session.hpp b/libtorrent/include/libtorrent/session.hpp index 3eb43556..f241a5fa 100644 --- a/libtorrent/include/libtorrent/session.hpp +++ b/libtorrent/include/libtorrent/session.hpp @@ -437,6 +437,13 @@ namespace libtorrent void add_dht_node(std::pair const& node); void add_dht_router(std::pair const& node); + // [MF] twister + void dht_putData(std::string const &username, std::string const &resource, bool multi, + entry const &value, std::string const &sig_user, + int timeutc, int seq); + + void dht_getData(std::string const &username, std::string const &resource, bool multi); + #ifndef TORRENT_NO_DEPRECATE // deprecated in 0.15 // use save_state and load_state instead diff --git a/libtorrent/src/alert.cpp b/libtorrent/src/alert.cpp index 12c4a163..2647cccb 100644 --- a/libtorrent/src/alert.cpp +++ b/libtorrent/src/alert.cpp @@ -351,6 +351,13 @@ namespace libtorrent { return msg; } + std::string dht_reply_data_alert::message() const + { + char msg[200]; + snprintf(msg, sizeof(msg), "reply to dht getData received %d entries", m_lst.size()); + return msg; + } + stats_alert::stats_alert(torrent_handle const& h, int in , stat const& s) : torrent_alert(h) diff --git a/libtorrent/src/kademlia/dht_tracker.cpp b/libtorrent/src/kademlia/dht_tracker.cpp index 5752ba2f..6bfd1ae8 100644 --- a/libtorrent/src/kademlia/dht_tracker.cpp +++ b/libtorrent/src/kademlia/dht_tracker.cpp @@ -422,6 +422,19 @@ namespace libtorrent { namespace dht m_dht.announce(ih, listen_port, seed, f); } + void dht_tracker::putData(std::string const &username, std::string const &resource, bool multi, + entry const &value, std::string const &sig_user, + int timeutc, int seq) + { + m_dht.putData(username,resource, multi, value, sig_user, timeutc, seq); + } + + void dht_tracker::getData(std::string const &username, std::string const &resource, bool multi, + boost::function f) + { + m_dht.getData(username, resource, multi, f); + } + // translate bittorrent kademlia message into the generice kademlia message // used by the library diff --git a/libtorrent/src/session.cpp b/libtorrent/src/session.cpp index e7546f1a..c934abe9 100644 --- a/libtorrent/src/session.cpp +++ b/libtorrent/src/session.cpp @@ -329,6 +329,12 @@ namespace libtorrent #define TORRENT_ASYNC_CALL2(x, a1, a2) \ m_impl->m_io_service.dispatch(boost::bind(&session_impl:: x, m_impl.get(), a1, a2)) +#define TORRENT_ASYNC_CALL3(x, a1, a2, a3) \ + m_impl->m_io_service.dispatch(boost::bind(&session_impl:: x, m_impl.get(), a1, a2, a3)) + +#define TORRENT_ASYNC_CALL7(x, a1, a2, a3, a4, a5, a6, a7) \ + m_impl->m_io_service.dispatch(boost::bind(&session_impl:: x, m_impl.get(), a1, a2, a3, a4, a5, a6, a7)) + #define TORRENT_WAIT \ mutex::scoped_lock l(m_impl->mut); \ while (!done) { m_impl->cond.wait(l); }; @@ -845,6 +851,22 @@ namespace libtorrent #endif } + void session::dht_putData(std::string const &username, std::string const &resource, bool multi, + entry const &value, std::string const &sig_user, + int timeutc, int seq) + { +#ifndef TORRENT_DISABLE_DHT + TORRENT_ASYNC_CALL7(dht_putData, username, resource, multi, value, sig_user, timeutc, seq); +#endif + } + + void session::dht_getData(std::string const &username, std::string const &resource, bool multi) + { +#ifndef TORRENT_DISABLE_DHT + TORRENT_ASYNC_CALL3(dht_getData, username, resource, multi); +#endif + } + bool session::is_dht_running() const { #ifndef TORRENT_DISABLE_DHT diff --git a/libtorrent/src/session_impl.cpp b/libtorrent/src/session_impl.cpp index 2d563fea..bc0807db 100644 --- a/libtorrent/src/session_impl.cpp +++ b/libtorrent/src/session_impl.cpp @@ -5733,6 +5733,26 @@ retry: boost::bind(&session_impl::on_dht_router_name_lookup, this, _1, _2)); } + + void session_impl::dht_putData(std::string const &username, std::string const &resource, bool multi, + entry const &value, std::string const &sig_user, + int timeutc, int seq) + { + if (m_dht) m_dht->putData(username, resource, multi, value, sig_user, timeutc, seq); + } + + void post_dht_getData(aux::session_impl *si, entry::list_type const&lst) + { + if( si->m_alerts.should_post() ) { + si->m_alerts.post_alert(dht_reply_data_alert(lst)); + } + } + + void session_impl::dht_getData(std::string const &username, std::string const &resource, bool multi) + { + if (m_dht) m_dht->getData(username, resource, multi, boost::bind( post_dht_getData, this, _1)); + } + void session_impl::on_dht_router_name_lookup(error_code const& e , tcp::resolver::iterator host) {