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:
@@ -651,6 +651,7 @@ int poll_interval = 5;
|
|||||||
int max_connections_per_torrent = 50;
|
int max_connections_per_torrent = 50;
|
||||||
|
|
||||||
bool share_mode = false;
|
bool share_mode = false;
|
||||||
|
bool disable_storage = false;
|
||||||
|
|
||||||
using boost::bind;
|
using boost::bind;
|
||||||
|
|
||||||
@@ -683,6 +684,7 @@ void add_torrent(libtorrent::session& ses
|
|||||||
printf("%s\n", t->name().c_str());
|
printf("%s\n", t->name().c_str());
|
||||||
|
|
||||||
add_torrent_params p;
|
add_torrent_params p;
|
||||||
|
if (disable_storage) p.storage = disabled_storage_constructor;
|
||||||
p.share_mode = share_mode;
|
p.share_mode = share_mode;
|
||||||
lazy_entry resume_data;
|
lazy_entry resume_data;
|
||||||
|
|
||||||
@@ -1034,6 +1036,7 @@ int main(int argc, char* argv[])
|
|||||||
" -O Disallow disk job reordering\n"
|
" -O Disallow disk job reordering\n"
|
||||||
" -j disable disk read-ahead\n"
|
" -j disable disk read-ahead\n"
|
||||||
" -z disable piece hash checks (used for benchmarking)\n"
|
" -z disable piece hash checks (used for benchmarking)\n"
|
||||||
|
" -0 disable disk I/O, read garbage and don't flush to disk\n"
|
||||||
"\n\n"
|
"\n\n"
|
||||||
"TORRENT is a path to a .torrent file\n"
|
"TORRENT is a path to a .torrent file\n"
|
||||||
"MAGNETURL is a magnet link\n"
|
"MAGNETURL is a magnet link\n"
|
||||||
@@ -1110,6 +1113,7 @@ int main(int argc, char* argv[])
|
|||||||
from_hex(argv[i], 40, (char*)&info_hash[0]);
|
from_hex(argv[i], 40, (char*)&info_hash[0]);
|
||||||
|
|
||||||
add_torrent_params p;
|
add_torrent_params p;
|
||||||
|
if (disable_storage) p.storage = disabled_storage_constructor;
|
||||||
p.share_mode = share_mode;
|
p.share_mode = share_mode;
|
||||||
p.tracker_url = argv[i] + 41;
|
p.tracker_url = argv[i] + 41;
|
||||||
p.info_hash = info_hash;
|
p.info_hash = info_hash;
|
||||||
@@ -1253,6 +1257,7 @@ int main(int argc, char* argv[])
|
|||||||
settings.active_limit = (std::max)(atoi(arg) * 2, settings.active_limit);
|
settings.active_limit = (std::max)(atoi(arg) * 2, settings.active_limit);
|
||||||
break;
|
break;
|
||||||
case 'q': loop_limit = atoi(arg); break;
|
case 'q': loop_limit = atoi(arg); break;
|
||||||
|
case '0': disable_storage = true; --i;
|
||||||
}
|
}
|
||||||
++i; // skip the argument
|
++i; // skip the argument
|
||||||
}
|
}
|
||||||
@@ -1330,6 +1335,7 @@ int main(int argc, char* argv[])
|
|||||||
|| std::strstr(i->c_str(), "magnet:") == i->c_str())
|
|| std::strstr(i->c_str(), "magnet:") == i->c_str())
|
||||||
{
|
{
|
||||||
add_torrent_params p;
|
add_torrent_params p;
|
||||||
|
if (disable_storage) p.storage = disabled_storage_constructor;
|
||||||
p.share_mode = share_mode;
|
p.share_mode = share_mode;
|
||||||
p.save_path = save_path;
|
p.save_path = save_path;
|
||||||
p.storage_mode = (storage_mode_t)allocation_mode;
|
p.storage_mode = (storage_mode_t)allocation_mode;
|
||||||
|
@@ -356,8 +356,9 @@ void print_usage()
|
|||||||
fprintf(stderr, "usage: connection_tester command ...\n\n"
|
fprintf(stderr, "usage: connection_tester command ...\n\n"
|
||||||
"command is one of:\n"
|
"command is one of:\n"
|
||||||
" gen-torrent generate a test torrent\n"
|
" gen-torrent generate a test torrent\n"
|
||||||
" this command takes one extra argument, specifying the file to save\n"
|
" this command takes two extra arguments:\n"
|
||||||
" the .torrent file to\n\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"
|
" upload start an uploader test\n"
|
||||||
" download start a downloader test\n"
|
" download start a downloader test\n"
|
||||||
" dual start a download and upload 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"
|
" 3. destination-port - the port the target listens on\n"
|
||||||
" 4. torrent-file - the torrent file previously generated by gen-torrent\n\n"
|
" 4. torrent-file - the torrent file previously generated by gen-torrent\n\n"
|
||||||
"examples:\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 upload 200 127.0.0.1 6881 test.torrent\n"
|
||||||
"connection_tester download 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");
|
"connection_tester dual 200 127.0.0.1 6881 test.torrent\n");
|
||||||
exit(1);
|
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;
|
file_storage fs;
|
||||||
// 1 MiB piece size
|
// 1 MiB piece size
|
||||||
const int piece_size = 1024 * 1024;
|
const int piece_size = 1024 * 1024;
|
||||||
// 30 GiB should be enough to not fit in physical RAM
|
const int num_pieces = size;
|
||||||
const int num_pieces = 30 * 1024;
|
|
||||||
const size_type total_size = size_type(piece_size) * num_pieces;
|
const size_type total_size = size_type(piece_size) * num_pieces;
|
||||||
fs.add_file("stress_test_file", total_size);
|
fs.add_file("stress_test_file", total_size);
|
||||||
libtorrent::create_torrent t(fs, piece_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 (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;
|
std::vector<char> tmp;
|
||||||
generate_torrent(tmp);
|
generate_torrent(tmp, size ? size : 1024);
|
||||||
|
|
||||||
FILE* output = stdout;
|
FILE* output = stdout;
|
||||||
if (strcmp("-", argv[2]) != 0)
|
if (strcmp("-", argv[3]) != 0)
|
||||||
output = fopen(argv[2], "wb+");
|
output = fopen(argv[3], "wb+");
|
||||||
fwrite(&tmp[0], 1, tmp.size(), output);
|
fwrite(&tmp[0], 1, tmp.size(), output);
|
||||||
if (output != stdout)
|
if (output != stdout)
|
||||||
fclose(output);
|
fclose(output);
|
||||||
|
Reference in New Issue
Block a user