use span in gzip, http_parser and http_connection

This commit is contained in:
arvidn 2017-09-04 00:13:08 +02:00 committed by Arvid Norberg
parent 53ff169db1
commit 95c8c3018a
16 changed files with 118 additions and 127 deletions

View File

@ -35,13 +35,14 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/error_code.hpp"
#include "libtorrent/span.hpp"
#include <vector>
namespace libtorrent {
TORRENT_EXTRA_EXPORT void inflate_gzip(
char const* in, int size
span<char const> in
, std::vector<char>& buffer
, int maximum_size
, error_code& error);

View File

@ -67,7 +67,7 @@ struct resolver_interface;
const int default_max_bottled_buffer_size = 2 * 1024 * 1024;
typedef std::function<void(error_code const&
, http_parser const&, char const* data, int size, http_connection&)> http_handler;
, http_parser const&, span<char const> data, http_connection&)> http_handler;
typedef std::function<void(http_connection&)> http_connect_handler;
@ -143,7 +143,7 @@ private:
, error_code const& e);
void on_assign_bandwidth(error_code const& e);
void callback(error_code e, char* data = nullptr, int size = 0);
void callback(error_code e, span<char> data = {});
aux::vector<char> m_recvbuffer;

View File

@ -94,7 +94,7 @@ namespace libtorrent {
// instanced parsed. It will use the internal chunk list to determine
// where the chunks are in the buffer. It returns the new length of
// the buffer
int collapse_chunk_headers(char* buffer, int size) const;
span<char> collapse_chunk_headers(span<char> buffer) const;
// returns false if the buffer doesn't contain a complete
// chunk header. In this case, call the function again with

View File

@ -80,7 +80,7 @@ namespace libtorrent {
void on_filter(http_connection& c, std::vector<tcp::endpoint>& endpoints);
void on_connect(http_connection& c);
void on_response(error_code const& ec, http_parser const& parser
, char const* data, int size);
, span<char const> data);
virtual void on_timeout(error_code const&) {}
@ -92,7 +92,7 @@ namespace libtorrent {
};
TORRENT_EXTRA_EXPORT tracker_response parse_tracker_response(
char const* data, int size, error_code& ec
span<char const> data, error_code& ec
, int flags, sha1_hash const& scrape_ih);
TORRENT_EXTRA_EXPORT bool extract_peer_info(bdecode_node const& info

View File

@ -1045,7 +1045,7 @@ namespace libtorrent {
#ifndef TORRENT_NO_DEPRECATE
void on_torrent_download(error_code const& ec, http_parser const& parser
, char const* data, int size);
, span<char const> data);
#endif
int sequence_number() const { return m_sequence_number; }

View File

@ -120,8 +120,8 @@ std::shared_ptr<http_connection> test_request(io_service& ios
, resolver& res
, std::string const& url
, char const* expected_data
, int expected_size
, int expected_status
, int const expected_size
, int const expected_status
, error_condition expected_error
, lt::aux::proxy_settings const& ps
, int* connect_handler_called
@ -133,7 +133,7 @@ std::shared_ptr<http_connection> test_request(io_service& ios
auto h = std::make_shared<http_connection>(ios
, res
, [=](error_code const& ec, http_parser const& parser
, char const* data, const int size, http_connection&)
, span<char const> data, http_connection&)
{
std::printf("RESPONSE: %s\n", url.c_str());
++*handler_called;
@ -156,7 +156,7 @@ std::shared_ptr<http_connection> test_request(io_service& ios
const int http_status = parser.status_code();
if (expected_size != -1)
{
TEST_EQUAL(size, expected_size);
TEST_EQUAL(int(data.size()), expected_size);
}
TEST_CHECK(error_ok);
if (expected_status != -1)
@ -166,8 +166,8 @@ std::shared_ptr<http_connection> test_request(io_service& ios
if (http_status == 200)
{
TEST_CHECK(expected_data
&& size == expected_size
&& memcmp(expected_data, data, size) == 0);
&& int(data.size()) == expected_size
&& memcmp(expected_data, data.data(), data.size()) == 0);
}
}
, true, 1024*1024
@ -632,7 +632,7 @@ TORRENT_TEST(http_connection_ssl_proxy)
auto h = std::make_shared<http_connection>(client_ios
, res
, [&client_counter](error_code const& ec, http_parser const& parser
, char const* data, const int size, http_connection& c)
, span<char const>, http_connection& c)
{
client_counter++;
TEST_EQUAL(ec, boost::asio::error::operation_not_supported);

View File

@ -112,23 +112,23 @@ namespace libtorrent {
namespace {
// returns -1 if gzip header is invalid or the header size in bytes
int gzip_header(const char* buf, int size)
int gzip_header(span<char const> const buf)
{
TORRENT_ASSERT(buf != nullptr);
TORRENT_ASSERT(!buf.empty());
const unsigned char* buffer = reinterpret_cast<const unsigned char*>(buf);
const int total_size = size;
span<unsigned char const> buffer(
reinterpret_cast<const unsigned char*>(buf.data()), buf.size());
// gzip is defined in https://tools.ietf.org/html/rfc1952
// The zip header cannot be shorter than 10 bytes
if (size < 10 || buf == nullptr) return -1;
if (buffer.size() < 10) return -1;
// check the magic header of gzip
if ((buffer[0] != GZIP_MAGIC0) || (buffer[1] != GZIP_MAGIC1)) return -1;
int method = buffer[2];
int flags = buffer[3];
int const method = buffer[2];
int const flags = buffer[3];
// check for reserved flag and make sure it's compressed with the correct metod
// we only support deflate
@ -139,63 +139,51 @@ namespace {
// |ID1|ID2|CM |FLG| MTIME |XFL|OS | (more-->)
// +---+---+---+---+---+---+---+---+---+---+
size -= 10;
buffer += 10;
buffer = buffer.subspan(10);
if (flags & FEXTRA)
{
int extra_len;
if (buffer.size() < 2) return -1;
if (size < 2) return -1;
extra_len = (buffer[1] << 8) | buffer[0];
if (size < (extra_len+2)) return -1;
size -= (extra_len + 2);
buffer += (extra_len + 2);
std::size_t const extra_len = static_cast<std::size_t>((buffer[1] << 8) | buffer[0]);
if (buffer.size() < extra_len + 2) return -1;
buffer = buffer.subspan(extra_len + 2);
}
if (flags & FNAME)
{
while (size && *buffer)
if (buf.empty()) return -1;
while (buffer[0] != 0)
{
--size;
++buffer;
buffer = buffer.subspan(1);
if (buf.empty()) return -1;
}
if (!size || *buffer) return -1;
--size;
++buffer;
buffer = buffer.subspan(1);
}
if (flags & FCOMMENT)
{
while (size && *buffer)
if (buf.empty()) return -1;
while (buffer[0] != 0)
{
--size;
++buffer;
buffer = buffer.subspan(1);
if (buf.empty()) return -1;
}
if (!size || *buffer) return -1;
--size;
++buffer;
buffer = buffer.subspan(1);
}
if (flags & FHCRC)
{
if (size < 2) return -1;
size -= 2;
// buffer += 2;
if (buffer.size() < 2) return -1;
buffer = buffer.subspan(2);
}
return total_size - size;
return static_cast<int>(buf.size() - buffer.size());
}
} // anonymous namespace
TORRENT_EXTRA_EXPORT void inflate_gzip(
char const* in
, int size
span<char const> in
, std::vector<char>& buffer
, int maximum_size
, error_code& ec)
@ -203,7 +191,7 @@ namespace {
ec.clear();
TORRENT_ASSERT(maximum_size > 0);
int header_len = gzip_header(in, size);
int header_len = gzip_header(in);
if (header_len < 0)
{
ec = gzip_errors::invalid_gzip_header;
@ -214,8 +202,8 @@ namespace {
// if needed
unsigned long destlen = 4096;
int ret = 0;
unsigned long srclen = std::uint32_t(size - header_len);
in += header_len;
in = in.subspan(static_cast<std::size_t>(header_len));
unsigned long srclen = std::uint32_t(in.size());
do
{
@ -226,8 +214,10 @@ namespace {
return;
}
ret = puff(reinterpret_cast<unsigned char*>(&buffer[0]), &destlen
, reinterpret_cast<const unsigned char*>(in), &srclen);
ret = puff(reinterpret_cast<unsigned char*>(buffer.data())
, &destlen
, reinterpret_cast<const unsigned char*>(in.data())
, &srclen);
// if the destination buffer wasn't large enough, double its
// size and try again. Unless it's already at its max, in which

View File

@ -143,7 +143,7 @@ void http_connection::get(std::string const& url, time_duration timeout, int pri
if (ec)
{
m_timer.get_io_service().post(std::bind(&http_connection::callback
, me, ec, static_cast<char*>(nullptr), 0));
, me, ec, span<char>{}));
return;
}
@ -155,7 +155,7 @@ void http_connection::get(std::string const& url, time_duration timeout, int pri
{
error_code err(errors::unsupported_url_protocol);
m_timer.get_io_service().post(std::bind(&http_connection::callback
, me, err, static_cast<char*>(nullptr), 0));
, me, err, span<char>{}));
return;
}
@ -254,7 +254,7 @@ void http_connection::start(std::string const& hostname, int port
if (ec)
{
m_timer.get_io_service().post(std::bind(&http_connection::callback
, me, ec, nullptr, 0));
, me, ec, span<char>{}));
return;
}
@ -292,7 +292,7 @@ void http_connection::start(std::string const& hostname, int port
if (is_i2p && i2p_conn->proxy().type != settings_pack::i2p_proxy)
{
m_timer.get_io_service().post(std::bind(&http_connection::callback
, me, error_code(errors::no_i2p_router), static_cast<char*>(nullptr), 0));
, me, error_code(errors::no_i2p_router), span<char>{}));
return;
}
#endif
@ -333,7 +333,7 @@ void http_connection::start(std::string const& hostname, int port
if (ec)
{
m_timer.get_io_service().post(std::bind(&http_connection::callback
, me, ec, nullptr, 0));
, me, ec, span<char>{}));
return;
}
}
@ -354,7 +354,7 @@ void http_connection::start(std::string const& hostname, int port
if (ec)
{
m_timer.get_io_service().post(std::bind(&http_connection::callback
, me, ec, nullptr, 0));
, me, ec, span<char>{}));
return;
}
}
@ -363,7 +363,7 @@ void http_connection::start(std::string const& hostname, int port
if (ec)
{
m_timer.get_io_service().post(std::bind(&http_connection::callback
, me, ec, nullptr, 0));
, me, ec, span<char>{}));
return;
}
@ -632,29 +632,27 @@ void http_connection::on_connect(error_code const& e)
}
}
// TODO: 3 use span<char> instead of data, size
void http_connection::callback(error_code e, char* data, int size)
void http_connection::callback(error_code e, span<char> data)
{
if (m_bottled && m_called) return;
std::vector<char> buf;
if (data && m_bottled && m_parser.header_finished())
if (!data.empty() && m_bottled && m_parser.header_finished())
{
size = m_parser.collapse_chunk_headers(data, size);
data = m_parser.collapse_chunk_headers(data);
std::string const& encoding = m_parser.header("content-encoding");
if ((encoding == "gzip" || encoding == "x-gzip") && size > 0 && data)
if ((encoding == "gzip" || encoding == "x-gzip"))
{
error_code ec;
inflate_gzip(data, size, buf, m_max_bottled_buffer_size, ec);
inflate_gzip(data, buf, m_max_bottled_buffer_size, ec);
if (ec)
{
if (m_handler) m_handler(ec, m_parser, data, size, *this);
if (m_handler) m_handler(ec, m_parser, data, *this);
return;
}
size = int(buf.size());
data = size == 0 ? nullptr : &buf[0];
data = buf;
}
// if we completed the whole response, no need
@ -665,7 +663,7 @@ void http_connection::callback(error_code e, char* data, int size)
m_called = true;
error_code ec;
m_timer.cancel(ec);
if (m_handler) m_handler(e, m_parser, data, size, *this);
if (m_handler) m_handler(e, m_parser, data, *this);
}
void http_connection::on_write(error_code const& e)
@ -737,7 +735,7 @@ void http_connection::on_read(error_code const& e
body = span<char>(m_recvbuffer.data() + m_parser.body_start()
, m_parser.get_body().size());
}
callback(ec, body.data(), int(body.size()));
callback(ec, body);
return;
}
@ -760,7 +758,7 @@ void http_connection::on_read(error_code const& e
{
// HTTP parse error
error_code ec = errors::http_parse_error;
callback(ec, nullptr, 0);
callback(ec);
return;
}
@ -803,8 +801,11 @@ void http_connection::on_read(error_code const& e
if (!m_bottled && m_parser.header_finished())
{
if (m_read_pos > m_parser.body_start())
callback(e, m_recvbuffer.data() + m_parser.body_start()
, m_read_pos - m_parser.body_start());
{
callback(e, span<char>(m_recvbuffer)
.first(static_cast<std::size_t>(m_read_pos))
.subspan(static_cast<std::size_t>(m_parser.body_start())));
}
m_read_pos = 0;
m_last_receive = clock_type::now();
}
@ -812,15 +813,15 @@ void http_connection::on_read(error_code const& e
{
error_code ec;
m_timer.cancel(ec);
span<char> body(m_recvbuffer.data() + m_parser.body_start()
, m_parser.get_body().size());
callback(e, body.data(), int(body.size()));
callback(e, span<char>(m_recvbuffer)
.first(static_cast<std::size_t>(m_read_pos))
.subspan(static_cast<std::size_t>(m_parser.body_start())));
}
}
else
{
TORRENT_ASSERT(!m_bottled);
callback(e, m_recvbuffer.data(), m_read_pos);
callback(e, span<char>(m_recvbuffer).first(static_cast<std::size_t>(m_read_pos)));
m_read_pos = 0;
m_last_receive = clock_type::now();
}

View File

@ -547,28 +547,28 @@ restart_response:
m_partial_chunk_header = 0;
}
int http_parser::collapse_chunk_headers(char* buffer, int size) const
span<char> http_parser::collapse_chunk_headers(span<char> buffer) const
{
if (!chunked_encoding()) return size;
if (!chunked_encoding()) return buffer;
// go through all chunks and compact them
// since we're bottled, and the buffer is our after all
// it's OK to mutate it
char* write_ptr = buffer;
char* write_ptr = buffer.data();
// the offsets in the array are from the start of the
// buffer, not start of the body, so subtract the size
// of the HTTP header from them
int const offset = body_start();
std::size_t const offset = static_cast<std::size_t>(body_start());
for (auto const& i : chunks())
{
TORRENT_ASSERT(i.second - i.first < (std::numeric_limits<int>::max)());
TORRENT_ASSERT(i.second - offset <= size);
int len = int(i.second - i.first);
if (i.first - offset + len > size) len = size - int(i.first) + offset;
std::memmove(write_ptr, buffer + i.first - offset, std::size_t(len));
write_ptr += len;
size_t const chunk_start = static_cast<std::size_t>(i.first);
size_t const chunk_end = static_cast<std::size_t>(i.second);
TORRENT_ASSERT(i.second - i.first < std::numeric_limits<int>::max());
TORRENT_ASSERT(chunk_end - offset <= buffer.size());
span<char> chunk = buffer.subspan(chunk_start - offset, chunk_end - chunk_start);
std::memmove(write_ptr, chunk.data(), chunk.size());
write_ptr += chunk.size();
}
size = int(write_ptr - buffer);
return size;
return buffer.first(static_cast<std::size_t>(write_ptr - buffer.data()));
}
}

View File

@ -201,7 +201,7 @@ namespace libtorrent {
}
m_tracker_connection = std::make_shared<http_connection>(get_io_service(), m_man.host_resolver()
, std::bind(&http_tracker_connection::on_response, shared_from_this(), _1, _2, _3, _4)
, std::bind(&http_tracker_connection::on_response, shared_from_this(), _1, _2, _3)
, true, settings.get_int(settings_pack::max_http_recv_buffer_size)
, std::bind(&http_tracker_connection::on_connect, shared_from_this(), _1)
, std::bind(&http_tracker_connection::on_filter, shared_from_this(), _1, _2)
@ -301,7 +301,7 @@ namespace libtorrent {
}
void http_tracker_connection::on_response(error_code const& ec
, http_parser const& parser, char const* data, int size)
, http_parser const& parser, span<char const> data)
{
// keep this alive
std::shared_ptr<http_tracker_connection> me(shared_from_this());
@ -331,7 +331,7 @@ namespace libtorrent {
return;
}
received_bytes(size + parser.body_start());
received_bytes(static_cast<int>(data.size()) + parser.body_start());
// handle tracker response
error_code ecode;
@ -343,7 +343,7 @@ namespace libtorrent {
return;
}
tracker_response resp = parse_tracker_response(data, size, ecode
tracker_response resp = parse_tracker_response(data, ecode
, tracker_req().kind, tracker_req().info_hash);
if (!resp.warning_message.empty())
@ -421,13 +421,13 @@ namespace libtorrent {
return true;
}
tracker_response parse_tracker_response(char const* data, int const size, error_code& ec
tracker_response parse_tracker_response(span<char const> const data, error_code& ec
, int const flags, sha1_hash const& scrape_ih)
{
tracker_response resp;
bdecode_node e;
int res = bdecode(data, data + size, e, ec);
int const res = bdecode(data.begin(), data.end(), e, ec);
if (ec) return resp;

View File

@ -396,7 +396,7 @@ namespace libtorrent {
#ifndef TORRENT_NO_DEPRECATE
// deprecated in 1.2
void torrent::on_torrent_download(error_code const& ec
, http_parser const& parser, char const* data, int size) try
, http_parser const& parser, span<char const> data) try
{
if (m_abort) return;
@ -415,7 +415,7 @@ namespace libtorrent {
}
error_code e;
auto tf = std::make_shared<torrent_info>(data, size, std::ref(e), 0);
auto tf = std::make_shared<torrent_info>(data, std::ref(e), from_span);
if (e)
{
set_error(e, torrent_status::error_file_url);
@ -701,7 +701,7 @@ namespace libtorrent {
new http_connection(m_ses.get_io_service()
, m_ses.get_resolver()
, std::bind(&torrent::on_torrent_download, shared_from_this()
, _1, _2, _3, _4)
, _1, _2, _3)
, true // bottled
//bottled buffer size
, settings().get_int(settings_pack::max_http_recv_buffer_size)

View File

@ -320,7 +320,7 @@ void upnp::resend_request(error_code const& ec)
d.upnp_connection = std::make_shared<http_connection>(m_io_service
, m_resolver
, std::bind(&upnp::on_upnp_xml, self(), _1, _2
, std::ref(d), _5));
, std::ref(d), _4));
d.upnp_connection->get(d.url, seconds(30), 1);
}
TORRENT_CATCH (std::exception const& exc)
@ -660,12 +660,11 @@ void upnp::try_map_upnp(bool const timer)
#ifndef TORRENT_DISABLE_LOGGING
log("connecting to: %s", d.url.c_str());
#endif
if (d.upnp_connection) d.upnp_connection->close();
d.upnp_connection = std::make_shared<http_connection>(m_io_service
, m_resolver
, std::bind(&upnp::on_upnp_xml, self(), _1, _2
, std::ref(d), _5));
, std::ref(d), _4));
d.upnp_connection->get(d.url, seconds(30), 1);
}
TORRENT_CATCH (std::exception const& exc)
@ -815,7 +814,7 @@ void upnp::update_map(rootdevice& d, port_mapping_t const i)
d.upnp_connection = std::make_shared<http_connection>(m_io_service
, m_resolver
, std::bind(&upnp::on_upnp_map_response, self(), _1, _2
, std::ref(d), i, _5), true, default_max_bottled_buffer_size
, std::ref(d), i, _4), true, default_max_bottled_buffer_size
, std::bind(&upnp::create_port_mapping, self(), _1, std::ref(d), i));
d.upnp_connection->start(d.hostname, d.port
@ -827,7 +826,7 @@ void upnp::update_map(rootdevice& d, port_mapping_t const i)
d.upnp_connection = std::make_shared<http_connection>(m_io_service
, m_resolver
, std::bind(&upnp::on_upnp_unmap_response, self(), _1, _2
, std::ref(d), i, _5), true, default_max_bottled_buffer_size
, std::ref(d), i, _4), true, default_max_bottled_buffer_size
, std::bind(&upnp::delete_port_mapping, self(), std::ref(d), i));
d.upnp_connection->start(d.hostname, d.port
, seconds(10), 1, nullptr, false, 5, m.local_ep.address());
@ -1037,7 +1036,7 @@ void upnp::on_upnp_xml(error_code const& e
d.upnp_connection = std::make_shared<http_connection>(m_io_service
, m_resolver
, std::bind(&upnp::on_upnp_get_ip_address_response, self(), _1, _2
, std::ref(d), _5), true, default_max_bottled_buffer_size
, std::ref(d), _4), true, default_max_bottled_buffer_size
, std::bind(&upnp::get_ip_address, self(), std::ref(d)));
d.upnp_connection->start(d.hostname, d.port
, seconds(10), 1);

View File

@ -47,7 +47,7 @@ TORRENT_TEST(zeroes)
TEST_CHECK(!ec);
std::vector<char> inflated;
inflate_gzip(&zipped[0], int(zipped.size()), inflated, 1000000, ec);
inflate_gzip(zipped, inflated, 1000000, ec);
if (ec) {
std::printf("failed to unzip: %s\n", ec.message().c_str());
@ -68,7 +68,7 @@ TORRENT_TEST(corrupt)
TEST_CHECK(!ec);
std::vector<char> inflated;
inflate_gzip(&zipped[0], int(zipped.size()), inflated, 1000000, ec);
inflate_gzip(zipped, inflated, 1000000, ec);
// we expect this to fail
TEST_CHECK(ec);

View File

@ -77,19 +77,19 @@ void http_connect_handler(http_connection& c)
}
void http_handler(error_code const& ec, http_parser const& parser
, char const* data, int size, http_connection& c)
, span<char const> data, http_connection& c)
{
++handler_called;
data_size = size;
data_size = data.size();
g_error_code = ec;
TORRENT_ASSERT(size == 0 || parser.finished());
TORRENT_ASSERT(data.empty() || parser.finished());
if (parser.header_finished())
{
http_status = parser.status_code();
if (http_status == 200)
{
TEST_CHECK(memcmp(data, data_buffer, size) == 0);
TEST_CHECK(memcmp(data.data(), data_buffer, data.size()) == 0);
}
}
print_http_header(parser);

View File

@ -518,9 +518,9 @@ TORRENT_TEST(chunked_encoding)
char mutable_buffer[100];
span<char const> body = parser.get_body();
memcpy(mutable_buffer, body.begin(), body.size());
int const len = parser.collapse_chunk_headers(mutable_buffer, int(body.size()));
body = parser.collapse_chunk_headers({mutable_buffer, body.size()});
TEST_CHECK(std::equal(mutable_buffer, mutable_buffer + len, "test12340123456789abcdef"));
TEST_CHECK(body == span<char const>("test12340123456789abcdef", 24));
}
TORRENT_TEST(invalid_content_length)

View File

@ -69,7 +69,7 @@ TORRENT_TEST(parse_hostname_peers)
"2:ip13:test_hostname4:porti1000eed"
"7:peer id20:bbbbabaababababababa2:ip12:another_host4:porti1001eeee";
error_code ec;
tracker_response resp = parse_tracker_response(response, sizeof(response) - 1
tracker_response resp = parse_tracker_response(response
, ec, false, sha1_hash());
TEST_EQUAL(ec, error_code());
@ -93,7 +93,7 @@ TORRENT_TEST(parse_peers4)
char const response[] = "d5:peers12:\x01\x02\x03\x04\x30\x10"
"\x09\x08\x07\x06\x20\x10" "e";
error_code ec;
tracker_response resp = parse_tracker_response(response, sizeof(response) - 1
tracker_response resp = parse_tracker_response(response
, ec, false, sha1_hash());
TEST_EQUAL(ec, error_code());
@ -157,7 +157,7 @@ TORRENT_TEST(parse_i2p_peers)
0xa0, 0x75, 0xab, 0x65 };
error_code ec;
tracker_response resp = parse_tracker_response(
reinterpret_cast<char const*>(response), sizeof(response)
{ reinterpret_cast<char const*>(response), sizeof(response) }
, ec, tracker_request::i2p, sha1_hash());
TEST_EQUAL(ec, error_code());
@ -176,7 +176,7 @@ TORRENT_TEST(parse_interval)
{
char const response[] = "d8:intervali1042e12:min intervali10e5:peers0:e";
error_code ec;
tracker_response resp = parse_tracker_response(response, sizeof(response) - 1
tracker_response resp = parse_tracker_response(response
, ec, false, sha1_hash());
TEST_EQUAL(ec, error_code());
@ -190,7 +190,7 @@ TORRENT_TEST(parse_warning)
{
char const response[] = "d5:peers0:15:warning message12:test messagee";
error_code ec;
tracker_response resp = parse_tracker_response(response, sizeof(response) - 1
tracker_response resp = parse_tracker_response(response
, ec, false, sha1_hash());
TEST_EQUAL(ec, error_code());
@ -202,7 +202,7 @@ TORRENT_TEST(parse_failure_reason)
{
char const response[] = "d5:peers0:14:failure reason12:test messagee";
error_code ec;
tracker_response resp = parse_tracker_response(response, sizeof(response) - 1
tracker_response resp = parse_tracker_response(response
, ec, false, sha1_hash());
TEST_EQUAL(ec, errors::tracker_failure);
@ -215,7 +215,7 @@ TORRENT_TEST(parse_scrape_response)
char const response[] = "d5:filesd20:aaaaaaaaaaaaaaaaaaaad"
"8:completei1e10:incompletei2e10:downloadedi3e11:downloadersi6eeee";
error_code ec;
tracker_response resp = parse_tracker_response(response, sizeof(response) - 1
tracker_response resp = parse_tracker_response(response
, ec, true, sha1_hash("aaaaaaaaaaaaaaaaaaaa"));
TEST_EQUAL(ec, error_code());
@ -230,7 +230,7 @@ TORRENT_TEST(parse_scrape_response_with_zero)
char const response[] = "d5:filesd20:aaa\0aaaaaaaaaaaaaaaad"
"8:completei4e10:incompletei5e10:downloadedi6eeee";
error_code ec;
tracker_response resp = parse_tracker_response(response, sizeof(response) - 1
tracker_response resp = parse_tracker_response(response
, ec, true, sha1_hash("aaa\0aaaaaaaaaaaaaaaa"));
TEST_EQUAL(ec, error_code());
@ -244,7 +244,7 @@ TORRENT_TEST(parse_external_ip)
{
char const response[] = "d5:peers0:11:external ip4:\x01\x02\x03\x04" "e";
error_code ec;
tracker_response resp = parse_tracker_response(response, sizeof(response) - 1
tracker_response resp = parse_tracker_response(response
, ec, false, sha1_hash());
TEST_EQUAL(ec, error_code());
@ -258,7 +258,7 @@ TORRENT_TEST(parse_external_ip6)
char const response[] = "d5:peers0:11:external ip"
"16:\xf1\x02\x03\x04\0\0\0\0\0\0\0\0\0\0\xff\xff" "e";
error_code ec;
tracker_response resp = parse_tracker_response(response, sizeof(response) - 1
tracker_response resp = parse_tracker_response(response
, ec, false, sha1_hash());
TEST_EQUAL(ec, error_code());