diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 69f971f13..967ecef0a 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -39,6 +39,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/peer_connection.hpp" #include "libtorrent/config.hpp" #include "libtorrent/assert.hpp" +#include "libtorrent/identify_client.hpp" #include @@ -51,11 +52,51 @@ namespace libtorrent {} virtual std::string message() const - { return handle.is_valid()?handle.name():"- "; } + { return handle.is_valid()?handle.name():" - "; } torrent_handle handle; }; + struct TORRENT_EXPORT peer_alert: torrent_alert + { + peer_alert(torrent_handle const& h, tcp::endpoint const& ip_ + , peer_id const& pid_) + : torrent_alert(h) + , ip(ip_) + , pid(pid_) + {} + + const static int static_category = alert::peer_notification; + virtual int category() const { return static_category; } + virtual std::string message() const + { + error_code ec; + return torrent_alert::message() + " peer (" + ip.address().to_string(ec) + + ", " + identify_client(pid) + ")"; + } + + tcp::endpoint ip; + peer_id pid; + }; + + struct TORRENT_EXPORT tracker_alert: torrent_alert + { + tracker_alert(torrent_handle const& h + , std::string const& url_) + : torrent_alert(h) + , url(url_) + { assert(!url.empty()); } + + const static int static_category = alert::tracker_notification; + virtual int category() const { return static_category; } + virtual std::string message() const + { + return torrent_alert::message() + " (" + url + ")"; + } + + std::string url; + }; + struct TORRENT_EXPORT file_renamed_alert: torrent_alert { file_renamed_alert(torrent_handle const& h @@ -139,25 +180,6 @@ namespace libtorrent torrent_status::state_t state; }; - struct TORRENT_EXPORT tracker_alert: torrent_alert - { - tracker_alert(torrent_handle const& h - , std::string const& url_) - : torrent_alert(h) - , url(url_) - { assert(!url.empty()); } - - const static int static_category = alert::tracker_notification; - virtual int category() const { return static_category; } - virtual std::string message() const - { - return torrent_alert::message() + " (" + url + ")"; - } - - - std::string url; - }; - struct TORRENT_EXPORT tracker_error_alert: tracker_alert { tracker_error_alert(torrent_handle const& h @@ -338,85 +360,60 @@ namespace libtorrent int piece_index; }; - struct TORRENT_EXPORT peer_ban_alert: torrent_alert + struct TORRENT_EXPORT peer_ban_alert: peer_alert { - peer_ban_alert(tcp::endpoint const& pip, torrent_handle h) - : torrent_alert(h) - , ip(pip) + peer_ban_alert(torrent_handle h, tcp::endpoint const& ip + , peer_id const& pid) + : peer_alert(h, ip, pid) {} virtual std::auto_ptr clone() const { return std::auto_ptr(new peer_ban_alert(*this)); } virtual char const* what() const { return "peer banned"; } - const static int static_category = alert::peer_notification; - virtual int category() const { return static_category; } virtual std::string message() const { error_code ec; - return torrent_alert::message() + " banned peer " - + ip.address().to_string(ec); + return peer_alert::message() + " banned peer"; } - - tcp::endpoint ip; }; - struct TORRENT_EXPORT peer_unsnubbed_alert: torrent_alert + struct TORRENT_EXPORT peer_unsnubbed_alert: peer_alert { - peer_unsnubbed_alert(torrent_handle const& h, tcp::endpoint const& ip_ - , peer_id const& pid_) - : torrent_alert(h) - , ip(ip_) - , pid(pid_) + peer_unsnubbed_alert(torrent_handle h, tcp::endpoint const& ip + , peer_id const& pid) + : peer_alert(h, ip, pid) {} virtual std::auto_ptr clone() const { return std::auto_ptr(new peer_unsnubbed_alert(*this)); } virtual char const* what() const { return "peer unsnubbed"; } - const static int static_category = alert::peer_notification; - virtual int category() const { return static_category; } virtual std::string message() const { - error_code ec; - return torrent_alert::message() + " peer unsnubbed: (" + ip.address().to_string(ec) - + ")"; + return peer_alert::message() + " peer unsnubbed"; } - - tcp::endpoint ip; - peer_id pid; }; - struct TORRENT_EXPORT peer_snubbed_alert: torrent_alert + struct TORRENT_EXPORT peer_snubbed_alert: peer_alert { - peer_snubbed_alert(torrent_handle const& h, tcp::endpoint const& ip_ - , peer_id const& pid_) - : torrent_alert(h) - , ip(ip_) - , pid(pid_) + peer_snubbed_alert(torrent_handle h, tcp::endpoint const& ip + , peer_id const& pid) + : peer_alert(h, ip, pid) {} virtual std::auto_ptr clone() const { return std::auto_ptr(new peer_snubbed_alert(*this)); } virtual char const* what() const { return "peer snubbed"; } - const static int static_category = alert::peer_notification; - virtual int category() const { return static_category; } virtual std::string message() const { - error_code ec; - return torrent_alert::message() + " peer snubbed: (" + ip.address().to_string(ec) - + ")"; + return peer_alert::message() + " peer snubbed"; } - - tcp::endpoint ip; - peer_id pid; }; - struct TORRENT_EXPORT peer_error_alert: torrent_alert + struct TORRENT_EXPORT peer_error_alert: peer_alert { - peer_error_alert(torrent_handle const& h, tcp::endpoint const& ip_ - , peer_id const& pid_, std::string const& msg_) - : torrent_alert(h) - , ip(ip_) - , pid(pid_) + peer_error_alert(torrent_handle const& h, tcp::endpoint const& ip + , peer_id const& pid, std::string const& msg_) + : peer_alert(h, ip, pid) , msg(msg_) {} @@ -428,19 +425,17 @@ namespace libtorrent virtual std::string message() const { error_code ec; - return torrent_alert::message() + " peer error: (" + ip.address().to_string(ec) - + ") " + msg; + return peer_alert::message() + " peer error: " + msg; } - tcp::endpoint ip; - peer_id pid; std::string msg; }; - struct TORRENT_EXPORT peer_connect_alert: torrent_alert + struct TORRENT_EXPORT peer_connect_alert: peer_alert { - peer_connect_alert(torrent_handle const& h, tcp::endpoint const& ip_) - : torrent_alert(h), ip(ip_) + peer_connect_alert(torrent_handle h, tcp::endpoint const& ip + , peer_id const& pid) + : peer_alert(h, ip, pid) {} virtual std::auto_ptr clone() const @@ -450,21 +445,15 @@ namespace libtorrent virtual int category() const { return static_category; } virtual std::string message() const { - error_code ec; - return torrent_alert::message() + " connecting to peer " - + ip.address().to_string(ec); + return peer_alert::message() + " connecting to peer"; } - - tcp::endpoint ip; }; - struct TORRENT_EXPORT peer_disconnected_alert: torrent_alert + struct TORRENT_EXPORT peer_disconnected_alert: peer_alert { - peer_disconnected_alert(torrent_handle const& h, tcp::endpoint const& ip_ - , peer_id const& pid_, std::string const& msg_) - : torrent_alert(h) - , ip(ip_) - , pid(pid_) + peer_disconnected_alert(torrent_handle const& h, tcp::endpoint const& ip + , peer_id const& pid, std::string const& msg_) + : peer_alert(h, ip, pid) , msg(msg_) {} @@ -475,44 +464,32 @@ namespace libtorrent virtual int category() const { return static_category; } virtual std::string message() const { - error_code ec; - return torrent_alert::message() + " disconnecting " - + ip.address().to_string(ec) + ": " + msg; + return peer_alert::message() + " disconnecting: " + msg; } - tcp::endpoint ip; - peer_id pid; std::string msg; }; - struct TORRENT_EXPORT invalid_request_alert: torrent_alert + struct TORRENT_EXPORT invalid_request_alert: peer_alert { - invalid_request_alert( - peer_request const& r - , torrent_handle const& h - , tcp::endpoint const& sender - , peer_id const& pid_) - : torrent_alert(h) - , ip(sender) + invalid_request_alert(torrent_handle const& h, tcp::endpoint const& ip + , peer_id const& pid, peer_request const& r) + : peer_alert(h, ip, pid) , request(r) - , pid(pid_) {} virtual std::auto_ptr clone() const { return std::auto_ptr(new invalid_request_alert(*this)); } virtual char const* what() const { return "invalid piece request"; } - const static int static_category = alert::peer_notification; - virtual int category() const { return static_category; } virtual std::string message() const { - error_code ec; - return torrent_alert::message() + " peer " - + ip.address().to_string(ec) + " sent an invalid piece request"; + return peer_alert::message() + " peer sent an invalid piece request " + "( piece: " + boost::lexical_cast(request.piece) + + " start: " + boost::lexical_cast(request.start) + + " len: " + boost::lexical_cast(request.length) + ")"; } - tcp::endpoint ip; peer_request request; - peer_id pid; }; struct TORRENT_EXPORT torrent_finished_alert: torrent_alert @@ -556,13 +533,11 @@ namespace libtorrent } }; - struct TORRENT_EXPORT request_dropped_alert: torrent_alert + struct TORRENT_EXPORT request_dropped_alert: peer_alert { - request_dropped_alert( - const torrent_handle& h - , int block_num - , int piece_num) - : torrent_alert(h) + request_dropped_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);} @@ -578,19 +553,17 @@ namespace libtorrent virtual int category() const { return static_category; } virtual std::string message() const { - return torrent_alert::message() + " block " - + boost::lexical_cast(block_index) + " in piece " - + boost::lexical_cast(piece_index) + " was dropped by remote peer"; + return peer_alert::message() + " peer dropped block ( piece: " + + boost::lexical_cast(piece_index) + " block: " + + boost::lexical_cast(block_index) + ")"; } }; - struct TORRENT_EXPORT block_timeout_alert: torrent_alert + struct TORRENT_EXPORT block_timeout_alert: peer_alert { - block_timeout_alert( - const torrent_handle& h - , int block_num - , int piece_num) - : torrent_alert(h) + block_timeout_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);} @@ -606,19 +579,17 @@ namespace libtorrent virtual int category() const { return static_category; } virtual std::string message() const { - return torrent_alert::message() + " timed out block " - + boost::lexical_cast(block_index) + " in piece " - + boost::lexical_cast(piece_index); + return peer_alert::message() + " peer timed out request ( piece: " + + boost::lexical_cast(piece_index) + " block: " + + boost::lexical_cast(block_index) + ")"; } }; - struct TORRENT_EXPORT block_finished_alert: torrent_alert + struct TORRENT_EXPORT block_finished_alert: peer_alert { - block_finished_alert( - const torrent_handle& h - , int block_num - , int piece_num) - : torrent_alert(h) + block_finished_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);} @@ -633,20 +604,17 @@ namespace libtorrent virtual int category() const { return static_category; } virtual std::string message() const { - return torrent_alert::message() + " block " - + boost::lexical_cast(block_index) + " in piece " - + boost::lexical_cast(piece_index) + " finished downloading"; + return peer_alert::message() + " block finished downloading ( piece: " + + boost::lexical_cast(piece_index) + " block: " + + boost::lexical_cast(block_index) + ")"; } }; - struct TORRENT_EXPORT block_downloading_alert: torrent_alert + struct TORRENT_EXPORT block_downloading_alert: peer_alert { - block_downloading_alert( - const torrent_handle& h - , char const* speedmsg - , int block_num - , int piece_num) - : torrent_alert(h) + block_downloading_alert(const torrent_handle& h, tcp::endpoint const& ip + , peer_id const& pid, char const* speedmsg, int block_num, int piece_num) + : peer_alert(h, ip, pid) , peer_speedmsg(speedmsg) , block_index(block_num) , piece_index(piece_num) @@ -663,9 +631,10 @@ namespace libtorrent virtual int category() const { return static_category; } virtual std::string message() const { - return torrent_alert::message() + " requested block " - + boost::lexical_cast(block_index) + " in piece " - + boost::lexical_cast(piece_index); + return peer_alert::message() + " requested block ( piece: " + + boost::lexical_cast(piece_index) + " block: " + + boost::lexical_cast(block_index) + ") " + + peer_speedmsg; } }; diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 4254e2dbd..e27ddac3e 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1381,8 +1381,8 @@ namespace libtorrent if (t->alerts().should_post()) { - t->alerts().post_alert(invalid_request_alert(r - , t->get_handle(), m_remote, m_peer_id)); + t->alerts().post_alert(invalid_request_alert( + t->get_handle(), m_remote, m_peer_id, r)); } } } @@ -1554,7 +1554,7 @@ namespace libtorrent { if (m_ses.m_alerts.should_post()) m_ses.m_alerts.post_alert(request_dropped_alert(t->get_handle() - , i->block.block_index, i->block.piece_index)); + , remote(), pid(), i->block.block_index, i->block.piece_index)); picker.abort_download(i->block); i = m_download_queue.erase(i); } @@ -1664,7 +1664,7 @@ namespace libtorrent if (t->alerts().should_post()) { t->alerts().post_alert(block_finished_alert(t->get_handle(), - block_finished.block_index, block_finished.piece_index)); + remote(), pid(), block_finished.block_index, block_finished.piece_index)); } // did we just finish the piece? @@ -1948,7 +1948,7 @@ namespace libtorrent if (t->alerts().should_post()) { t->alerts().post_alert(block_downloading_alert(t->get_handle(), - speedmsg, block.block_index, block.piece_index)); + remote(), pid(), speedmsg, block.block_index, block.piece_index)); } m_request_queue.push_back(block); @@ -2813,7 +2813,7 @@ namespace libtorrent if (m_ses.m_alerts.should_post()) { m_ses.m_alerts.post_alert(block_timeout_alert(t->get_handle() - , r.block_index, r.piece_index)); + , remote(), pid(), r.block_index, r.piece_index)); } m_download_queue.pop_back(); } @@ -3424,7 +3424,7 @@ namespace libtorrent if (t->alerts().should_post()) { t->alerts().post_alert(peer_connect_alert( - t->get_handle(), m_remote)); + t->get_handle(), remote(), pid())); } } diff --git a/src/torrent.cpp b/src/torrent.cpp index b9dea84f6..c062a5db6 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1417,8 +1417,10 @@ namespace libtorrent // ban it. if (m_ses.m_alerts.should_post()) { + peer_id pid; + if (p->connection) pid = p->connection->pid(); m_ses.m_alerts.post_alert(peer_ban_alert( - p->ip, get_handle())); + get_handle(), p->ip, pid)); } // mark the peer as banned