better fix for failing pieces

This commit is contained in:
Arvid Norberg 2008-06-23 14:45:01 +00:00
parent eb9a24261f
commit c210b11b80
3 changed files with 35 additions and 4 deletions

View File

@ -505,6 +505,13 @@ namespace libtorrent
// test
void piece_finished(int index, int passed_hash_check);
void piece_failed(int index);
// this will restore the piece picker state for a piece
// by re marking all the requests to blocks in this piece
// that are still outstanding in peers' download queues.
// this is done when a piece fails
void restore_piece_state(int index);
void received_redundant_data(int num_bytes)
{ TORRENT_ASSERT(num_bytes > 0); m_total_redundant_bytes += num_bytes; }

View File

@ -1778,8 +1778,6 @@ namespace libtorrent
// this might be the case if a piece fails, is restored, and then
// completed from a different peer (from which the piece was requested
// before it failed the hash check)
if (m_piece_map[block.piece_index].downloading == 0)
mark_as_downloading(block, peer, piece_picker::none);
TORRENT_ASSERT(m_piece_map[block.piece_index].downloading);
@ -1787,8 +1785,6 @@ namespace libtorrent
= std::find_if(m_downloads.begin(), m_downloads.end(), has_index(block.piece_index));
TORRENT_ASSERT(i != m_downloads.end());
block_info& info = i->info[block.block_index];
if (info.state == block_info::state_none)
mark_as_downloading(block, peer, piece_picker::none);
info.peer = peer;
TORRENT_ASSERT(info.state == block_info::state_requested);

View File

@ -1289,6 +1289,7 @@ namespace libtorrent
{
TORRENT_ASSERT(passed_hash_check == -1);
m_picker->restore_piece(index);
restore_piece_state(index);
}
}
@ -1402,6 +1403,7 @@ namespace libtorrent
// start with redownloading the pieces that the client
// that has sent the least number of pieces
m_picker->restore_piece(index);
restore_piece_state(index);
TORRENT_ASSERT(m_storage);
TORRENT_ASSERT(m_picker->have_piece(index) == false);
@ -1419,6 +1421,32 @@ namespace libtorrent
#endif
}
void torrent::restore_piece_state(int index)
{
TORRENT_ASSERT(has_picker());
for (peer_iterator i = m_connections.begin();
i != m_connections.end(); ++i)
{
peer_connection* p = *i;
std::deque<piece_block> const& dq = p->download_queue();
std::deque<piece_block> const& rq = p->request_queue();
for (std::deque<piece_block>::const_iterator k = dq.begin()
, end(dq.end()); k != end; ++k)
{
if (k->piece_index != index) continue;
m_picker->mark_as_downloading(*k, p->peer_info_struct()
, (piece_picker::piece_state_t)p->peer_speed());
}
for (std::deque<piece_block>::const_iterator k = rq.begin()
, end(rq.end()); k != end; ++k)
{
if (k->piece_index != index) continue;
m_picker->mark_as_downloading(*k, p->peer_info_struct()
, (piece_picker::piece_state_t)p->peer_speed());
}
}
}
void torrent::abort()
{
INVARIANT_CHECK;