From 6f82d3b8aeb4091904d76b8b7a053fa38c0e7c5d Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 15 Mar 2014 22:20:19 +0000 Subject: [PATCH] merged i2p_alert fix from RC_0_16 --- include/libtorrent/alert_types.hpp | 15 +++++++++++++++ src/alert.cpp | 7 +++++++ src/i2p_stream.cpp | 3 +-- src/session_impl.cpp | 3 +++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 06875bd5f..28f13bfca 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -2041,6 +2041,21 @@ namespace libtorrent std::string salt; boost::uint64_t seq; }; + + // this alert is used to report errors in the i2p SAM connection + struct TORRENT_EXPORT i2p_alert : alert + { + i2p_alert(error_code const& ec) : error(ec) {} + + TORRENT_DEFINE_ALERT(i2p_alert); + + const static int static_category = alert::error_notification; + virtual std::string message() const; + + // the error that occurred in the i2p SAM connection + error_code error; + }; + #undef TORRENT_DEFINE_ALERT } diff --git a/src/alert.cpp b/src/alert.cpp index 180166330..61d1044b0 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -610,6 +610,13 @@ namespace libtorrent { return msg; } + std::string i2p_alert::message() const + { + char msg[600]; + snprintf(msg, sizeof(msg), "i2p_error: [%s] %s" + , error.category().name(), convert_from_native(error.message()).c_str()); + return msg; + } } // namespace libtorrent diff --git a/src/i2p_stream.cpp b/src/i2p_stream.cpp index 1d2115599..1273e858e 100644 --- a/src/i2p_stream.cpp +++ b/src/i2p_stream.cpp @@ -148,8 +148,7 @@ namespace libtorrent void i2p_connection::async_name_lookup(char const* name , i2p_connection::name_lookup_handler handler) { -// TORRENT_ASSERT(is_open()); - if (m_state == sam_idle && m_name_lookup.empty()) + if (m_state == sam_idle && m_name_lookup.empty() && is_open()) do_name_lookup(name, handler); else m_name_lookup.push_back(std::make_pair(std::string(name), handler)); diff --git a/src/session_impl.cpp b/src/session_impl.cpp index c7a3d3409..9d9947bb5 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2455,6 +2455,9 @@ retry: { if (ec) { + if (m_alerts.should_post()) + m_alerts.post_alert(i2p_alert(ec)); + #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING char msg[200]; snprintf(msg, sizeof(msg), "i2p open failed (%d) %s", ec.value(), ec.message().c_str());