From 9ab349f1d0a1ded87fa3ffa4c2755a644940679b Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 20 Jan 2014 09:20:47 +0000 Subject: [PATCH] improve dht error reporting --- include/libtorrent/alert_types.hpp | 27 +++++++++++++++++++++++++++ src/alert.cpp | 21 +++++++++++++++++++++ src/session_impl.cpp | 10 ++++++++-- src/utp_stream.cpp | 3 +-- 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 16cd68b8b..6be76993f 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -1906,6 +1906,33 @@ namespace libtorrent feed_item item; }; + // posted when something fails in the DHT. This is not necessarily a fatal + // error, but it could prevent proper operation + struct TORRENT_EXPORT dht_error_alert: alert + { + // internal + dht_error_alert(int op, error_code const& ec) + : error(ec), operation(op_t(op)) {} + + TORRENT_DEFINE_ALERT(dht_error_alert); + + const static int static_category = alert::error_notification + | alert::dht_notification; + virtual std::string message() const; + + // the error code + error_code error; + + enum op_t + { + unknown, + hostname_lookup + }; + + // the operation that failed + op_t operation; + }; + #undef TORRENT_DEFINE_ALERT diff --git a/src/alert.cpp b/src/alert.cpp index 81ca9eff5..04e3b8456 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -538,5 +538,26 @@ namespace libtorrent { , error.category().name(), convert_from_native(error.message()).c_str()); return msg; } + + std::string dht_error_alert::message() const + { + const static char* const operation_names[] = + { + "unknown" + "hostname lookup" + }; + + int op = operation; + if (op < 0 || op > sizeof(operation_names)/sizeof(operation_names[0])) + op = 0; + + char msg[600]; + snprintf(msg, sizeof(msg), "DHT error [%s] (%d) %s" + , operation_names[op] + , error.value() + , convert_from_native(error.message()).c_str()); + return msg; + } + } // namespace libtorrent diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 774467a6f..44c216266 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -5750,8 +5750,14 @@ retry: #if defined TORRENT_ASIO_DEBUGGING complete_async("session_impl::on_dht_router_name_lookup"); #endif - // TODO: 1 report errors as alerts - if (e) return; + if (e) + { + if (m_alerts.should_post()) + m_alerts.post_alert(dht_error_alert( + dht_error_alert::hostname_lookup, e)); + return; + } + while (host != tcp::resolver::iterator()) { // router nodes should be added before the DHT is started (and bootstrapped) diff --git a/src/utp_stream.cpp b/src/utp_stream.cpp index 57f3e584b..3034befc7 100644 --- a/src/utp_stream.cpp +++ b/src/utp_stream.cpp @@ -1900,8 +1900,7 @@ bool utp_socket_impl::send_pkt(int flags) m_mtu_ceiling = p->size - 1; if (m_mtu_floor > m_mtu_ceiling) m_mtu_floor = m_mtu_ceiling; update_mtu_limits(); - // TODO: 2 we might want to do something else here - // as well, to resend the packet immediately without + // resend the packet immediately without // it being an MTU probe p->mtu_probe = false; if (m_mtu_seq == m_ack_nr)