fixed an assert in teh web seed downloader

This commit is contained in:
Arvid Norberg 2006-12-21 02:44:00 +00:00
parent ae4267e0a0
commit 1b46fb9e1b
4 changed files with 19 additions and 22 deletions

View File

@ -199,7 +199,7 @@ namespace libtorrent
void get_downloaders(std::vector<tcp::endpoint>& d, int index) const; void get_downloaders(std::vector<tcp::endpoint>& d, int index) const;
const std::vector<downloading_piece>& get_download_queue() const std::vector<downloading_piece> const& get_download_queue() const
{ return m_downloads; } { return m_downloads; }
boost::optional<tcp::endpoint> get_downloader(piece_block block) const; boost::optional<tcp::endpoint> get_downloader(piece_block block) const;

View File

@ -1127,8 +1127,11 @@ namespace libtorrent
assert(verified); assert(verified);
t->completed(); t->completed();
} }
} }
#ifndef NDEBUG
t->check_invariant();
#endif
} }
// ----------------------------- // -----------------------------

View File

@ -979,6 +979,13 @@ namespace libtorrent
p->second->received_valid_data(index); 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); m_picker->we_have(index);
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);
@ -2151,13 +2158,6 @@ namespace libtorrent
if (m_torrent_file.hash_for_piece(piece_index) != digest) if (m_torrent_file.hash_for_piece(piece_index) != digest)
return false; 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; return true;
} }

View File

@ -395,18 +395,16 @@ namespace libtorrent
int copy_size = std::min(front_request.length - int(m_piece.size()) int copy_size = std::min(front_request.length - int(m_piece.size())
, http_body.left()); , http_body.left());
std::copy(http_body.begin, http_body.begin + copy_size, std::back_inserter(m_piece)); 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; http_body.begin += copy_size;
if (int(m_piece.size()) == front_request.length) int piece_size = int(m_piece.size());
{ if (piece_size < front_request.length)
return;
m_requests.pop_front(); m_requests.pop_front();
incoming_piece(front_request, &m_piece[0]); incoming_piece(front_request, &m_piece[0]);
m_piece.clear(); m_piece.clear();
} }
else
{
return;
}
}
// report all received blocks to the bittorrent engine // report all received blocks to the bittorrent engine
while (!m_requests.empty() while (!m_requests.empty()
@ -485,10 +483,6 @@ namespace libtorrent
} }
} }
// --------------------------
// SEND DATA
// --------------------------
void web_peer_connection::get_peer_info(peer_info& p) const void web_peer_connection::get_peer_info(peer_info& p) const
{ {
assert(!associated_torrent().expired()); assert(!associated_torrent().expired());