From 1313e32954c90148ab57b58a793d9d075254c5c6 Mon Sep 17 00:00:00 2001 From: Daniel Wallin Date: Sun, 7 Dec 2003 15:03:06 +0000 Subject: [PATCH] fixed new storage --- src/storage.cpp | 20 +++++++++++++++++--- src/torrent.cpp | 5 +++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/storage.cpp b/src/storage.cpp index cf33217bc..cba9f3a71 100755 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -1635,16 +1635,22 @@ namespace libtorrent { &large_digest, &small_digest }; - bool found = false; + int found_piece = -1; for (int i = 0; i < m_info.num_pieces(); ++i) { + if (i > current_piece) + break; + if (pieces[i]) continue; const sha1_hash& hash = digest[ i == m_info.num_pieces() - 1]->get(); + if (hash == m_info.hash_for_piece(i)) + found_piece = i; +/* if (hash == m_info.hash_for_piece(i)) { m_bytes_left -= m_info.piece_size(i); @@ -1654,10 +1660,18 @@ namespace libtorrent { pieces[i] = true; found = true; break; - } + }*/ } - if (!found) + if (found_piece != -1) + { + m_bytes_left -= m_info.piece_size(found_piece); + + m_piece_to_slot[found_piece] = current_piece; + m_slot_to_piece[current_piece] = found_piece; + pieces[found_piece] = true; + } + else { m_slot_to_piece[current_piece] = -2; diff --git a/src/torrent.cpp b/src/torrent.cpp index f8a162781..b24ba7f5b 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -512,6 +512,11 @@ namespace libtorrent boost::mutex& mutex) { m_storage.check_pieces(mutex, data, m_have_pieces); + m_num_pieces = std::accumulate( + m_have_pieces.begin() + , m_have_pieces.end() + , 0); + m_picker.files_checked(m_have_pieces); #ifndef NDEBUG m_picker.integrity_check(this);