added alert messages for blocks finishing, pieces finishing and blocks being requested. patch by micah

This commit is contained in:
Arvid Norberg 2007-08-01 06:14:16 +00:00
parent 54aa76f940
commit 1973af7779
5 changed files with 97 additions and 3 deletions

View File

@ -184,6 +184,63 @@ namespace libtorrent
{ return std::auto_ptr<alert>(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<alert> clone() const
{ return std::auto_ptr<alert>(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<alert> clone() const
{ return std::auto_ptr<alert>(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<alert> clone() const
{ return std::auto_ptr<alert>(new block_downloading_alert(*this)); }
};
struct TORRENT_EXPORT storage_moved_alert: torrent_alert
{
storage_moved_alert(torrent_handle const& h, std::string const& path)

View File

@ -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;

View File

@ -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);
}

View File

@ -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);

View File

@ -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)
{