From 3564562dabcd806ef2c2681850da7b894945de1d Mon Sep 17 00:00:00 2001 From: Steven Siloti Date: Wed, 5 Aug 2015 20:20:24 -0700 Subject: [PATCH] pass raw buffer in dht_direct_response_alert --- include/libtorrent/alert_types.hpp | 10 ++++++++-- src/alert.cpp | 19 +++++++++++++++---- src/session_impl.cpp | 4 +--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 4ea045b61..7050ac2cc 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -2385,7 +2385,7 @@ namespace libtorrent struct TORRENT_EXPORT dht_direct_response_alert: alert { dht_direct_response_alert(aux::stack_allocator& alloc, void* userdata - , udp::endpoint const& addr, entry const& response); + , udp::endpoint const& addr, bdecode_node const& response); TORRENT_DEFINE_ALERT(dht_direct_response_alert, 88) @@ -2394,7 +2394,13 @@ namespace libtorrent void* userdata; udp::endpoint addr; - entry response; + + void response(bdecode_node& ret) const; + + private: + aux::stack_allocator& m_alloc; + int m_response_idx; + int m_response_size; }; #undef TORRENT_DEFINE_ALERT_IMPL diff --git a/src/alert.cpp b/src/alert.cpp index f08f40b8c..9a407bcf0 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -1832,9 +1832,11 @@ namespace libtorrent { } dht_direct_response_alert::dht_direct_response_alert( - aux::stack_allocator&, void* userdata - , udp::endpoint const& addr, entry const& response) - : userdata(userdata), addr(addr), response(response) + aux::stack_allocator& alloc, void* userdata + , udp::endpoint const& addr, bdecode_node const& response) + : userdata(userdata), addr(addr), m_alloc(alloc) + , m_response_idx(alloc.copy_buffer(response.data_section().first, response.data_section().second)) + , m_response_size(response.data_section().second) {} std::string dht_direct_response_alert::message() const @@ -1842,9 +1844,18 @@ namespace libtorrent { char msg[1050]; snprintf(msg, sizeof(msg), "DHT direct response (address=%s) [ %s ]" , addr.address().to_string().c_str() - , response.to_string().c_str()); + , std::string(m_alloc.ptr(m_response_idx), m_response_size).c_str()); return msg; } + void dht_direct_response_alert::response(bdecode_node& ret) const + { + char const* start = m_alloc.ptr(m_response_idx); + char const* end = start + m_response_size; + error_code ec; + bdecode(start, end, ret, ec); + TORRENT_ASSERT(!ec); + } + } // namespace libtorrent diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 5ab9d7c43..188aea0c0 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -5549,9 +5549,7 @@ retry: void on_direct_response(alert_manager& alerts, void* userdata, dht::msg const& msg) { - entry e; - e = msg.message; - alerts.emplace_alert(userdata, msg.addr, e); + alerts.emplace_alert(userdata, msg.addr, msg.message); } } // anonymous namespace