diff --git a/src/piece_picker.cpp b/src/piece_picker.cpp index 5f612c114..b941b4b5e 100755 --- a/src/piece_picker.cpp +++ b/src/piece_picker.cpp @@ -1023,12 +1023,11 @@ namespace libtorrent piece_pos& p = m_piece_map[block.piece_index]; int prio = p.priority(m_sequenced_download_threshold); - if (prio == 0) return; if (p.downloading == 0) { p.downloading = 1; - move(prio, p.index); + if (prio > 0) move(prio, p.index); downloading_piece dp; dp.index = block.piece_index; diff --git a/test/test_piece_picker.cpp b/test/test_piece_picker.cpp index a11442cbe..f24038ee4 100644 --- a/test/test_piece_picker.cpp +++ b/test/test_piece_picker.cpp @@ -26,25 +26,27 @@ int test_main() unfinished.push_back(partial); p.files_checked(have, unfinished); + TEST_CHECK(p.is_downloading(piece_block(1, 0))); + TEST_CHECK(p.is_downloading(piece_block(1, 2))); - p.mark_as_filtered(4); + p.set_piece_priority(4, 0); - TEST_CHECK(p.is_filtered(4) == true); - TEST_CHECK(p.is_filtered(3) == false); + TEST_CHECK(p.piece_priority(4) == 0); + TEST_CHECK(p.piece_priority(3) == 1); - p.mark_as_filtered(3); - TEST_CHECK(p.is_filtered(3) == true); - p.mark_as_unfiltered(3); - TEST_CHECK(p.is_filtered(3) == false); + p.set_piece_priority(3, 0); + TEST_CHECK(p.piece_priority(3) == 0); + p.set_piece_priority(3, 1); + TEST_CHECK(p.piece_priority(3) == 1); TEST_CHECK(p.num_filtered() == 1); TEST_CHECK(p.num_have_filtered() == 0); - std::vector filtered_pieces; - p.filtered_pieces(filtered_pieces); - bool expected1[] = {false, false, false, false, true, false}; - TEST_CHECK(std::equal(filtered_pieces.begin() - , filtered_pieces.end(), expected1)); + std::vector piece_priorities; + p.piece_priorities(piece_priorities); + int expected1[] = {1, 1, 1, 1, 0, 1}; + TEST_CHECK(std::equal(piece_priorities.begin() + , piece_priorities.end(), expected1)); std::vector peer1(num_pieces, false); std::vector peer2(num_pieces, false); @@ -106,12 +108,8 @@ int test_main() // now, if all peers would have piece 1 (the piece we have partially) // it should be prioritized over picking a completely new piece. - peer1[1] = true; - peer2[1] = true; peer3[1] = true; p.inc_refcount(1); - p.inc_refcount(1); - p.inc_refcount(1); picked.clear(); p.pick_pieces(peer3, picked, 1, false, tcp::endpoint()); @@ -201,7 +199,7 @@ int test_main() picked.clear(); p.pick_pieces(peer1, picked, 100, true, tcp::endpoint()); - TEST_CHECK(picked.size() == 14); + TEST_CHECK(picked.size() == 12); piece_block expected5[] = { @@ -211,7 +209,6 @@ int test_main() , piece_block(5, 2), piece_block(5, 3) , piece_block(2, 0), piece_block(2, 1) , piece_block(2, 2), piece_block(2, 3) - , piece_block(1, 1), piece_block(1, 3) }; TEST_CHECK(std::equal(picked.begin()