fix error handling for DHT direct requests

This commit is contained in:
Steven Siloti 2015-08-08 20:29:29 -07:00
parent 135f4761e1
commit 1b4b1c4403
3 changed files with 18 additions and 2 deletions

View File

@ -2389,6 +2389,10 @@ namespace libtorrent
dht_direct_response_alert(aux::stack_allocator& alloc, void* userdata
, udp::endpoint const& addr, bdecode_node const& response);
// for when there was a timeout so we don't have a response
dht_direct_response_alert(aux::stack_allocator& alloc, void* userdata
, udp::endpoint const& addr);
TORRENT_DEFINE_ALERT(dht_direct_response_alert, 88)
static const int static_category = alert::dht_notification;

View File

@ -1839,17 +1839,26 @@ namespace libtorrent {
, m_response_size(response.data_section().second)
{}
dht_direct_response_alert::dht_direct_response_alert(
aux::stack_allocator& alloc
, void* userdata
, udp::endpoint const& addr)
: userdata(userdata), addr(addr), m_alloc(alloc)
, m_response_idx(-1), m_response_size(0)
{}
std::string dht_direct_response_alert::message() const
{
char msg[1050];
snprintf(msg, sizeof(msg), "DHT direct response (address=%s) [ %s ]"
, addr.address().to_string().c_str()
, std::string(m_alloc.ptr(m_response_idx), m_response_size).c_str());
, m_response_size ? std::string(m_alloc.ptr(m_response_idx), m_response_size).c_str() : "");
return msg;
}
bdecode_node dht_direct_response_alert::response() const
{
if (m_response_size == 0) return bdecode_node();
char const* start = m_alloc.ptr(m_response_idx);
char const* end = start + m_response_size;
error_code ec;

View File

@ -5552,7 +5552,10 @@ retry:
void on_direct_response(alert_manager& alerts, void* userdata, dht::msg const& msg)
{
alerts.emplace_alert<dht_direct_response_alert>(userdata, msg.addr, msg.message);
if (msg.message.type() == bdecode_node::none_t)
alerts.emplace_alert<dht_direct_response_alert>(userdata, msg.addr);
else
alerts.emplace_alert<dht_direct_response_alert>(userdata, msg.addr, msg.message);
}
} // anonymous namespace