forked from premiere/premiere-libtorrent
add switch to create pad files in test torrents in connection-tester
This commit is contained in:
parent
5b83085406
commit
cc93f8f3a7
|
@ -726,6 +726,8 @@ void print_usage()
|
|||
" options for this command:\n"
|
||||
" -s <size> the size of the torrent in megabytes\n"
|
||||
" -n <num-files> the number of files in the test torrent\n"
|
||||
" -a introduce a lot of pad-files\n"
|
||||
" (pad files are not supported for gen-data or upload)\n"
|
||||
" -t <file> the file to save the .torrent file to\n"
|
||||
" -T <name> the name of the torrent (and directory\n"
|
||||
" its files are saved in)\n\n"
|
||||
|
@ -775,13 +777,12 @@ void hasher_thread(libtorrent::create_torrent* t, int start_piece, int end_piece
|
|||
}
|
||||
|
||||
// size is in megabytes
|
||||
void generate_torrent(std::vector<char>& buf, int size, int num_files
|
||||
, char const* torrent_name)
|
||||
void generate_torrent(std::vector<char>& buf, int num_pieces, int num_files
|
||||
, char const* torrent_name, bool with_padding)
|
||||
{
|
||||
file_storage fs;
|
||||
// 1 MiB piece size
|
||||
const int piece_size = 1024 * 1024;
|
||||
const int num_pieces = size;
|
||||
const boost::int64_t total_size = boost::int64_t(piece_size) * num_pieces;
|
||||
|
||||
boost::int64_t s = total_size;
|
||||
|
@ -797,8 +798,9 @@ void generate_torrent(std::vector<char>& buf, int size, int num_files
|
|||
file_size += 200;
|
||||
}
|
||||
|
||||
// fs.add_file("stress_test_file", total_size);
|
||||
libtorrent::create_torrent t(fs, piece_size);
|
||||
libtorrent::create_torrent t(fs, piece_size, with_padding ? 100 : -1);
|
||||
|
||||
num_pieces = t.num_pieces();
|
||||
|
||||
// generate the hashes in 4 threads
|
||||
thread t1(boost::bind(&hasher_thread, &t, 0, 1 * num_pieces / 4, piece_size, false));
|
||||
|
@ -872,6 +874,7 @@ int main(int argc, char* argv[])
|
|||
char const* destination_ip = "127.0.0.1";
|
||||
int destination_port = 6881;
|
||||
int churn = 0;
|
||||
bool gen_pad_files = false;
|
||||
|
||||
argv += 2;
|
||||
argc -= 2;
|
||||
|
@ -892,6 +895,7 @@ int main(int argc, char* argv[])
|
|||
switch (optname[1])
|
||||
{
|
||||
case 'C': test_corruption = true; continue;
|
||||
case 'a': gen_pad_files = true; continue;
|
||||
}
|
||||
|
||||
if (argc == 0)
|
||||
|
@ -926,7 +930,7 @@ int main(int argc, char* argv[])
|
|||
name = name.substr(0, name.find_last_of('.'));
|
||||
printf("generating torrent: %s\n", name.c_str());
|
||||
generate_torrent(tmp, size ? size : 1024, num_files ? num_files : 1
|
||||
, name.c_str());
|
||||
, name.c_str(), gen_pad_files);
|
||||
|
||||
FILE* output = stdout;
|
||||
if (strcmp("-", torrent_file) != 0)
|
||||
|
|
|
@ -151,7 +151,7 @@ namespace libtorrent
|
|||
// be a multiple of 16 kiB. If a piece size of 0 is specified, a
|
||||
// piece_size will be calculated such that the torrent file is roughly 40 kB.
|
||||
//
|
||||
// If a ``pad_size_limit`` is specified (other than -1), any file larger than
|
||||
// If a ``pad_file_limit`` is specified (other than -1), any file larger than
|
||||
// the specified number of bytes will be preceded by a pad file to align it
|
||||
// with the start of a piece. The pad_file_limit is ignored unless the
|
||||
// ``optimize_alignment`` flag is passed. Typically it doesn't make sense
|
||||
|
|
Loading…
Reference in New Issue