2013-09-30 00:50:06 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright (c) 2008-2013, Arvid Norberg
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in
|
|
|
|
the documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the author nor the names of its
|
|
|
|
contributors may be used to endorse or promote products derived
|
|
|
|
from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
2014-07-06 21:18:00 +02:00
|
|
|
|
2013-09-30 00:50:06 +02:00
|
|
|
#include "libtorrent/session.hpp"
|
|
|
|
#include "libtorrent/hasher.hpp"
|
|
|
|
#include "libtorrent/file_pool.hpp"
|
2017-04-11 06:52:46 +02:00
|
|
|
#include "libtorrent/aux_/path.hpp"
|
2013-09-30 00:50:06 +02:00
|
|
|
#include "libtorrent/storage.hpp"
|
|
|
|
#include "libtorrent/bencode.hpp"
|
|
|
|
#include "libtorrent/create_torrent.hpp"
|
|
|
|
#include "libtorrent/alert_types.hpp"
|
2015-09-18 06:23:45 +02:00
|
|
|
#include "libtorrent/torrent_info.hpp"
|
|
|
|
#include "libtorrent/announce_entry.hpp"
|
2017-03-18 17:19:49 +01:00
|
|
|
#include "libtorrent/string_view.hpp"
|
2013-09-30 00:50:06 +02:00
|
|
|
|
2014-09-01 10:59:12 +02:00
|
|
|
#include "test.hpp"
|
2013-10-01 18:47:05 +02:00
|
|
|
#include "setup_transfer.hpp"
|
2014-09-02 10:03:01 +02:00
|
|
|
#include "web_seed_suite.hpp"
|
2016-01-22 05:32:20 +01:00
|
|
|
#include "make_torrent.hpp"
|
2013-10-01 18:47:05 +02:00
|
|
|
|
2016-06-20 17:32:06 +02:00
|
|
|
#include <tuple>
|
2014-07-06 21:18:00 +02:00
|
|
|
#include <fstream>
|
|
|
|
#include "setup_transfer.hpp"
|
|
|
|
|
2013-09-30 00:50:06 +02:00
|
|
|
#include <iostream>
|
|
|
|
|
2017-04-12 20:05:53 +02:00
|
|
|
using namespace lt;
|
2013-09-30 00:50:06 +02:00
|
|
|
|
2015-07-16 07:38:48 +02:00
|
|
|
namespace {
|
|
|
|
|
2013-09-30 00:50:06 +02:00
|
|
|
int peer_disconnects = 0;
|
|
|
|
|
2015-04-03 22:15:48 +02:00
|
|
|
bool on_alert(alert const* a)
|
2013-09-30 00:50:06 +02:00
|
|
|
{
|
|
|
|
if (alert_cast<peer_disconnected_alert>(a))
|
|
|
|
++peer_disconnects;
|
|
|
|
else if (alert_cast<peer_error_alert>(a))
|
|
|
|
++peer_disconnects;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-01 06:10:03 +02:00
|
|
|
static char const* proxy_name[] = {"", "_socks4", "_socks5", "_socks5_pw", "_http", "_http_pw", "_i2p"};
|
|
|
|
|
2015-07-16 07:38:48 +02:00
|
|
|
} // anonymous namespace
|
|
|
|
|
2013-09-30 00:50:06 +02:00
|
|
|
// proxy: 0=none, 1=socks4, 2=socks5, 3=socks5_pw 4=http 5=http_pw
|
2016-08-17 23:26:35 +02:00
|
|
|
void test_transfer(lt::session& ses, std::shared_ptr<torrent_info> torrent_file
|
2016-06-19 01:24:27 +02:00
|
|
|
, int proxy, char const* protocol, bool url_seed
|
2015-10-03 17:20:10 +02:00
|
|
|
, bool chunked_encoding, bool test_ban, bool keepalive, bool proxy_peers)
|
2013-09-30 00:50:06 +02:00
|
|
|
{
|
2017-04-12 20:05:53 +02:00
|
|
|
using namespace lt;
|
2013-09-30 00:50:06 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
TORRENT_ASSERT(torrent_file->web_seeds().size() > 0);
|
|
|
|
|
2013-10-01 06:10:03 +02:00
|
|
|
std::string save_path = "tmp2_web_seed";
|
|
|
|
save_path += proxy_name[proxy];
|
|
|
|
|
2013-09-30 00:50:06 +02:00
|
|
|
error_code ec;
|
2013-10-01 06:10:03 +02:00
|
|
|
remove_all(save_path, ec);
|
2013-09-30 00:50:06 +02:00
|
|
|
|
2013-10-01 06:10:03 +02:00
|
|
|
static char const* test_name[] = {"no", "SOCKS4", "SOCKS5", "SOCKS5 password", "HTTP", "HTTP password"};
|
2013-09-30 00:50:06 +02:00
|
|
|
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("\n\n ==== TESTING === proxy: %s ==== protocol: %s "
|
2014-06-15 20:02:59 +02:00
|
|
|
"==== seed: %s === transfer-encoding: %s === corruption: %s "
|
|
|
|
"==== keepalive: %s\n\n\n"
|
|
|
|
, test_name[proxy], protocol, url_seed ? "URL seed" : "HTTP seed"
|
|
|
|
, chunked_encoding ? "chunked": "none", test_ban ? "yes" : "no"
|
|
|
|
, keepalive ? "yes" : "no");
|
2013-09-30 00:50:06 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
int proxy_port = 0;
|
2013-09-30 00:50:06 +02:00
|
|
|
if (proxy)
|
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
proxy_port = start_proxy(proxy);
|
|
|
|
if (proxy_port < 0)
|
|
|
|
{
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("failed to start proxy");
|
2014-07-06 21:18:00 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
settings_pack pack;
|
|
|
|
pack.set_str(settings_pack::proxy_hostname, "127.0.0.1");
|
|
|
|
pack.set_str(settings_pack::proxy_username, "testuser");
|
|
|
|
pack.set_str(settings_pack::proxy_password, "testpass");
|
2017-04-02 20:22:17 +02:00
|
|
|
pack.set_int(settings_pack::proxy_type, proxy);
|
2014-07-06 21:18:00 +02:00
|
|
|
pack.set_int(settings_pack::proxy_port, proxy_port);
|
2015-10-03 17:20:10 +02:00
|
|
|
pack.set_bool(settings_pack::proxy_peer_connections, proxy_peers);
|
2014-07-06 21:18:00 +02:00
|
|
|
ses.apply_settings(pack);
|
2013-09-30 00:50:06 +02:00
|
|
|
}
|
2014-01-22 07:25:28 +01:00
|
|
|
else
|
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
settings_pack pack;
|
|
|
|
pack.set_str(settings_pack::proxy_hostname, "");
|
|
|
|
pack.set_str(settings_pack::proxy_username, "");
|
|
|
|
pack.set_str(settings_pack::proxy_password, "");
|
|
|
|
pack.set_int(settings_pack::proxy_type, settings_pack::none);
|
|
|
|
pack.set_int(settings_pack::proxy_port, 0);
|
2015-10-03 17:20:10 +02:00
|
|
|
pack.set_bool(settings_pack::proxy_peer_connections, proxy_peers);
|
2014-07-06 21:18:00 +02:00
|
|
|
ses.apply_settings(pack);
|
2014-01-22 07:25:28 +01:00
|
|
|
}
|
2013-09-30 00:50:06 +02:00
|
|
|
|
|
|
|
add_torrent_params p;
|
|
|
|
p.flags &= ~add_torrent_params::flag_paused;
|
|
|
|
p.flags &= ~add_torrent_params::flag_auto_managed;
|
2016-01-22 05:32:20 +01:00
|
|
|
|
|
|
|
// the reason to set sequential download is to make sure that the order in
|
|
|
|
// which files are requested from the web server is consistent. Any specific
|
|
|
|
// scenario that needs testing should be an explicit test case
|
|
|
|
p.flags |= add_torrent_params::flag_sequential_download;
|
2013-09-30 00:50:06 +02:00
|
|
|
p.ti = torrent_file;
|
2013-10-01 06:10:03 +02:00
|
|
|
p.save_path = save_path;
|
2013-09-30 00:50:06 +02:00
|
|
|
torrent_handle th = ses.add_torrent(p, ec);
|
2016-05-17 15:24:06 +02:00
|
|
|
std::printf("adding torrent, save_path = \"%s\" cwd = \"%s\" torrent = \"%s\"\n"
|
2014-07-06 21:18:00 +02:00
|
|
|
, save_path.c_str(), current_working_directory().c_str()
|
|
|
|
, torrent_file->name().c_str());
|
2013-09-30 00:50:06 +02:00
|
|
|
|
|
|
|
std::vector<announce_entry> empty;
|
|
|
|
th.replace_trackers(empty);
|
|
|
|
|
2016-06-18 20:01:38 +02:00
|
|
|
const std::int64_t total_size = torrent_file->total_size();
|
2013-09-30 00:50:06 +02:00
|
|
|
|
|
|
|
file_storage const& fs = torrent_file->files();
|
|
|
|
int pad_file_size = 0;
|
2016-12-22 16:42:33 +01:00
|
|
|
for (file_index_t i(0); i < fs.end_file(); ++i)
|
2013-09-30 00:50:06 +02:00
|
|
|
{
|
2015-01-21 16:46:12 +01:00
|
|
|
if (fs.file_flags(i) & file_storage::flag_pad_file)
|
2016-04-20 06:45:32 +02:00
|
|
|
pad_file_size += int(fs.file_size(i));
|
2013-09-30 00:50:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
peer_disconnects = 0;
|
2016-06-18 20:01:38 +02:00
|
|
|
std::map<std::string, std::int64_t> cnt = get_counters(ses);
|
2013-09-30 00:50:06 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < 40; ++i)
|
|
|
|
{
|
|
|
|
torrent_status s = th.status();
|
|
|
|
|
2015-01-04 22:31:02 +01:00
|
|
|
cnt = get_counters(ses);
|
2013-09-30 00:50:06 +02:00
|
|
|
|
2016-07-09 22:26:26 +02:00
|
|
|
print_ses_rate(i / 10.f, &s, nullptr);
|
2017-04-02 20:22:17 +02:00
|
|
|
print_alerts(ses, " >> ses", false, false, &on_alert);
|
2013-09-30 00:50:06 +02:00
|
|
|
|
|
|
|
if (test_ban && th.url_seeds().empty() && th.http_seeds().empty())
|
|
|
|
{
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("testing ban: URL seed removed\n");
|
2013-09-30 00:50:06 +02:00
|
|
|
// when we don't have any web seeds left, we know we successfully banned it
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
if (s.is_seeding)
|
2013-09-30 00:50:06 +02:00
|
|
|
{
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("SEEDING\n");
|
|
|
|
std::printf("session.payload: %d session.redundant: %d\n"
|
2015-01-04 22:31:02 +01:00
|
|
|
, int(cnt["net.recv_payload_bytes"]), int(cnt["net.recv_redundant_bytes"]));
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("torrent.payload: %d torrent.redundant: %d\n"
|
2014-07-06 21:18:00 +02:00
|
|
|
, int(s.total_payload_download), int(s.total_redundant_bytes));
|
|
|
|
|
2013-09-30 00:50:06 +02:00
|
|
|
TEST_EQUAL(s.total_payload_download - s.total_redundant_bytes, total_size - pad_file_size);
|
|
|
|
break;
|
|
|
|
}
|
2014-07-06 21:18:00 +02:00
|
|
|
|
|
|
|
// if the web seed connection is disconnected, we're going to fail
|
|
|
|
// the test. make sure to do so quickly
|
2016-01-22 05:32:20 +01:00
|
|
|
if (!test_ban && keepalive && peer_disconnects >= 1) break;
|
2014-07-06 21:18:00 +02:00
|
|
|
|
2016-06-26 15:24:06 +02:00
|
|
|
std::this_thread::sleep_for(lt::milliseconds(100));
|
2013-09-30 00:50:06 +02:00
|
|
|
}
|
|
|
|
|
2015-01-04 22:31:02 +01:00
|
|
|
cnt = get_counters(ses);
|
2014-09-03 05:17:47 +02:00
|
|
|
|
2016-01-22 05:32:20 +01:00
|
|
|
if (test_ban)
|
|
|
|
{
|
|
|
|
// for test_ban tests, make sure we removed
|
|
|
|
// the url seed (i.e. banned it)
|
|
|
|
// torrents that don't have very many pieces will not ban the web seeds,
|
|
|
|
// since they won't have an opportunity to accrue enough negative points
|
|
|
|
if (torrent_file->files().num_pieces() > 3)
|
|
|
|
{
|
|
|
|
TEST_CHECK(th.url_seeds().empty());
|
|
|
|
TEST_CHECK(th.http_seeds().empty());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2013-10-01 06:10:03 +02:00
|
|
|
{
|
2016-07-31 00:03:06 +02:00
|
|
|
// if the web seed sent corrupt data and we banned it, we probably didn't
|
2016-01-22 05:32:20 +01:00
|
|
|
// end up using all the cache anyway
|
2014-03-15 22:55:12 +01:00
|
|
|
torrent_status st = th.status();
|
|
|
|
TEST_EQUAL(st.is_seeding, true);
|
|
|
|
|
|
|
|
if (st.is_seeding)
|
|
|
|
{
|
2016-01-22 05:32:20 +01:00
|
|
|
// we need to sleep here a bit to let the session sync with the torrent stats
|
|
|
|
// commented out because it takes such a long time
|
2014-03-15 22:55:12 +01:00
|
|
|
for (int i = 0; i < 50; ++i)
|
|
|
|
{
|
2014-10-25 22:07:50 +02:00
|
|
|
cnt = get_counters(ses);
|
|
|
|
if (cnt["disk.read_cache_blocks"]
|
|
|
|
== (torrent_file->total_size() + 0x3fff) / 0x4000
|
|
|
|
&& cnt["disk.disk_blocks_in_use"]
|
|
|
|
== (torrent_file->total_size() + 0x3fff) / 0x4000)
|
2014-03-15 22:55:12 +01:00
|
|
|
break;
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("cache_size: %d/%d\n", int(cnt["disk.read_cache_blocks"])
|
2014-10-25 22:07:50 +02:00
|
|
|
, int(cnt["disk.disk_blocks_in_use"]));
|
2016-06-26 15:24:06 +02:00
|
|
|
std::this_thread::sleep_for(lt::milliseconds(100));
|
2014-03-15 22:55:12 +01:00
|
|
|
}
|
2016-04-11 02:46:51 +02:00
|
|
|
TEST_CHECK(std::abs(int(cnt["disk.disk_blocks_in_use"]
|
|
|
|
- (torrent_file->total_size() + 0x3fff) / 0x4000)) <= 2);
|
2014-03-15 22:55:12 +01:00
|
|
|
}
|
2013-10-01 06:10:03 +02:00
|
|
|
}
|
2013-09-30 00:50:06 +02:00
|
|
|
|
2017-01-02 16:16:33 +01:00
|
|
|
std::cout << "total_size: " << total_size
|
2014-10-25 22:07:50 +02:00
|
|
|
<< " read cache size: " << cnt["disk.disk_blocks_in_use"]
|
|
|
|
<< " total used buffer: " << cnt["disk.disk_blocks_in_use"]
|
2015-01-04 22:31:02 +01:00
|
|
|
<< " session total download: " << cnt["net.recv_payload_bytes"]
|
2013-09-30 00:50:06 +02:00
|
|
|
<< " torrent total download: " << th.status().total_payload_download
|
|
|
|
<< " redundant: " << th.status().total_redundant_bytes
|
|
|
|
<< std::endl;
|
|
|
|
|
|
|
|
// if test_ban is true, we're not supposed to have completed the download
|
|
|
|
// otherwise, we are supposed to have
|
|
|
|
TEST_CHECK(th.status().is_seeding == !test_ban);
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
if (proxy) stop_proxy(proxy_port);
|
2013-09-30 00:50:06 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
th.flush_cache();
|
2013-09-30 00:50:06 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
// synchronize to make sure the files have been created on disk
|
|
|
|
wait_for_alert(ses, cache_flushed_alert::alert_type, "ses");
|
2013-09-30 00:50:06 +02:00
|
|
|
|
2017-04-02 20:22:17 +02:00
|
|
|
print_alerts(ses, " >> ses", true, false, &on_alert, true);
|
2013-09-30 00:50:06 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
if (!test_ban)
|
|
|
|
{
|
2016-12-22 16:42:33 +01:00
|
|
|
for (file_index_t i(0); i < fs.end_file(); ++i)
|
2016-01-22 05:32:20 +01:00
|
|
|
{
|
|
|
|
bool const expect = !fs.pad_file_at(i);
|
|
|
|
std::string file_path = combine_path(save_path, fs.file_path(i));
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("checking file: %s\n", file_path.c_str());
|
2016-01-22 05:32:20 +01:00
|
|
|
TEST_EQUAL(exists(file_path), expect);
|
|
|
|
}
|
2014-07-06 21:18:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ses.remove_torrent(th);
|
2013-09-30 00:50:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// proxy: 0=none, 1=socks4, 2=socks5, 3=socks5_pw 4=http 5=http_pw
|
|
|
|
// protocol: "http" or "https"
|
|
|
|
// test_url_seed determines whether to use url-seed or http-seed
|
2014-06-15 20:02:59 +02:00
|
|
|
int EXPORT run_http_suite(int proxy, char const* protocol, bool test_url_seed
|
2015-10-03 17:20:10 +02:00
|
|
|
, bool chunked_encoding, bool test_ban, bool keepalive, bool test_rename
|
|
|
|
, bool proxy_peers)
|
2013-09-30 00:50:06 +02:00
|
|
|
{
|
2017-04-12 20:05:53 +02:00
|
|
|
using namespace lt;
|
2013-09-30 00:50:06 +02:00
|
|
|
|
2013-11-03 09:15:51 +01:00
|
|
|
std::string save_path = "web_seed";
|
2013-10-01 06:10:03 +02:00
|
|
|
save_path += proxy_name[proxy];
|
|
|
|
|
2013-09-30 00:50:06 +02:00
|
|
|
error_code ec;
|
2017-03-18 17:19:49 +01:00
|
|
|
int const port = start_web_server(protocol == "https"_sv, chunked_encoding, keepalive);
|
2013-09-30 00:50:06 +02:00
|
|
|
|
2016-01-22 05:32:20 +01:00
|
|
|
std::vector<torrent_args> test_cases;
|
2013-09-30 00:50:06 +02:00
|
|
|
|
|
|
|
if (test_url_seed)
|
|
|
|
{
|
2016-01-22 05:32:20 +01:00
|
|
|
char url[512];
|
2017-04-02 20:22:17 +02:00
|
|
|
std::snprintf(url, sizeof(url), "%s://127.0.0.1:%d/%s", protocol, port, save_path.c_str());
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("testing: %s\n", url);
|
2016-01-22 05:32:20 +01:00
|
|
|
|
|
|
|
create_directories(combine_path(save_path, "torrent_dir"), ec);
|
|
|
|
|
|
|
|
torrent_args args;
|
|
|
|
|
|
|
|
// test case 1
|
|
|
|
test_cases.push_back(torrent_args().file("0").file("5,padfile").file("11")
|
|
|
|
.file("16000").file("368,padfile")
|
|
|
|
.file("16384,padfile").file("16384,padfile").file("17").file("10")
|
|
|
|
.file("8000").file("8000").file("1").file("1").file("1").file("1")
|
|
|
|
.file("1").file("100").file("0").file("1").file("1").file("1")
|
|
|
|
.file("100").file("1").file("1").file("1").file("1").file("1,padfile")
|
|
|
|
.file("1,padfile").file("1,padfile").file("1").file("0").file("0")
|
|
|
|
.file("0").file("1").file("13").file("65000").file("34").file("75")
|
|
|
|
.file("2").file("30").file("400").file("500").file("23000")
|
|
|
|
.file("900").file("43000").file("400").file("4300").file("6")
|
|
|
|
.file("4,padfile")
|
|
|
|
.name("torrent_dir")
|
|
|
|
.url_seed(url));
|
|
|
|
|
|
|
|
// test case 2 (the end of the torrent are padfiles)
|
|
|
|
test_cases.push_back(torrent_args()
|
|
|
|
.file("0,padfile")
|
|
|
|
.file("11")
|
|
|
|
.file("5")
|
|
|
|
.file("16000")
|
|
|
|
.file("368,padfile")
|
|
|
|
.file("16384,padfile")
|
|
|
|
.name("torrent_dir")
|
|
|
|
.url_seed(url));
|
|
|
|
|
|
|
|
// test case 3 (misaligned)
|
|
|
|
test_cases.push_back(torrent_args()
|
|
|
|
.file("16383")
|
|
|
|
.file("11")
|
|
|
|
.file("5")
|
|
|
|
.file("16000")
|
|
|
|
.name("torrent_dir")
|
|
|
|
.url_seed(url));
|
|
|
|
|
|
|
|
// test case 4 (a full piece padfile)
|
|
|
|
test_cases.push_back(torrent_args()
|
|
|
|
.file("32768,padfile")
|
|
|
|
.file("16000")
|
|
|
|
.file("11")
|
|
|
|
.file("5")
|
|
|
|
.name("torrent_dir")
|
|
|
|
.url_seed(url));
|
|
|
|
|
|
|
|
// test case 5 (properly aligned padfile)
|
|
|
|
test_cases.push_back(torrent_args()
|
|
|
|
.file("32760")
|
|
|
|
.file("8,padfile")
|
|
|
|
.file("32760")
|
|
|
|
.file("8")
|
|
|
|
.file("32700")
|
|
|
|
.file("68,padfile")
|
|
|
|
.file("32000")
|
|
|
|
.name("torrent_dir")
|
|
|
|
.url_seed(url));
|
|
|
|
|
2017-04-02 20:22:17 +02:00
|
|
|
std::snprintf(url, sizeof(url), "%s://127.0.0.1:%d/%s/test-single-file"
|
|
|
|
, protocol, port, save_path.c_str());
|
2016-01-22 05:32:20 +01:00
|
|
|
|
|
|
|
// test case 6 (single file torrent)
|
|
|
|
test_cases.push_back(torrent_args()
|
|
|
|
.file("199092,name=test-single-file")
|
|
|
|
.name("torrent_dir")
|
|
|
|
.url_seed(url));
|
2013-09-30 00:50:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-22 05:32:20 +01:00
|
|
|
char url[512];
|
2016-05-17 15:24:06 +02:00
|
|
|
std::snprintf(url, sizeof(url), "%s://127.0.0.1:%d/%s/seed", protocol, port, save_path.c_str());
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("testing: %s\n", url);
|
2013-09-30 00:50:06 +02:00
|
|
|
|
2016-01-22 05:32:20 +01:00
|
|
|
// there's really just one test case for http seeds
|
|
|
|
test_cases.push_back(torrent_args().file("589824,name=seed")
|
|
|
|
.http_seed(url));
|
2013-09-30 00:50:06 +02:00
|
|
|
}
|
|
|
|
|
2017-04-02 20:22:17 +02:00
|
|
|
int idx = 0;
|
|
|
|
for (auto const& c : test_cases)
|
2013-09-30 00:50:06 +02:00
|
|
|
{
|
2017-04-02 20:22:17 +02:00
|
|
|
std::printf("\n\n ==== test case %d ====\n\n\n", idx++);
|
2013-09-30 00:50:06 +02:00
|
|
|
|
2017-04-02 20:22:17 +02:00
|
|
|
std::shared_ptr<torrent_info> torrent_file = make_test_torrent(c);
|
2014-07-06 21:18:00 +02:00
|
|
|
|
2016-01-22 05:32:20 +01:00
|
|
|
// if test_ban is true, we create the files with alternate content (that
|
|
|
|
// doesn't match the hashes in the .torrent file)
|
|
|
|
generate_files(*torrent_file, save_path, test_ban);
|
2013-09-30 00:50:06 +02:00
|
|
|
|
2016-01-22 05:32:20 +01:00
|
|
|
if (ec)
|
2013-09-30 00:50:06 +02:00
|
|
|
{
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("error creating hashes for test torrent: %s\n"
|
2016-01-22 05:32:20 +01:00
|
|
|
, ec.message().c_str());
|
|
|
|
TEST_CHECK(false);
|
|
|
|
return 0;
|
2013-09-30 00:50:06 +02:00
|
|
|
}
|
2015-06-17 05:45:05 +02:00
|
|
|
|
2013-09-30 00:50:06 +02:00
|
|
|
{
|
2016-01-22 05:32:20 +01:00
|
|
|
const int mask = alert::all_categories
|
|
|
|
& ~(alert::progress_notification
|
|
|
|
| alert::performance_warning
|
|
|
|
| alert::stats_notification);
|
|
|
|
|
|
|
|
settings_pack pack;
|
|
|
|
pack.set_int(settings_pack::max_queued_disk_bytes, 256 * 1024);
|
|
|
|
pack.set_str(settings_pack::listen_interfaces, "0.0.0.0:51000");
|
|
|
|
pack.set_int(settings_pack::max_retry_port_bind, 1000);
|
|
|
|
pack.set_int(settings_pack::alert_mask, mask);
|
|
|
|
pack.set_bool(settings_pack::enable_lsd, false);
|
|
|
|
pack.set_bool(settings_pack::enable_natpmp, false);
|
|
|
|
pack.set_bool(settings_pack::enable_upnp, false);
|
|
|
|
pack.set_bool(settings_pack::enable_dht, false);
|
2017-04-12 20:05:53 +02:00
|
|
|
lt::session ses(pack, 0);
|
2016-01-22 05:32:20 +01:00
|
|
|
|
2016-06-19 01:24:27 +02:00
|
|
|
test_transfer(ses, torrent_file, proxy, protocol, test_url_seed
|
2015-10-03 17:20:10 +02:00
|
|
|
, chunked_encoding, test_ban, keepalive, proxy_peers);
|
2016-01-22 05:32:20 +01:00
|
|
|
|
|
|
|
if (test_url_seed && test_rename)
|
|
|
|
{
|
2016-12-22 16:42:33 +01:00
|
|
|
torrent_file->rename_file(file_index_t(0), combine_path(save_path, combine_path("torrent_dir", "renamed_test1")));
|
2016-06-19 01:24:27 +02:00
|
|
|
test_transfer(ses, torrent_file, 0, protocol, test_url_seed
|
2016-01-22 05:32:20 +01:00
|
|
|
, chunked_encoding, test_ban, keepalive, proxy_peers);
|
|
|
|
}
|
2013-09-30 00:50:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stop_web_server();
|
|
|
|
return 0;
|
|
|
|
}
|