removed const_interval, mutable_buffer and const_buffer types (#956)

removed const_interval, mutable_buffer and const_buffer types
This commit is contained in:
Alden Torres 2016-07-27 22:31:08 -04:00 committed by Arvid Norberg
parent 7a95ba636e
commit 98918d61f5
21 changed files with 208 additions and 216 deletions

View File

@ -72,6 +72,40 @@ namespace libtorrent { namespace aux
view = view.subspan(sizeof(T));
}
template <class Byte>
inline typename std::enable_if<sizeof(Byte)==1, void>::type
write_impl(std::uint8_t val, span<Byte>& view)
{
view[0] = val;
view = view.subspan(1);
}
template <class Byte>
inline typename std::enable_if<sizeof(Byte)==1, void>::type
write_impl(std::int8_t val, span<Byte>& view)
{
view[0] = val;
view = view.subspan(1);
}
template <class Byte>
inline typename std::enable_if<sizeof(Byte)==1, std::uint8_t>::type
read_impl(span<Byte>& view, type<std::uint8_t>)
{
std::uint8_t ret = static_cast<std::uint8_t>(view[0]);
view = view.subspan(1);
return ret;
}
template <class Byte>
inline typename std::enable_if<sizeof(Byte)==1, std::int8_t>::type
read_impl(span<Byte>& view, type<std::int8_t>)
{
std::uint8_t ret = static_cast<std::int8_t>(view[0]);
view = view.subspan(1);
return ret;
}
// -- adaptors
template <typename Byte>
@ -153,4 +187,3 @@ namespace libtorrent { namespace aux
}}
#endif // TORRENT_AUX_IO_HPP_INCLUDED

View File

@ -33,8 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_BLOOM_FILTER_HPP_INCLUDED
#define TORRENT_BLOOM_FILTER_HPP_INCLUDED
#include "libtorrent/peer_id.hpp" // for sha1_hash
#include "libtorrent/config.hpp" // for sha1_hash
#include "libtorrent/sha1_hash.hpp"
#include <cmath> // for log()
#include <cstdint>
@ -77,5 +76,4 @@ namespace libtorrent
}
#endif
#endif // TORRENT_BLOOM_FILTER_HPP_INCLUDED

View File

@ -161,8 +161,8 @@ namespace libtorrent
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
// next_barrier, buffers-to-prepend
virtual
std::tuple<int, span<aux::const_buffer>>
hit_send_barrier(span<aux::mutable_buffer> iovec) override;
std::tuple<int, span<span<char const>>>
hit_send_barrier(span<span<char>> iovec) override;
#endif
virtual void get_specific_peer_info(peer_info& p) const override;

View File

@ -59,13 +59,6 @@ namespace libtorrent {
}
}
// TODO: eventually move this file to aux_ or create a new one
namespace aux
{
using mutable_buffer = span<char>;
using const_buffer = span<char const>;
}
// the buffer is allocated once and cannot be resized. The size() may be
// larger than requested, in case the underlying allocator over allocated. In
// order to "grow" an allocation, create a new buffer and initialize it by
@ -75,36 +68,6 @@ class buffer
{
public:
struct const_interval
{
const_interval(char const* b, char const* e)
: begin(b)
, end(e)
{}
char operator[](int index) const
{
TORRENT_ASSERT(begin + index < end);
return begin[index];
}
bool operator==(const const_interval& p_interval)
{
return begin == p_interval.begin
&& end == p_interval.end;
}
int left() const
{
TORRENT_ASSERT(end >= begin);
TORRENT_ASSERT(end - begin < (std::numeric_limits<int>::max)());
return int(end - begin);
}
char const* begin;
char const* end;
};
// allocate an uninitialized buffer of the specified size
buffer(std::size_t size = 0)
{

View File

@ -112,7 +112,7 @@ namespace libtorrent
void clear();
void build_mutable_iovec(int bytes, std::vector<aux::mutable_buffer>& vec);
void build_mutable_iovec(int bytes, std::vector<span<char>>& vec);
~chained_buffer();

View File

@ -464,12 +464,12 @@ namespace libtorrent
// received. The purpose of this is to allow early disconnects for invalid
// messages and for reporting progress of receiving large messages.
virtual bool on_extended(int /*length*/, int /*msg*/,
buffer::const_interval /*body*/)
span<char const> /*body*/)
{ return false; }
// this is not called for web seeds
virtual bool on_unknown_message(int /*length*/, int /*msg*/,
buffer::const_interval /*body*/)
span<char const> /*body*/)
{ return false; }
// called when a piece that this peer participated in either

View File

@ -99,8 +99,8 @@ namespace libtorrent
struct encryption_handler
{
std::tuple<int, span<aux::const_buffer>>
encrypt(span<aux::mutable_buffer> iovec);
std::tuple<int, span<span<char const>>>
encrypt(span<span<char>> iovec);
int decrypt(crypto_receive_buffer& recv_buffer
, std::size_t& bytes_transferred);
@ -144,10 +144,10 @@ namespace libtorrent
void set_incoming_key(unsigned char const* key, int len) override;
void set_outgoing_key(unsigned char const* key, int len) override;
std::tuple<int, span<aux::const_buffer>>
encrypt(span<aux::mutable_buffer> buf) override;
std::tuple<int, span<span<char const>>>
encrypt(span<span<char>> buf) override;
void decrypt(span<aux::mutable_buffer> buf
void decrypt(span<span<char>> buf
, int& consume
, int& produce
, int& packet_size) override;

View File

@ -747,11 +747,11 @@ namespace libtorrent
void send_piece_suggestions(int num);
virtual
std::tuple<int, span<aux::const_buffer>>
hit_send_barrier(span<aux::mutable_buffer> /* iovec */)
std::tuple<int, span<span<char const>>>
hit_send_barrier(span<span<char>> /* iovec */)
{
return std::make_tuple(INT_MAX
, span<aux::const_buffer>());
, span<span<char const>>());
}
void attach_to_torrent(sha1_hash const& ih);

View File

@ -85,8 +85,7 @@ struct TORRENT_EXTRA_EXPORT receive_buffer
// return the interval between the start of the buffer to the read cursor.
// This is the "current" packet.
// TODO: 3 use span
buffer::const_interval get() const;
span<char const> get() const;
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
// returns the buffer from the current packet start position to the last
@ -94,7 +93,7 @@ struct TORRENT_EXTRA_EXPORT receive_buffer
span<char> mutable_buffer();
// returns the last 'bytes' from the receive buffer
aux::mutable_buffer mutable_buffer(int bytes);
span<char> mutable_buffer(int bytes);
#endif
// the purpose of this function is to free up and cut off all messages
@ -203,10 +202,9 @@ struct crypto_receive_buffer
int advance_pos(int bytes);
// TODO: 3 use span
buffer::const_interval get() const;
span<char const> get() const;
aux::mutable_buffer mutable_buffer(std::size_t bytes);
span<char> mutable_buffer(std::size_t bytes);
private:
// explicitly disallow assignment, to silence msvc warning

View File

@ -73,4 +73,3 @@ namespace libtorrent
return ret;
}
}

View File

@ -62,6 +62,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/alert_types.hpp"
#include "libtorrent/invariant_check.hpp"
#include "libtorrent/io.hpp"
#include "libtorrent/aux_/io.hpp"
#include "libtorrent/socket_io.hpp"
#include "libtorrent/version.hpp"
#include "libtorrent/extensions.hpp"
@ -606,7 +607,7 @@ namespace libtorrent
#endif
write_pe_vc_cryptofield(ptr, encrypt_size, crypto_provide, pad_size);
aux::mutable_buffer vec(ptr, encrypt_size);
span<char> vec(ptr, encrypt_size);
m_rc4->encrypt(vec);
send_buffer(msg, sizeof(msg) - 512 + pad_size);
}
@ -627,7 +628,7 @@ namespace libtorrent
char msg[512 + 8 + 4 + 2];
write_pe_vc_cryptofield(msg, sizeof(msg), crypto_select, pad_size);
aux::mutable_buffer vec(msg, buf_size);
span<char> vec(msg, buf_size);
m_rc4->encrypt(vec);
send_buffer(msg, buf_size);
@ -835,14 +836,14 @@ namespace libtorrent
boost::shared_ptr<torrent> t = associated_torrent().lock();
TORRENT_ASSERT(t);
buffer::const_interval recv_buffer = m_recv_buffer.get();
span<char const> recv_buffer = m_recv_buffer.get();
// are we currently receiving a 'piece' message?
if (m_state != read_packet
|| recv_buffer.left() <= 9
|| int(recv_buffer.size()) <= 9
|| recv_buffer[0] != msg_piece)
return boost::optional<piece_block_progress>();
const char* ptr = recv_buffer.begin + 1;
const char* ptr = recv_buffer.begin() + 1;
peer_request r;
r.piece = detail::read_int32(ptr);
r.start = detail::read_int32(ptr);
@ -856,7 +857,7 @@ namespace libtorrent
p.piece_index = r.piece;
p.block_index = r.start / t->block_size();
p.bytes_downloaded = recv_buffer.left() - 9;
p.bytes_downloaded = int(recv_buffer.size()) - 9;
p.full_block_bytes = r.length;
return boost::optional<piece_block_progress>(p);
@ -1015,9 +1016,9 @@ namespace libtorrent
}
if (!m_recv_buffer.packet_finished()) return;
buffer::const_interval recv_buffer = m_recv_buffer.get();
span<char const> recv_buffer = m_recv_buffer.get();
const char* ptr = recv_buffer.begin + 1;
const char* ptr = recv_buffer.begin() + 1;
int const index = detail::read_int32(ptr);
incoming_have(index);
@ -1048,10 +1049,10 @@ namespace libtorrent
if (!m_recv_buffer.packet_finished()) return;
buffer::const_interval recv_buffer = m_recv_buffer.get();
span<char const> recv_buffer = m_recv_buffer.get();
bitfield bits;
bits.assign(recv_buffer.begin + 1
bits.assign(recv_buffer.begin() + 1
, t->valid_metadata()?get_bitfield().size():(m_recv_buffer.packet_size()-1)*8);
incoming_bitfield(bits);
@ -1074,10 +1075,10 @@ namespace libtorrent
}
if (!m_recv_buffer.packet_finished()) return;
buffer::const_interval recv_buffer = m_recv_buffer.get();
span<char const> recv_buffer = m_recv_buffer.get();
peer_request r;
const char* ptr = recv_buffer.begin + 1;
const char* ptr = recv_buffer.begin() + 1;
r.piece = detail::read_int32(ptr);
r.start = detail::read_int32(ptr);
r.length = detail::read_int32(ptr);
@ -1095,12 +1096,12 @@ namespace libtorrent
TORRENT_ASSERT(received >= 0);
buffer::const_interval recv_buffer = m_recv_buffer.get();
span<char const> recv_buffer = m_recv_buffer.get();
int recv_pos = m_recv_buffer.pos(); // recv_buffer.end - recv_buffer.begin;
boost::shared_ptr<torrent> t = associated_torrent().lock();
TORRENT_ASSERT(t);
bool const merkle = static_cast<std::uint8_t>(recv_buffer.begin[0]) == 250;
bool const merkle = static_cast<std::uint8_t>(recv_buffer.front()) == 250;
if (merkle)
{
if (recv_pos == 1)
@ -1115,7 +1116,7 @@ namespace libtorrent
}
if (recv_pos >= 13)
{
char const* ptr = recv_buffer.begin + 9;
char const* ptr = recv_buffer.begin() + 9;
int const list_size = detail::read_int32(ptr);
if (list_size > m_recv_buffer.packet_size() - 13)
@ -1153,7 +1154,7 @@ namespace libtorrent
if (recv_pos >= header_size)
{
const char* ptr = recv_buffer.begin + 1;
const char* ptr = recv_buffer.begin() + 1;
p.piece = detail::read_int32(ptr);
p.start = detail::read_int32(ptr);
@ -1224,7 +1225,7 @@ namespace libtorrent
#endif
bdecode_node hash_list;
error_code ec;
if (bdecode(recv_buffer.begin + 13, recv_buffer.begin+ 13 + list_size
if (bdecode(recv_buffer.begin() + 13, recv_buffer.begin() + 13 + list_size
, hash_list, ec) != 0)
{
disconnect(errors::invalid_hash_piece, op_bittorrent, 2);
@ -1259,7 +1260,7 @@ namespace libtorrent
}
}
incoming_piece(p, recv_buffer.begin + header_size);
incoming_piece(p, recv_buffer.begin() + header_size);
}
// -----------------------------
@ -1279,10 +1280,10 @@ namespace libtorrent
}
if (!m_recv_buffer.packet_finished()) return;
buffer::const_interval recv_buffer = m_recv_buffer.get();
span<char const> recv_buffer = m_recv_buffer.get();
peer_request r;
const char* ptr = recv_buffer.begin + 1;
const char* ptr = recv_buffer.begin() + 1;
r.piece = detail::read_int32(ptr);
r.start = detail::read_int32(ptr);
r.length = detail::read_int32(ptr);
@ -1307,9 +1308,9 @@ namespace libtorrent
}
if (!m_recv_buffer.packet_finished()) return;
buffer::const_interval recv_buffer = m_recv_buffer.get();
span<char const> recv_buffer = m_recv_buffer.get();
const char* ptr = recv_buffer.begin + 1;
const char* ptr = recv_buffer.begin() + 1;
int listen_port = detail::read_uint16(ptr);
incoming_dht_port(listen_port);
@ -1337,9 +1338,9 @@ namespace libtorrent
if (!m_recv_buffer.packet_finished()) return;
buffer::const_interval recv_buffer = m_recv_buffer.get();
span<char const> recv_buffer = m_recv_buffer.get();
const char* ptr = recv_buffer.begin + 1;
const char* ptr = recv_buffer.begin() + 1;
int const piece = detail::read_uint32(ptr);
incoming_suggest(piece);
}
@ -1383,10 +1384,10 @@ namespace libtorrent
if (!m_recv_buffer.packet_finished()) return;
buffer::const_interval recv_buffer = m_recv_buffer.get();
span<char const> recv_buffer = m_recv_buffer.get();
peer_request r;
const char* ptr = recv_buffer.begin + 1;
const char* ptr = recv_buffer.begin() + 1;
r.piece = detail::read_int32(ptr);
r.start = detail::read_int32(ptr);
r.length = detail::read_int32(ptr);
@ -1406,8 +1407,8 @@ namespace libtorrent
}
if (!m_recv_buffer.packet_finished()) return;
buffer::const_interval recv_buffer = m_recv_buffer.get();
const char* ptr = recv_buffer.begin + 1;
span<char const> recv_buffer = m_recv_buffer.get();
const char* ptr = recv_buffer.begin() + 1;
int index = detail::read_int32(ptr);
incoming_allowed_fast(index);
@ -1429,16 +1430,16 @@ namespace libtorrent
// because we wouldn't be able to respond
if (m_holepunch_id == 0) return;
buffer::const_interval recv_buffer = m_recv_buffer.get();
TORRENT_ASSERT(*recv_buffer.begin == msg_extended);
++recv_buffer.begin;
TORRENT_ASSERT(*recv_buffer.begin == holepunch_msg);
++recv_buffer.begin;
span<char const> recv_buffer = m_recv_buffer.get();
TORRENT_ASSERT(recv_buffer.front() == msg_extended);
recv_buffer = recv_buffer.subspan(1);
TORRENT_ASSERT(recv_buffer.front() == holepunch_msg);
recv_buffer = recv_buffer.subspan(1);
const char* ptr = recv_buffer.begin;
const char* ptr = recv_buffer.begin();
// ignore invalid messages
if (recv_buffer.left() < 2) return;
if (int(recv_buffer.size()) < 2) return;
int const msg_type = detail::read_uint8(ptr);
int const addr_type = detail::read_uint8(ptr);
@ -1447,7 +1448,7 @@ namespace libtorrent
if (addr_type == 0)
{
if (recv_buffer.left() < 2 + 4 + 2) return;
if (int(recv_buffer.size()) < 2 + 4 + 2) return;
// IPv4 address
ep = detail::read_v4_endpoint<tcp::endpoint>(ptr);
}
@ -1455,7 +1456,7 @@ namespace libtorrent
else if (addr_type == 1)
{
// IPv6 address
if (recv_buffer.left() < 2 + 18 + 2) return;
if (int(recv_buffer.size()) < 2 + 18 + 2) return;
ep = detail::read_v6_endpoint<tcp::endpoint>(ptr);
}
#endif
@ -1634,13 +1635,13 @@ namespace libtorrent
return;
}
buffer::const_interval recv_buffer = m_recv_buffer.get();
if (recv_buffer.left() < 2) return;
span<char const> recv_buffer = m_recv_buffer.get();
if (int(recv_buffer.size()) < 2) return;
TORRENT_ASSERT(*recv_buffer.begin == msg_extended);
++recv_buffer.begin;
TORRENT_ASSERT(recv_buffer.front() == msg_extended);
recv_buffer = recv_buffer.subspan(1);
int extended_id = detail::read_uint8(recv_buffer.begin);
int extended_id = aux::read_uint8(recv_buffer);
if (extended_id == 0)
{
@ -1660,7 +1661,7 @@ namespace libtorrent
#endif
return;
}
bool ul = detail::read_uint8(recv_buffer.begin) != 0;
bool ul = aux::read_uint8(recv_buffer) != 0;
#ifndef TORRENT_DISABLE_LOGGING
peer_log(peer_log_alert::incoming_message, "UPLOAD_ONLY"
, "%s", (ul?"true":"false"));
@ -1680,7 +1681,7 @@ namespace libtorrent
#endif
return;
}
bool sm = detail::read_uint8(recv_buffer.begin) != 0;
bool sm = aux::read_uint8(recv_buffer) != 0;
#ifndef TORRENT_DISABLE_LOGGING
peer_log(peer_log_alert::incoming_message, "SHARE_MODE"
, "%s", (sm?"true":"false"));
@ -1710,7 +1711,7 @@ namespace libtorrent
#endif
return;
}
int piece = detail::read_uint32(recv_buffer.begin);
int piece = aux::read_uint32(recv_buffer);
incoming_dont_have(piece);
return;
}
@ -1740,12 +1741,12 @@ namespace libtorrent
boost::shared_ptr<torrent> t = associated_torrent().lock();
TORRENT_ASSERT(t);
buffer::const_interval recv_buffer = m_recv_buffer.get();
span<char const> recv_buffer = m_recv_buffer.get();
bdecode_node root;
error_code ec;
int pos;
int ret = bdecode(recv_buffer.begin + 2, recv_buffer.end, root, ec, &pos);
int ret = bdecode(recv_buffer.begin() + 2, recv_buffer.end(), root, ec, &pos);
if (ret != 0 || ec || root.type() != bdecode_node::dict_t)
{
#ifndef TORRENT_DISABLE_LOGGING
@ -1859,9 +1860,9 @@ namespace libtorrent
return false;
}
buffer::const_interval recv_buffer = m_recv_buffer.get();
span<char const> recv_buffer = m_recv_buffer.get();
TORRENT_ASSERT(recv_buffer.left() >= 1);
TORRENT_ASSERT(int(recv_buffer.size()) >= 1);
int packet_type = static_cast<std::uint8_t>(recv_buffer[0]);
if (m_settings.get_bool(settings_pack::support_merkle_torrents)
@ -1905,8 +1906,7 @@ namespace libtorrent
, end(m_extensions.end()); i != end; ++i)
{
if ((*i)->on_unknown_message(m_recv_buffer.packet_size(), packet_type
, buffer::const_interval(recv_buffer.begin+1
, recv_buffer.end)))
, recv_buffer.subspan(1)))
return m_recv_buffer.packet_finished();
}
#endif
@ -2549,7 +2549,7 @@ namespace libtorrent
{
boost::shared_ptr<torrent> t = associated_torrent().lock();
buffer::const_interval recv_buffer = m_recv_buffer.get();
span<char const> recv_buffer = m_recv_buffer.get();
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
// m_state is set to read_pe_dhkey in initial state
@ -2562,7 +2562,8 @@ namespace libtorrent
TORRENT_ASSERT(!m_encrypted);
TORRENT_ASSERT(!m_rc4_encrypted);
TORRENT_ASSERT(m_recv_buffer.packet_size() == dh_key_len);
TORRENT_ASSERT(recv_buffer == m_recv_buffer.get());
TORRENT_ASSERT(recv_buffer.begin() == m_recv_buffer.get().begin());
TORRENT_ASSERT(recv_buffer.size() == m_recv_buffer.get().size());
if (!m_recv_buffer.packet_finished()) return;
@ -2573,7 +2574,7 @@ namespace libtorrent
// read dh key, generate shared secret
m_dh_key_exchange->compute_secret(
reinterpret_cast<std::uint8_t const*>(recv_buffer.begin));
reinterpret_cast<std::uint8_t const*>(recv_buffer.begin()));
#ifndef TORRENT_DISABLE_LOGGING
peer_log(peer_log_alert::info, "ENCRYPTION", "received DH key");
@ -2619,9 +2620,10 @@ namespace libtorrent
TORRENT_ASSERT(!m_encrypted);
TORRENT_ASSERT(!m_rc4_encrypted);
TORRENT_ASSERT(!is_outgoing());
TORRENT_ASSERT(recv_buffer == m_recv_buffer.get());
TORRENT_ASSERT(recv_buffer.begin() == m_recv_buffer.get().begin());
TORRENT_ASSERT(recv_buffer.size() == m_recv_buffer.get().size());
if (recv_buffer.left() < 20)
if (int(recv_buffer.size()) < 20)
{
received_bytes(0, int(bytes_transferred));
@ -2645,14 +2647,14 @@ namespace libtorrent
}
int const syncoffset = get_syncoffset(m_sync_hash->data(), 20
, recv_buffer.begin, recv_buffer.left());
, recv_buffer.begin(), int(recv_buffer.size()));
// No sync
if (syncoffset == -1)
{
received_bytes(0, int(bytes_transferred));
std::size_t bytes_processed = recv_buffer.left() - 20;
std::size_t bytes_processed = int(recv_buffer.size()) - 20;
m_sync_bytes_read += int(bytes_processed);
if (m_sync_bytes_read >= 512)
{
@ -2678,7 +2680,7 @@ namespace libtorrent
m_state = read_pe_skey_vc;
// skey,vc - 28 bytes
m_sync_hash.reset();
int transferred_used = int(bytes_processed - recv_buffer.left() + bytes_transferred);
int transferred_used = int(bytes_processed - int(recv_buffer.size()) + bytes_transferred);
TORRENT_ASSERT(transferred_used <= int(bytes_transferred));
received_bytes(0, transferred_used);
bytes_transferred -= transferred_used;
@ -2704,7 +2706,7 @@ namespace libtorrent
TORRENT_ASSERT(!is_disconnecting());
sha1_hash ih(recv_buffer.begin);
sha1_hash ih(recv_buffer.begin());
torrent const* ti = m_ses.find_encrypted_torrent(ih, m_dh_key_exchange->get_hash_xor_mask());
if (ti)
@ -2737,7 +2739,7 @@ namespace libtorrent
rc4_decrypt(m_recv_buffer.mutable_buffer().subspan(20, 8));
const char sh_vc[] = {0,0,0,0, 0,0,0,0};
if (!std::equal(sh_vc, sh_vc + 8, recv_buffer.begin + 20))
if (!std::equal(sh_vc, sh_vc + 8, recv_buffer.begin() + 20))
{
disconnect(errors::invalid_encryption_constant, op_encryption, 2);
return;
@ -2756,9 +2758,10 @@ namespace libtorrent
TORRENT_ASSERT(is_outgoing());
TORRENT_ASSERT(!m_encrypted);
TORRENT_ASSERT(!m_rc4_encrypted);
TORRENT_ASSERT(recv_buffer == m_recv_buffer.get());
TORRENT_ASSERT(recv_buffer.begin() == m_recv_buffer.get().begin());
TORRENT_ASSERT(recv_buffer.size() == m_recv_buffer.get().size());
if (recv_buffer.left() < 8)
if (int(recv_buffer.size()) < 8)
{
received_bytes(0, int(bytes_transferred));
if (m_recv_buffer.packet_finished())
@ -2783,12 +2786,12 @@ namespace libtorrent
TORRENT_ASSERT(m_sync_vc.get());
int const syncoffset = get_syncoffset(m_sync_vc.get(), 8
, recv_buffer.begin, recv_buffer.left());
, recv_buffer.begin(), int(recv_buffer.size()));
// No sync
if (syncoffset == -1)
{
std::size_t bytes_processed = recv_buffer.left() - 8;
std::size_t bytes_processed = int(recv_buffer.size()) - 8;
m_sync_bytes_read += int(bytes_processed);
received_bytes(0, int(bytes_transferred));
@ -2812,7 +2815,7 @@ namespace libtorrent
, "sync point (verification constant) found at offset %d"
, int(m_sync_bytes_read + bytes_processed - 8));
#endif
int transferred_used = int(bytes_processed - recv_buffer.left() + bytes_transferred);
int transferred_used = int(bytes_processed - int(recv_buffer.size()) + bytes_transferred);
TORRENT_ASSERT(transferred_used <= int(bytes_transferred));
received_bytes(0, transferred_used);
bytes_transferred -= transferred_used;
@ -2843,7 +2846,7 @@ namespace libtorrent
recv_buffer = m_recv_buffer.get();
std::uint32_t crypto_field = detail::read_uint32(recv_buffer.begin);
std::uint32_t crypto_field = aux::read_uint32(recv_buffer);
#ifndef TORRENT_DISABLE_LOGGING
peer_log(peer_log_alert::info, "ENCRYPTION", "crypto %s : [%s%s ]"
@ -2907,7 +2910,7 @@ namespace libtorrent
m_rc4_encrypted = true;
}
int len_pad = detail::read_int16(recv_buffer.begin);
int len_pad = aux::read_int16(recv_buffer);
if (len_pad < 0 || len_pad > 512)
{
disconnect(errors::invalid_pad_size, op_encryption, 2);
@ -2952,8 +2955,8 @@ namespace libtorrent
if (!is_outgoing())
{
recv_buffer.begin += pad_size;
int len_ia = detail::read_int16(recv_buffer.begin);
recv_buffer = recv_buffer.subspan(pad_size);
int len_ia = aux::read_int16(recv_buffer);
if (len_ia < 0)
{
@ -3079,7 +3082,7 @@ namespace libtorrent
const char protocol_string[] = "\x13" "BitTorrent protocol";
if (packet_size != 19 ||
memcmp(recv_buffer.begin, protocol_string, 20) != 0)
memcmp(recv_buffer.begin(), protocol_string, 20) != 0)
{
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
#ifndef TORRENT_DISABLE_LOGGING
@ -3183,7 +3186,7 @@ namespace libtorrent
#endif
#ifndef TORRENT_DISABLE_EXTENSIONS
std::memcpy(m_reserved_bits, recv_buffer.begin, 8);
std::memcpy(m_reserved_bits, recv_buffer.begin(), 8);
if ((recv_buffer[5] & 0x10))
m_supports_extensions = true;
#endif
@ -3202,7 +3205,7 @@ namespace libtorrent
// now, we have to see if there's a torrent with the
// info_hash we got from the peer
sha1_hash info_hash;
std::copy(recv_buffer.begin + 8, recv_buffer.begin + 28
std::copy(recv_buffer.begin() + 8, recv_buffer.begin() + 28
, info_hash.data());
attach_to_torrent(info_hash);
@ -3211,7 +3214,7 @@ namespace libtorrent
else
{
// verify info hash
if (!std::equal(recv_buffer.begin + 8, recv_buffer.begin + 28
if (!std::equal(recv_buffer.begin() + 8, recv_buffer.begin() + 28
, t->torrent_file().info_hash().data()))
{
#ifndef TORRENT_DISABLE_LOGGING
@ -3260,21 +3263,21 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_LOGGING
{
char hex_pid[41];
aux::to_hex(recv_buffer.begin, 20, hex_pid);
aux::to_hex(recv_buffer.begin(), 20, hex_pid);
hex_pid[40] = 0;
char ascii_pid[21];
ascii_pid[20] = 0;
for (int i = 0; i != 20; ++i)
{
if (is_print(recv_buffer.begin[i])) ascii_pid[i] = recv_buffer.begin[i];
if (is_print(recv_buffer[i])) ascii_pid[i] = recv_buffer[i];
else ascii_pid[i] = '.';
}
peer_log(peer_log_alert::incoming, "HANDSHAKE", "received peer_id: %s client: %s ascii: \"%s\""
, hex_pid, identify_client(peer_id(recv_buffer.begin)).c_str(), ascii_pid);
, hex_pid, identify_client(peer_id(recv_buffer.begin())).c_str(), ascii_pid);
}
#endif
peer_id pid;
std::copy(recv_buffer.begin, recv_buffer.begin + 20, pid.data());
std::copy(recv_buffer.begin(), recv_buffer.begin() + 20, pid.data());
if (t->settings().get_bool(settings_pack::allow_multiple_connections_per_ip))
{
@ -3393,7 +3396,8 @@ namespace libtorrent
if (m_state == read_packet_size)
{
// Make sure this is not fallen though into
TORRENT_ASSERT(recv_buffer == m_recv_buffer.get());
TORRENT_ASSERT(recv_buffer.begin() == m_recv_buffer.get().begin());
TORRENT_ASSERT(recv_buffer.size() == m_recv_buffer.get().size());
TORRENT_ASSERT(m_recv_buffer.packet_size() == 5);
if (!t) return;
@ -3402,14 +3406,14 @@ namespace libtorrent
// byte here, instead it's counted in the message
// handler itself, for the specific message
TORRENT_ASSERT(bytes_transferred <= 5);
int used_bytes = recv_buffer.left() > 4 ? int(bytes_transferred) - 1: int(bytes_transferred);
int used_bytes = int(recv_buffer.size()) > 4 ? int(bytes_transferred) - 1: int(bytes_transferred);
received_bytes(0, used_bytes);
bytes_transferred -= used_bytes;
if (recv_buffer.left() < 4) return;
if (int(recv_buffer.size()) < 4) return;
TORRENT_ASSERT(bytes_transferred <= 1);
const char* ptr = recv_buffer.begin;
const char* ptr = recv_buffer.begin();
int packet_size = detail::read_int32(ptr);
// don't accept packets larger than 1 MB
@ -3432,18 +3436,19 @@ namespace libtorrent
m_recv_buffer.cut(4, 5);
return;
}
if (recv_buffer.left() < 5) return;
if (int(recv_buffer.size()) < 5) return;
m_state = read_packet;
m_recv_buffer.cut(4, packet_size);
recv_buffer = m_recv_buffer.get();
TORRENT_ASSERT(recv_buffer.left() == 1);
TORRENT_ASSERT(int(recv_buffer.size()) == 1);
TORRENT_ASSERT(bytes_transferred == 1);
}
if (m_state == read_packet)
{
TORRENT_ASSERT(recv_buffer == m_recv_buffer.get());
TORRENT_ASSERT(recv_buffer.begin() == m_recv_buffer.get().begin());
TORRENT_ASSERT(recv_buffer.size() == m_recv_buffer.get().size());
if (!t)
{
received_bytes(0, int(bytes_transferred));
@ -3475,12 +3480,12 @@ namespace libtorrent
}
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
std::tuple<int, span<aux::const_buffer>>
std::tuple<int, span<span<char const>>>
bt_peer_connection::hit_send_barrier(
span<aux::mutable_buffer> iovec)
span<span<char>> iovec)
{
int next_barrier;
span<aux::const_buffer> out_iovec;
span<span<char const>> out_iovec;
std::tie(next_barrier, out_iovec) = m_enc_handler.encrypt(iovec);
#ifndef TORRENT_DISABLE_LOGGING
if (next_barrier != 0)

View File

@ -151,7 +151,7 @@ namespace libtorrent
return m_tmp_vec;
}
void chained_buffer::build_mutable_iovec(int bytes, std::vector<aux::mutable_buffer> &vec)
void chained_buffer::build_mutable_iovec(int bytes, std::vector<span<char>> &vec)
{
build_vec(bytes, vec);
}

View File

@ -120,7 +120,7 @@ namespace libtorrent
}
else
{
int receive_buffer_size = m_recv_buffer.get().left() - m_parser.body_start();
int receive_buffer_size = int(m_recv_buffer.get().size()) - m_parser.body_start();
// TODO: 1 in chunked encoding mode, this assert won't hold.
// the chunk headers should be subtracted from the receive_buffer_size
TORRENT_ASSERT_VAL(receive_buffer_size <= t->block_size(), receive_buffer_size);
@ -226,10 +226,10 @@ namespace libtorrent
for (;;)
{
buffer::const_interval recv_buffer = m_recv_buffer.get();
span<char const> recv_buffer = m_recv_buffer.get();
if (bytes_transferred == 0) break;
TORRENT_ASSERT(recv_buffer.left() > 0);
TORRENT_ASSERT(int(recv_buffer.size()) > 0);
TORRENT_ASSERT(!m_requests.empty());
if (m_requests.empty())
@ -247,8 +247,8 @@ namespace libtorrent
bool parse_error = false;
int protocol = 0;
int payload = 0;
std::tie(payload, protocol) = m_parser.incoming(span<char const>(
recv_buffer.begin, recv_buffer.left()), parse_error);
std::tie(payload, protocol) = m_parser.incoming(
recv_buffer, parse_error);
received_bytes(0, protocol);
bytes_transferred -= protocol;
#if TORRENT_USE_ASSERTS
@ -262,9 +262,9 @@ namespace libtorrent
return;
}
TORRENT_ASSERT(recv_buffer.left() == 0 || *recv_buffer.begin == 'H');
TORRENT_ASSERT(int(recv_buffer.size()) == 0 || recv_buffer.front() == 'H');
TORRENT_ASSERT(recv_buffer.left() <= m_recv_buffer.packet_size());
TORRENT_ASSERT(int(recv_buffer.size()) <= m_recv_buffer.packet_size());
// this means the entire status line hasn't been received yet
if (m_parser.status_code() == -1)
@ -352,18 +352,18 @@ namespace libtorrent
m_body_start = m_parser.body_start();
}
recv_buffer.begin += m_body_start;
recv_buffer = recv_buffer.subspan(m_body_start);
// =========================
// === CHUNKED ENCODING ===
// =========================
while (m_parser.chunked_encoding()
&& m_chunk_pos >= 0
&& m_chunk_pos < recv_buffer.left())
&& m_chunk_pos < int(recv_buffer.size()))
{
int header_size = 0;
std::int64_t chunk_size = 0;
span<char const> chunk_start(recv_buffer.begin + m_chunk_pos, recv_buffer.left() - m_chunk_pos);
span<char const> chunk_start(recv_buffer.begin() + m_chunk_pos, int(recv_buffer.size()) - m_chunk_pos);
TORRENT_ASSERT(chunk_start[0] == '\r'
|| aux::is_hex(chunk_start.data(), 1));
bool ret = m_parser.parse_chunk_header(chunk_start, &chunk_size, &header_size);
@ -393,11 +393,11 @@ namespace libtorrent
TORRENT_ASSERT(m_chunk_pos + m_body_start < INT_MAX);
m_recv_buffer.cut(header_size, t->block_size() + 1024, int(m_chunk_pos + m_body_start));
recv_buffer = m_recv_buffer.get();
recv_buffer.begin += m_body_start;
recv_buffer = recv_buffer.subspan(m_body_start);
m_chunk_pos += chunk_size;
if (chunk_size == 0)
{
TORRENT_ASSERT(m_recv_buffer.get().left() < m_chunk_pos + m_body_start + 1
TORRENT_ASSERT(int(m_recv_buffer.get().size()) < m_chunk_pos + m_body_start + 1
|| m_recv_buffer.get()[int(m_chunk_pos + m_body_start)] == 'H'
|| (m_parser.chunked_encoding() && m_recv_buffer.get()[int(m_chunk_pos + m_body_start)] == '\r'));
m_chunk_pos = -1;
@ -416,7 +416,7 @@ namespace libtorrent
{
if (!m_parser.finished()) return;
int retry_time = atol(std::string(recv_buffer.begin, recv_buffer.end).c_str());
int retry_time = atol(std::string(recv_buffer.begin(), recv_buffer.end()).c_str());
if (retry_time <= 0) retry_time = 60;
#ifndef TORRENT_DISABLE_LOGGING
peer_log(peer_log_alert::info, "CONNECT", "retrying in %d seconds", retry_time);
@ -431,20 +431,20 @@ namespace libtorrent
// we only received the header, no data
if (recv_buffer.left() == 0) break;
if (int(recv_buffer.size()) == 0) break;
if (recv_buffer.left() < front_request.length) break;
if (int(recv_buffer.size()) < front_request.length) break;
// if the response is chunked, we need to receive the last
// terminating chunk and the tail headers before we can proceed
if (m_parser.chunked_encoding() && m_chunk_pos >= 0) break;
m_requests.pop_front();
incoming_piece(front_request, recv_buffer.begin);
incoming_piece(front_request, recv_buffer.begin());
if (associated_torrent().expired()) return;
int size_to_cut = m_body_start + front_request.length;
TORRENT_ASSERT(m_recv_buffer.get().left() < size_to_cut + 1
TORRENT_ASSERT(int(m_recv_buffer.get().size()) < size_to_cut + 1
|| m_recv_buffer.get()[size_to_cut] == 'H'
|| (m_parser.chunked_encoding() && m_recv_buffer.get()[size_to_cut] == '\r'));
@ -467,4 +467,3 @@ namespace libtorrent
}
}

View File

@ -101,21 +101,21 @@ namespace libtorrent
m_xor_mask = hasher(req3).update(buffer).final();
}
std::tuple<int, span<aux::const_buffer>>
std::tuple<int, span<span<char const>>>
encryption_handler::encrypt(
span<aux::mutable_buffer> iovec)
span<span<char>> iovec)
{
TORRENT_ASSERT(!m_send_barriers.empty());
TORRENT_ASSERT(m_send_barriers.front().enc_handler);
int to_process = m_send_barriers.front().next;
aux::mutable_buffer* bufs;
span<char>* bufs;
size_t num_bufs;
bool need_destruct = false;
if (to_process != INT_MAX)
{
bufs = TORRENT_ALLOCA(aux::mutable_buffer, iovec.size());
bufs = TORRENT_ALLOCA(span<char>, iovec.size());
need_destruct = true;
num_bufs = 0;
for (int i = 0; to_process > 0 && i < iovec.size(); ++i)
@ -124,13 +124,13 @@ namespace libtorrent
int const size = int(iovec[i].size());
if (to_process < size)
{
new (&bufs[i]) aux::mutable_buffer(
new (&bufs[i]) span<char>(
iovec[i].data(), to_process);
to_process = 0;
}
else
{
new (&bufs[i]) aux::mutable_buffer(iovec[i]);
new (&bufs[i]) span<char>(iovec[i]);
to_process -= size;
}
}
@ -142,7 +142,7 @@ namespace libtorrent
}
int next_barrier = 0;
span<aux::const_buffer> out_iovec;
span<span<char const>> out_iovec;
if (num_bufs != 0)
{
std::tie(next_barrier, out_iovec)
@ -198,7 +198,7 @@ namespace libtorrent
int consume = 0;
if (recv_buffer.crypto_packet_finished())
{
aux::mutable_buffer wr_buf = recv_buffer.mutable_buffer(bytes_transferred);
span<char> wr_buf = recv_buffer.mutable_buffer(bytes_transferred);
int packet_size = 0;
int produce = int(bytes_transferred);
m_dec_handler->decrypt(wr_buf, consume, produce, packet_size);
@ -244,7 +244,7 @@ namespace libtorrent
{
int consume = 0;
int produce = 0;
std::vector<aux::mutable_buffer> wr_buf;
std::vector<span<char>> wr_buf;
crypto->decrypt(wr_buf, consume, produce, packet_size);
TORRENT_ASSERT(wr_buf.empty());
TORRENT_ASSERT(consume == 0);
@ -272,7 +272,7 @@ namespace libtorrent
int produce = 0;
int packet_size = 0;
char buf[1024];
aux::mutable_buffer vec(buf, sizeof(buf));
span<char> vec(buf, sizeof(buf));
decrypt(vec, consume, produce, packet_size);
}
@ -282,14 +282,14 @@ namespace libtorrent
rc4_init(key, len, &m_rc4_outgoing);
// Discard first 1024 bytes
char buf[1024];
aux::mutable_buffer vec(buf, sizeof(buf));
span<char> vec(buf, sizeof(buf));
encrypt(vec);
}
std::tuple<int, span<aux::const_buffer>>
rc4_handler::encrypt(span<aux::mutable_buffer> bufs)
std::tuple<int, span<span<char const>>>
rc4_handler::encrypt(span<span<char>> bufs)
{
span<aux::const_buffer> empty;
span<span<char const>> empty;
if (!m_encrypt) return std::make_tuple(0, empty);
if (bufs.size() == 0) return std::make_tuple(0, empty);
@ -308,7 +308,7 @@ namespace libtorrent
return std::make_tuple(bytes_processed, empty);
}
void rc4_handler::decrypt(span<aux::mutable_buffer> bufs
void rc4_handler::decrypt(span<span<char>> bufs
, int& consume
, int& produce
, int& packet_size)

View File

@ -2497,8 +2497,8 @@ namespace libtorrent
check_invariant();
#endif
#if TORRENT_USE_ASSERTS
buffer::const_interval recv_buffer = m_recv_buffer.get();
int recv_pos = recv_buffer.end - recv_buffer.begin;
span<char const> recv_buffer = m_recv_buffer.get();
int recv_pos = recv_buffer.end() - recv_buffer.begin();
TORRENT_ASSERT(recv_pos >= 9);
#endif
@ -5468,12 +5468,12 @@ namespace libtorrent
if (m_send_barrier == 0)
{
std::vector<aux::mutable_buffer> vec;
std::vector<span<char>> vec;
// limit outgoing crypto messages to 1MB
int const send_bytes = (std::min)(m_send_buffer.size(), 1024*1024);
m_send_buffer.build_mutable_iovec(send_bytes, vec);
int next_barrier;
span<aux::const_buffer> inject_vec;
span<span<char const>> inject_vec;
std::tie(next_barrier, inject_vec) = hit_send_barrier(vec);
for (auto i = inject_vec.rbegin(); i != inject_vec.rend(); ++i)
{

View File

@ -136,17 +136,16 @@ void receive_buffer::cut(int const size, int const packet_size, int const offset
m_packet_size = packet_size;
}
buffer::const_interval receive_buffer::get() const
span<char const> receive_buffer::get() const
{
if (m_recv_buffer.empty())
{
TORRENT_ASSERT(m_recv_pos == 0);
return buffer::const_interval(nullptr,nullptr);
return span<char const>();
}
TORRENT_ASSERT(m_recv_start + m_recv_pos <= m_recv_buffer.size());
return buffer::const_interval(&m_recv_buffer[0] + m_recv_start
, &m_recv_buffer[0] + m_recv_start + m_recv_pos);
return span<char const>(m_recv_buffer).subspan(m_recv_start, m_recv_pos);
}
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
@ -156,7 +155,7 @@ span<char> receive_buffer::mutable_buffer()
return span<char>(m_recv_buffer).subspan(m_recv_start, m_recv_pos);
}
aux::mutable_buffer receive_buffer::mutable_buffer(int const bytes)
span<char> receive_buffer::mutable_buffer(int const bytes)
{
INVARIANT_CHECK;
// bytes is the number of bytes we just received, and m_recv_pos has
@ -317,15 +316,15 @@ int crypto_receive_buffer::advance_pos(int bytes)
return sub_transferred;
}
buffer::const_interval crypto_receive_buffer::get() const
span<char const> crypto_receive_buffer::get() const
{
buffer::const_interval recv_buffer = m_connection_buffer.get();
span<char const> recv_buffer = m_connection_buffer.get();
if (m_recv_pos < m_connection_buffer.pos())
recv_buffer.end = recv_buffer.begin + m_recv_pos;
recv_buffer = recv_buffer.subspan(0, m_recv_pos);
return recv_buffer;
}
aux::mutable_buffer crypto_receive_buffer::mutable_buffer(
span<char> crypto_receive_buffer::mutable_buffer(
std::size_t const bytes)
{
int const pending_decryption = (m_recv_pos != INT_MAX)

View File

@ -315,7 +315,7 @@ namespace libtorrent { namespace
}
bool on_extended(int length
, int extended_msg, buffer::const_interval body) override
, int extended_msg, span<char const> body) override
{
if (extended_msg != 2) return false;
if (m_message_index == 0) return false;
@ -333,7 +333,7 @@ namespace libtorrent { namespace
if (!m_pc.packet_finished()) return true;
int len;
entry msg = bdecode(body.begin, body.end, len);
entry msg = bdecode(body.begin(), body.end(), len);
if (msg.type() != entry::dictionary_t)
{
#ifndef TORRENT_DISABLE_LOGGING
@ -369,14 +369,14 @@ namespace libtorrent { namespace
case metadata_req:
{
if (!m_torrent.valid_metadata()
|| piece < 0 || piece >= int(m_tp.get_metadata_size() + 16 * 1024 - 1)/(16*1024))
|| piece < 0 || piece >= (m_tp.get_metadata_size() + 16 * 1024 - 1) / (16 * 1024))
{
#ifndef TORRENT_DISABLE_LOGGING
m_pc.peer_log(peer_log_alert::info, "UT_METADATA"
, "have: %d invalid piece %d metadata size: %d"
, int(m_torrent.valid_metadata()), piece
, m_torrent.valid_metadata()
? int(m_tp.get_metadata_size()) : 0);
? m_tp.get_metadata_size() : 0);
#endif
write_metadata_packet(metadata_dont_have, piece);
return true;
@ -406,7 +406,7 @@ namespace libtorrent { namespace
m_sent_requests.erase(i);
entry const* total_size = msg.find_key("total_size");
m_tp.received_metadata(*this, body.begin + len, body.left() - len, piece
m_tp.received_metadata(*this, body.begin() + len, int(body.size()) - len, piece
, (total_size && total_size->type() == entry::int_t) ? total_size->integer() : 0);
maybe_send_request();
}
@ -664,4 +664,3 @@ namespace libtorrent
}
#endif

View File

@ -280,7 +280,7 @@ namespace libtorrent { namespace
return true;
}
bool on_extended(int length, int msg, buffer::const_interval body) override
bool on_extended(int length, int msg, span<char const> body) override
{
if (msg != extension_index) return false;
if (m_message_index == 0) return false;
@ -291,7 +291,7 @@ namespace libtorrent { namespace
return true;
}
if (body.left() < length) return true;
if (int(body.size()) < length) return true;
time_point now = aux::time_now();
if (now - seconds(60) < m_last_pex[0])
@ -309,7 +309,7 @@ namespace libtorrent { namespace
bdecode_node pex_msg;
error_code ec;
int const ret = bdecode(body.begin, body.end, pex_msg, ec);
int const ret = bdecode(body.begin(), body.end(), pex_msg, ec);
if (ret != 0 || pex_msg.type() != bdecode_node::dict_t)
{
m_pc.disconnect(errors::invalid_pex_message, op_bittorrent, 2);

View File

@ -655,7 +655,7 @@ void web_peer_connection::on_receive(error_code const& error
// in case the first file on this series of requests is a padfile
// we need to handle it right now
span<char const> recv_buffer(m_recv_buffer.get().begin, m_recv_buffer.get().left());
span<char const> recv_buffer = m_recv_buffer.get();
handle_padfile();
if (associated_torrent().expired()) return;
@ -927,7 +927,7 @@ void web_peer_connection::on_receive(error_code const& error
done:
// now, remove all the bytes we've processed from the receive buffer
m_recv_buffer.cut(recv_buffer.data() - m_recv_buffer.get().begin
m_recv_buffer.cut(recv_buffer.data() - m_recv_buffer.get().begin()
, t->block_size() + request_size_overhead);
}
@ -1087,4 +1087,3 @@ void web_peer_connection::handle_padfile()
}
} // libtorrent namespace

View File

@ -62,9 +62,9 @@ void test_enc_handler(libtorrent::crypto_plugin& a, libtorrent::crypto_plugin& b
using namespace libtorrent::aux;
{
mutable_buffer iovec(&buf[0], buf_len);
lt::span<char> iovec(&buf[0], buf_len);
int next_barrier;
lt::span<const_buffer> iovec_out;
lt::span<lt::span<char const>> iovec_out;
std::tie(next_barrier, iovec_out) = a.encrypt(iovec);
TEST_CHECK(buf != cmp_buf);
TEST_EQUAL(iovec_out.size(), 0);
@ -75,7 +75,7 @@ void test_enc_handler(libtorrent::crypto_plugin& a, libtorrent::crypto_plugin& b
int consume = 0;
int produce = buf_len;
int packet_size = 0;
mutable_buffer iovec(&buf[0], buf_len);
lt::span<char> iovec(&buf[0], buf_len);
b.decrypt(iovec, consume, produce, packet_size);
TEST_CHECK(buf == cmp_buf);
TEST_EQUAL(consume, 0);
@ -84,9 +84,9 @@ void test_enc_handler(libtorrent::crypto_plugin& a, libtorrent::crypto_plugin& b
}
{
mutable_buffer iovec(&buf[0], buf_len);
lt::span<char> iovec(&buf[0], buf_len);
int next_barrier;
lt::span<const_buffer> iovec_out;
lt::span<lt::span<char const>> iovec_out;
std::tie(next_barrier, iovec_out) = b.encrypt(iovec);
TEST_EQUAL(iovec_out.size(), 0);
TEST_CHECK(buf != cmp_buf);
@ -95,7 +95,7 @@ void test_enc_handler(libtorrent::crypto_plugin& a, libtorrent::crypto_plugin& b
int consume = 0;
int produce = buf_len;
int packet_size = 0;
mutable_buffer iovec2(&buf[0], buf_len);
lt::span<char> iovec2(&buf[0], buf_len);
a.decrypt(iovec2, consume, produce, packet_size);
TEST_CHECK(buf == cmp_buf);
TEST_EQUAL(consume, 0);

View File

@ -229,7 +229,7 @@ TORRENT_TEST(recv_buffer_mutable_buffers)
b.cut(100, 1000); // packet size = 1000
packet_transferred = b.advance_pos(999);
TEST_EQUAL(packet_transferred, 999);
aux::mutable_buffer vec = b.mutable_buffer(999);
span<char> vec = b.mutable_buffer(999);
// previous packet
// |