tweak heuristic of how to interpret url seeds in multi-file torrents

This commit is contained in:
arvidn 2018-12-10 14:15:29 +01:00 committed by Arvid Norberg
parent 0413ee581a
commit 6debd872de
4 changed files with 33 additions and 25 deletions

View File

@ -1,5 +1,6 @@
1.2 release 1.2 release
* tweak heuristic of how to interpret url seeds in multi-file torrents
* support &ipv4= tracker argument for private torrents * support &ipv4= tracker argument for private torrents
* renamed debug_notification to connect_notification * renamed debug_notification to connect_notification
* when updating listen sockets, only post alerts for new ones * when updating listen sockets, only post alerts for new ones

View File

@ -1377,7 +1377,7 @@ namespace {
{ {
web_seed_entry ent(maybe_url_encode(url_seeds.string_value().to_string()) web_seed_entry ent(maybe_url_encode(url_seeds.string_value().to_string())
, web_seed_entry::url_seed); , web_seed_entry::url_seed);
if (m_flags & multifile) if ((m_flags & multifile) && num_files() > 1)
ensure_trailing_slash(ent.url); ensure_trailing_slash(ent.url);
m_web_seeds.push_back(ent); m_web_seeds.push_back(ent);
} }
@ -1392,7 +1392,7 @@ namespace {
if (url.string_length() == 0) continue; if (url.string_length() == 0) continue;
web_seed_entry ent(maybe_url_encode(url.string_value().to_string()) web_seed_entry ent(maybe_url_encode(url.string_value().to_string())
, web_seed_entry::url_seed); , web_seed_entry::url_seed);
if (m_flags & multifile) if ((m_flags & multifile) && num_files() > 1)
ensure_trailing_slash(ent.url); ensure_trailing_slash(ent.url);
if (!unique.insert(ent.url).second) continue; if (!unique.insert(ent.url).second) continue;
m_web_seeds.push_back(ent); m_web_seeds.push_back(ent);

View File

@ -117,6 +117,7 @@ static test_torrent_t test_torrents[] =
{ "no_creation_date.torrent" }, { "no_creation_date.torrent" },
{ "url_seed.torrent" }, { "url_seed.torrent" },
{ "url_seed_multi.torrent" }, { "url_seed_multi.torrent" },
{ "url_seed_multi_single_file.torrent" },
{ "url_seed_multi_space.torrent" }, { "url_seed_multi_space.torrent" },
{ "url_seed_multi_space_nolist.torrent" }, { "url_seed_multi_space_nolist.torrent" },
{ "root_hash.torrent" }, { "root_hash.torrent" },
@ -699,50 +700,50 @@ TORRENT_TEST(parse_torrents)
TEST_EQUAL(ti3.name(), "test2..test3.......test4"); TEST_EQUAL(ti3.name(), "test2..test3.......test4");
std::string root_dir = parent_path(current_working_directory()); std::string root_dir = parent_path(current_working_directory());
for (int i = 0; i < int(sizeof(test_torrents)/sizeof(test_torrents[0])); ++i) for (auto const t : test_torrents)
{ {
std::printf("loading %s\n", test_torrents[i].file); std::printf("loading %s\n", t.file);
std::string filename = combine_path(combine_path(root_dir, "test_torrents") std::string filename = combine_path(combine_path(root_dir, "test_torrents")
, test_torrents[i].file); , t.file);
error_code ec; error_code ec;
auto ti = std::make_shared<torrent_info>(filename, ec); auto ti = std::make_shared<torrent_info>(filename, ec);
TEST_CHECK(!ec); TEST_CHECK(!ec);
if (ec) std::printf(" loading(\"%s\") -> failed %s\n", filename.c_str() if (ec) std::printf(" loading(\"%s\") -> failed %s\n", filename.c_str()
, ec.message().c_str()); , ec.message().c_str());
if (std::string(test_torrents[i].file) == "whitespace_url.torrent") if (t.file == "whitespace_url.torrent"_sv)
{ {
// make sure we trimmed the url // make sure we trimmed the url
TEST_CHECK(ti->trackers().size() > 0); TEST_CHECK(ti->trackers().size() > 0);
if (ti->trackers().size() > 0) if (ti->trackers().size() > 0)
TEST_CHECK(ti->trackers()[0].url == "udp://test.com/announce"); TEST_CHECK(ti->trackers()[0].url == "udp://test.com/announce");
} }
else if (std::string(test_torrents[i].file) == "duplicate_files.torrent") else if (t.file == "duplicate_files.torrent"_sv)
{ {
// make sure we disambiguated the files // make sure we disambiguated the files
TEST_EQUAL(ti->num_files(), 2); TEST_EQUAL(ti->num_files(), 2);
TEST_CHECK(ti->files().file_path(file_index_t{0}) == combine_path(combine_path("temp", "foo"), "bar.txt")); TEST_CHECK(ti->files().file_path(file_index_t{0}) == combine_path(combine_path("temp", "foo"), "bar.txt"));
TEST_CHECK(ti->files().file_path(file_index_t{1}) == combine_path(combine_path("temp", "foo"), "bar.1.txt")); TEST_CHECK(ti->files().file_path(file_index_t{1}) == combine_path(combine_path("temp", "foo"), "bar.1.txt"));
} }
else if (std::string(test_torrents[i].file) == "pad_file.torrent") else if (t.file == "pad_file.torrent"_sv)
{ {
TEST_EQUAL(ti->num_files(), 2); TEST_EQUAL(ti->num_files(), 2);
TEST_EQUAL(bool(ti->files().file_flags(file_index_t{0}) & file_storage::flag_pad_file), false); TEST_EQUAL(bool(ti->files().file_flags(file_index_t{0}) & file_storage::flag_pad_file), false);
TEST_EQUAL(bool(ti->files().file_flags(file_index_t{1}) & file_storage::flag_pad_file), true); TEST_EQUAL(bool(ti->files().file_flags(file_index_t{1}) & file_storage::flag_pad_file), true);
} }
else if (std::string(test_torrents[i].file) == "creation_date.torrent") else if (t.file == "creation_date.torrent"_sv)
{ {
TEST_EQUAL(ti->creation_date(), 1234567); TEST_EQUAL(ti->creation_date(), 1234567);
} }
else if (std::string(test_torrents[i].file) == "duplicate_web_seeds.torrent") else if (t.file == "duplicate_web_seeds.torrent"_sv)
{ {
TEST_EQUAL(ti->web_seeds().size(), 3); TEST_EQUAL(ti->web_seeds().size(), 3);
} }
else if (std::string(test_torrents[i].file) == "no_creation_date.torrent") else if (t.file == "no_creation_date.torrent"_sv)
{ {
TEST_CHECK(!ti->creation_date()); TEST_CHECK(!ti->creation_date());
} }
else if (std::string(test_torrents[i].file) == "url_seed.torrent") else if (t.file == "url_seed.torrent"_sv)
{ {
TEST_EQUAL(ti->web_seeds().size(), 1); TEST_EQUAL(ti->web_seeds().size(), 1);
TEST_EQUAL(ti->web_seeds()[0].url, "http://test.com/file"); TEST_EQUAL(ti->web_seeds()[0].url, "http://test.com/file");
@ -752,7 +753,7 @@ TORRENT_TEST(parse_torrents)
TEST_EQUAL(ti->url_seeds()[0], "http://test.com/file"); TEST_EQUAL(ti->url_seeds()[0], "http://test.com/file");
#endif #endif
} }
else if (std::string(test_torrents[i].file) == "url_seed_multi.torrent") else if (t.file == "url_seed_multi.torrent"_sv)
{ {
TEST_EQUAL(ti->web_seeds().size(), 1); TEST_EQUAL(ti->web_seeds().size(), 1);
TEST_EQUAL(ti->web_seeds()[0].url, "http://test.com/file/"); TEST_EQUAL(ti->web_seeds()[0].url, "http://test.com/file/");
@ -762,8 +763,13 @@ TORRENT_TEST(parse_torrents)
TEST_EQUAL(ti->url_seeds()[0], "http://test.com/file/"); TEST_EQUAL(ti->url_seeds()[0], "http://test.com/file/");
#endif #endif
} }
else if (std::string(test_torrents[i].file) == "url_seed_multi_space.torrent" else if (t.file == "url_seed_multi_single_file.torrent"_sv)
|| std::string(test_torrents[i].file) == "url_seed_multi_space_nolist.torrent") {
TEST_EQUAL(ti->web_seeds().size(), 1);
TEST_EQUAL(ti->web_seeds()[0].url, "http://test.com/file/temp/foo/bar.txt");
}
else if (t.file == "url_seed_multi_space.torrent"_sv
|| t.file == "url_seed_multi_space_nolist.torrent"_sv)
{ {
TEST_EQUAL(ti->web_seeds().size(), 1); TEST_EQUAL(ti->web_seeds().size(), 1);
TEST_EQUAL(ti->web_seeds()[0].url, "http://test.com/test%20file/foo%20bar/"); TEST_EQUAL(ti->web_seeds()[0].url, "http://test.com/test%20file/foo%20bar/");
@ -773,14 +779,14 @@ TORRENT_TEST(parse_torrents)
TEST_EQUAL(ti->url_seeds()[0], "http://test.com/test%20file/foo%20bar/"); TEST_EQUAL(ti->url_seeds()[0], "http://test.com/test%20file/foo%20bar/");
#endif #endif
} }
else if (std::string(test_torrents[i].file) == "invalid_name2.torrent") else if (t.file == "invalid_name2.torrent"_sv)
{ {
// if, after all invalid characters are removed from the name, it ends up // if, after all invalid characters are removed from the name, it ends up
// being empty, it's set to the info-hash. Some torrents also have an empty name // being empty, it's set to the info-hash. Some torrents also have an empty name
// in which case it's also set to the info-hash // in which case it's also set to the info-hash
TEST_EQUAL(ti->name(), "b61560c2918f463768cd122b6d2fdd47b77bdb35"); TEST_EQUAL(ti->name(), "b61560c2918f463768cd122b6d2fdd47b77bdb35");
} }
else if (std::string(test_torrents[i].file) == "invalid_name3.torrent") else if (t.file == "invalid_name3.torrent"_sv)
{ {
// windows does not allow trailing spaces in filenames // windows does not allow trailing spaces in filenames
#ifdef TORRENT_WINDOWS #ifdef TORRENT_WINDOWS
@ -789,42 +795,42 @@ TORRENT_TEST(parse_torrents)
TEST_EQUAL(ti->name(), "foobar "); TEST_EQUAL(ti->name(), "foobar ");
#endif #endif
} }
else if (std::string(test_torrents[i].file) == "slash_path.torrent") else if (t.file == "slash_path.torrent"_sv)
{ {
TEST_EQUAL(ti->num_files(), 1); TEST_EQUAL(ti->num_files(), 1);
TEST_EQUAL(ti->files().file_path(file_index_t{0}), "temp" SEPARATOR "bar"); TEST_EQUAL(ti->files().file_path(file_index_t{0}), "temp" SEPARATOR "bar");
} }
else if (std::string(test_torrents[i].file) == "slash_path2.torrent") else if (t.file == "slash_path2.torrent"_sv)
{ {
TEST_EQUAL(ti->num_files(), 1); TEST_EQUAL(ti->num_files(), 1);
TEST_EQUAL(ti->files().file_path(file_index_t{0}), "temp" SEPARATOR "abc....def" SEPARATOR "bar"); TEST_EQUAL(ti->files().file_path(file_index_t{0}), "temp" SEPARATOR "abc....def" SEPARATOR "bar");
} }
else if (std::string(test_torrents[i].file) == "slash_path3.torrent") else if (t.file == "slash_path3.torrent"_sv)
{ {
TEST_EQUAL(ti->num_files(), 1); TEST_EQUAL(ti->num_files(), 1);
TEST_EQUAL(ti->files().file_path(file_index_t{0}), "temp....abc"); TEST_EQUAL(ti->files().file_path(file_index_t{0}), "temp....abc");
} }
else if (std::string(test_torrents[i].file) == "symlink_zero_size.torrent") else if (t.file == "symlink_zero_size.torrent"_sv)
{ {
TEST_EQUAL(ti->num_files(), 2); TEST_EQUAL(ti->num_files(), 2);
TEST_EQUAL(ti->files().symlink(file_index_t(1)), combine_path("foo", "bar")); TEST_EQUAL(ti->files().symlink(file_index_t(1)), combine_path("foo", "bar"));
} }
else if (std::string(test_torrents[i].file) == "pad_file_no_path.torrent") else if (t.file == "pad_file_no_path.torrent"_sv)
{ {
TEST_EQUAL(ti->num_files(), 2); TEST_EQUAL(ti->num_files(), 2);
TEST_EQUAL(ti->files().file_path(file_index_t{1}), combine_path(".pad", "0")); TEST_EQUAL(ti->files().file_path(file_index_t{1}), combine_path(".pad", "0"));
} }
else if (std::string(test_torrents[i].file) == "absolute_filename.torrent") else if (t.file == "absolute_filename.torrent"_sv)
{ {
TEST_EQUAL(ti->num_files(), 2); TEST_EQUAL(ti->num_files(), 2);
TEST_EQUAL(ti->files().file_path(file_index_t{0}), combine_path("temp", "abcde")); TEST_EQUAL(ti->files().file_path(file_index_t{0}), combine_path("temp", "abcde"));
TEST_EQUAL(ti->files().file_path(file_index_t{1}), combine_path("temp", "foobar")); TEST_EQUAL(ti->files().file_path(file_index_t{1}), combine_path("temp", "foobar"));
} }
else if (std::string(test_torrents[i].file) == "invalid_filename.torrent") else if (t.file == "invalid_filename.torrent"_sv)
{ {
TEST_EQUAL(ti->num_files(), 2); TEST_EQUAL(ti->num_files(), 2);
} }
else if (std::string(test_torrents[i].file) == "invalid_filename2.torrent") else if (t.file == "invalid_filename2.torrent"_sv)
{ {
TEST_EQUAL(ti->num_files(), 3); TEST_EQUAL(ti->num_files(), 3);
} }

View File

@ -0,0 +1 @@
d10:created by10:libtorrent13:creation datei1359599503e4:infod5:filesld6:lengthi425e4:pathl3:foo7:bar.txteee4:name4:temp12:piece lengthi16384e6:pieces20:‚ž¼Œ&¾ÇJW}ÜA4u,·¼‡e8:url-listl37:http://test.com/file/temp/foo/bar.txtee