From 1b46fb9e1b73d14d14ede0e40d8dcf9b850489d1 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 21 Dec 2006 02:44:00 +0000 Subject: [PATCH] fixed an assert in teh web seed downloader --- include/libtorrent/piece_picker.hpp | 2 +- src/peer_connection.cpp | 5 ++++- src/torrent.cpp | 14 +++++++------- src/web_peer_connection.cpp | 20 +++++++------------- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/include/libtorrent/piece_picker.hpp b/include/libtorrent/piece_picker.hpp index 23f20a79a..c3e7a55a2 100755 --- a/include/libtorrent/piece_picker.hpp +++ b/include/libtorrent/piece_picker.hpp @@ -199,7 +199,7 @@ namespace libtorrent void get_downloaders(std::vector& d, int index) const; - const std::vector& get_download_queue() const + std::vector const& get_download_queue() const { return m_downloads; } boost::optional get_downloader(piece_block block) const; diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index f35a3a195..22d3e8c1b 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1127,8 +1127,11 @@ namespace libtorrent assert(verified); t->completed(); } - } + +#ifndef NDEBUG + t->check_invariant(); +#endif } // ----------------------------- diff --git a/src/torrent.cpp b/src/torrent.cpp index 4283ae269..32e21a1f8 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -979,6 +979,13 @@ namespace libtorrent p->second->received_valid_data(index); } + if (!m_have_pieces[index]) + m_num_pieces++; + m_have_pieces[index] = true; + + assert(std::accumulate(m_have_pieces.begin(), m_have_pieces.end(), 0) + == m_num_pieces); + m_picker->we_have(index); for (peer_iterator i = m_connections.begin(); i != m_connections.end(); ++i) i->second->announce_piece(index); @@ -2151,13 +2158,6 @@ namespace libtorrent if (m_torrent_file.hash_for_piece(piece_index) != digest) return false; - if (!m_have_pieces[piece_index]) - m_num_pieces++; - m_have_pieces[piece_index] = true; - - assert(std::accumulate(m_have_pieces.begin(), m_have_pieces.end(), 0) - == m_num_pieces); - return true; } diff --git a/src/web_peer_connection.cpp b/src/web_peer_connection.cpp index cf1be6a59..2dd1f43bc 100755 --- a/src/web_peer_connection.cpp +++ b/src/web_peer_connection.cpp @@ -395,17 +395,15 @@ namespace libtorrent int copy_size = std::min(front_request.length - int(m_piece.size()) , http_body.left()); std::copy(http_body.begin, http_body.begin + copy_size, std::back_inserter(m_piece)); + assert(int(m_piece.size() <= front_request.length)); http_body.begin += copy_size; - if (int(m_piece.size()) == front_request.length) - { - m_requests.pop_front(); - incoming_piece(front_request, &m_piece[0]); - m_piece.clear(); - } - else - { + int piece_size = int(m_piece.size()); + if (piece_size < front_request.length) return; - } + + m_requests.pop_front(); + incoming_piece(front_request, &m_piece[0]); + m_piece.clear(); } // report all received blocks to the bittorrent engine @@ -485,10 +483,6 @@ namespace libtorrent } } - // -------------------------- - // SEND DATA - // -------------------------- - void web_peer_connection::get_peer_info(peer_info& p) const { assert(!associated_torrent().expired());