extend tracker test to test announce_to_all_trackers and announce_to_all_tiers as well
This commit is contained in:
parent
bdee0b563c
commit
6d865f0c60
|
@ -1291,13 +1291,12 @@ TORRENT_TEST(tracker_user_agent_privacy_mode_private_torrent)
|
||||||
// the trackers at random and announces to it. Since both trackers are working,
|
// the trackers at random and announces to it. Since both trackers are working,
|
||||||
// it should not announce to the tracker it did not initially pick.
|
// it should not announce to the tracker it did not initially pick.
|
||||||
|
|
||||||
// #error parameterize this test over adding the trackers into different tiers
|
template <typename TestFun>
|
||||||
// and setting "announce_to_all_tiers"
|
void test_tracker_tiers(lt::settings_pack pack, TestFun test)
|
||||||
|
|
||||||
TORRENT_TEST(tracker_tiers)
|
|
||||||
{
|
{
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
|
|
||||||
|
pack.set_int(settings_pack::alert_mask, alert::error_notification | alert::torrent_log_notification);
|
||||||
char const* peer0_ip = "50.0.0.1";
|
char const* peer0_ip = "50.0.0.1";
|
||||||
char const* peer1_ip = "50.0.0.2";
|
char const* peer1_ip = "50.0.0.2";
|
||||||
|
|
||||||
|
@ -1313,32 +1312,31 @@ TORRENT_TEST(tracker_tiers)
|
||||||
|
|
||||||
sim::asio::io_service tracker1(sim, address_v4::from_string("3.0.0.1"));
|
sim::asio::io_service tracker1(sim, address_v4::from_string("3.0.0.1"));
|
||||||
sim::asio::io_service tracker2(sim, address_v4::from_string("3.0.0.2"));
|
sim::asio::io_service tracker2(sim, address_v4::from_string("3.0.0.2"));
|
||||||
|
sim::asio::io_service tracker3(sim, address_v4::from_string("3.0.0.3"));
|
||||||
|
sim::asio::io_service tracker4(sim, address_v4::from_string("3.0.0.4"));
|
||||||
sim::http_server http1(tracker1, 8080);
|
sim::http_server http1(tracker1, 8080);
|
||||||
sim::http_server http2(tracker2, 8080);
|
sim::http_server http2(tracker2, 8080);
|
||||||
|
sim::http_server http3(tracker3, 8080);
|
||||||
|
sim::http_server http4(tracker4, 8080);
|
||||||
|
|
||||||
bool received_announce[2] = {false, false};
|
bool received_announce[4] = {false, false, false, false};
|
||||||
http1.register_handler("/announce"
|
|
||||||
, [&](std::string method, std::string req
|
auto const return_no_peers = [&](std::string method, std::string req
|
||||||
, std::map<std::string, std::string>&)
|
, std::map<std::string, std::string>&, int const tracker_index)
|
||||||
{
|
{
|
||||||
received_announce[0] = true;
|
received_announce[tracker_index] = true;
|
||||||
std::string const ret = "d8:intervali60e5:peers0:e";
|
std::string const ret = "d8:intervali60e5:peers0:e";
|
||||||
return sim::send_response(200, "OK", static_cast<int>(ret.size())) + ret;
|
return sim::send_response(200, "OK", static_cast<int>(ret.size())) + ret;
|
||||||
});
|
};
|
||||||
|
|
||||||
http2.register_handler("/announce"
|
using namespace std::placeholders;
|
||||||
, [&](std::string method, std::string req
|
http1.register_handler("/announce", std::bind(return_no_peers, _1, _2, _3, 0));
|
||||||
, std::map<std::string, std::string>&)
|
http2.register_handler("/announce", std::bind(return_no_peers, _1, _2, _3, 1));
|
||||||
{
|
http3.register_handler("/announce", std::bind(return_no_peers, _1, _2, _3, 2));
|
||||||
received_announce[1] = true;
|
http4.register_handler("/announce", std::bind(return_no_peers, _1, _2, _3, 3));
|
||||||
std::string const ret = "d8:intervali60e5:peers0:e";
|
|
||||||
return sim::send_response(200, "OK", static_cast<int>(ret.size())) + ret;
|
|
||||||
});
|
|
||||||
|
|
||||||
lt::session_proxy zombie[2];
|
lt::session_proxy zombie[2];
|
||||||
|
|
||||||
// setup settings pack to use for the session (customization point)
|
|
||||||
lt::settings_pack pack = settings();
|
|
||||||
// create session
|
// create session
|
||||||
std::shared_ptr<lt::session> ses[2];
|
std::shared_ptr<lt::session> ses[2];
|
||||||
pack.set_str(settings_pack::listen_interfaces, peer0_ip + std::string(":6881"));
|
pack.set_str(settings_pack::listen_interfaces, peer0_ip + std::string(":6881"));
|
||||||
|
@ -1367,6 +1365,8 @@ TORRENT_TEST(tracker_tiers)
|
||||||
// random and stick to it, never announce to the other one.
|
// random and stick to it, never announce to the other one.
|
||||||
params.ti->add_tracker("http://3.0.0.1:8080/announce", 0);
|
params.ti->add_tracker("http://3.0.0.1:8080/announce", 0);
|
||||||
params.ti->add_tracker("http://3.0.0.2:8080/announce", 0);
|
params.ti->add_tracker("http://3.0.0.2:8080/announce", 0);
|
||||||
|
params.ti->add_tracker("http://3.0.0.3:8080/announce", 1);
|
||||||
|
params.ti->add_tracker("http://3.0.0.4:8080/announce", 1);
|
||||||
params.save_path = save_path(0);
|
params.save_path = save_path(0);
|
||||||
ses[0]->async_add_torrent(params);
|
ses[0]->async_add_torrent(params);
|
||||||
|
|
||||||
|
@ -1374,9 +1374,9 @@ TORRENT_TEST(tracker_tiers)
|
||||||
params.save_path = save_path(1);
|
params.save_path = save_path(1);
|
||||||
ses[1]->async_add_torrent(params);
|
ses[1]->async_add_torrent(params);
|
||||||
|
|
||||||
sim::timer t(sim, lt::minutes(30), [&](boost::system::error_code const&)
|
sim::timer t(sim, lt::seconds(30), [&](boost::system::error_code const&)
|
||||||
{
|
{
|
||||||
TEST_CHECK(received_announce[0] != received_announce[1]);
|
test(received_announce);
|
||||||
TEST_CHECK(ses[0]->get_torrents()[0].status().is_seeding);
|
TEST_CHECK(ses[0]->get_torrents()[0].status().is_seeding);
|
||||||
TEST_CHECK(ses[1]->get_torrents()[0].status().is_seeding);
|
TEST_CHECK(ses[1]->get_torrents()[0].status().is_seeding);
|
||||||
|
|
||||||
|
@ -1392,6 +1392,59 @@ TORRENT_TEST(tracker_tiers)
|
||||||
sim.run();
|
sim.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TORRENT_TEST(tracker_tiers)
|
||||||
|
{
|
||||||
|
settings_pack pack = settings();
|
||||||
|
pack.set_bool(settings_pack::announce_to_all_tiers, false);
|
||||||
|
pack.set_bool(settings_pack::announce_to_all_trackers, false);
|
||||||
|
// setup settings pack to use for the session (customization point)
|
||||||
|
test_tracker_tiers(pack, [](bool (&received_announce)[4]) {
|
||||||
|
TEST_CHECK(received_announce[0] != received_announce[1]);
|
||||||
|
TEST_EQUAL(received_announce[2], false);
|
||||||
|
TEST_EQUAL(received_announce[3], false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
TORRENT_TEST(tracker_tiers_all_trackers)
|
||||||
|
{
|
||||||
|
settings_pack pack = settings();
|
||||||
|
pack.set_bool(settings_pack::announce_to_all_tiers, false);
|
||||||
|
pack.set_bool(settings_pack::announce_to_all_trackers, true);
|
||||||
|
// setup settings pack to use for the session (customization point)
|
||||||
|
test_tracker_tiers(pack, [](bool (&received_announce)[4]) {
|
||||||
|
TEST_EQUAL(received_announce[0], true);
|
||||||
|
TEST_EQUAL(received_announce[1], true);
|
||||||
|
TEST_EQUAL(received_announce[2], false);
|
||||||
|
TEST_EQUAL(received_announce[3], false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
TORRENT_TEST(tracker_tiers_all_tiers)
|
||||||
|
{
|
||||||
|
settings_pack pack = settings();
|
||||||
|
pack.set_bool(settings_pack::announce_to_all_tiers, true);
|
||||||
|
pack.set_bool(settings_pack::announce_to_all_trackers, false);
|
||||||
|
// setup settings pack to use for the session (customization point)
|
||||||
|
test_tracker_tiers(pack, [](bool (&received_announce)[4]) {
|
||||||
|
TEST_CHECK(received_announce[0] != received_announce[1]);
|
||||||
|
TEST_CHECK(received_announce[2] != received_announce[3]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
TORRENT_TEST(tracker_tiers_all_trackers_and_tiers)
|
||||||
|
{
|
||||||
|
settings_pack pack = settings();
|
||||||
|
pack.set_bool(settings_pack::announce_to_all_tiers, true);
|
||||||
|
pack.set_bool(settings_pack::announce_to_all_trackers, true);
|
||||||
|
// setup settings pack to use for the session (customization point)
|
||||||
|
test_tracker_tiers(pack, [](bool (&received_announce)[4]) {
|
||||||
|
TEST_EQUAL(received_announce[0], true);
|
||||||
|
TEST_EQUAL(received_announce[1], true);
|
||||||
|
TEST_EQUAL(received_announce[2], true);
|
||||||
|
TEST_EQUAL(received_announce[3], true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: test external IP
|
// TODO: test external IP
|
||||||
// TODO: test with different queuing settings
|
// TODO: test with different queuing settings
|
||||||
// TODO: test when a torrent transitions from downloading to finished and
|
// TODO: test when a torrent transitions from downloading to finished and
|
||||||
|
|
Loading…
Reference in New Issue