From 55a944c0149100daeb98ee9341a193ed75d22dbf Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 8 Jul 2008 18:41:04 +0000 Subject: [PATCH] added a unwanted_block_alert --- include/libtorrent/alert_types.hpp | 23 +++++++++++++++++++++++ src/peer_connection.cpp | 4 ++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 967ecef0a..a1c556d82 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -638,6 +638,29 @@ namespace libtorrent } }; + struct TORRENT_EXPORT unwanted_block_alert: peer_alert + { + unwanted_block_alert(const torrent_handle& h, tcp::endpoint const& ip + , peer_id const& pid, int block_num, int piece_num) + : peer_alert(h, ip, pid) + , block_index(block_num) + , piece_index(piece_num) + { TORRENT_ASSERT(block_index >= 0 && piece_index >= 0);} + + int block_index; + int piece_index; + + virtual std::auto_ptr clone() const + { return std::auto_ptr(new unwanted_block_alert(*this)); } + virtual char const* what() const { return "unwanted block received"; } + virtual std::string message() const + { + return peer_alert::message() + " received block not in download queue ( piece: " + + boost::lexical_cast(piece_index) + " block: " + + boost::lexical_cast(block_index) + ")"; + } + }; + struct TORRENT_EXPORT storage_moved_alert: torrent_alert { storage_moved_alert(torrent_handle const& h, std::string const& path_) diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index e27ddac3e..d05a4f9ea 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1523,8 +1523,8 @@ namespace libtorrent { if (t->alerts().should_post()) { - t->alerts().post_alert(peer_error_alert(t->get_handle(), m_remote - , m_peer_id, "got a block that was not in the request queue")); + t->alerts().post_alert(unwanted_block_alert(t->get_handle(), m_remote + , m_peer_id, block_finished.block_index, block_finished.piece_index)); } #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING (*m_logger) << " *** The block we just got was not in the "