fixed incorrect assert in bytes_done()

This commit is contained in:
Arvid Norberg 2006-12-31 14:48:18 +00:00
parent 0fc8c2efa3
commit 45864b15ec
4 changed files with 35 additions and 25 deletions

View File

@ -1106,13 +1106,6 @@ namespace libtorrent
picker.mark_as_finished(block_finished, m_remote); picker.mark_as_finished(block_finished, m_remote);
try
{
t->get_policy().block_finished(*this, block_finished);
send_block_requests();
}
catch (std::exception const&) {}
#ifndef NDEBUG #ifndef NDEBUG
try try
{ {
@ -1166,6 +1159,14 @@ namespace libtorrent
t->completed(); t->completed();
} }
} }
try
{
t->get_policy().block_finished(*this, block_finished);
send_block_requests();
}
catch (std::exception const&) {}
#ifndef NDEBUG #ifndef NDEBUG
} }
catch (std::exception const& e) catch (std::exception const& e)
@ -1381,7 +1382,7 @@ namespace libtorrent
void peer_connection::send_block_requests() void peer_connection::send_block_requests()
{ {
INVARIANT_CHECK; // INVARIANT_CHECK;
if (has_peer_choked()) return; if (has_peer_choked()) return;
@ -2156,6 +2157,8 @@ namespace libtorrent
return; return;
} }
check_postcondition post_checker_(t, false);
if (!m_in_constructor && t->connection_for(remote()) != this) if (!m_in_constructor && t->connection_for(remote()) != this)
{ {
assert(false); assert(false);

View File

@ -136,6 +136,12 @@ namespace libtorrent
if (i->finished_blocks[j]) if (i->finished_blocks[j])
mark_as_finished(piece_block(i->index, j), peer); mark_as_finished(piece_block(i->index, j), peer);
} }
if (is_piece_finished(i->index))
{
// TODO: handle this case by verifying the
// piece and either accept it or discard it
assert(false);
}
} }
} }
} }

View File

@ -1115,7 +1115,7 @@ namespace libtorrent
INVARIANT_CHECK; INVARIANT_CHECK;
// if the peer hasn't choked us, ask for another piece // if the peer hasn't choked us, ask for another piece
if (!c.has_peer_choked()) if (!c.has_peer_choked() && !m_torrent->is_seed())
request_a_block(*m_torrent, c); request_a_block(*m_torrent, c);
} }

View File

@ -733,24 +733,25 @@ namespace libtorrent
dl_queue.begin(); i != dl_queue.end(); ++i) dl_queue.begin(); i != dl_queue.end(); ++i)
{ {
int corr = 0; int corr = 0;
assert(!m_have_pieces[i->index]); int index = i->index;
assert(!m_have_pieces[index]);
assert(int(i->finished_blocks.count()) assert(int(i->finished_blocks.count())
< m_torrent_file.piece_size(i->index) / m_block_size); < m_picker->blocks_in_piece(index));
#ifndef NDEBUG #ifndef NDEBUG
for (std::vector<piece_picker::downloading_piece>::const_iterator j = boost::next(i); for (std::vector<piece_picker::downloading_piece>::const_iterator j = boost::next(i);
j != dl_queue.end(); ++j) j != dl_queue.end(); ++j)
{ {
assert(j->index != i->index); assert(j->index != index);
} }
#endif #endif
for (int j = 0; j < blocks_per_piece; ++j) for (int j = 0; j < blocks_per_piece; ++j)
{ {
assert(i->finished_blocks[j] == 0 || i->finished_blocks[j] == 1); assert(i->finished_blocks[j] == 0 || i->finished_blocks[j] == 1);
assert(m_picker->is_finished(piece_block(i->index, j)) == i->finished_blocks[j]); assert(m_picker->is_finished(piece_block(index, j)) == i->finished_blocks[j]);
corr += i->finished_blocks[j] * m_block_size; corr += i->finished_blocks[j] * m_block_size;
assert(i->index != last_piece || j < m_picker->blocks_in_last_piece() assert(index != last_piece || j < m_picker->blocks_in_last_piece()
|| i->finished_blocks[j] == 0); || i->finished_blocks[j] == 0);
} }
@ -763,7 +764,7 @@ namespace libtorrent
corr += m_torrent_file.piece_size(last_piece) % m_block_size; corr += m_torrent_file.piece_size(last_piece) % m_block_size;
} }
total_done += corr; total_done += corr;
if (!m_picker->is_filtered(i->index)) if (!m_picker->is_filtered(index))
wanted_done += corr; wanted_done += corr;
} }
@ -959,7 +960,7 @@ namespace libtorrent
void torrent::announce_piece(int index) void torrent::announce_piece(int index)
{ {
INVARIANT_CHECK; // INVARIANT_CHECK;
assert(index >= 0); assert(index >= 0);
assert(index < m_torrent_file.num_pieces()); assert(index < m_torrent_file.num_pieces());
@ -972,14 +973,6 @@ namespace libtorrent
std::set<tcp::endpoint> peers; std::set<tcp::endpoint> peers;
std::copy(downloaders.begin(), downloaders.end(), std::inserter(peers, peers.begin())); std::copy(downloaders.begin(), downloaders.end(), std::inserter(peers, peers.begin()));
for (std::set<tcp::endpoint>::iterator i = peers.begin()
, end(peers.end()); i != end; ++i)
{
peer_iterator p = m_connections.find(*i);
if (p == m_connections.end()) continue;
p->second->received_valid_data(index);
}
if (!m_have_pieces[index]) if (!m_have_pieces[index])
m_num_pieces++; m_num_pieces++;
m_have_pieces[index] = true; m_have_pieces[index] = true;
@ -991,6 +984,14 @@ namespace libtorrent
for (peer_iterator i = m_connections.begin(); i != m_connections.end(); ++i) for (peer_iterator i = m_connections.begin(); i != m_connections.end(); ++i)
i->second->announce_piece(index); i->second->announce_piece(index);
for (std::set<tcp::endpoint>::iterator i = peers.begin()
, end(peers.end()); i != end; ++i)
{
peer_iterator p = m_connections.find(*i);
if (p == m_connections.end()) continue;
p->second->received_valid_data(index);
}
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin() for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i) , end(m_extensions.end()); i != end; ++i)
@ -2179,7 +2180,7 @@ namespace libtorrent
bool torrent::verify_piece(int piece_index) bool torrent::verify_piece(int piece_index)
{ {
INVARIANT_CHECK; // INVARIANT_CHECK;
assert(m_storage.get()); assert(m_storage.get());
assert(piece_index >= 0); assert(piece_index >= 0);