diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 7b32d2502..48491bca4 100755 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -184,6 +184,63 @@ namespace libtorrent { return std::auto_ptr(new torrent_finished_alert(*this)); } }; + struct TORRENT_EXPORT piece_finished_alert: torrent_alert + { + piece_finished_alert( + const torrent_handle& h + , int piece_num + , const std::string& msg) + : torrent_alert(h, alert::warning, msg) + , piece_index(piece_num) + { assert(piece_index >= 0);} + + int piece_index; + + virtual std::auto_ptr clone() const + { return std::auto_ptr(new piece_finished_alert(*this)); } + }; + + struct TORRENT_EXPORT block_finished_alert: torrent_alert + { + block_finished_alert( + const torrent_handle& h + , int block_num + , int piece_num + , const std::string& msg) + : torrent_alert(h, alert::warning, msg) + , block_index(block_num) + , piece_index(piece_num) + { assert(block_index >= 0 && piece_index >= 0);} + + int block_index; + int piece_index; + + virtual std::auto_ptr clone() const + { return std::auto_ptr(new block_finished_alert(*this)); } + }; + + struct TORRENT_EXPORT block_downloading_alert: torrent_alert + { + block_downloading_alert( + const torrent_handle& h + , std::string& speedmsg + , int block_num + , int piece_num + , const std::string& msg) + : torrent_alert(h, alert::warning, msg) + , peer_speedmsg(speedmsg) + , block_index(block_num) + , piece_index(piece_num) + { assert(block_index >= 0 && piece_index >= 0);} + + std::string peer_speedmsg; + int block_index; + int piece_index; + + virtual std::auto_ptr clone() const + { return std::auto_ptr(new block_downloading_alert(*this)); } + }; + struct TORRENT_EXPORT storage_moved_alert: torrent_alert { storage_moved_alert(torrent_handle const& h, std::string const& path) diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index a4c8af923..6fbaaffad 100755 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -241,6 +241,12 @@ namespace libtorrent enum { max_blocks_per_piece = 256 }; int piece_index; int blocks_in_piece; + // the number of blocks in the finished state + int finished; + // the number of blocks in the writing state + int writing; + // the number of blocks in the requested state + int requested; block_info blocks[max_blocks_per_piece]; enum state_t { none, slow, medium, fast }; state_t piece_state; diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index a2564601f..48018aa8f 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1193,6 +1193,11 @@ namespace libtorrent assert(p.start == j.offset); piece_block block_finished(p.piece, p.start / t->block_size()); picker.mark_as_finished(block_finished, peer_info_struct()); + if (t->alerts().should_post(alert::info)) + { + t->alerts().post_alert(block_finished_alert(t->get_handle(), + block_finished.block_index, block_finished.piece_index, "block finished")); + } if (!has_peer_choked() && !t->is_seed() && !m_torrent.expired()) { @@ -1300,11 +1305,29 @@ namespace libtorrent piece_picker::piece_state_t state; peer_speed_t speed = peer_speed(); - if (speed == fast) state = piece_picker::fast; - else if (speed == medium) state = piece_picker::medium; - else state = piece_picker::slow; + std::string speedmsg; + if (speed == fast) + { + speedmsg = "fast"; + state = piece_picker::fast; + } + else if (speed == medium) + { + speedmsg = "medium"; + state = piece_picker::medium; + } + else + { + speedmsg = "slow"; + state = piece_picker::slow; + } t->picker().mark_as_downloading(block, peer_info_struct(), state); + if (t->alerts().should_post(alert::info)) + { + t->alerts().post_alert(block_downloading_alert(t->get_handle(), + speedmsg, block.block_index, block.piece_index, "block downloading")); + } m_request_queue.push_back(block); } diff --git a/src/torrent.cpp b/src/torrent.cpp index 39f29172f..9d83cc6d9 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -831,6 +831,11 @@ namespace libtorrent if (passed_hash_check) { + if (m_ses.m_alerts.should_post(alert::info)) + { + m_ses.m_alerts.post_alert(piece_finished_alert(get_handle() + , index, "piece finished")); + } // the following call may cause picker to become invalid // in case we just became a seed announce_piece(index); diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index 10e1172fa..4538e66e8 100755 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -773,6 +773,9 @@ namespace libtorrent partial_piece_info pi; pi.piece_state = (partial_piece_info::state_t)i->state; pi.blocks_in_piece = p.blocks_in_piece(i->index); + pi.finished = (int)i->finished; + pi.writing = (int)i->writing; + pi.requested = (int)i->requested; int piece_size = t->torrent_file().piece_size(i->index); for (int j = 0; j < pi.blocks_in_piece; ++j) {