fixed piece picker and test
This commit is contained in:
parent
29e43d7f62
commit
bec03261f5
|
@ -1023,12 +1023,11 @@ namespace libtorrent
|
||||||
|
|
||||||
piece_pos& p = m_piece_map[block.piece_index];
|
piece_pos& p = m_piece_map[block.piece_index];
|
||||||
int prio = p.priority(m_sequenced_download_threshold);
|
int prio = p.priority(m_sequenced_download_threshold);
|
||||||
if (prio == 0) return;
|
|
||||||
|
|
||||||
if (p.downloading == 0)
|
if (p.downloading == 0)
|
||||||
{
|
{
|
||||||
p.downloading = 1;
|
p.downloading = 1;
|
||||||
move(prio, p.index);
|
if (prio > 0) move(prio, p.index);
|
||||||
|
|
||||||
downloading_piece dp;
|
downloading_piece dp;
|
||||||
dp.index = block.piece_index;
|
dp.index = block.piece_index;
|
||||||
|
|
|
@ -26,25 +26,27 @@ int test_main()
|
||||||
unfinished.push_back(partial);
|
unfinished.push_back(partial);
|
||||||
|
|
||||||
p.files_checked(have, unfinished);
|
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.piece_priority(4) == 0);
|
||||||
TEST_CHECK(p.is_filtered(3) == false);
|
TEST_CHECK(p.piece_priority(3) == 1);
|
||||||
|
|
||||||
p.mark_as_filtered(3);
|
p.set_piece_priority(3, 0);
|
||||||
TEST_CHECK(p.is_filtered(3) == true);
|
TEST_CHECK(p.piece_priority(3) == 0);
|
||||||
p.mark_as_unfiltered(3);
|
p.set_piece_priority(3, 1);
|
||||||
TEST_CHECK(p.is_filtered(3) == false);
|
TEST_CHECK(p.piece_priority(3) == 1);
|
||||||
|
|
||||||
TEST_CHECK(p.num_filtered() == 1);
|
TEST_CHECK(p.num_filtered() == 1);
|
||||||
TEST_CHECK(p.num_have_filtered() == 0);
|
TEST_CHECK(p.num_have_filtered() == 0);
|
||||||
|
|
||||||
std::vector<bool> filtered_pieces;
|
std::vector<int> piece_priorities;
|
||||||
p.filtered_pieces(filtered_pieces);
|
p.piece_priorities(piece_priorities);
|
||||||
bool expected1[] = {false, false, false, false, true, false};
|
int expected1[] = {1, 1, 1, 1, 0, 1};
|
||||||
TEST_CHECK(std::equal(filtered_pieces.begin()
|
TEST_CHECK(std::equal(piece_priorities.begin()
|
||||||
, filtered_pieces.end(), expected1));
|
, piece_priorities.end(), expected1));
|
||||||
|
|
||||||
std::vector<bool> peer1(num_pieces, false);
|
std::vector<bool> peer1(num_pieces, false);
|
||||||
std::vector<bool> peer2(num_pieces, false);
|
std::vector<bool> peer2(num_pieces, false);
|
||||||
|
@ -106,12 +108,8 @@ int test_main()
|
||||||
|
|
||||||
// now, if all peers would have piece 1 (the piece we have partially)
|
// now, if all peers would have piece 1 (the piece we have partially)
|
||||||
// it should be prioritized over picking a completely new piece.
|
// it should be prioritized over picking a completely new piece.
|
||||||
peer1[1] = true;
|
|
||||||
peer2[1] = true;
|
|
||||||
peer3[1] = true;
|
peer3[1] = true;
|
||||||
p.inc_refcount(1);
|
p.inc_refcount(1);
|
||||||
p.inc_refcount(1);
|
|
||||||
p.inc_refcount(1);
|
|
||||||
|
|
||||||
picked.clear();
|
picked.clear();
|
||||||
p.pick_pieces(peer3, picked, 1, false, tcp::endpoint());
|
p.pick_pieces(peer3, picked, 1, false, tcp::endpoint());
|
||||||
|
@ -201,7 +199,7 @@ int test_main()
|
||||||
picked.clear();
|
picked.clear();
|
||||||
p.pick_pieces(peer1, picked, 100, true, tcp::endpoint());
|
p.pick_pieces(peer1, picked, 100, true, tcp::endpoint());
|
||||||
|
|
||||||
TEST_CHECK(picked.size() == 14);
|
TEST_CHECK(picked.size() == 12);
|
||||||
|
|
||||||
piece_block expected5[] =
|
piece_block expected5[] =
|
||||||
{
|
{
|
||||||
|
@ -211,7 +209,6 @@ int test_main()
|
||||||
, piece_block(5, 2), piece_block(5, 3)
|
, piece_block(5, 2), piece_block(5, 3)
|
||||||
, piece_block(2, 0), piece_block(2, 1)
|
, piece_block(2, 0), piece_block(2, 1)
|
||||||
, piece_block(2, 2), piece_block(2, 3)
|
, piece_block(2, 2), piece_block(2, 3)
|
||||||
, piece_block(1, 1), piece_block(1, 3)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_CHECK(std::equal(picked.begin()
|
TEST_CHECK(std::equal(picked.begin()
|
||||||
|
|
Loading…
Reference in New Issue