make connection tester able to create variable sized torrents for more diverse testing. add option to client_test test to turn off disk storage

This commit is contained in:
Arvid Norberg
2011-07-10 20:17:32 +00:00
parent a609624d14
commit 1ed32d2758
2 changed files with 18 additions and 10 deletions

View File

@@ -356,8 +356,9 @@ void print_usage()
fprintf(stderr, "usage: connection_tester command ...\n\n"
"command is one of:\n"
" gen-torrent generate a test torrent\n"
" this command takes one extra argument, specifying the file to save\n"
" the .torrent file to\n\n"
" this command takes two extra arguments:\n"
" 1. the size of the torrent in megabytes\n"
" 2. the file to save the .torrent file to\n\n"
" upload start an uploader test\n"
" download start a downloader test\n"
" dual start a download and upload test\n"
@@ -367,20 +368,20 @@ void print_usage()
" 3. destination-port - the port the target listens on\n"
" 4. torrent-file - the torrent file previously generated by gen-torrent\n\n"
"examples:\n\n"
"connection_tester gen-torrent test.torrent\n"
"connection_tester gen-torrent 1024 test.torrent\n"
"connection_tester upload 200 127.0.0.1 6881 test.torrent\n"
"connection_tester download 200 127.0.0.1 6881 test.torrent\n"
"connection_tester dual 200 127.0.0.1 6881 test.torrent\n");
exit(1);
}
void generate_torrent(std::vector<char>& buf)
// size is in megabytes
void generate_torrent(std::vector<char>& buf, int size)
{
file_storage fs;
// 1 MiB piece size
const int piece_size = 1024 * 1024;
// 30 GiB should be enough to not fit in physical RAM
const int num_pieces = 30 * 1024;
const int num_pieces = size;
const size_type total_size = size_type(piece_size) * num_pieces;
fs.add_file("stress_test_file", total_size);
libtorrent::create_torrent t(fs, piece_size);
@@ -413,14 +414,15 @@ int main(int argc, char* argv[])
if (strcmp(argv[1], "gen-torrent") == 0)
{
if (argc != 3) print_usage();
if (argc != 4) print_usage();
int size = atoi(argv[2]);
std::vector<char> tmp;
generate_torrent(tmp);
generate_torrent(tmp, size ? size : 1024);
FILE* output = stdout;
if (strcmp("-", argv[2]) != 0)
output = fopen(argv[2], "wb+");
if (strcmp("-", argv[3]) != 0)
output = fopen(argv[3], "wb+");
fwrite(&tmp[0], 1, tmp.size(), output);
if (output != stdout)
fclose(output);