mirror of
https://github.com/transmission/transmission
synced 2024-12-22 07:42:37 +00:00
feat: download first and last piece first in sequential mode (#6893)
* feat: download first and last piece first in sequential mode * test: fix tests
This commit is contained in:
parent
b4bbc8744e
commit
b3912fa1a5
2 changed files with 27 additions and 6 deletions
|
@ -351,7 +351,26 @@ private:
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto const salt = is_sequential ? piece : salter();
|
auto const salt = [&]()
|
||||||
|
{
|
||||||
|
if (!is_sequential)
|
||||||
|
{
|
||||||
|
return salter();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Download first and last piece first
|
||||||
|
if (piece == 0U)
|
||||||
|
{
|
||||||
|
return 0U;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (piece == n_pieces - 1U)
|
||||||
|
{
|
||||||
|
return 1U;
|
||||||
|
}
|
||||||
|
|
||||||
|
return piece + 1U;
|
||||||
|
}();
|
||||||
candidates_.emplace_back(piece, salt, &mediator_);
|
candidates_.emplace_back(piece, salt, &mediator_);
|
||||||
}
|
}
|
||||||
std::sort(std::begin(candidates_), std::end(candidates_));
|
std::sort(std::begin(candidates_), std::end(candidates_));
|
||||||
|
|
|
@ -1511,7 +1511,8 @@ TEST_F(PeerMgrWishlistTest, settingSequentialDownloadRebuildsWishlist)
|
||||||
return wishlist.next(n_wanted, PeerHasAllPieces, ClientHasNoActiveRequests);
|
return wishlist.next(n_wanted, PeerHasAllPieces, ClientHasNoActiveRequests);
|
||||||
};
|
};
|
||||||
|
|
||||||
// we should get pieces in order when we ask for blocks
|
// we should get pieces in sequential order when we ask for blocks,
|
||||||
|
// except the last piece should follow immediately after the first piece
|
||||||
// NB: when all other things are equal in the wishlist, pieces are
|
// NB: when all other things are equal in the wishlist, pieces are
|
||||||
// picked at random so this test -could- pass even if there's a bug.
|
// picked at random so this test -could- pass even if there's a bug.
|
||||||
// So test several times to shake out any randomness
|
// So test several times to shake out any randomness
|
||||||
|
@ -1526,8 +1527,8 @@ TEST_F(PeerMgrWishlistTest, settingSequentialDownloadRebuildsWishlist)
|
||||||
}
|
}
|
||||||
EXPECT_EQ(150U, requested.count());
|
EXPECT_EQ(150U, requested.count());
|
||||||
EXPECT_EQ(100U, requested.count(0, 100));
|
EXPECT_EQ(100U, requested.count(0, 100));
|
||||||
EXPECT_EQ(50U, requested.count(100, 200));
|
EXPECT_EQ(0U, requested.count(100, 200));
|
||||||
EXPECT_EQ(0U, requested.count(200, 300));
|
EXPECT_EQ(50U, requested.count(200, 300));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Same premise as previous test, but ask for more blocks.
|
// Same premise as previous test, but ask for more blocks.
|
||||||
|
@ -1540,7 +1541,8 @@ TEST_F(PeerMgrWishlistTest, settingSequentialDownloadRebuildsWishlist)
|
||||||
requested.set_span(span.begin, span.end);
|
requested.set_span(span.begin, span.end);
|
||||||
}
|
}
|
||||||
EXPECT_EQ(250U, requested.count());
|
EXPECT_EQ(250U, requested.count());
|
||||||
EXPECT_EQ(200U, requested.count(0, 200));
|
EXPECT_EQ(100U, requested.count(0, 100));
|
||||||
EXPECT_EQ(50U, requested.count(200, 300));
|
EXPECT_EQ(50U, requested.count(100, 200));
|
||||||
|
EXPECT_EQ(100U, requested.count(200, 300));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue