2013-11-03 09:15:51 +01:00
|
|
|
/*
|
2008-07-01 20:59:13 +02:00
|
|
|
|
|
|
|
Copyright (c) 2008, 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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2007-09-10 08:12:41 +02:00
|
|
|
#include <fstream>
|
2014-03-25 05:13:58 +01:00
|
|
|
#include <map>
|
2016-07-15 20:35:57 +02:00
|
|
|
#include <tuple>
|
|
|
|
#include <functional>
|
|
|
|
#include <random>
|
2007-09-10 08:12:41 +02:00
|
|
|
|
2006-05-28 21:03:54 +02:00
|
|
|
#include "libtorrent/session.hpp"
|
|
|
|
#include "libtorrent/hasher.hpp"
|
2009-12-06 00:41:33 +01:00
|
|
|
#include "libtorrent/http_parser.hpp"
|
2007-09-10 08:12:41 +02:00
|
|
|
#include "libtorrent/assert.hpp"
|
2008-01-02 04:18:29 +01:00
|
|
|
#include "libtorrent/alert_types.hpp"
|
2008-05-14 07:29:42 +02:00
|
|
|
#include "libtorrent/create_torrent.hpp"
|
2009-12-15 14:11:07 +01:00
|
|
|
#include "libtorrent/socket_io.hpp" // print_endpoint
|
2014-07-06 21:18:00 +02:00
|
|
|
#include "libtorrent/ip_filter.hpp"
|
2015-04-25 04:12:02 +02:00
|
|
|
#include "libtorrent/session_stats.hpp"
|
2015-06-20 20:11:03 +02:00
|
|
|
#include "libtorrent/random.hpp"
|
2015-09-18 06:23:45 +02:00
|
|
|
#include "libtorrent/torrent_info.hpp"
|
2016-02-10 01:09:53 +01:00
|
|
|
#include "libtorrent/broadcast_socket.hpp" // for supports_ipv6()
|
2016-06-04 16:01:43 +02:00
|
|
|
#include "libtorrent/hex.hpp" // to_hex
|
2017-04-02 20:22:17 +02:00
|
|
|
#include "libtorrent/aux_/vector.hpp"
|
2017-04-11 06:52:46 +02:00
|
|
|
#include "libtorrent/aux_/path.hpp"
|
2018-11-05 13:08:55 +01:00
|
|
|
#include "libtorrent/random.hpp"
|
2015-04-25 04:12:02 +02:00
|
|
|
|
|
|
|
#include "test.hpp"
|
|
|
|
#include "test_utils.hpp"
|
|
|
|
#include "setup_transfer.hpp"
|
2010-10-12 10:57:43 +02:00
|
|
|
|
2013-09-22 05:37:33 +02:00
|
|
|
#ifndef _WIN32
|
|
|
|
#include <spawn.h>
|
2016-07-10 05:17:55 +02:00
|
|
|
#include <csignal>
|
2013-09-22 05:37:33 +02:00
|
|
|
#endif
|
|
|
|
|
2017-04-12 20:05:53 +02:00
|
|
|
using namespace lt;
|
2008-01-02 04:18:29 +01:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
#if defined TORRENT_WINDOWS
|
|
|
|
#include <conio.h>
|
|
|
|
#endif
|
|
|
|
|
2018-07-30 01:10:52 +02:00
|
|
|
std::shared_ptr<torrent_info> generate_torrent()
|
2018-07-29 10:33:09 +02:00
|
|
|
{
|
|
|
|
file_storage fs;
|
2018-07-30 01:10:52 +02:00
|
|
|
fs.add_file("test_resume/tmp1", 128 * 1024 * 8);
|
|
|
|
fs.add_file("test_resume/tmp2", 128 * 1024);
|
|
|
|
fs.add_file("test_resume/tmp3", 128 * 1024);
|
2018-07-29 10:33:09 +02:00
|
|
|
lt::create_torrent t(fs, 128 * 1024, 6);
|
|
|
|
|
|
|
|
t.add_tracker("http://torrent_file_tracker.com/announce");
|
|
|
|
t.add_url_seed("http://torrent_file_url_seed.com/");
|
|
|
|
|
2018-07-30 01:10:52 +02:00
|
|
|
TEST_CHECK(t.num_pieces() > 0);
|
|
|
|
for (auto const i : fs.piece_range())
|
2018-07-29 10:33:09 +02:00
|
|
|
{
|
|
|
|
sha1_hash ph;
|
2018-07-30 01:10:52 +02:00
|
|
|
aux::random_bytes(ph);
|
2018-07-29 10:33:09 +02:00
|
|
|
t.set_hash(i, ph);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<char> buf;
|
|
|
|
bencode(std::back_inserter(buf), t.generate());
|
2018-07-30 01:10:52 +02:00
|
|
|
return std::make_shared<torrent_info>(buf, from_span);
|
2018-07-29 10:33:09 +02:00
|
|
|
}
|
|
|
|
|
2017-04-02 20:22:17 +02:00
|
|
|
namespace {
|
|
|
|
std::uint32_t g_addr = 0x92343023;
|
|
|
|
}
|
2015-08-13 08:06:30 +02:00
|
|
|
|
|
|
|
void init_rand_address()
|
|
|
|
{
|
|
|
|
g_addr = 0x92343023;
|
|
|
|
}
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
address rand_v4()
|
|
|
|
{
|
2016-02-10 01:09:53 +01:00
|
|
|
address_v4 ret;
|
|
|
|
do
|
|
|
|
{
|
2015-06-06 05:02:07 +02:00
|
|
|
g_addr += 0x3080ca;
|
2016-02-10 01:09:53 +01:00
|
|
|
ret = address_v4(g_addr);
|
|
|
|
} while (is_any(ret) || is_local(ret) || is_loopback(ret));
|
|
|
|
return ret;
|
2014-07-06 21:18:00 +02:00
|
|
|
}
|
|
|
|
|
2015-12-19 08:09:06 +01:00
|
|
|
sha1_hash rand_hash()
|
|
|
|
{
|
|
|
|
sha1_hash ret;
|
2018-11-05 13:08:55 +01:00
|
|
|
aux::random_bytes(ret);
|
2015-12-19 08:09:06 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-09-17 15:42:04 +02:00
|
|
|
sha1_hash to_hash(char const* s)
|
|
|
|
{
|
|
|
|
sha1_hash ret;
|
2017-04-02 20:22:17 +02:00
|
|
|
aux::from_hex({s, 40}, ret.data());
|
2016-09-17 15:42:04 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
address rand_v6()
|
|
|
|
{
|
|
|
|
address_v6::bytes_type bytes;
|
2016-06-19 01:24:27 +02:00
|
|
|
for (int i = 0; i < int(bytes.size()); ++i)
|
2017-04-02 20:22:17 +02:00
|
|
|
bytes[static_cast<std::size_t>(i)] = std::uint8_t(lt::random(0xff));
|
2014-07-06 21:18:00 +02:00
|
|
|
return address_v6(bytes);
|
|
|
|
}
|
|
|
|
|
2016-06-18 20:01:38 +02:00
|
|
|
static std::uint16_t g_port = 0;
|
2015-06-06 05:02:07 +02:00
|
|
|
|
2017-04-12 20:05:53 +02:00
|
|
|
tcp::endpoint rand_tcp_ep(lt::address(&rand_addr)())
|
2014-07-06 21:18:00 +02:00
|
|
|
{
|
2017-02-18 06:13:46 +01:00
|
|
|
// make sure we don't produce the same "random" port twice
|
2015-06-06 05:02:07 +02:00
|
|
|
g_port = (g_port + 1) % 14038;
|
2017-02-18 06:13:46 +01:00
|
|
|
return tcp::endpoint(rand_addr(), g_port + 1024);
|
2014-07-06 21:18:00 +02:00
|
|
|
}
|
|
|
|
|
2017-04-12 20:05:53 +02:00
|
|
|
udp::endpoint rand_udp_ep(lt::address(&rand_addr)())
|
2014-07-06 21:18:00 +02:00
|
|
|
{
|
2015-06-06 05:02:07 +02:00
|
|
|
g_port = (g_port + 1) % 14037;
|
2016-01-10 20:25:44 +01:00
|
|
|
return udp::endpoint(rand_addr(), g_port + 1024);
|
2014-07-06 21:18:00 +02:00
|
|
|
}
|
|
|
|
|
2017-04-12 20:05:53 +02:00
|
|
|
std::map<std::string, std::int64_t> get_counters(lt::session& s)
|
2014-09-03 05:17:47 +02:00
|
|
|
{
|
2017-04-12 20:05:53 +02:00
|
|
|
using namespace lt;
|
2014-09-03 05:17:47 +02:00
|
|
|
s.post_session_stats();
|
|
|
|
|
2016-06-18 20:01:38 +02:00
|
|
|
std::map<std::string, std::int64_t> ret;
|
2015-04-03 22:15:48 +02:00
|
|
|
alert const* a = wait_for_alert(s, session_stats_alert::alert_type
|
2014-09-03 05:17:47 +02:00
|
|
|
, "get_counters()");
|
|
|
|
|
2015-04-03 22:15:48 +02:00
|
|
|
TEST_CHECK(a);
|
|
|
|
if (!a) return ret;
|
2014-09-03 05:17:47 +02:00
|
|
|
|
2015-04-03 22:15:48 +02:00
|
|
|
session_stats_alert const* sa = alert_cast<session_stats_alert>(a);
|
2014-09-03 05:17:47 +02:00
|
|
|
if (!sa) return ret;
|
|
|
|
|
|
|
|
static std::vector<stats_metric> metrics = session_stats_metrics();
|
2017-04-02 20:22:17 +02:00
|
|
|
for (auto const& m : metrics)
|
2018-11-01 23:05:30 +01:00
|
|
|
ret[m.name] = sa->counters()[m.value_index];
|
2014-09-03 05:17:47 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2016-06-11 21:37:28 +02:00
|
|
|
namespace {
|
|
|
|
bool should_print(lt::alert* a)
|
|
|
|
{
|
|
|
|
#ifndef TORRENT_DISABLE_LOGGING
|
|
|
|
if (auto pla = alert_cast<peer_log_alert>(a))
|
|
|
|
{
|
|
|
|
if (pla->direction != peer_log_alert::incoming_message
|
2018-06-22 08:31:26 +02:00
|
|
|
&& pla->direction != peer_log_alert::outgoing_message
|
|
|
|
&& pla->direction != peer_log_alert::info)
|
2016-06-11 21:37:28 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (alert_cast<session_stats_alert>(a)
|
|
|
|
|| alert_cast<piece_finished_alert>(a)
|
|
|
|
|| alert_cast<block_finished_alert>(a)
|
|
|
|
|| alert_cast<block_downloading_alert>(a))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2014-09-03 05:17:47 +02:00
|
|
|
|
2017-05-18 05:04:50 +02:00
|
|
|
alert const* wait_for_alert(lt::session& ses, int type, char const* name
|
2018-03-26 11:25:18 +02:00
|
|
|
, pop_alerts const p, lt::time_duration timeout)
|
2013-06-18 09:33:49 +02:00
|
|
|
{
|
2017-05-18 05:04:50 +02:00
|
|
|
// we pop alerts in batches, but we wait for individual messages. This is a
|
|
|
|
// cache to keep around alerts that came *after* the one we're waiting for.
|
|
|
|
// To let subsequent calls to this function be able to pick those up, despite
|
|
|
|
// already being popped off the sessions alert queue.
|
|
|
|
static std::map<lt::session*, std::vector<alert*>> cache;
|
|
|
|
auto& alerts = cache[&ses];
|
|
|
|
|
2018-03-26 11:25:18 +02:00
|
|
|
time_point const end_time = lt::clock_type::now() + timeout;
|
|
|
|
|
2015-04-03 22:15:48 +02:00
|
|
|
while (true)
|
2013-06-18 09:33:49 +02:00
|
|
|
{
|
2015-03-15 07:05:41 +01:00
|
|
|
time_point now = clock_type::now();
|
2016-07-09 22:26:26 +02:00
|
|
|
if (now > end_time) return nullptr;
|
2013-11-24 02:32:51 +01:00
|
|
|
|
2016-07-09 22:26:26 +02:00
|
|
|
alert const* ret = nullptr;
|
2016-02-08 08:05:00 +01:00
|
|
|
|
2017-05-18 05:04:50 +02:00
|
|
|
if (alerts.empty())
|
|
|
|
{
|
|
|
|
ses.wait_for_alert(end_time - now);
|
|
|
|
ses.pop_alerts(&alerts);
|
|
|
|
}
|
|
|
|
for (auto i = alerts.begin(); i != alerts.end(); ++i)
|
2013-06-18 09:33:49 +02:00
|
|
|
{
|
2017-05-18 05:04:50 +02:00
|
|
|
auto a = *i;
|
2016-06-19 01:24:27 +02:00
|
|
|
if (should_print(a))
|
2016-06-11 21:37:28 +02:00
|
|
|
{
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("%s: %s: [%s] %s\n", time_now_string(), name
|
2016-06-19 01:24:27 +02:00
|
|
|
, a->what(), a->message().c_str());
|
2016-06-11 21:37:28 +02:00
|
|
|
}
|
2016-11-10 01:53:55 +01:00
|
|
|
if (a->type() == type)
|
2013-06-18 09:33:49 +02:00
|
|
|
{
|
2016-06-19 01:24:27 +02:00
|
|
|
ret = a;
|
2017-05-18 05:04:50 +02:00
|
|
|
if (p == pop_alerts::pop_all) alerts.clear();
|
|
|
|
else alerts.erase(alerts.begin(), std::next(i));
|
|
|
|
return ret;
|
2013-06-18 09:33:49 +02:00
|
|
|
}
|
|
|
|
}
|
2017-05-18 05:04:50 +02:00
|
|
|
alerts.clear();
|
2013-06-18 09:33:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-12 19:50:49 +01:00
|
|
|
int load_file(std::string const& filename, std::vector<char>& v
|
2017-04-12 20:05:53 +02:00
|
|
|
, lt::error_code& ec, int limit)
|
2013-07-19 23:41:33 +02:00
|
|
|
{
|
|
|
|
ec.clear();
|
|
|
|
FILE* f = fopen(filename.c_str(), "rb");
|
2016-07-09 22:26:26 +02:00
|
|
|
if (f == nullptr)
|
2013-07-19 23:41:33 +02:00
|
|
|
{
|
2015-11-24 06:50:51 +01:00
|
|
|
ec.assign(errno, boost::system::system_category());
|
2013-07-19 23:41:33 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int r = fseek(f, 0, SEEK_END);
|
|
|
|
if (r != 0)
|
|
|
|
{
|
2015-11-24 06:50:51 +01:00
|
|
|
ec.assign(errno, boost::system::system_category());
|
2013-07-19 23:41:33 +02:00
|
|
|
fclose(f);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
long s = ftell(f);
|
|
|
|
if (s < 0)
|
|
|
|
{
|
2015-11-24 06:50:51 +01:00
|
|
|
ec.assign(errno, boost::system::system_category());
|
2013-07-19 23:41:33 +02:00
|
|
|
fclose(f);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s > limit)
|
|
|
|
{
|
|
|
|
fclose(f);
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = fseek(f, 0, SEEK_SET);
|
|
|
|
if (r != 0)
|
|
|
|
{
|
2015-11-24 06:50:51 +01:00
|
|
|
ec.assign(errno, boost::system::system_category());
|
2013-07-19 23:41:33 +02:00
|
|
|
fclose(f);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-04-02 20:22:17 +02:00
|
|
|
v.resize(static_cast<std::size_t>(s));
|
2013-07-19 23:41:33 +02:00
|
|
|
if (s == 0)
|
|
|
|
{
|
|
|
|
fclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-25 23:22:09 +02:00
|
|
|
r = int(fread(&v[0], 1, v.size(), f));
|
2013-07-19 23:41:33 +02:00
|
|
|
if (r < 0)
|
|
|
|
{
|
2015-11-24 06:50:51 +01:00
|
|
|
ec.assign(errno, boost::system::system_category());
|
2013-07-19 23:41:33 +02:00
|
|
|
fclose(f);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
if (r != s) return -3;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
bool print_alerts(lt::session& ses, char const* name
|
2017-04-02 20:22:17 +02:00
|
|
|
, bool allow_no_torrents, bool allow_failed_fastresume
|
2017-04-12 20:05:53 +02:00
|
|
|
, std::function<bool(lt::alert const*)> predicate, bool no_output)
|
2008-01-02 04:18:29 +01:00
|
|
|
{
|
2018-02-18 22:35:34 +01:00
|
|
|
TEST_CHECK(!ses.get_torrents().empty() || allow_no_torrents);
|
2015-04-03 22:15:48 +02:00
|
|
|
std::vector<alert*> alerts;
|
2011-03-14 03:59:46 +01:00
|
|
|
ses.pop_alerts(&alerts);
|
2016-06-19 01:24:27 +02:00
|
|
|
for (auto a : alerts)
|
2008-01-02 04:18:29 +01:00
|
|
|
{
|
2016-06-19 01:24:27 +02:00
|
|
|
if (peer_disconnected_alert const* p = alert_cast<peer_disconnected_alert>(a))
|
2008-05-12 09:01:25 +02:00
|
|
|
{
|
2016-11-12 19:50:49 +01:00
|
|
|
std::printf("%s: %s: [%s] (%s): %s\n", time_now_string(), name, a->what()
|
2016-10-19 07:32:15 +02:00
|
|
|
, print_endpoint(p->endpoint).c_str(), p->message().c_str());
|
2008-05-12 09:01:25 +02:00
|
|
|
}
|
2018-02-22 15:12:15 +01:00
|
|
|
else if (a->type() == invalid_request_alert::alert_type)
|
2018-02-18 22:35:34 +01:00
|
|
|
{
|
2018-02-22 15:12:15 +01:00
|
|
|
fprintf(stdout, "peer error: %s\n", a->message().c_str());
|
2018-02-18 22:35:34 +01:00
|
|
|
TEST_CHECK(false);
|
|
|
|
}
|
2018-02-22 15:12:15 +01:00
|
|
|
else if (a->type() == fastresume_rejected_alert::alert_type)
|
2018-02-18 22:35:34 +01:00
|
|
|
{
|
2018-02-22 15:12:15 +01:00
|
|
|
fprintf(stdout, "resume data error: %s\n", a->message().c_str());
|
2018-02-18 22:35:34 +01:00
|
|
|
TEST_CHECK(allow_failed_fastresume);
|
|
|
|
}
|
2016-11-12 19:50:49 +01:00
|
|
|
else if (should_print(a) && !no_output)
|
2008-05-12 09:01:25 +02:00
|
|
|
{
|
2016-11-12 19:50:49 +01:00
|
|
|
std::printf("%s: %s: [%s] %s\n", time_now_string(), name, a->what(), a->message().c_str());
|
2008-05-12 09:01:25 +02:00
|
|
|
}
|
2011-04-10 03:36:07 +02:00
|
|
|
|
2016-07-09 22:26:26 +02:00
|
|
|
TEST_CHECK(alert_cast<fastresume_rejected_alert>(a) == nullptr || allow_failed_fastresume);
|
2014-07-06 21:18:00 +02:00
|
|
|
|
2016-06-19 01:24:27 +02:00
|
|
|
invalid_request_alert const* ira = alert_cast<invalid_request_alert>(a);
|
2014-07-06 21:18:00 +02:00
|
|
|
if (ira)
|
|
|
|
{
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("peer error: %s\n", ira->message().c_str());
|
2014-07-06 21:18:00 +02:00
|
|
|
TEST_CHECK(false);
|
|
|
|
}
|
2008-01-02 04:18:29 +01:00
|
|
|
}
|
2018-02-22 15:12:15 +01:00
|
|
|
return predicate && std::any_of(alerts.begin(), alerts.end(), predicate);
|
2008-01-02 04:18:29 +01:00
|
|
|
}
|
2006-10-11 16:02:21 +02:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
void wait_for_listen(lt::session& ses, char const* name)
|
2010-12-24 01:37:01 +01:00
|
|
|
{
|
2017-04-02 20:22:17 +02:00
|
|
|
bool listen_done = false;
|
2016-07-09 22:26:26 +02:00
|
|
|
alert const* a = nullptr;
|
2010-12-24 01:37:01 +01:00
|
|
|
do
|
|
|
|
{
|
2018-03-22 17:01:38 +01:00
|
|
|
listen_done = print_alerts(ses, name, true, true, [](lt::alert const* al)
|
2018-02-22 15:12:15 +01:00
|
|
|
{ return alert_cast<listen_failed_alert>(al) || alert_cast<listen_succeeded_alert>(al); }
|
|
|
|
, false);
|
2010-12-24 01:37:01 +01:00
|
|
|
if (listen_done) break;
|
|
|
|
a = ses.wait_for_alert(milliseconds(500));
|
|
|
|
} while (a);
|
2013-08-18 00:29:34 +02:00
|
|
|
// we din't receive a listen alert!
|
|
|
|
TEST_CHECK(listen_done);
|
2010-12-24 01:37:01 +01:00
|
|
|
}
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
void wait_for_downloading(lt::session& ses, char const* name)
|
|
|
|
{
|
2015-08-27 03:47:20 +02:00
|
|
|
time_point start = clock_type::now();
|
2017-04-02 20:22:17 +02:00
|
|
|
bool downloading_done = false;
|
2016-07-09 22:26:26 +02:00
|
|
|
alert const* a = nullptr;
|
2014-07-06 21:18:00 +02:00
|
|
|
do
|
|
|
|
{
|
2018-02-22 15:12:15 +01:00
|
|
|
downloading_done = print_alerts(ses, name, true, true
|
2018-03-22 17:01:38 +01:00
|
|
|
, [](lt::alert const* al)
|
2017-04-02 20:22:17 +02:00
|
|
|
{
|
|
|
|
state_changed_alert const* sc = alert_cast<state_changed_alert>(al);
|
2018-02-22 15:12:15 +01:00
|
|
|
return sc && sc->state == torrent_status::downloading;
|
2017-04-02 20:22:17 +02:00
|
|
|
}, false);
|
2014-07-06 21:18:00 +02:00
|
|
|
if (downloading_done) break;
|
2015-08-27 03:47:20 +02:00
|
|
|
if (total_seconds(clock_type::now() - start) > 10) break;
|
|
|
|
a = ses.wait_for_alert(seconds(2));
|
2014-07-06 21:18:00 +02:00
|
|
|
} while (a);
|
2015-08-27 03:47:20 +02:00
|
|
|
if (!downloading_done)
|
|
|
|
{
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("%s: did not receive a state_changed_alert indicating "
|
2015-08-27 03:47:20 +02:00
|
|
|
"the torrent is downloading. waited: %d ms\n"
|
2016-03-13 21:18:44 +01:00
|
|
|
, name, int(total_milliseconds(clock_type::now() - start)));
|
2015-08-27 03:47:20 +02:00
|
|
|
}
|
2014-07-06 21:18:00 +02:00
|
|
|
}
|
|
|
|
|
2017-04-02 20:22:17 +02:00
|
|
|
void print_ses_rate(float const time
|
2017-04-12 20:05:53 +02:00
|
|
|
, lt::torrent_status const* st1
|
|
|
|
, lt::torrent_status const* st2
|
|
|
|
, lt::torrent_status const* st3)
|
2013-06-14 18:38:26 +02:00
|
|
|
{
|
2014-03-05 10:37:49 +01:00
|
|
|
if (st1)
|
|
|
|
{
|
2017-04-02 20:22:17 +02:00
|
|
|
std::printf("%3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", static_cast<double>(time)
|
2014-03-05 10:37:49 +01:00
|
|
|
, int(st1->download_payload_rate / 1000)
|
|
|
|
, int(st1->upload_payload_rate / 1000)
|
|
|
|
, int(st1->progress * 100)
|
|
|
|
, st1->num_peers
|
|
|
|
, st1->connect_candidates
|
2015-11-03 06:12:30 +01:00
|
|
|
, st1->errc ? (" [" + st1->errc.message() + "]").c_str() : "");
|
2014-03-05 10:37:49 +01:00
|
|
|
}
|
2013-06-14 18:38:26 +02:00
|
|
|
if (st2)
|
2017-04-02 20:22:17 +02:00
|
|
|
std::printf(" : %3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", static_cast<double>(time)
|
2014-01-26 09:18:13 +01:00
|
|
|
, int(st2->download_payload_rate / 1000)
|
|
|
|
, int(st2->upload_payload_rate / 1000)
|
|
|
|
, int(st2->progress * 100)
|
|
|
|
, st2->num_peers
|
|
|
|
, st2->connect_candidates
|
2015-11-03 06:12:30 +01:00
|
|
|
, st2->errc ? (" [" + st1->errc.message() + "]").c_str() : "");
|
2013-06-14 18:38:26 +02:00
|
|
|
if (st3)
|
2017-04-02 20:22:17 +02:00
|
|
|
std::printf(" : %3.1fs | %dkB/s %dkB/s %d%% %d cc:%d%s", static_cast<double>(time)
|
2014-01-26 09:18:13 +01:00
|
|
|
, int(st3->download_payload_rate / 1000)
|
|
|
|
, int(st3->upload_payload_rate / 1000)
|
|
|
|
, int(st3->progress * 100)
|
|
|
|
, st3->num_peers
|
|
|
|
, st3->connect_candidates
|
2015-11-03 06:12:30 +01:00
|
|
|
, st3->errc ? (" [" + st1->errc.message() + "]").c_str() : "");
|
2013-06-14 18:38:26 +02:00
|
|
|
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("\n");
|
2013-06-14 18:38:26 +02:00
|
|
|
}
|
|
|
|
|
2013-09-22 15:34:32 +02:00
|
|
|
#ifdef _WIN32
|
2018-03-22 17:01:38 +01:00
|
|
|
using pid_type = DWORD;
|
2013-09-23 07:36:50 +02:00
|
|
|
#else
|
2018-03-22 17:01:38 +01:00
|
|
|
using pid_type = pid_t;
|
2013-09-22 15:34:32 +02:00
|
|
|
#endif
|
|
|
|
|
2017-04-02 20:22:17 +02:00
|
|
|
namespace {
|
|
|
|
|
2013-09-22 05:37:33 +02:00
|
|
|
// returns 0 on failure, otherwise pid
|
2013-09-23 07:36:50 +02:00
|
|
|
pid_type async_run(char const* cmdline)
|
2013-09-20 05:06:26 +02:00
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
char buf[2048];
|
2016-05-17 15:24:06 +02:00
|
|
|
std::snprintf(buf, sizeof(buf), "%s", cmdline);
|
2013-09-20 05:06:26 +02:00
|
|
|
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
STARTUPINFOA startup;
|
|
|
|
memset(&startup, 0, sizeof(startup));
|
|
|
|
startup.cb = sizeof(startup);
|
|
|
|
startup.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
|
2016-11-12 19:50:49 +01:00
|
|
|
startup.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
2013-09-20 05:06:26 +02:00
|
|
|
startup.hStdError = GetStdHandle(STD_INPUT_HANDLE);
|
2016-11-12 19:50:49 +01:00
|
|
|
int ret = CreateProcessA(NULL, buf, NULL, NULL, TRUE
|
|
|
|
, CREATE_NEW_PROCESS_GROUP, NULL, NULL, &startup, &pi);
|
2013-09-20 05:06:26 +02:00
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
int error = GetLastError();
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("failed (%d) %s\n", error, error_code(error, system_category()).message().c_str());
|
2013-09-22 05:37:33 +02:00
|
|
|
return 0;
|
2013-09-20 05:06:26 +02:00
|
|
|
}
|
2013-09-22 05:37:33 +02:00
|
|
|
return pi.dwProcessId;
|
2013-09-20 05:06:26 +02:00
|
|
|
#else
|
2013-09-23 07:36:50 +02:00
|
|
|
pid_type p;
|
2013-09-22 05:37:33 +02:00
|
|
|
char arg_storage[4096];
|
|
|
|
char* argp = arg_storage;
|
|
|
|
std::vector<char*> argv;
|
|
|
|
argv.push_back(argp);
|
|
|
|
for (char const* in = cmdline; *in != '\0'; ++in)
|
|
|
|
{
|
|
|
|
if (*in != ' ')
|
|
|
|
{
|
|
|
|
*argp++ = *in;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*argp++ = '\0';
|
|
|
|
argv.push_back(argp);
|
|
|
|
}
|
|
|
|
*argp = '\0';
|
2016-07-09 22:26:26 +02:00
|
|
|
argv.push_back(nullptr);
|
2013-09-22 05:37:33 +02:00
|
|
|
|
2016-07-09 22:26:26 +02:00
|
|
|
int ret = posix_spawnp(&p, argv[0], nullptr, nullptr, &argv[0], nullptr);
|
2013-09-20 05:06:26 +02:00
|
|
|
if (ret != 0)
|
2013-09-22 05:37:33 +02:00
|
|
|
{
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("failed (%d) %s\n", errno, strerror(errno));
|
2013-09-22 05:37:33 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return p;
|
2013-09-20 05:06:26 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-11-03 09:15:51 +01:00
|
|
|
void stop_process(pid_type p)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
HANDLE proc = OpenProcess(PROCESS_TERMINATE | SYNCHRONIZE, FALSE, p);
|
2018-02-18 22:35:34 +01:00
|
|
|
if (proc == NULL) return;
|
2013-11-03 09:15:51 +01:00
|
|
|
TerminateProcess(proc, 138);
|
2018-02-18 22:35:34 +01:00
|
|
|
WaitForSingleObject(proc, 5000);
|
2013-11-03 09:15:51 +01:00
|
|
|
CloseHandle(proc);
|
|
|
|
#else
|
2016-05-17 15:24:06 +02:00
|
|
|
std::printf("killing pid: %d\n", p);
|
2013-11-03 09:15:51 +01:00
|
|
|
kill(p, SIGKILL);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-04-02 20:22:17 +02:00
|
|
|
} // anonymous namespace
|
|
|
|
|
2018-02-22 15:12:15 +01:00
|
|
|
struct proxy_t
|
|
|
|
{
|
|
|
|
pid_type pid;
|
|
|
|
int type;
|
|
|
|
};
|
|
|
|
|
|
|
|
// maps port to proxy type
|
|
|
|
static std::map<int, proxy_t> running_proxies;
|
|
|
|
|
2018-02-18 22:35:34 +01:00
|
|
|
void stop_proxy(int port)
|
|
|
|
{
|
2018-02-22 15:12:15 +01:00
|
|
|
auto const it = running_proxies.find(port);
|
2018-02-18 22:35:34 +01:00
|
|
|
|
|
|
|
if (it == running_proxies.end()) return;
|
|
|
|
|
2018-02-22 15:12:15 +01:00
|
|
|
std::printf("stopping proxy on port %d\n", port);
|
2018-02-18 22:35:34 +01:00
|
|
|
|
|
|
|
stop_process(it->second.pid);
|
|
|
|
running_proxies.erase(it);
|
|
|
|
}
|
|
|
|
|
2013-08-04 01:30:37 +02:00
|
|
|
void stop_all_proxies()
|
|
|
|
{
|
2013-09-22 05:37:33 +02:00
|
|
|
std::map<int, proxy_t> proxies = running_proxies;
|
2018-02-18 22:35:34 +01:00
|
|
|
running_proxies.clear();
|
2018-02-22 15:12:15 +01:00
|
|
|
for (auto const& i : proxies)
|
2013-08-04 01:30:37 +02:00
|
|
|
{
|
2018-02-22 15:12:15 +01:00
|
|
|
stop_process(i.second.pid);
|
2011-09-10 07:36:38 +02:00
|
|
|
}
|
2007-11-28 01:16:14 +01:00
|
|
|
}
|
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
// returns a port on success and -1 on failure
|
2012-06-09 18:58:16 +02:00
|
|
|
int start_proxy(int proxy_type)
|
2007-11-28 01:16:14 +01:00
|
|
|
{
|
2017-04-12 20:05:53 +02:00
|
|
|
using namespace lt;
|
2007-11-28 01:16:14 +01:00
|
|
|
|
2014-03-25 05:13:58 +01:00
|
|
|
std::map<int, proxy_t> :: iterator i = running_proxies.begin();
|
|
|
|
for (; i != running_proxies.end(); ++i)
|
2013-08-19 05:54:45 +02:00
|
|
|
{
|
2014-03-25 05:13:58 +01:00
|
|
|
if (i->second.type == proxy_type) { return i->first; }
|
2013-08-19 05:54:45 +02:00
|
|
|
}
|
2012-06-09 18:58:16 +02:00
|
|
|
|
2017-04-02 20:22:17 +02:00
|
|
|
int port = 2000 + static_cast<int>(lt::random(6000));
|
2015-06-25 02:50:30 +02:00
|
|
|
error_code ec;
|
|
|
|
io_service ios;
|
|
|
|
|
|
|
|
// make sure the port we pick is free
|
|
|
|
do {
|
|
|
|
++port;
|
|
|
|
tcp::socket s(ios);
|
|
|
|
s.open(tcp::v4(), ec);
|
|
|
|
if (ec) break;
|
2016-06-19 01:24:27 +02:00
|
|
|
s.bind(tcp::endpoint(address::from_string("127.0.0.1")
|
2016-09-07 23:51:18 +02:00
|
|
|
, std::uint16_t(port)), ec);
|
2015-06-25 02:50:30 +02:00
|
|
|
} while (ec);
|
|
|
|
|
2013-10-01 06:30:15 +02:00
|
|
|
|
2009-10-26 02:29:39 +01:00
|
|
|
char const* type = "";
|
|
|
|
char const* auth = "";
|
2013-09-22 05:37:33 +02:00
|
|
|
char const* cmd = "";
|
2009-10-26 02:29:39 +01:00
|
|
|
|
2007-11-28 01:16:14 +01:00
|
|
|
switch (proxy_type)
|
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
case settings_pack::socks4:
|
2009-10-26 02:29:39 +01:00
|
|
|
type = "socks4";
|
2013-09-22 05:37:33 +02:00
|
|
|
auth = " --allow-v4";
|
|
|
|
cmd = "python ../socks.py";
|
2007-11-28 01:16:14 +01:00
|
|
|
break;
|
2014-07-06 21:18:00 +02:00
|
|
|
case settings_pack::socks5:
|
2009-10-26 02:29:39 +01:00
|
|
|
type = "socks5";
|
2013-09-22 05:37:33 +02:00
|
|
|
cmd = "python ../socks.py";
|
2007-11-28 01:16:14 +01:00
|
|
|
break;
|
2014-07-06 21:18:00 +02:00
|
|
|
case settings_pack::socks5_pw:
|
2009-10-26 02:29:39 +01:00
|
|
|
type = "socks5";
|
2013-09-22 05:37:33 +02:00
|
|
|
auth = " --username testuser --password testpass";
|
|
|
|
cmd = "python ../socks.py";
|
2007-11-28 01:16:14 +01:00
|
|
|
break;
|
2014-07-06 21:18:00 +02:00
|
|
|
case settings_pack::http:
|
2009-10-26 02:29:39 +01:00
|
|
|
type = "http";
|
2013-09-22 05:37:33 +02:00
|
|
|
cmd = "python ../http.py";
|
2007-11-28 01:16:14 +01:00
|
|
|
break;
|
2014-07-06 21:18:00 +02:00
|
|
|
case settings_pack::http_pw:
|
2009-10-26 02:29:39 +01:00
|
|
|
type = "http";
|
2013-09-23 08:25:27 +02:00
|
|
|
auth = " --username testuser --password testpass";
|
2013-09-22 05:37:33 +02:00
|
|
|
cmd = "python ../http.py";
|
2007-11-28 01:16:14 +01:00
|
|
|
break;
|
|
|
|
}
|
2009-10-26 02:29:39 +01:00
|
|
|
char buf[512];
|
2016-05-17 15:24:06 +02:00
|
|
|
std::snprintf(buf, sizeof(buf), "%s --port %d%s", cmd, port, auth);
|
2009-10-26 02:29:39 +01:00
|
|
|
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("%s starting proxy on port %d (%s %s)...\n", time_now_string(), port, type, auth);
|
|
|
|
std::printf("%s\n", buf);
|
2013-11-03 09:15:51 +01:00
|
|
|
pid_type r = async_run(buf);
|
2015-06-06 08:42:23 +02:00
|
|
|
if (r == 0) abort();
|
2013-09-22 05:37:33 +02:00
|
|
|
proxy_t t = { r, proxy_type };
|
|
|
|
running_proxies.insert(std::make_pair(port, t));
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("%s launched\n", time_now_string());
|
2016-06-26 15:24:06 +02:00
|
|
|
std::this_thread::sleep_for(lt::milliseconds(500));
|
2012-06-09 18:58:16 +02:00
|
|
|
return port;
|
2007-11-27 01:06:59 +01:00
|
|
|
}
|
|
|
|
|
2017-04-12 20:05:53 +02:00
|
|
|
using namespace lt;
|
2006-05-28 21:03:54 +02:00
|
|
|
|
2007-09-01 06:43:13 +02:00
|
|
|
template <class T>
|
2016-08-17 23:26:35 +02:00
|
|
|
std::shared_ptr<T> clone_ptr(std::shared_ptr<T> const& ptr)
|
2007-09-01 06:43:13 +02:00
|
|
|
{
|
2016-08-17 23:26:35 +02:00
|
|
|
return std::make_shared<T>(*ptr);
|
2007-09-01 06:43:13 +02:00
|
|
|
}
|
|
|
|
|
2017-04-02 20:22:17 +02:00
|
|
|
std::uint8_t random_byte()
|
|
|
|
{ return static_cast<std::uint8_t>(lt::random(0xff)); }
|
2014-02-05 10:38:32 +01:00
|
|
|
|
2016-12-22 16:42:33 +01:00
|
|
|
std::vector<char> generate_piece(piece_index_t const idx, int const piece_size)
|
2016-07-15 20:35:57 +02:00
|
|
|
{
|
2017-04-12 20:05:53 +02:00
|
|
|
using namespace lt;
|
2017-04-02 20:22:17 +02:00
|
|
|
std::vector<char> ret(static_cast<std::size_t>(piece_size));
|
2016-07-15 20:35:57 +02:00
|
|
|
|
2017-04-02 20:22:17 +02:00
|
|
|
std::mt19937 rng(static_cast<std::uint32_t>(static_cast<int>(idx)));
|
2016-07-15 20:35:57 +02:00
|
|
|
std::uniform_int_distribution<int> rand(-128, 127);
|
|
|
|
for (char& c : ret)
|
|
|
|
{
|
|
|
|
c = static_cast<char>(rand(rng));
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-06-10 13:31:26 +02:00
|
|
|
lt::file_storage make_file_storage(span<const int> const file_sizes
|
2016-07-15 20:35:57 +02:00
|
|
|
, int const piece_size, std::string base_name)
|
|
|
|
{
|
2017-04-12 20:05:53 +02:00
|
|
|
using namespace lt;
|
2016-07-15 20:35:57 +02:00
|
|
|
file_storage fs;
|
2018-11-01 23:05:30 +01:00
|
|
|
for (std::ptrdiff_t i = 0; i != file_sizes.size(); ++i)
|
2016-07-15 20:35:57 +02:00
|
|
|
{
|
|
|
|
char filename[200];
|
2018-06-10 13:31:26 +02:00
|
|
|
std::snprintf(filename, sizeof(filename), "test%d", int(i));
|
2016-07-15 20:35:57 +02:00
|
|
|
char dirname[200];
|
|
|
|
std::snprintf(dirname, sizeof(dirname), "%s%d", base_name.c_str()
|
2018-06-10 13:31:26 +02:00
|
|
|
, int(i) / 5);
|
2016-07-15 20:35:57 +02:00
|
|
|
std::string full_path = combine_path(dirname, filename);
|
|
|
|
|
|
|
|
fs.add_file(full_path, file_sizes[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
fs.set_piece_length(piece_size);
|
|
|
|
fs.set_num_pieces(int((fs.total_size() + piece_size - 1) / piece_size));
|
|
|
|
|
|
|
|
return fs;
|
|
|
|
}
|
|
|
|
|
2018-06-10 13:31:26 +02:00
|
|
|
std::shared_ptr<lt::torrent_info> make_torrent(span<const int> const file_sizes
|
|
|
|
, int const piece_size)
|
2016-07-15 20:35:57 +02:00
|
|
|
{
|
2017-04-12 20:05:53 +02:00
|
|
|
using namespace lt;
|
2018-06-10 13:31:26 +02:00
|
|
|
file_storage fs = make_file_storage(file_sizes, piece_size);
|
2016-07-15 20:35:57 +02:00
|
|
|
|
2017-04-12 20:05:53 +02:00
|
|
|
lt::create_torrent ct(fs, piece_size, 0x4000
|
|
|
|
, lt::create_torrent::optimize_alignment);
|
2016-07-15 20:35:57 +02:00
|
|
|
|
2018-06-02 19:29:40 +02:00
|
|
|
for (auto const i : fs.piece_range())
|
2016-07-15 20:35:57 +02:00
|
|
|
{
|
2016-07-22 16:29:39 +02:00
|
|
|
std::vector<char> piece = generate_piece(i, fs.piece_size(i));
|
|
|
|
ct.set_hash(i, hasher(piece).final());
|
2016-07-15 20:35:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<char> buf;
|
|
|
|
bencode(std::back_inserter(buf), ct.generate());
|
2017-07-20 09:27:47 +02:00
|
|
|
return std::make_shared<torrent_info>(buf, from_span);
|
2016-07-15 20:35:57 +02:00
|
|
|
}
|
|
|
|
|
2018-06-10 13:31:26 +02:00
|
|
|
void create_random_files(std::string const& path, span<const int> file_sizes
|
2017-08-08 14:25:21 +02:00
|
|
|
, file_storage* fs)
|
2013-01-06 05:53:26 +01:00
|
|
|
{
|
|
|
|
error_code ec;
|
2017-04-02 20:22:17 +02:00
|
|
|
aux::vector<char> random_data(300000);
|
2018-11-01 23:05:30 +01:00
|
|
|
for (std::ptrdiff_t i = 0; i != file_sizes.size(); ++i)
|
2013-01-06 05:53:26 +01:00
|
|
|
{
|
2018-11-05 13:08:55 +01:00
|
|
|
aux::random_bytes(random_data);
|
2013-01-06 05:53:26 +01:00
|
|
|
char filename[200];
|
2018-06-10 13:31:26 +02:00
|
|
|
std::snprintf(filename, sizeof(filename), "test%d", int(i));
|
2014-03-07 09:39:55 +01:00
|
|
|
char dirname[200];
|
2018-06-10 13:31:26 +02:00
|
|
|
std::snprintf(dirname, sizeof(dirname), "test_dir%d", int(i) / 5);
|
2014-03-07 09:39:55 +01:00
|
|
|
|
|
|
|
std::string full_path = combine_path(path, dirname);
|
2018-02-25 17:17:42 +01:00
|
|
|
lt::create_directories(full_path, ec);
|
2018-06-10 13:13:33 +02:00
|
|
|
if (ec) std::printf("create_directory(%s) failed: (%d) %s\n"
|
2018-02-25 17:17:42 +01:00
|
|
|
, full_path.c_str(), ec.value(), ec.message().c_str());
|
|
|
|
|
2014-03-07 09:39:55 +01:00
|
|
|
full_path = combine_path(full_path, filename);
|
2018-06-10 13:13:33 +02:00
|
|
|
std::printf("creating file: %s\n", full_path.c_str());
|
2014-03-07 09:39:55 +01:00
|
|
|
|
2013-01-06 05:53:26 +01:00
|
|
|
int to_write = file_sizes[i];
|
2017-08-08 14:25:21 +02:00
|
|
|
if (fs) fs->add_file(full_path, to_write);
|
2017-07-15 02:59:20 +02:00
|
|
|
file f(full_path, open_mode::write_only, ec);
|
2016-10-10 02:23:45 +02:00
|
|
|
if (ec) std::printf("failed to create file \"%s\": (%d) %s\n"
|
2013-01-07 01:55:15 +01:00
|
|
|
, full_path.c_str(), ec.value(), ec.message().c_str());
|
2016-06-18 20:01:38 +02:00
|
|
|
std::int64_t offset = 0;
|
2013-01-06 05:53:26 +01:00
|
|
|
while (to_write > 0)
|
|
|
|
{
|
2017-04-02 20:22:17 +02:00
|
|
|
int const s = std::min(to_write, static_cast<int>(random_data.size()));
|
2018-11-01 23:05:30 +01:00
|
|
|
iovec_t const b = { random_data.data(), s};
|
2016-10-27 02:40:56 +02:00
|
|
|
f.writev(offset, b, ec);
|
2016-10-10 02:23:45 +02:00
|
|
|
if (ec) std::printf("failed to write file \"%s\": (%d) %s\n"
|
2013-01-07 01:55:15 +01:00
|
|
|
, full_path.c_str(), ec.value(), ec.message().c_str());
|
2013-01-06 05:53:26 +01:00
|
|
|
offset += s;
|
|
|
|
to_write -= s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-17 23:26:35 +02:00
|
|
|
std::shared_ptr<torrent_info> create_torrent(std::ostream* file
|
2015-09-20 03:06:56 +02:00
|
|
|
, char const* name, int piece_size
|
2013-07-28 17:06:28 +02:00
|
|
|
, int num_pieces, bool add_tracker, std::string ssl_certificate)
|
2006-05-28 21:03:54 +02:00
|
|
|
{
|
2016-08-17 23:26:35 +02:00
|
|
|
// exercise the path when encountering invalid urls
|
2009-05-30 20:50:38 +02:00
|
|
|
char const* invalid_tracker_url = "http:";
|
2009-06-23 03:52:44 +02:00
|
|
|
char const* invalid_tracker_protocol = "foo://non/existent-name.com/announce";
|
2015-07-12 05:01:27 +02:00
|
|
|
|
2008-05-28 10:44:40 +02:00
|
|
|
file_storage fs;
|
2008-08-19 17:04:14 +02:00
|
|
|
int total_size = piece_size * num_pieces;
|
2015-09-20 03:06:56 +02:00
|
|
|
fs.add_file(name, total_size);
|
2017-04-12 20:05:53 +02:00
|
|
|
lt::create_torrent t(fs, piece_size);
|
2010-02-18 05:37:02 +01:00
|
|
|
if (add_tracker)
|
|
|
|
{
|
|
|
|
t.add_tracker(invalid_tracker_url);
|
|
|
|
t.add_tracker(invalid_tracker_protocol);
|
|
|
|
}
|
2006-05-28 21:03:54 +02:00
|
|
|
|
2013-07-28 17:06:28 +02:00
|
|
|
if (!ssl_certificate.empty())
|
|
|
|
{
|
|
|
|
std::vector<char> file_buf;
|
|
|
|
error_code ec;
|
|
|
|
int res = load_file(ssl_certificate, file_buf, ec);
|
|
|
|
if (ec || res < 0)
|
|
|
|
{
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("failed to load SSL certificate: %s\n", ec.message().c_str());
|
2013-07-28 17:06:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::string pem;
|
|
|
|
std::copy(file_buf.begin(), file_buf.end(), std::back_inserter(pem));
|
|
|
|
t.set_root_cert(pem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-02 20:22:17 +02:00
|
|
|
aux::vector<char> piece(static_cast<std::size_t>(piece_size));
|
2007-07-03 01:48:06 +02:00
|
|
|
for (int i = 0; i < int(piece.size()); ++i)
|
2007-06-20 20:41:53 +02:00
|
|
|
piece[i] = (i % 26) + 'A';
|
2015-06-10 07:22:01 +02:00
|
|
|
|
2006-05-28 21:03:54 +02:00
|
|
|
// calculate the hash for all pieces
|
2016-07-22 16:29:39 +02:00
|
|
|
sha1_hash ph = hasher(piece).final();
|
2018-06-02 19:29:40 +02:00
|
|
|
for (auto const i : fs.piece_range())
|
2008-05-14 07:29:42 +02:00
|
|
|
t.set_hash(i, ph);
|
2007-10-04 11:32:09 +02:00
|
|
|
|
|
|
|
if (file)
|
|
|
|
{
|
|
|
|
while (total_size > 0)
|
|
|
|
{
|
2017-04-02 20:22:17 +02:00
|
|
|
file->write(&piece[0], std::min(piece.end_index(), total_size));
|
|
|
|
total_size -= piece.end_index();
|
2007-10-04 11:32:09 +02:00
|
|
|
}
|
|
|
|
}
|
2015-06-10 07:22:01 +02:00
|
|
|
|
2008-05-14 07:29:42 +02:00
|
|
|
std::vector<char> tmp;
|
2016-09-07 23:51:18 +02:00
|
|
|
std::back_insert_iterator<std::vector<char>> out(tmp);
|
2009-10-26 02:29:39 +01:00
|
|
|
|
2011-09-05 07:50:41 +02:00
|
|
|
entry tor = t.generate();
|
|
|
|
|
|
|
|
bencode(out, tor);
|
2009-12-15 14:11:07 +01:00
|
|
|
error_code ec;
|
2017-07-20 09:27:47 +02:00
|
|
|
return std::make_shared<torrent_info>(tmp, ec, from_span);
|
2013-08-18 00:29:34 +02:00
|
|
|
}
|
|
|
|
|
2016-06-20 17:32:06 +02:00
|
|
|
std::tuple<torrent_handle, torrent_handle, torrent_handle>
|
2014-07-06 21:18:00 +02:00
|
|
|
setup_transfer(lt::session* ses1, lt::session* ses2, lt::session* ses3
|
2007-12-30 10:36:01 +01:00
|
|
|
, bool clear_files, bool use_metadata_transfer, bool connect_peers
|
2008-08-18 22:02:50 +02:00
|
|
|
, std::string suffix, int piece_size
|
2016-08-17 23:26:35 +02:00
|
|
|
, std::shared_ptr<torrent_info>* torrent, bool super_seeding
|
2014-03-05 10:37:49 +01:00
|
|
|
, add_torrent_params const* p, bool stop_lsd, bool use_ssl_ports
|
2016-08-17 23:26:35 +02:00
|
|
|
, std::shared_ptr<torrent_info>* torrent2)
|
2007-10-04 11:32:09 +02:00
|
|
|
{
|
2014-12-31 16:51:45 +01:00
|
|
|
TORRENT_ASSERT(ses1);
|
|
|
|
TORRENT_ASSERT(ses2);
|
2007-10-04 11:32:09 +02:00
|
|
|
|
2011-02-16 11:16:52 +01:00
|
|
|
if (stop_lsd)
|
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
settings_pack pack;
|
|
|
|
pack.set_bool(settings_pack::enable_lsd, false);
|
|
|
|
ses1->apply_settings(pack);
|
|
|
|
ses2->apply_settings(pack);
|
|
|
|
if (ses3) ses3->apply_settings(pack);
|
2011-02-16 11:16:52 +01:00
|
|
|
}
|
2010-12-24 01:37:01 +01:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
// This has the effect of applying the global
|
|
|
|
// rule to all peers, regardless of if they're local or not
|
|
|
|
ip_filter f;
|
|
|
|
f.add_rule(address_v4::from_string("0.0.0.0")
|
|
|
|
, address_v4::from_string("255.255.255.255")
|
2017-01-22 04:40:19 +01:00
|
|
|
, 1 << static_cast<std::uint32_t>(lt::session::global_peer_class_id));
|
2014-07-06 21:18:00 +02:00
|
|
|
ses1->set_peer_class_filter(f);
|
|
|
|
ses2->set_peer_class_filter(f);
|
|
|
|
if (ses3) ses3->set_peer_class_filter(f);
|
|
|
|
|
|
|
|
settings_pack pack;
|
|
|
|
if (ses3) pack.set_bool(settings_pack::allow_multiple_connections_per_ip, true);
|
|
|
|
pack.set_int(settings_pack::mixed_mode_algorithm, settings_pack::prefer_tcp);
|
|
|
|
pack.set_int(settings_pack::max_failcount, 1);
|
2014-12-31 16:51:45 +01:00
|
|
|
ses1->apply_settings(pack);
|
|
|
|
ses2->apply_settings(pack);
|
2007-10-04 11:32:09 +02:00
|
|
|
if (ses3)
|
2008-10-30 06:31:26 +01:00
|
|
|
{
|
2014-12-31 16:51:45 +01:00
|
|
|
ses3->apply_settings(pack);
|
2008-10-30 06:31:26 +01:00
|
|
|
}
|
2007-10-04 11:32:09 +02:00
|
|
|
|
2016-08-17 23:26:35 +02:00
|
|
|
std::shared_ptr<torrent_info> t;
|
2016-07-09 22:26:26 +02:00
|
|
|
if (torrent == nullptr)
|
2008-08-18 22:02:50 +02:00
|
|
|
{
|
2009-10-26 02:29:39 +01:00
|
|
|
error_code ec;
|
2012-06-17 01:23:36 +02:00
|
|
|
create_directory("tmp1" + suffix, ec);
|
|
|
|
std::ofstream file(combine_path("tmp1" + suffix, "temporary").c_str());
|
2015-09-20 03:06:56 +02:00
|
|
|
t = ::create_torrent(&file, "temporary", piece_size, 9, false);
|
2008-08-18 22:02:50 +02:00
|
|
|
file.close();
|
|
|
|
if (clear_files)
|
|
|
|
{
|
2012-06-17 01:23:36 +02:00
|
|
|
remove_all(combine_path("tmp2" + suffix, "temporary"), ec);
|
|
|
|
remove_all(combine_path("tmp3" + suffix, "temporary"), ec);
|
2008-08-18 22:02:50 +02:00
|
|
|
}
|
2016-12-22 16:44:36 +01:00
|
|
|
std::printf("generated torrent: %s tmp1%s/temporary\n", aux::to_hex(t->info_hash()).c_str(), suffix.c_str());
|
2008-08-18 22:02:50 +02:00
|
|
|
}
|
|
|
|
else
|
2007-12-30 10:36:01 +01:00
|
|
|
{
|
2008-08-18 22:02:50 +02:00
|
|
|
t = *torrent;
|
2007-12-30 10:36:01 +01:00
|
|
|
}
|
2006-05-28 21:03:54 +02:00
|
|
|
|
|
|
|
// they should not use the same save dir, because the
|
|
|
|
// file pool will complain if two torrents are trying to
|
|
|
|
// use the same files
|
2009-02-03 08:46:24 +01:00
|
|
|
add_torrent_params param;
|
2017-07-09 16:32:01 +02:00
|
|
|
param.flags &= ~torrent_flags::paused;
|
|
|
|
param.flags &= ~torrent_flags::auto_managed;
|
2009-02-03 08:46:24 +01:00
|
|
|
if (p) param = *p;
|
|
|
|
param.ti = clone_ptr(t);
|
2012-06-17 01:23:36 +02:00
|
|
|
param.save_path = "tmp1" + suffix;
|
2017-07-09 16:32:01 +02:00
|
|
|
param.flags |= torrent_flags::seed_mode;
|
2009-12-15 14:11:07 +01:00
|
|
|
error_code ec;
|
|
|
|
torrent_handle tor1 = ses1->add_torrent(param, ec);
|
2014-07-06 21:18:00 +02:00
|
|
|
if (ec)
|
|
|
|
{
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("ses1.add_torrent: %s\n", ec.message().c_str());
|
2016-06-20 17:32:06 +02:00
|
|
|
return std::make_tuple(torrent_handle(), torrent_handle(), torrent_handle());
|
2014-07-06 21:18:00 +02:00
|
|
|
}
|
2017-07-01 17:43:39 +02:00
|
|
|
if (super_seeding)
|
|
|
|
{
|
2017-07-09 16:32:01 +02:00
|
|
|
tor1.set_flags(torrent_flags::super_seeding);
|
2017-07-01 17:43:39 +02:00
|
|
|
}
|
2012-03-19 05:02:13 +01:00
|
|
|
|
|
|
|
// the downloader cannot use seed_mode
|
2017-07-09 16:32:01 +02:00
|
|
|
param.flags &= ~torrent_flags::seed_mode;
|
2012-03-19 05:02:13 +01:00
|
|
|
|
2008-01-02 04:18:29 +01:00
|
|
|
TEST_CHECK(!ses1->get_torrents().empty());
|
2014-07-06 21:18:00 +02:00
|
|
|
|
2007-06-06 02:41:20 +02:00
|
|
|
torrent_handle tor2;
|
2007-06-09 01:02:31 +02:00
|
|
|
torrent_handle tor3;
|
2009-02-03 08:46:24 +01:00
|
|
|
|
2008-01-02 04:18:29 +01:00
|
|
|
if (ses3)
|
|
|
|
{
|
2009-02-03 08:46:24 +01:00
|
|
|
param.ti = clone_ptr(t);
|
2012-06-17 01:23:36 +02:00
|
|
|
param.save_path = "tmp3" + suffix;
|
2009-12-15 14:11:07 +01:00
|
|
|
tor3 = ses3->add_torrent(param, ec);
|
2008-01-02 04:18:29 +01:00
|
|
|
TEST_CHECK(!ses3->get_torrents().empty());
|
|
|
|
}
|
2007-06-09 01:02:31 +02:00
|
|
|
|
2015-06-10 07:22:01 +02:00
|
|
|
if (use_metadata_transfer)
|
2009-02-03 08:46:24 +01:00
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
param.ti.reset();
|
2009-02-03 08:46:24 +01:00
|
|
|
param.info_hash = t->info_hash();
|
|
|
|
}
|
2014-03-05 10:37:49 +01:00
|
|
|
else if (torrent2)
|
|
|
|
{
|
|
|
|
param.ti = clone_ptr(*torrent2);
|
|
|
|
}
|
2007-06-06 02:41:20 +02:00
|
|
|
else
|
2009-02-03 08:46:24 +01:00
|
|
|
{
|
|
|
|
param.ti = clone_ptr(t);
|
|
|
|
}
|
2012-06-17 01:23:36 +02:00
|
|
|
param.save_path = "tmp2" + suffix;
|
2009-02-03 08:46:24 +01:00
|
|
|
|
2009-12-15 14:11:07 +01:00
|
|
|
tor2 = ses2->add_torrent(param, ec);
|
2008-01-02 04:18:29 +01:00
|
|
|
TEST_CHECK(!ses2->get_torrents().empty());
|
2006-11-14 01:08:16 +01:00
|
|
|
|
2014-12-31 16:51:45 +01:00
|
|
|
TORRENT_ASSERT(ses1->get_torrents().size() == 1);
|
|
|
|
TORRENT_ASSERT(ses2->get_torrents().size() == 1);
|
2007-06-10 22:46:09 +02:00
|
|
|
|
2016-06-26 15:24:06 +02:00
|
|
|
// std::this_thread::sleep_for(lt::milliseconds(100));
|
2006-05-28 21:03:54 +02:00
|
|
|
|
2007-10-01 04:09:12 +02:00
|
|
|
if (connect_peers)
|
2007-06-09 01:02:31 +02:00
|
|
|
{
|
2015-06-16 04:00:02 +02:00
|
|
|
wait_for_downloading(*ses2, "ses2");
|
2013-09-03 10:39:30 +02:00
|
|
|
|
2014-10-06 05:03:01 +02:00
|
|
|
int port = 0;
|
2013-07-28 17:06:28 +02:00
|
|
|
if (use_ssl_ports)
|
2016-02-24 01:13:14 +01:00
|
|
|
{
|
2014-10-06 05:03:01 +02:00
|
|
|
port = ses2->ssl_listen_port();
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("%s: ses2->ssl_listen_port(): %d\n", time_now_string(), port);
|
2016-02-24 01:13:14 +01:00
|
|
|
}
|
2014-10-06 05:03:01 +02:00
|
|
|
|
|
|
|
if (port == 0)
|
2016-02-24 01:13:14 +01:00
|
|
|
{
|
2014-10-06 05:03:01 +02:00
|
|
|
port = ses2->listen_port();
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("%s: ses2->listen_port(): %d\n", time_now_string(), port);
|
2016-02-24 01:13:14 +01:00
|
|
|
}
|
2014-10-06 05:03:01 +02:00
|
|
|
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("%s: ses1: connecting peer port: %d\n"
|
2015-04-24 05:48:08 +02:00
|
|
|
, time_now_string(), port);
|
2014-10-06 05:03:01 +02:00
|
|
|
tor1.connect_peer(tcp::endpoint(address::from_string("127.0.0.1", ec)
|
2016-09-07 23:51:18 +02:00
|
|
|
, std::uint16_t(port)));
|
2007-10-01 04:09:12 +02:00
|
|
|
|
|
|
|
if (ses3)
|
|
|
|
{
|
|
|
|
// give the other peers some time to get an initial
|
|
|
|
// set of pieces before they start sharing with each-other
|
2013-07-28 17:06:28 +02:00
|
|
|
|
2015-06-16 04:00:02 +02:00
|
|
|
wait_for_downloading(*ses3, "ses3");
|
|
|
|
|
2014-10-06 05:03:01 +02:00
|
|
|
port = 0;
|
|
|
|
int port2 = 0;
|
2013-07-28 17:06:28 +02:00
|
|
|
if (use_ssl_ports)
|
|
|
|
{
|
2014-10-06 05:03:01 +02:00
|
|
|
port = ses2->ssl_listen_port();
|
|
|
|
port2 = ses1->ssl_listen_port();
|
2013-07-28 17:06:28 +02:00
|
|
|
}
|
2014-10-06 05:03:01 +02:00
|
|
|
|
|
|
|
if (port == 0) port = ses2->listen_port();
|
|
|
|
if (port2 == 0) port2 = ses1->listen_port();
|
|
|
|
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("ses3: connecting peer port: %d\n", port);
|
2014-10-06 05:03:01 +02:00
|
|
|
tor3.connect_peer(tcp::endpoint(
|
2016-09-07 23:51:18 +02:00
|
|
|
address::from_string("127.0.0.1", ec), std::uint16_t(port)));
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("ses3: connecting peer port: %d\n", port2);
|
2013-07-28 17:06:28 +02:00
|
|
|
tor3.connect_peer(tcp::endpoint(
|
|
|
|
address::from_string("127.0.0.1", ec)
|
2016-09-07 23:51:18 +02:00
|
|
|
, std::uint16_t(port2)));
|
2007-10-01 04:09:12 +02:00
|
|
|
}
|
2007-06-09 01:02:31 +02:00
|
|
|
}
|
2006-05-28 21:03:54 +02:00
|
|
|
|
2016-06-20 17:32:06 +02:00
|
|
|
return std::make_tuple(tor1, tor2, tor3);
|
2006-05-28 21:03:54 +02:00
|
|
|
}
|
|
|
|
|
2017-04-02 20:22:17 +02:00
|
|
|
namespace {
|
2013-11-03 09:15:51 +01:00
|
|
|
pid_type web_server_pid = 0;
|
2017-04-02 20:22:17 +02:00
|
|
|
}
|
2009-12-06 00:41:33 +01:00
|
|
|
|
2017-04-28 07:13:26 +02:00
|
|
|
int start_web_server(bool ssl, bool chunked_encoding, bool keepalive, int min_interval)
|
2009-12-06 00:41:33 +01:00
|
|
|
{
|
2017-04-02 20:22:17 +02:00
|
|
|
int port = 2000 + static_cast<int>(lt::random(6000));
|
2015-06-23 05:55:47 +02:00
|
|
|
error_code ec;
|
|
|
|
io_service ios;
|
|
|
|
|
2015-06-25 02:50:30 +02:00
|
|
|
// make sure the port we pick is free
|
2015-06-23 05:55:47 +02:00
|
|
|
do {
|
|
|
|
++port;
|
|
|
|
tcp::socket s(ios);
|
|
|
|
s.open(tcp::v4(), ec);
|
|
|
|
if (ec) break;
|
2016-06-19 01:24:27 +02:00
|
|
|
s.bind(tcp::endpoint(address::from_string("127.0.0.1")
|
2016-09-07 23:51:18 +02:00
|
|
|
, std::uint16_t(port)), ec);
|
2015-06-23 05:55:47 +02:00
|
|
|
} while (ec);
|
2009-12-17 09:50:35 +01:00
|
|
|
|
2013-11-03 09:15:51 +01:00
|
|
|
char buf[200];
|
2017-04-28 07:13:26 +02:00
|
|
|
std::snprintf(buf, sizeof(buf), "python ../web_server.py %d %d %d %d %d"
|
|
|
|
, port, chunked_encoding, ssl, keepalive, min_interval);
|
2010-01-24 00:57:11 +01:00
|
|
|
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("%s starting web_server on port %d...\n", time_now_string(), port);
|
2009-12-06 00:41:33 +01:00
|
|
|
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("%s\n", buf);
|
2013-11-03 09:15:51 +01:00
|
|
|
pid_type r = async_run(buf);
|
2015-06-06 08:42:23 +02:00
|
|
|
if (r == 0) abort();
|
2013-11-03 09:15:51 +01:00
|
|
|
web_server_pid = r;
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("%s launched\n", time_now_string());
|
2016-06-26 15:24:06 +02:00
|
|
|
std::this_thread::sleep_for(lt::milliseconds(500));
|
2010-01-24 00:57:11 +01:00
|
|
|
return port;
|
2009-12-06 00:41:33 +01:00
|
|
|
}
|
|
|
|
|
2013-11-03 09:15:51 +01:00
|
|
|
void stop_web_server()
|
2011-09-10 07:36:38 +02:00
|
|
|
{
|
2013-11-03 09:15:51 +01:00
|
|
|
if (web_server_pid == 0) return;
|
2016-10-10 02:23:45 +02:00
|
|
|
std::printf("stopping web server\n");
|
2013-11-03 09:15:51 +01:00
|
|
|
stop_process(web_server_pid);
|
|
|
|
web_server_pid = 0;
|
2011-09-10 07:36:38 +02:00
|
|
|
}
|
|
|
|
|
2015-09-22 05:49:22 +02:00
|
|
|
tcp::endpoint ep(char const* ip, int port)
|
|
|
|
{
|
|
|
|
error_code ec;
|
2016-09-07 23:51:18 +02:00
|
|
|
tcp::endpoint ret(address::from_string(ip, ec), std::uint16_t(port));
|
2016-06-04 16:01:43 +02:00
|
|
|
TEST_CHECK(!ec);
|
|
|
|
return ret;
|
2015-09-22 05:49:22 +02:00
|
|
|
}
|
2016-06-04 16:03:13 +02:00
|
|
|
|
2016-09-17 15:42:04 +02:00
|
|
|
udp::endpoint uep(char const* ip, int port)
|
|
|
|
{
|
|
|
|
error_code ec;
|
|
|
|
udp::endpoint ret(address::from_string(ip, ec), std::uint16_t(port));
|
|
|
|
TEST_CHECK(!ec);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-04-12 20:05:53 +02:00
|
|
|
lt::address addr(char const* ip)
|
2016-06-04 16:03:13 +02:00
|
|
|
{
|
|
|
|
lt::error_code ec;
|
|
|
|
auto ret = lt::address::from_string(ip, ec);
|
|
|
|
TEST_CHECK(!ec);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-04-12 20:05:53 +02:00
|
|
|
lt::address_v4 addr4(char const* ip)
|
2016-06-04 16:03:13 +02:00
|
|
|
{
|
|
|
|
lt::error_code ec;
|
|
|
|
auto ret = lt::address_v4::from_string(ip, ec);
|
|
|
|
TEST_CHECK(!ec);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-04-12 20:05:53 +02:00
|
|
|
lt::address_v6 addr6(char const* ip)
|
2016-06-04 16:03:13 +02:00
|
|
|
{
|
|
|
|
lt::error_code ec;
|
|
|
|
auto ret = lt::address_v6::from_string(ip, ec);
|
|
|
|
TEST_CHECK(!ec);
|
|
|
|
return ret;
|
|
|
|
}
|