forked from premiere/premiere-libtorrent
extend connection_tester to allow building test torrents with any number of files
This commit is contained in:
parent
6a3ee5a7cf
commit
b69014f3cd
|
@ -536,7 +536,8 @@ void print_usage()
|
||||||
" gen-torrent generate a test torrent\n"
|
" gen-torrent generate a test torrent\n"
|
||||||
" this command takes two extra arguments:\n"
|
" this command takes two extra arguments:\n"
|
||||||
" 1. the size of the torrent in megabytes\n"
|
" 1. the size of the torrent in megabytes\n"
|
||||||
" 2. the file to save the .torrent file to\n\n"
|
" 2. the number of files in the test torrent\n"
|
||||||
|
" 3. the file to save the .torrent file to\n\n"
|
||||||
" gen-data generate the data file(s) for the test torrent\n"
|
" gen-data generate the data file(s) for the test torrent\n"
|
||||||
" this command takes two extra arguments:\n"
|
" this command takes two extra arguments:\n"
|
||||||
" 1. the torrent file that was previously generated\n"
|
" 1. the torrent file that was previously generated\n"
|
||||||
|
@ -554,7 +555,7 @@ 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 1024 test.torrent\n"
|
"connection_tester gen-torrent 1024 4 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");
|
||||||
|
@ -580,7 +581,7 @@ void hasher_thread(libtorrent::create_torrent* t, int start_piece, int end_piece
|
||||||
}
|
}
|
||||||
|
|
||||||
// size is in megabytes
|
// size is in megabytes
|
||||||
void generate_torrent(std::vector<char>& buf, int size)
|
void generate_torrent(std::vector<char>& buf, int size, int num_files)
|
||||||
{
|
{
|
||||||
file_storage fs;
|
file_storage fs;
|
||||||
// 1 MiB piece size
|
// 1 MiB piece size
|
||||||
|
@ -590,7 +591,7 @@ void generate_torrent(std::vector<char>& buf, int size)
|
||||||
|
|
||||||
size_type s = total_size;
|
size_type s = total_size;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
size_type file_size = total_size / 9;
|
size_type file_size = total_size / num_files;
|
||||||
while (s > 0)
|
while (s > 0)
|
||||||
{
|
{
|
||||||
char b[100];
|
char b[100];
|
||||||
|
@ -651,15 +652,16 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
if (strcmp(argv[1], "gen-torrent") == 0)
|
if (strcmp(argv[1], "gen-torrent") == 0)
|
||||||
{
|
{
|
||||||
if (argc != 4) print_usage();
|
if (argc != 5) print_usage();
|
||||||
|
|
||||||
int size = atoi(argv[2]);
|
int size = atoi(argv[2]);
|
||||||
|
int num_files = atoi(argv[3]);
|
||||||
std::vector<char> tmp;
|
std::vector<char> tmp;
|
||||||
generate_torrent(tmp, size ? size : 1024);
|
generate_torrent(tmp, size ? size : 1024, num_files ? num_files : 1);
|
||||||
|
|
||||||
FILE* output = stdout;
|
FILE* output = stdout;
|
||||||
if (strcmp("-", argv[3]) != 0)
|
if (strcmp("-", argv[4]) != 0)
|
||||||
output = fopen(argv[3], "wb+");
|
output = fopen(argv[4], "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);
|
||||||
|
|
Loading…
Reference in New Issue