raise auto piece size selection limit to 16 MB in create_torrent()

16 MB is chosen to have a bit more future proof
Also rewrite the auto piece size selection algorithm, so that it will scale with
torrent content size, suggested by @ssiloti.
This commit is contained in:
Chocobo1 2018-01-05 13:54:14 +08:00 committed by Arvid Norberg
parent 7141542591
commit 1877724c17
1 changed files with 11 additions and 7 deletions

View File

@ -332,16 +332,20 @@ namespace libtorrent
// a piece_size of 0 means automatic
if (piece_size == 0 && !m_merkle_torrent)
{
const int target_size = 40 * 1024;
piece_size = int(fs.total_size() / (target_size / 20));
// size_table is computed from the following:
// target_list_size = sqrt(total_size) * 2;
// target_piece_size = total_size / (target_list_size / hash_size);
// Given hash_size = 20 bytes, target_piece_size = (16*1024 * pow(2, i))
// we can determine size_table = (total_size = pow(2 * target_piece_size / hash_size, 2))
boost::int64_t const size_table[] = {2684355, 10737418, 42949673, 171798692, 687194767,
2748779069LL, 10995116278LL, 43980465111LL, 175921860444LL, 703687441777LL};
int i = 16*1024;
for (; i < 2*1024*1024; i *= 2)
int i = 0;
for (int max = sizeof(size_table) / sizeof(size_table[0]); i < max; ++i)
{
if (piece_size > i) continue;
break;
if (size_table[i] >= fs.total_size()) break;
}
piece_size = i;
piece_size = 0x4000 << i;
}
else if (piece_size == 0 && m_merkle_torrent)
{