From 45864b15ec2cfec410371a1649de23339044a76b Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 31 Dec 2006 14:48:18 +0000 Subject: [PATCH] fixed incorrect assert in bytes_done() --- src/peer_connection.cpp | 19 +++++++++++-------- src/piece_picker.cpp | 6 ++++++ src/policy.cpp | 2 +- src/torrent.cpp | 33 +++++++++++++++++---------------- 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 126c64ae8..b8eae09ca 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1106,13 +1106,6 @@ namespace libtorrent 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 try { @@ -1166,6 +1159,14 @@ namespace libtorrent t->completed(); } } + + try + { + t->get_policy().block_finished(*this, block_finished); + send_block_requests(); + } + catch (std::exception const&) {} + #ifndef NDEBUG } catch (std::exception const& e) @@ -1381,7 +1382,7 @@ namespace libtorrent void peer_connection::send_block_requests() { - INVARIANT_CHECK; +// INVARIANT_CHECK; if (has_peer_choked()) return; @@ -2156,6 +2157,8 @@ namespace libtorrent return; } + check_postcondition post_checker_(t, false); + if (!m_in_constructor && t->connection_for(remote()) != this) { assert(false); diff --git a/src/piece_picker.cpp b/src/piece_picker.cpp index 93445e0b6..6e2b0271d 100755 --- a/src/piece_picker.cpp +++ b/src/piece_picker.cpp @@ -136,6 +136,12 @@ namespace libtorrent if (i->finished_blocks[j]) 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); + } } } } diff --git a/src/policy.cpp b/src/policy.cpp index c06fb385b..094612fa0 100755 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -1115,7 +1115,7 @@ namespace libtorrent INVARIANT_CHECK; // 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); } diff --git a/src/torrent.cpp b/src/torrent.cpp index 9d1f118be..7210d074b 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -733,24 +733,25 @@ namespace libtorrent dl_queue.begin(); i != dl_queue.end(); ++i) { int corr = 0; - assert(!m_have_pieces[i->index]); + int index = i->index; + assert(!m_have_pieces[index]); assert(int(i->finished_blocks.count()) - < m_torrent_file.piece_size(i->index) / m_block_size); + < m_picker->blocks_in_piece(index)); #ifndef NDEBUG for (std::vector::const_iterator j = boost::next(i); j != dl_queue.end(); ++j) { - assert(j->index != i->index); + assert(j->index != index); } #endif for (int j = 0; j < blocks_per_piece; ++j) { 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; - 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); } @@ -763,7 +764,7 @@ namespace libtorrent corr += m_torrent_file.piece_size(last_piece) % m_block_size; } total_done += corr; - if (!m_picker->is_filtered(i->index)) + if (!m_picker->is_filtered(index)) wanted_done += corr; } @@ -959,7 +960,7 @@ namespace libtorrent void torrent::announce_piece(int index) { - INVARIANT_CHECK; +// INVARIANT_CHECK; assert(index >= 0); assert(index < m_torrent_file.num_pieces()); @@ -972,14 +973,6 @@ namespace libtorrent std::set peers; std::copy(downloaders.begin(), downloaders.end(), std::inserter(peers, peers.begin())); - for (std::set::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]) m_num_pieces++; m_have_pieces[index] = true; @@ -991,6 +984,14 @@ namespace libtorrent for (peer_iterator i = m_connections.begin(); i != m_connections.end(); ++i) i->second->announce_piece(index); + for (std::set::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 for (extension_list_t::iterator i = m_extensions.begin() , end(m_extensions.end()); i != end; ++i) @@ -2179,7 +2180,7 @@ namespace libtorrent bool torrent::verify_piece(int piece_index) { - INVARIANT_CHECK; +// INVARIANT_CHECK; assert(m_storage.get()); assert(piece_index >= 0);