pass raw buffer in dht_direct_response_alert

This commit is contained in:
Steven Siloti 2015-08-05 20:20:24 -07:00
parent 182c30f2d6
commit 3564562dab
3 changed files with 24 additions and 9 deletions

View File

@ -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

View File

@ -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

View File

@ -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<dht_direct_response_alert>(userdata, msg.addr, e);
alerts.emplace_alert<dht_direct_response_alert>(userdata, msg.addr, msg.message);
}
} // anonymous namespace