use span in torrent_info constructors and deprecate the redundant flags argument

This commit is contained in:
arvidn 2017-07-20 00:27:47 -07:00 committed by Arvid Norberg
parent 17bbbf4ec5
commit c4eb4c8b5f
27 changed files with 188 additions and 200 deletions

View File

@ -176,39 +176,29 @@ namespace
} // namespace unnamed
std::shared_ptr<torrent_info> buffer_constructor0(char const* buf, int len, int flags)
std::shared_ptr<torrent_info> buffer_constructor0(bytes b)
{
error_code ec;
std::shared_ptr<torrent_info> ret = std::make_shared<torrent_info>(buf
, len, ec, flags);
std::shared_ptr<torrent_info> ret = std::make_shared<torrent_info>(b.arr
, ec, from_span);
#ifndef BOOST_NO_EXCEPTIONS
if (ec) throw system_error(ec);
#endif
return ret;
}
std::shared_ptr<torrent_info> buffer_constructor1(char const* buf, int len)
{
return buffer_constructor0(buf, len, 0);
}
std::shared_ptr<torrent_info> file_constructor0(std::string const& filename, int flags)
std::shared_ptr<torrent_info> file_constructor0(std::string const& filename)
{
error_code ec;
std::shared_ptr<torrent_info> ret = std::make_shared<torrent_info>(filename
, ec, flags);
, ec);
#ifndef BOOST_NO_EXCEPTIONS
if (ec) throw system_error(ec);
#endif
return ret;
}
std::shared_ptr<torrent_info> file_constructor1(std::string const& filename)
{
return file_constructor0(filename, 0);
}
std::shared_ptr<torrent_info> bencoded_constructor0(entry const& ent, int flags)
std::shared_ptr<torrent_info> bencoded_constructor0(entry const& ent)
{
std::vector<char> buf;
bencode(std::back_inserter(buf), ent);
@ -222,19 +212,13 @@ std::shared_ptr<torrent_info> bencoded_constructor0(entry const& ent, int flags)
#endif
}
std::shared_ptr<torrent_info> ret = std::make_shared<torrent_info>(e
, ec, flags);
std::shared_ptr<torrent_info> ret = std::make_shared<torrent_info>(e, ec);
#ifndef BOOST_NO_EXCEPTIONS
if (ec) throw system_error(ec);
#endif
return ret;
}
std::shared_ptr<torrent_info> bencoded_constructor1(entry const& ent)
{
return bencoded_constructor0(ent, 0);
}
using by_value = return_value_policy<return_by_value>;
void bind_torrent_info()
{
@ -252,17 +236,14 @@ void bind_torrent_info()
;
class_<torrent_info, std::shared_ptr<torrent_info>>("torrent_info", no_init)
.def(init<sha1_hash const&, int>((arg("info_hash"), arg("flags") = 0)))
.def(init<sha1_hash const&>(arg("info_hash")))
.def("__init__", make_constructor(&bencoded_constructor0))
.def("__init__", make_constructor(&bencoded_constructor1))
.def("__init__", make_constructor(&buffer_constructor0))
.def("__init__", make_constructor(&buffer_constructor1))
.def("__init__", make_constructor(&file_constructor0))
.def("__init__", make_constructor(&file_constructor1))
.def(init<torrent_info const&>((arg("ti"))))
#if !defined TORRENT_NO_DEPRECATE
.def(init<std::wstring, int>((arg("file"), arg("flags") = 0)))
.def(init<std::wstring>((arg("file"))))
#endif
.def("add_tracker", &torrent_info::add_tracker, arg("url"))

View File

@ -206,3 +206,4 @@ TLS
RC4
Hellman
html
namespace

View File

@ -53,7 +53,7 @@ int main(int argc, char* argv[])
error_code ec;
add_torrent_params p;
p.save_path = "./";
p.ti = std::make_shared<torrent_info>(std::string(argv[1]), std::ref(ec), 0);
p.ti = std::make_shared<torrent_info>(std::string(argv[1]), std::ref(ec));
if (ec)
{
std::fprintf(stderr, "%s\n", ec.message().c_str());

View File

@ -247,10 +247,11 @@ struct bdecode_token
// There are 5 different types of nodes, see type_t.
struct TORRENT_EXPORT bdecode_node
{
// TODO: 3 deprecate this overload
TORRENT_EXPORT friend int bdecode(char const* start, char const* end, bdecode_node& ret
#ifndef TORRENT_NO_DEPRECATE
TORRENT_DEPRECATED_EXPORT friend int bdecode(char const* start, char const* end, bdecode_node& ret
, error_code& ec, int* error_pos, int depth_limit
, int token_limit);
#endif
TORRENT_EXPORT friend bdecode_node bdecode(span<char const> buffer
, error_code& ec, int* error_pos, int depth_limit, int token_limit);

View File

@ -438,6 +438,7 @@ namespace detail {
if (err) return entry();
return e;
}
entry bdecode(span<char const> buffer);
}
#endif // TORRENT_BENCODE_HPP_INCLUDED

View File

@ -110,6 +110,12 @@ namespace libtorrent {
std::uint8_t type;
};
// hidden
class from_span_t {};
// used to disambiguate a bencoded buffer and a filename
extern TORRENT_EXPORT from_span_t from_span;
// TODO: there may be some opportunities to optimize the size if torrent_info.
// specifically to turn some std::string and std::vector into pointers
class TORRENT_EXPORT torrent_info
@ -146,30 +152,50 @@ namespace libtorrent {
// an error occurs. These overloads are not available when building
// without exception support.
//
// The ``flags`` argument is currently unused.
// The overload that takes a ``span`` also needs an extra parameter of
// type ``from_span_t`` to disambiguate the ``std::string`` overload for
// string literals. There is an object in the libtorrent namespace of this
// type called ``from_span``.
#ifndef BOOST_NO_EXCEPTIONS
explicit torrent_info(bdecode_node const& torrent_file, int flags = 0);
explicit torrent_info(char const* buffer, int size, int flags = 0);
explicit torrent_info(std::string const& filename, int flags = 0);
explicit torrent_info(bdecode_node const& torrent_file);
torrent_info(char const* buffer, int size)
: torrent_info(span<char const>{buffer, std::size_t(size)}, from_span) {}
explicit torrent_info(span<char const> buffer, from_span_t);
explicit torrent_info(std::string const& filename);
#endif // BOOST_NO_EXCEPTIONS
explicit torrent_info(torrent_info const& t);
explicit torrent_info(sha1_hash const& info_hash, int flags = 0);
torrent_info(bdecode_node const& torrent_file, error_code& ec, int flags = 0);
torrent_info(char const* buffer, int size, error_code& ec, int flags = 0);
torrent_info(std::string const& filename, error_code& ec, int flags = 0);
explicit torrent_info(sha1_hash const& info_hash);
torrent_info(bdecode_node const& torrent_file, error_code& ec);
torrent_info(char const* buffer, int size, error_code& ec)
: torrent_info(span<char const>{buffer, std::size_t(size)}, ec, from_span) {}
torrent_info(span<char const> buffer, error_code& ec, from_span_t);
torrent_info(std::string const& filename, error_code& ec);
#ifndef TORRENT_NO_DEPRECATE
#ifndef BOOST_NO_EXCEPTIONS
TORRENT_DEPRECATED
explicit torrent_info(lazy_entry const& torrent_file, int flags = 0);
torrent_info(char const* buffer, int size, int)
: torrent_info(span<char const>{buffer, std::size_t(size)}, from_span) {}
#endif
TORRENT_DEPRECATED
torrent_info(lazy_entry const& torrent_file, error_code& ec
, int flags = 0);
torrent_info(bdecode_node const& torrent_file, error_code& ec, int)
: torrent_info(torrent_file, ec) {}
TORRENT_DEPRECATED
torrent_info(std::string const& filename, error_code& ec, int)
: torrent_info(filename, ec) {}
TORRENT_DEPRECATED
torrent_info(char const* buffer, int size, error_code& ec, int)
: torrent_info(span<char const>{buffer, std::size_t(size)}, ec, from_span) {}
TORRENT_DEPRECATED
explicit torrent_info(lazy_entry const& torrent_file);
TORRENT_DEPRECATED
torrent_info(lazy_entry const& torrent_file, error_code& eca);
// all wstring APIs are deprecated since 0.16.11 instead, use the wchar
// -> utf8 conversion functions and pass in utf8 strings
TORRENT_DEPRECATED
torrent_info(std::wstring const& filename, error_code& ec
, int flags = 0);
torrent_info(std::wstring const& filename, error_code& ec);
TORRENT_DEPRECATED
explicit torrent_info(std::wstring const& filename, int flags = 0);
explicit torrent_info(std::wstring const& filename);
#endif // TORRENT_NO_DEPRECATE
// frees all storage associated with this torrent_info object
@ -264,8 +290,7 @@ namespace libtorrent {
// deprecated in 1.1
TORRENT_DEPRECATED
bool parse_info_section(lazy_entry const& e, error_code& ec
, int flags);
bool parse_info_section(lazy_entry const& e, error_code& ec);
#endif // TORRENT_NO_DEPRECATE
// ``web_seeds()`` returns all url seeds and http seeds in the torrent.
@ -496,9 +521,8 @@ namespace libtorrent {
// This is used when loading a torrent from a magnet link for instance,
// where we only have the info-dict. The bdecode_node ``e`` points to a
// parsed info-dictionary. ``ec`` returns an error code if something
// fails (typically if the info dictionary is malformed). ``flags`` are
// currently unused.
bool parse_info_section(bdecode_node const& e, error_code& ec, int flags);
// fails (typically if the info dictionary is malformed).
bool parse_info_section(bdecode_node const& e, error_code& ec);
// This function looks up keys from the info-dictionary of the loaded
// torrent file. It can be used to access extension values put in the
@ -525,7 +549,7 @@ namespace libtorrent {
// __ http://bittorrent.org/beps/bep_0030.html
bool is_merkle_torrent() const { return !m_merkle_tree.empty(); }
bool parse_torrent_file(bdecode_node const& libtorrent, error_code& ec, int flags);
bool parse_torrent_file(bdecode_node const& libtorrent, error_code& ec);
// if we're logging member offsets, we need access to them
private:

View File

@ -789,8 +789,7 @@ std::shared_ptr<torrent_info> make_torrent(bool priv)
entry e = ct.generate();
std::vector<char> buf;
bencode(std::back_inserter(buf), e);
error_code ec;
return std::make_shared<torrent_info>(buf.data(), int(buf.size()), ec);
return std::make_shared<torrent_info>(buf, from_span);
}
// make sure we _do_ send our IPv6 address to trackers for private torrents

View File

@ -91,10 +91,8 @@ add_torrent_params create_torrent(file_storage& fs, bool const pad_files = false
entry tor = t.generate();
bencode(out, tor);
error_code ec;
add_torrent_params ret;
ret.ti = std::make_shared<torrent_info>(
&tmp[0], int(tmp.size()), std::ref(ec), 0);
ret.ti = std::make_shared<torrent_info>(tmp, from_span);
ret.flags &= ~lt::add_torrent_params::flag_auto_managed;
ret.flags &= ~lt::add_torrent_params::flag_paused;
ret.save_path = ".";

View File

@ -40,6 +40,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/lazy_entry.hpp"
#endif
#include "libtorrent/bdecode.hpp"
#include "libtorrent/bencode.hpp"
#include "libtorrent/entry.hpp"
#include "libtorrent/hex.hpp"
#include "libtorrent/string_util.hpp"
@ -48,39 +49,51 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent {
namespace detail {
char const* integer_to_str(char* buf, int size
, entry::integer_type val)
char const* integer_to_str(char* buf, int size
, entry::integer_type val)
{
int sign = 0;
if (val < 0)
{
int sign = 0;
if (val < 0)
{
sign = 1;
val = -val;
}
buf[--size] = '\0';
if (val == 0) buf[--size] = '0';
for (; size > sign && val != 0;)
{
buf[--size] = '0' + char(val % 10);
val /= 10;
}
if (sign) buf[--size] = '-';
return buf + size;
sign = 1;
val = -val;
}
buf[--size] = '\0';
if (val == 0) buf[--size] = '0';
for (; size > sign && val != 0;)
{
buf[--size] = '0' + char(val % 10);
val /= 10;
}
if (sign) buf[--size] = '-';
return buf + size;
}
} // detail
entry bdecode(span<char const> buffer)
{
entry e;
bool err = false;
auto it = buffer.begin();
detail::bdecode_recursive(it, buffer.end(), e, err, 0);
TORRENT_ASSERT(e.m_type_queried == false);
if (err) return entry();
return e;
}
namespace {
inline void TORRENT_NO_RETURN throw_error()
{ aux::throw_ex<system_error>(errors::invalid_entry_type); }
inline void TORRENT_NO_RETURN throw_error()
{ aux::throw_ex<system_error>(errors::invalid_entry_type); }
template <class T>
void call_destructor(T* o)
{
TORRENT_ASSERT(o);
o->~T();
}
template <class T>
void call_destructor(T* o)
{
TORRENT_ASSERT(o);
o->~T();
}
} // anonymous
entry& entry::operator[](string_view key)
{

View File

@ -105,7 +105,7 @@ namespace {
ret.ti = std::make_shared<torrent_info>(resume_ih);
error_code err;
if (!ret.ti->parse_info_section(info, err, 0))
if (!ret.ti->parse_info_section(info, err))
{
ec = err;
}

View File

@ -6646,7 +6646,7 @@ namespace libtorrent {
bdecode_node metadata;
error_code ec;
int ret = bdecode(metadata_buf.begin(), metadata_buf.end(), metadata, ec);
if (ret != 0 || !m_torrent_file->parse_info_section(metadata, ec, 0))
if (ret != 0 || !m_torrent_file->parse_info_section(metadata, ec))
{
update_gauge();
// this means the metadata is correct, since we

View File

@ -69,6 +69,8 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent {
from_span_t from_span;
namespace {
bool valid_path_character(std::int32_t const c)
@ -722,20 +724,17 @@ namespace libtorrent {
}
#ifndef TORRENT_NO_DEPRECATE
torrent_info::torrent_info(lazy_entry const& torrent_file, error_code& ec
, int const flags)
torrent_info::torrent_info(lazy_entry const& torrent_file, error_code& ec)
{
TORRENT_UNUSED(flags);
std::pair<char const*, int> buf = torrent_file.data_section();
bdecode_node e;
if (bdecode(buf.first, buf.first + buf.second, e, ec) != 0)
return;
parse_torrent_file(e, ec, 0);
parse_torrent_file(e, ec);
}
torrent_info::torrent_info(lazy_entry const& torrent_file, int const flags)
torrent_info::torrent_info(lazy_entry const& torrent_file)
{
TORRENT_UNUSED(flags);
std::pair<char const*, int> buf = torrent_file.data_section();
bdecode_node e;
error_code ec;
@ -744,10 +743,10 @@ namespace libtorrent {
aux::throw_ex<system_error>(ec);
}
#ifndef BOOST_NO_EXCEPTIONS
if (!parse_torrent_file(e, ec, 0))
if (!parse_torrent_file(e, ec))
aux::throw_ex<system_error>(ec);
#else
parse_torrent_file(e, ec, 0);
parse_torrent_file(e, ec);
#endif
}
@ -769,73 +768,65 @@ namespace libtorrent {
#endif
}
#ifndef BOOST_NO_EXCEPTIONS
if (!parse_torrent_file(e, ec, 0))
if (!parse_torrent_file(e, ec))
aux::throw_ex<system_error>(ec);
#else
parse_torrent_file(e, ec, 0);
parse_torrent_file(e, ec);
#endif
INVARIANT_CHECK;
}
#endif
#ifndef BOOST_NO_EXCEPTIONS
torrent_info::torrent_info(bdecode_node const& torrent_file
, int const flags)
torrent_info::torrent_info(bdecode_node const& torrent_file)
{
error_code ec;
if (!parse_torrent_file(torrent_file, ec, flags))
if (!parse_torrent_file(torrent_file, ec))
aux::throw_ex<system_error>(ec);
INVARIANT_CHECK;
}
torrent_info::torrent_info(char const* buffer
, int const size
, int const flags)
torrent_info::torrent_info(span<char const> buffer, from_span_t)
{
error_code ec;
bdecode_node e;
if (bdecode(buffer, buffer + size, e, ec) != 0)
aux::throw_ex<system_error>(ec);
bdecode_node e = bdecode(buffer, ec);
if (ec) aux::throw_ex<system_error>(ec);
if (!parse_torrent_file(e, ec, flags))
if (!parse_torrent_file(e, ec))
aux::throw_ex<system_error>(ec);
INVARIANT_CHECK;
}
torrent_info::torrent_info(std::string const& filename
, int const flags)
torrent_info::torrent_info(std::string const& filename)
{
std::vector<char> buf;
error_code ec;
int ret = load_file(filename, buf, ec);
if (ret < 0) aux::throw_ex<system_error>(ec);
bdecode_node e;
if (buf.empty() || bdecode(&buf[0], &buf[0] + buf.size(), e, ec) != 0)
aux::throw_ex<system_error>(ec);
bdecode_node e = bdecode(buf, ec);
if (ec) aux::throw_ex<system_error>(ec);
if (!parse_torrent_file(e, ec, flags))
if (!parse_torrent_file(e, ec))
aux::throw_ex<system_error>(ec);
INVARIANT_CHECK;
}
#ifndef TORRENT_NO_DEPRECATE
torrent_info::torrent_info(std::wstring const& filename
, int const flags)
torrent_info::torrent_info(std::wstring const& filename)
{
std::vector<char> buf;
error_code ec;
int ret = load_file(wchar_utf8(filename), buf, ec);
if (ret < 0) aux::throw_ex<system_error>(ec);
bdecode_node e;
if (buf.empty() || bdecode(&buf[0], &buf[0] + buf.size(), e, ec) != 0)
aux::throw_ex<system_error>(ec);
bdecode_node e = bdecode(buf, ec);
if (ec) aux::throw_ex<system_error>(ec);
if (!parse_torrent_file(e, ec, flags))
if (!parse_torrent_file(e, ec))
aux::throw_ex<system_error>(ec);
INVARIANT_CHECK;
@ -851,55 +842,46 @@ namespace libtorrent {
#endif
torrent_info::torrent_info(bdecode_node const& torrent_file
, error_code& ec
, int const flags)
, error_code& ec)
{
parse_torrent_file(torrent_file, ec, flags);
parse_torrent_file(torrent_file, ec);
INVARIANT_CHECK;
}
torrent_info::torrent_info(span<char const> buffer
, error_code& ec, from_span_t)
{
bdecode_node e = bdecode(buffer, ec);
if (ec) return;
parse_torrent_file(e, ec);
INVARIANT_CHECK;
}
torrent_info::torrent_info(char const* buffer
, int const size
, error_code& ec
, int const flags)
{
bdecode_node e;
if (bdecode(buffer, buffer + size, e, ec) != 0)
return;
parse_torrent_file(e, ec, flags);
INVARIANT_CHECK;
}
torrent_info::torrent_info(std::string const& filename, error_code& ec
, int const flags)
torrent_info::torrent_info(std::string const& filename, error_code& ec)
{
std::vector<char> buf;
int ret = load_file(filename, buf, ec);
if (ret < 0) return;
bdecode_node e;
if (buf.empty() || bdecode(&buf[0], &buf[0] + buf.size(), e, ec) != 0)
return;
parse_torrent_file(e, ec, flags);
bdecode_node e = bdecode(buf, ec);
if (ec) return;
parse_torrent_file(e, ec);
INVARIANT_CHECK;
}
#ifndef TORRENT_NO_DEPRECATE
torrent_info::torrent_info(std::wstring const& filename
, error_code& ec
, int const flags)
, error_code& ec)
{
std::vector<char> buf;
int ret = load_file(wchar_utf8(filename), buf, ec);
if (ret < 0) return;
bdecode_node e;
if (buf.empty() || bdecode(&buf[0], &buf[0] + buf.size(), e, ec) != 0)
return;
parse_torrent_file(e, ec, flags);
bdecode_node e = bdecode(buf, ec);
if (ec) return;
parse_torrent_file(e, ec);
INVARIANT_CHECK;
}
@ -909,11 +891,9 @@ namespace libtorrent {
// will not contain any hashes, comments, creation date
// just the necessary to use it with piece manager
// used for torrents with no metadata
torrent_info::torrent_info(sha1_hash const& info_hash, int const flags)
torrent_info::torrent_info(sha1_hash const& info_hash)
: m_info_hash(info_hash)
{
TORRENT_UNUSED(flags);
}
{}
torrent_info::~torrent_info() = default;
@ -971,9 +951,8 @@ namespace libtorrent {
}
bool torrent_info::parse_info_section(bdecode_node const& info
, error_code& ec, int const flags)
, error_code& ec)
{
TORRENT_UNUSED(flags);
if (info.type() != bdecode_node::dict_t)
{
ec = errors::torrent_info_no_dict;
@ -1242,7 +1221,7 @@ namespace libtorrent {
}
bool torrent_info::parse_torrent_file(bdecode_node const& torrent_file
, error_code& ec, int const flags)
, error_code& ec)
{
if (torrent_file.type() != bdecode_node::dict_t)
{
@ -1273,7 +1252,7 @@ namespace libtorrent {
ec = errors::torrent_missing_info;
return false;
}
if (!parse_info_section(info, ec, flags)) return false;
if (!parse_info_section(info, ec)) return false;
resolve_duplicate_filenames();
#ifndef TORRENT_DISABLE_MUTABLE_TORRENTS
@ -1490,8 +1469,7 @@ namespace {
, filter_web_seed_type(web_seed_entry::http_seed)).urls;
}
bool torrent_info::parse_info_section(lazy_entry const& le, error_code& ec
, int flags)
bool torrent_info::parse_info_section(lazy_entry const& le, error_code& ec)
{
if (le.type() == lazy_entry::none_t) return false;
std::pair<char const*, int> buf = le.data_section();
@ -1499,7 +1477,7 @@ namespace {
if (bdecode(buf.first, buf.first + buf.second, e, ec) != 0)
return false;
return parse_info_section(e, ec, flags);
return parse_info_section(e, ec);
}
#endif // TORRENT_NO_DEPRECATE

View File

@ -42,8 +42,7 @@ POSSIBILITY OF SUCH DAMAGE.
using namespace lt;
std::shared_ptr<lt::torrent_info> make_test_torrent(
torrent_args const& args)
std::shared_ptr<lt::torrent_info> make_test_torrent(torrent_args const& args)
{
entry e;
@ -162,7 +161,7 @@ std::shared_ptr<lt::torrent_info> make_test_torrent(
fwrite(&tmp[0], 1, tmp.size(), f);
fclose(f);
return std::make_shared<torrent_info>(&tmp[0], int(tmp.size()));
return std::make_shared<torrent_info>(tmp, from_span);
}
void generate_files(lt::torrent_info const& ti, std::string const& path

View File

@ -637,8 +637,7 @@ std::shared_ptr<lt::torrent_info> make_torrent(const int file_sizes[]
std::vector<char> buf;
bencode(std::back_inserter(buf), ct.generate());
error_code ec;
return std::make_shared<torrent_info>(&buf[0], int(buf.size()), ec);
return std::make_shared<torrent_info>(buf, from_span);
}
void create_random_files(std::string const& path, const int file_sizes[], int num_files)
@ -735,8 +734,7 @@ std::shared_ptr<torrent_info> create_torrent(std::ostream* file
bencode(out, tor);
error_code ec;
return std::make_shared<torrent_info>(
&tmp[0], int(tmp.size()), std::ref(ec), 0);
return std::make_shared<torrent_info>(tmp, ec, from_span);
}
std::tuple<torrent_handle, torrent_handle, torrent_handle>

View File

@ -114,7 +114,7 @@ void test_checking(int flags = read_only_files)
std::vector<char> buf;
bencode(std::back_inserter(buf), t.generate());
auto ti = std::make_shared<torrent_info>(&buf[0], int(buf.size()), ec);
auto ti = std::make_shared<torrent_info>(buf, ec, from_span);
std::printf("generated torrent: %s tmp1_checking/test_torrent_dir\n"
, aux::to_hex(ti->info_hash()).c_str());

View File

@ -48,7 +48,7 @@ TORRENT_TEST(create_verbatim_torrent)
char const test_torrent[] = "d4:infod4:name6:foobar6:lengthi12345e"
"12:piece lengthi65536e6:pieces20:ababababababababababee";
lt::torrent_info info(test_torrent, sizeof(test_torrent) - 1);
lt::torrent_info info(test_torrent, lt::from_span);
info.add_tracker("http://test.com");
info.add_tracker("http://test.com");

View File

@ -410,7 +410,7 @@ TORRENT_TEST(make_magnet_uri)
buf.push_back('\0');
std::printf("%s\n", &buf[0]);
error_code ec;
torrent_info ti(&buf[0], int(buf.size()), ec);
torrent_info ti(buf, ec, from_span);
TEST_EQUAL(al.size(), ti.trackers().size());
@ -437,7 +437,7 @@ TORRENT_TEST(make_magnet_uri2)
buf.push_back('\0');
std::printf("%s\n", &buf[0]);
error_code ec;
torrent_info ti(&buf[0], int(buf.size()), ec);
torrent_info ti(buf, ec, from_span);
std::string magnet = make_magnet_uri(ti);
std::printf("%s len: %d\n", magnet.c_str(), int(magnet.size()));

View File

@ -84,7 +84,7 @@ void test_read_piece(int flags)
std::vector<char> buf;
bencode(std::back_inserter(buf), t.generate());
auto ti = std::make_shared<torrent_info>(&buf[0], int(buf.size()), ec);
auto ti = std::make_shared<torrent_info>(buf, ec, from_span);
std::printf("generated torrent: %s tmp1_read_piece/test_torrent\n"
, aux::to_hex(ti->info_hash()).c_str());

View File

@ -191,7 +191,7 @@ std::shared_ptr<torrent_info> generate_torrent()
std::vector<char> buf;
bencode(std::back_inserter(buf), t.generate());
return std::make_shared<torrent_info>(&buf[0], buf.size());
return std::make_shared<torrent_info>(buf, from_span);
}
TORRENT_TEST(read_resume_torrent)

View File

@ -157,9 +157,8 @@ TORRENT_TEST(range_lookup_duplicated_files)
std::vector<char> tmp2;
bencode(std::back_inserter(tmp1), t1.generate());
bencode(std::back_inserter(tmp2), t2.generate());
error_code ec;
auto ti1 = std::make_shared<torrent_info>(&tmp1[0], int(tmp1.size()), ec);
auto ti2 = std::make_shared<torrent_info>(&tmp2[0], int(tmp2.size()), ec);
auto ti1 = std::make_shared<torrent_info>(tmp1, from_span);
auto ti2 = std::make_shared<torrent_info>(tmp2, from_span);
std::printf("resolving\n");
resolve_links l(ti1);

View File

@ -82,7 +82,7 @@ std::shared_ptr<torrent_info> generate_torrent()
std::vector<char> buf;
bencode(std::back_inserter(buf), t.generate());
return std::make_shared<torrent_info>(&buf[0], int(buf.size()));
return std::make_shared<torrent_info>(buf, from_span);
}
std::vector<char> generate_resume_data(torrent_info* ti

View File

@ -196,7 +196,7 @@ TORRENT_TEST(load_empty_file)
add_torrent_params atp;
error_code ignore_errors;
atp.ti = std::make_shared<torrent_info>("", 0, std::ref(ignore_errors));
atp.ti = std::make_shared<torrent_info>("", std::ref(ignore_errors), from_span);
atp.save_path = ".";
error_code ec;
torrent_handle h = ses.add_torrent(std::move(atp), ec);

View File

@ -139,8 +139,7 @@ std::shared_ptr<torrent_info> setup_torrent_info(file_storage& fs
bencode(std::back_inserter(buf), t.generate());
error_code ec;
auto info = std::make_shared<torrent_info>(&buf[0]
, int(buf.size()), std::ref(ec), 0);
auto info = std::make_shared<torrent_info>(buf, ec, from_span);
if (ec)
{
@ -464,7 +463,7 @@ void test_check_files(std::string const& test_path
std::vector<char> buf;
bencode(std::back_inserter(buf), t.generate());
info = std::make_shared<torrent_info>(&buf[0], int(buf.size()), std::ref(ec), 0);
info = std::make_shared<torrent_info>(buf, ec, from_span);
aux::session_settings set;
file_pool fp;
@ -549,7 +548,7 @@ void run_test(bool unbuffered)
std::vector<char> buf;
bencode(std::back_inserter(buf), t.generate());
info = std::make_shared<torrent_info>(&buf[0], int(buf.size()), std::ref(ec), 0);
info = std::make_shared<torrent_info>(buf, from_span);
std::cout << "=== test 1 === " << (unbuffered?"unbuffered":"buffered") << std::endl;
// run_storage_tests writes piece 0, 1 and 2. not 3
@ -593,7 +592,7 @@ void run_test(bool unbuffered)
std::vector<char> buf;
bencode(std::back_inserter(buf), t.generate());
info = std::make_shared<torrent_info>(&buf[0], int(buf.size()), std::ref(ec), 0);
info = std::make_shared<torrent_info>(buf, ec, from_span);
std::cout << "=== test 3 ===" << std::endl;

View File

@ -172,7 +172,7 @@ TORRENT_TEST(long_names)
std::vector<char> buf;
bencode(std::back_inserter(buf), torrent);
error_code ec;
auto ti = std::make_shared<torrent_info>(&buf[0], int(buf.size()), std::ref(ec));
auto ti = std::make_shared<torrent_info>(buf, std::ref(ec), from_span);
TEST_CHECK(!ec);
}
@ -190,7 +190,7 @@ TORRENT_TEST(total_wanted)
bencode(std::back_inserter(tmp), t.generate());
error_code ec;
auto info = std::make_shared<torrent_info>(
&tmp[0], int(tmp.size()), std::ref(ec));
tmp, std::ref(ec), from_span);
settings_pack pack = settings();
pack.set_int(settings_pack::alert_mask, alert::storage_notification);
@ -228,7 +228,7 @@ TORRENT_TEST(added_peers)
bencode(std::back_inserter(tmp), t.generate());
error_code ec;
auto info = std::make_shared<torrent_info>(
&tmp[0], int(tmp.size()), std::ref(ec));
tmp, std::ref(ec), from_span);
settings_pack pack = settings();
pack.set_str(settings_pack::listen_interfaces, "0.0.0.0:48130");
@ -282,7 +282,7 @@ TORRENT_TEST(torrent)
std::back_insert_iterator<std::vector<char>> out(tmp);
bencode(out, t.generate());
error_code ec;
auto info = std::make_shared<torrent_info>(&tmp[0], int(tmp.size()), std::ref(ec), 0);
auto info = std::make_shared<torrent_info>(tmp, std::ref(ec), from_span);
TEST_CHECK(info->num_pieces() > 0);
test_running_torrent(info, file_size);
@ -308,7 +308,7 @@ TORRENT_TEST(torrent)
std::back_insert_iterator<std::vector<char>> out(tmp);
bencode(out, t.generate());
error_code ec;
auto info = std::make_shared<torrent_info>(&tmp[0], int(tmp.size()), std::ref(ec), 0);
auto info = std::make_shared<torrent_info>(tmp, std::ref(ec), from_span);
test_running_torrent(info, 1024);
}
}
@ -356,7 +356,7 @@ TORRENT_TEST(duplicate_is_not_error)
plugin_creator creator(called);
add_torrent_params p;
p.ti = std::make_shared<torrent_info>(&tmp[0], int(tmp.size()), std::ref(ec), 0);
p.ti = std::make_shared<torrent_info>(tmp, std::ref(ec), from_span);
p.flags &= ~torrent_flags::paused;
p.flags &= ~torrent_flags::auto_managed;
p.flags &= ~torrent_flags::duplicate_is_error;
@ -410,7 +410,7 @@ TORRENT_TEST(rename_file)
std::back_insert_iterator<std::vector<char>> out(tmp);
bencode(out, t.generate());
error_code ec;
auto info = std::make_shared<torrent_info>(&tmp[0], int(tmp.size()), std::ref(ec), 0);
auto info = std::make_shared<torrent_info>(tmp, std::ref(ec), from_span);
TEST_EQUAL(info->files().file_path(file_index_t(0)), combine_path("test3","tmp1"));
@ -473,7 +473,7 @@ void test_queue(add_torrent_params p)
std::vector<char> buf;
bencode(std::back_inserter(buf), t.generate());
auto ti = std::make_shared<torrent_info>(buf.data(), int(buf.size()));
auto ti = std::make_shared<torrent_info>(buf, from_span);
add_torrent_params p;
p.ti = ti;
p.save_path = ".";

View File

@ -69,7 +69,7 @@ TORRENT_TEST(mutable_torrents)
entry tor = t.generate();
bencode(out, tor);
torrent_info ti(&tmp[0], int(tmp.size()));
torrent_info ti(tmp, from_span);
std::vector<sha1_hash> similar;
similar.push_back(sha1_hash("abababababababababab"));
@ -197,8 +197,7 @@ TORRENT_TEST(url_list_and_httpseeds)
torrent["info"] = info;
std::vector<char> buf;
bencode(std::back_inserter(buf), torrent);
error_code ec;
torrent_info ti(&buf[0], int(buf.size()), ec);
torrent_info ti(buf, from_span);
TEST_EQUAL(ti.web_seeds().size(), 4);
}
@ -614,8 +613,6 @@ TORRENT_TEST(verify_encoding)
TORRENT_TEST(parse_torrents)
{
error_code ec;
// test torrent parsing
entry info;
@ -629,7 +626,7 @@ TORRENT_TEST(parse_torrents)
std::vector<char> buf;
bencode(std::back_inserter(buf), torrent);
torrent_info ti(&buf[0], int(buf.size()), ec);
torrent_info ti(buf, from_span);
std::cout << ti.name() << std::endl;
TEST_CHECK(ti.name() == "test1");
@ -641,7 +638,7 @@ TORRENT_TEST(parse_torrents)
torrent["info"] = info;
buf.clear();
bencode(std::back_inserter(buf), torrent);
torrent_info ti2(&buf[0], int(buf.size()), ec);
torrent_info ti2(buf, from_span);
std::cout << ti2.name() << std::endl;
#ifdef TORRENT_WINDOWS
TEST_EQUAL(ti2.name(), "ctest1test2test3");
@ -653,7 +650,7 @@ TORRENT_TEST(parse_torrents)
torrent["info"] = info;
buf.clear();
bencode(std::back_inserter(buf), torrent);
torrent_info ti3(&buf[0], int(buf.size()), ec);
torrent_info ti3(buf, from_span);
std::cout << ti3.name() << std::endl;
TEST_EQUAL(ti3.name(), "test2..test3.......test4");
@ -663,6 +660,7 @@ TORRENT_TEST(parse_torrents)
std::printf("loading %s\n", test_torrents[i].file);
std::string filename = combine_path(combine_path(root_dir, "test_torrents")
, test_torrents[i].file);
error_code ec;
auto ti = std::make_shared<torrent_info>(filename, ec);
TEST_CHECK(!ec);
if (ec) std::printf(" loading(\"%s\") -> failed %s\n", filename.c_str()
@ -853,7 +851,7 @@ void test_resolve_duplicates(int test_case)
entry tor = t.generate();
bencode(out, tor);
torrent_info ti(&tmp[0], int(tmp.size()));
torrent_info ti(tmp, from_span);
std::vector<aux::vector<char const*, file_index_t>> const filenames
{
@ -905,7 +903,7 @@ TORRENT_TEST(resolve_duplicates)
TORRENT_TEST(empty_file)
{
error_code ec;
auto ti = std::make_shared<torrent_info>("", 0, ec);
auto ti = std::make_shared<torrent_info>("", ec, from_span);
TEST_CHECK(ec);
}
@ -913,7 +911,7 @@ TORRENT_TEST(empty_file2)
{
try
{
auto ti = std::make_shared<torrent_info>("", 0);
auto ti = std::make_shared<torrent_info>("", from_span);
TEST_ERROR("expected exception thrown");
}
catch (system_error const& e)

View File

@ -85,8 +85,7 @@ TORRENT_TEST(web_seed_redirect)
std::vector<char> buf;
bencode(std::back_inserter(buf), t.generate());
auto torrent_file = std::make_shared<torrent_info>(&buf[0]
, int(buf.size()), ec);
auto torrent_file = std::make_shared<torrent_info>(buf, ec, from_span);
{
settings_pack p = settings();

View File

@ -389,7 +389,7 @@ int main(int argc, char const* argv[])
render_variant(test_buffer, e);
lt::error_code ec;
lt::torrent_info t(test_buffer.c_str(), int(test_buffer.size()), ec);
lt::torrent_info t(test_buffer, ec, lt::from_span);
// TODO: add option to save to file unconditionally (to test other clients)
/*
@ -406,7 +406,7 @@ int main(int argc, char const* argv[])
fwrite(test_buffer.c_str(), test_buffer.size(), 1, f);
fclose(f);
}
*/
*/
if (g_seed > 0) break;
}
std::fprintf(stderr, "tested %d variants of %s\n", i, *argv);