Merge pull request #7009

7414e2bac Change epee binary output from std::stringstream to byte_stream (Lee Clagett)
This commit is contained in:
Alexander Blair 2020-12-10 17:34:50 -08:00
commit 1e9483a2d5
No known key found for this signature in database
GPG Key ID: C64552D877C32479
23 changed files with 126 additions and 106 deletions

View File

@ -70,7 +70,7 @@ namespace http
virtual bool connect(std::chrono::milliseconds timeout) = 0; virtual bool connect(std::chrono::milliseconds timeout) = 0;
virtual bool disconnect() = 0; virtual bool disconnect() = 0;
virtual bool is_connected(bool *ssl = NULL) = 0; virtual bool is_connected(bool *ssl = NULL) = 0;
virtual bool invoke(const boost::string_ref uri, const boost::string_ref method, const std::string& body, std::chrono::milliseconds timeout, const http_response_info** ppresponse_info = NULL, const fields_list& additional_params = fields_list()) = 0; virtual bool invoke(const boost::string_ref uri, const boost::string_ref method, const boost::string_ref body, std::chrono::milliseconds timeout, const http_response_info** ppresponse_info = NULL, const fields_list& additional_params = fields_list()) = 0;
virtual bool invoke_get(const boost::string_ref uri, std::chrono::milliseconds timeout, const std::string& body = std::string(), const http_response_info** ppresponse_info = NULL, const fields_list& additional_params = fields_list()) = 0; virtual bool invoke_get(const boost::string_ref uri, std::chrono::milliseconds timeout, const std::string& body = std::string(), const http_response_info** ppresponse_info = NULL, const fields_list& additional_params = fields_list()) = 0;
virtual bool invoke_post(const boost::string_ref uri, const std::string& body, std::chrono::milliseconds timeout, const http_response_info** ppresponse_info = NULL, const fields_list& additional_params = fields_list()) = 0; virtual bool invoke_post(const boost::string_ref uri, const std::string& body, std::chrono::milliseconds timeout, const http_response_info** ppresponse_info = NULL, const fields_list& additional_params = fields_list()) = 0;
virtual uint64_t get_bytes_sent() const = 0; virtual uint64_t get_bytes_sent() const = 0;

View File

@ -233,7 +233,7 @@ namespace net_utils
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
inline bool invoke(const boost::string_ref uri, const boost::string_ref method, const std::string& body, std::chrono::milliseconds timeout, const http_response_info** ppresponse_info = NULL, const fields_list& additional_params = fields_list()) override inline bool invoke(const boost::string_ref uri, const boost::string_ref method, const boost::string_ref body, std::chrono::milliseconds timeout, const http_response_info** ppresponse_info = NULL, const fields_list& additional_params = fields_list()) override
{ {
CRITICAL_REGION_LOCAL(m_lock); CRITICAL_REGION_LOCAL(m_lock);
if(!is_connected()) if(!is_connected())

View File

@ -118,8 +118,10 @@
return true; \ return true; \
} \ } \
uint64_t ticks2 = misc_utils::get_tick_count(); \ uint64_t ticks2 = misc_utils::get_tick_count(); \
epee::serialization::store_t_to_binary(static_cast<command_type::response&>(resp), response_info.m_body); \ epee::byte_slice buffer; \
epee::serialization::store_t_to_binary(static_cast<command_type::response&>(resp), buffer, 64 * 1024); \
uint64_t ticks3 = epee::misc_utils::get_tick_count(); \ uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
response_info.m_body.assign(reinterpret_cast<const char*>(buffer.data()), buffer.size()); \
response_info.m_mime_tipe = " application/octet-stream"; \ response_info.m_mime_tipe = " application/octet-stream"; \
response_info.m_header_info.m_content_type = " application/octet-stream"; \ response_info.m_header_info.m_content_type = " application/octet-stream"; \
MDEBUG( s_pattern << "() processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms"); \ MDEBUG( s_pattern << "() processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms"); \

View File

@ -31,7 +31,6 @@
#include <cstdint> #include <cstdint>
#include "byte_slice.h"
#include "net_utils_base.h" #include "net_utils_base.h"
#include "span.h" #include "span.h"
@ -39,6 +38,7 @@
namespace epee namespace epee
{ {
class byte_slice;
namespace levin namespace levin
{ {
#pragma pack(push) #pragma pack(push)
@ -86,7 +86,7 @@ namespace levin
template<class t_connection_context = net_utils::connection_context_base> template<class t_connection_context = net_utils::connection_context_base>
struct levin_commands_handler struct levin_commands_handler
{ {
virtual int invoke(int command, const epee::span<const uint8_t> in_buff, std::string& buff_out, t_connection_context& context)=0; virtual int invoke(int command, const epee::span<const uint8_t> in_buff, byte_slice& buff_out, t_connection_context& context)=0;
virtual int notify(int command, const epee::span<const uint8_t> in_buff, t_connection_context& context)=0; virtual int notify(int command, const epee::span<const uint8_t> in_buff, t_connection_context& context)=0;
virtual void callback(t_connection_context& context){}; virtual void callback(t_connection_context& context){};

View File

@ -514,16 +514,15 @@ public:
{ {
if(m_current_head.m_have_to_return_data) if(m_current_head.m_have_to_return_data)
{ {
std::string return_buff; byte_slice return_buff;
const uint32_t return_code = m_config.m_pcommands_handler->invoke( const uint32_t return_code = m_config.m_pcommands_handler->invoke(
m_current_head.m_command, buff_to_invoke, return_buff, m_connection_context m_current_head.m_command, buff_to_invoke, return_buff, m_connection_context
); );
bucket_head2 head = make_header(m_current_head.m_command, return_buff.size(), LEVIN_PACKET_RESPONSE, false); bucket_head2 head = make_header(m_current_head.m_command, return_buff.size(), LEVIN_PACKET_RESPONSE, false);
head.m_return_code = SWAP32LE(return_code); head.m_return_code = SWAP32LE(return_code);
return_buff.insert(0, reinterpret_cast<const char*>(&head), sizeof(head));
if(!m_pservice_endpoint->do_send(byte_slice{std::move(return_buff)})) if(!m_pservice_endpoint->do_send(byte_slice{{epee::as_byte_span(head), epee::to_span(return_buff)}}))
return false; return false;
MDEBUG(m_connection_context << "LEVIN_PACKET_SENT. [len=" << head.m_cb MDEBUG(m_connection_context << "LEVIN_PACKET_SENT. [len=" << head.m_cb

View File

@ -44,6 +44,7 @@
#include <boost/lambda/lambda.hpp> #include <boost/lambda/lambda.hpp>
#include <boost/interprocess/detail/atomic.hpp> #include <boost/interprocess/detail/atomic.hpp>
#include <boost/system/error_code.hpp> #include <boost/system/error_code.hpp>
#include <boost/utility/string_ref.hpp>
#include <functional> #include <functional>
#include "net/net_utils_base.h" #include "net/net_utils_base.h"
#include "net/net_ssl.h" #include "net/net_ssl.h"
@ -280,7 +281,7 @@ namespace net_utils
inline inline
bool send(const std::string& buff, std::chrono::milliseconds timeout) bool send(const boost::string_ref buff, std::chrono::milliseconds timeout)
{ {
try try
@ -298,7 +299,7 @@ namespace net_utils
// object is used as a callback and will update the ec variable when the // object is used as a callback and will update the ec variable when the
// operation completes. The blocking_udp_client.cpp example shows how you // operation completes. The blocking_udp_client.cpp example shows how you
// can use boost::bind rather than boost::lambda. // can use boost::bind rather than boost::lambda.
async_write(buff.c_str(), buff.size(), ec); async_write(buff.data(), buff.size(), ec);
// Block until the asynchronous operation has completed. // Block until the asynchronous operation has completed.
while (ec == boost::asio::error::would_block) while (ec == boost::asio::error::would_block)

View File

@ -29,6 +29,7 @@
#include <boost/utility/string_ref.hpp> #include <boost/utility/string_ref.hpp>
#include <chrono> #include <chrono>
#include <string> #include <string>
#include "byte_slice.h"
#include "portable_storage_template_helper.h" #include "portable_storage_template_helper.h"
#include "net/http_base.h" #include "net/http_base.h"
#include "net/http_server_handlers_map2.h" #include "net/http_server_handlers_map2.h"
@ -74,12 +75,12 @@ namespace epee
template<class t_request, class t_response, class t_transport> template<class t_request, class t_response, class t_transport>
bool invoke_http_bin(const boost::string_ref uri, const t_request& out_struct, t_response& result_struct, t_transport& transport, std::chrono::milliseconds timeout = std::chrono::seconds(15), const boost::string_ref method = "POST") bool invoke_http_bin(const boost::string_ref uri, const t_request& out_struct, t_response& result_struct, t_transport& transport, std::chrono::milliseconds timeout = std::chrono::seconds(15), const boost::string_ref method = "POST")
{ {
std::string req_param; byte_slice req_param;
if(!serialization::store_t_to_binary(out_struct, req_param)) if(!serialization::store_t_to_binary(out_struct, req_param, 16 * 1024))
return false; return false;
const http::http_response_info* pri = NULL; const http::http_response_info* pri = NULL;
if(!transport.invoke(uri, method, req_param, timeout, std::addressof(pri))) if(!transport.invoke(uri, method, boost::string_ref{reinterpret_cast<const char*>(req_param.data()), req_param.size()}, timeout, std::addressof(pri)))
{ {
LOG_PRINT_L1("Failed to invoke http request to " << uri); LOG_PRINT_L1("Failed to invoke http request to " << uri);
return false; return false;

View File

@ -27,8 +27,10 @@
#pragma once #pragma once
#include "portable_storage_template_helper.h" #include "portable_storage_template_helper.h"
#include <boost/utility/string_ref.hpp>
#include <boost/utility/value_init.hpp> #include <boost/utility/value_init.hpp>
#include <functional> #include <functional>
#include "byte_slice.h"
#include "span.h" #include "span.h"
#include "net/levin_base.h" #include "net/levin_base.h"
@ -110,11 +112,12 @@ namespace epee
const boost::uuids::uuid &conn_id = context.m_connection_id; const boost::uuids::uuid &conn_id = context.m_connection_id;
typename serialization::portable_storage stg; typename serialization::portable_storage stg;
out_struct.store(stg); out_struct.store(stg);
std::string buff_to_send, buff_to_recv; byte_slice buff_to_send;
stg.store_to_binary(buff_to_send); std::string buff_to_recv;
stg.store_to_binary(buff_to_send, 16 * 1024);
on_levin_traffic(context, true, true, false, buff_to_send.size(), command); on_levin_traffic(context, true, true, false, buff_to_send.size(), command);
int res = transport.invoke(command, buff_to_send, buff_to_recv, conn_id); int res = transport.invoke(command, boost::string_ref{reinterpret_cast<const char*>(buff_to_send.data()), buff_to_send.size()}, buff_to_recv, conn_id);
if( res <=0 ) if( res <=0 )
{ {
LOG_PRINT_L1("Failed to invoke command " << command << " return code " << res); LOG_PRINT_L1("Failed to invoke command " << command << " return code " << res);
@ -137,10 +140,10 @@ namespace epee
const boost::uuids::uuid &conn_id = context.m_connection_id; const boost::uuids::uuid &conn_id = context.m_connection_id;
typename serialization::portable_storage stg; typename serialization::portable_storage stg;
const_cast<t_arg&>(out_struct).store(stg);//TODO: add true const support to searilzation const_cast<t_arg&>(out_struct).store(stg);//TODO: add true const support to searilzation
std::string buff_to_send; byte_slice buff_to_send;
stg.store_to_binary(buff_to_send); stg.store_to_binary(buff_to_send, 16 * 1024);
on_levin_traffic(context, true, true, false, buff_to_send.size(), command); on_levin_traffic(context, true, true, false, buff_to_send.size(), command);
int res = transport.invoke_async(command, epee::strspan<uint8_t>(buff_to_send), conn_id, [cb, command](int code, const epee::span<const uint8_t> buff, typename t_transport::connection_context& context)->bool int res = transport.invoke_async(command, epee::to_span(buff_to_send), conn_id, [cb, command](int code, const epee::span<const uint8_t> buff, typename t_transport::connection_context& context)->bool
{ {
t_result result_struct = AUTO_VAL_INIT(result_struct); t_result result_struct = AUTO_VAL_INIT(result_struct);
if( code <=0 ) if( code <=0 )
@ -184,11 +187,11 @@ namespace epee
const boost::uuids::uuid &conn_id = context.m_connection_id; const boost::uuids::uuid &conn_id = context.m_connection_id;
serialization::portable_storage stg; serialization::portable_storage stg;
out_struct.store(stg); out_struct.store(stg);
std::string buff_to_send; byte_slice buff_to_send;
stg.store_to_binary(buff_to_send); stg.store_to_binary(buff_to_send);
on_levin_traffic(context, true, true, false, buff_to_send.size(), command); on_levin_traffic(context, true, true, false, buff_to_send.size(), command);
int res = transport.notify(command, epee::strspan<uint8_t>(buff_to_send), conn_id); int res = transport.notify(command, epee::to_span(buff_to_send), conn_id);
if(res <=0 ) if(res <=0 )
{ {
MERROR("Failed to notify command " << command << " return code " << res); MERROR("Failed to notify command " << command << " return code " << res);
@ -199,7 +202,7 @@ namespace epee
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
template<class t_owner, class t_in_type, class t_out_type, class t_context, class callback_t> template<class t_owner, class t_in_type, class t_out_type, class t_context, class callback_t>
int buff_to_t_adapter(int command, const epee::span<const uint8_t> in_buff, std::string& buff_out, callback_t cb, t_context& context ) int buff_to_t_adapter(int command, const epee::span<const uint8_t> in_buff, byte_slice& buff_out, callback_t cb, t_context& context )
{ {
serialization::portable_storage strg; serialization::portable_storage strg;
if(!strg.load_from_binary(in_buff)) if(!strg.load_from_binary(in_buff))
@ -222,7 +225,7 @@ namespace epee
serialization::portable_storage strg_out; serialization::portable_storage strg_out;
static_cast<t_out_type&>(out_struct).store(strg_out); static_cast<t_out_type&>(out_struct).store(strg_out);
if(!strg_out.store_to_binary(buff_out)) if(!strg_out.store_to_binary(buff_out, 32 * 1024))
{ {
LOG_ERROR("Failed to store_to_binary in command" << command); LOG_ERROR("Failed to store_to_binary in command" << command);
return -1; return -1;
@ -254,7 +257,7 @@ namespace epee
} }
#define CHAIN_LEVIN_INVOKE_MAP2(context_type) \ #define CHAIN_LEVIN_INVOKE_MAP2(context_type) \
int invoke(int command, const epee::span<const uint8_t> in_buff, std::string& buff_out, context_type& context) \ int invoke(int command, const epee::span<const uint8_t> in_buff, epee::byte_slice& buff_out, context_type& context) \
{ \ { \
bool handled = false; \ bool handled = false; \
return handle_invoke_map(false, command, in_buff, buff_out, context, handled); \ return handle_invoke_map(false, command, in_buff, buff_out, context, handled); \
@ -263,13 +266,13 @@ namespace epee
#define CHAIN_LEVIN_NOTIFY_MAP2(context_type) \ #define CHAIN_LEVIN_NOTIFY_MAP2(context_type) \
int notify(int command, const epee::span<const uint8_t> in_buff, context_type& context) \ int notify(int command, const epee::span<const uint8_t> in_buff, context_type& context) \
{ \ { \
bool handled = false; std::string fake_str;\ bool handled = false; epee::byte_slice fake_str; \
return handle_invoke_map(true, command, in_buff, fake_str, context, handled); \ return handle_invoke_map(true, command, in_buff, fake_str, context, handled); \
} }
#define CHAIN_LEVIN_INVOKE_MAP() \ #define CHAIN_LEVIN_INVOKE_MAP() \
int invoke(int command, const epee::span<const uint8_t> in_buff, std::string& buff_out, epee::net_utils::connection_context_base& context) \ int invoke(int command, const epee::span<const uint8_t> in_buff, epee::byte_slice& buff_out, epee::net_utils::connection_context_base& context) \
{ \ { \
bool handled = false; \ bool handled = false; \
return handle_invoke_map(false, command, in_buff, buff_out, context, handled); \ return handle_invoke_map(false, command, in_buff, buff_out, context, handled); \
@ -289,7 +292,7 @@ namespace epee
} }
#define BEGIN_INVOKE_MAP2(owner_type) \ #define BEGIN_INVOKE_MAP2(owner_type) \
template <class t_context> int handle_invoke_map(bool is_notify, int command, const epee::span<const uint8_t> in_buff, std::string& buff_out, t_context& context, bool& handled) \ template <class t_context> int handle_invoke_map(bool is_notify, int command, const epee::span<const uint8_t> in_buff, epee::byte_slice& buff_out, t_context& context, bool& handled) \
{ \ { \
try { \ try { \
typedef owner_type internal_owner_type_name; typedef owner_type internal_owner_type_name;

View File

@ -32,7 +32,6 @@
#include "misc_language.h" #include "misc_language.h"
#include "portable_storage_base.h" #include "portable_storage_base.h"
#include "portable_storage_to_bin.h"
#include "portable_storage_from_bin.h" #include "portable_storage_from_bin.h"
#include "portable_storage_to_json.h" #include "portable_storage_to_json.h"
#include "portable_storage_from_json.h" #include "portable_storage_from_json.h"
@ -42,6 +41,7 @@
namespace epee namespace epee
{ {
class byte_slice;
namespace serialization namespace serialization
{ {
/************************************************************************/ /************************************************************************/
@ -83,7 +83,7 @@ namespace epee
bool delete_entry(const std::string& pentry_name, hsection hparent_section = nullptr); bool delete_entry(const std::string& pentry_name, hsection hparent_section = nullptr);
//------------------------------------------------------------------------------- //-------------------------------------------------------------------------------
bool store_to_binary(binarybuffer& target); bool store_to_binary(byte_slice& target, std::size_t initial_buffer_size = 8192);
bool load_from_binary(const epee::span<const uint8_t> target); bool load_from_binary(const epee::span<const uint8_t> target);
bool load_from_binary(const std::string& target) { return load_from_binary(epee::strspan<uint8_t>(target)); } bool load_from_binary(const std::string& target) { return load_from_binary(epee::strspan<uint8_t>(target)); }
template<class trace_policy> template<class trace_policy>
@ -133,22 +133,6 @@ namespace epee
{ {
return false;//TODO: don't think i ever again will use xml - ambiguous and "overtagged" format return false;//TODO: don't think i ever again will use xml - ambiguous and "overtagged" format
} }
inline
bool portable_storage::store_to_binary(binarybuffer& target)
{
TRY_ENTRY();
std::stringstream ss;
storage_block_header sbh = AUTO_VAL_INIT(sbh);
sbh.m_signature_a = SWAP32LE(PORTABLE_STORAGE_SIGNATUREA);
sbh.m_signature_b = SWAP32LE(PORTABLE_STORAGE_SIGNATUREB);
sbh.m_ver = PORTABLE_STORAGE_FORMAT_VER;
ss.write((const char*)&sbh, sizeof(storage_block_header));
pack_entry_to_buff(ss, m_root);
target = ss.str();
return true;
CATCH_ENTRY("portable_storage::store_to_binary", false)
}
inline inline
bool portable_storage::load_from_binary(const epee::span<const uint8_t> source) bool portable_storage::load_from_binary(const epee::span<const uint8_t> source)
{ {

View File

@ -28,6 +28,7 @@
#include <string> #include <string>
#include "byte_slice.h"
#include "parserse_base_utils.h" #include "parserse_base_utils.h"
#include "portable_storage.h" #include "portable_storage.h"
#include "file_io_utils.h" #include "file_io_utils.h"
@ -111,18 +112,18 @@ namespace epee
} }
//----------------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------------
template<class t_struct> template<class t_struct>
bool store_t_to_binary(t_struct& str_in, std::string& binary_buff, size_t indent = 0) bool store_t_to_binary(t_struct& str_in, byte_slice& binary_buff, size_t initial_buffer_size = 8192)
{ {
portable_storage ps; portable_storage ps;
str_in.store(ps); str_in.store(ps);
return ps.store_to_binary(binary_buff); return ps.store_to_binary(binary_buff, initial_buffer_size);
} }
//----------------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------------
template<class t_struct> template<class t_struct>
std::string store_t_to_binary(t_struct& str_in, size_t indent = 0) byte_slice store_t_to_binary(t_struct& str_in, size_t initial_buffer_size = 8192)
{ {
std::string binary_buff; byte_slice binary_buff;
store_t_to_binary(str_in, binary_buff, indent); store_t_to_binary(str_in, binary_buff, initial_buffer_size);
return binary_buff; return binary_buff;
} }
} }

View File

@ -29,7 +29,7 @@
add_library(epee STATIC byte_slice.cpp byte_stream.cpp hex.cpp abstract_http_client.cpp http_auth.cpp mlog.cpp net_helper.cpp net_utils_base.cpp string_tools.cpp add_library(epee STATIC byte_slice.cpp byte_stream.cpp hex.cpp abstract_http_client.cpp http_auth.cpp mlog.cpp net_helper.cpp net_utils_base.cpp string_tools.cpp
wipeable_string.cpp levin_base.cpp memwipe.c connection_basic.cpp network_throttle.cpp network_throttle-detail.cpp mlocker.cpp buffer.cpp net_ssl.cpp wipeable_string.cpp levin_base.cpp memwipe.c connection_basic.cpp network_throttle.cpp network_throttle-detail.cpp mlocker.cpp buffer.cpp net_ssl.cpp
int-util.cpp) int-util.cpp portable_storage.cpp)
if (USE_READLINE AND (GNU_READLINE_FOUND OR (DEPENDS AND NOT MINGW))) if (USE_READLINE AND (GNU_READLINE_FOUND OR (DEPENDS AND NOT MINGW)))
add_library(epee_readline STATIC readline_buffer.cpp) add_library(epee_readline STATIC readline_buffer.cpp)

View File

@ -0,0 +1,29 @@
#include "byte_slice.h"
#include "byte_stream.h"
#include "misc_log_ex.h"
#include "span.h"
#include "storages/portable_storage.h"
#include "storages/portable_storage_to_bin.h"
namespace epee
{
namespace serialization
{
bool portable_storage::store_to_binary(byte_slice& target, const std::size_t initial_buffer_size)
{
TRY_ENTRY();
byte_stream ss;
ss.reserve(initial_buffer_size);
storage_block_header sbh{};
sbh.m_signature_a = SWAP32LE(PORTABLE_STORAGE_SIGNATUREA);
sbh.m_signature_b = SWAP32LE(PORTABLE_STORAGE_SIGNATUREB);
sbh.m_ver = PORTABLE_STORAGE_FORMAT_VER;
ss.write(epee::as_byte_span(sbh));
pack_entry_to_buff(ss, m_root);
target = epee::byte_slice{std::move(ss)};
return true;
CATCH_ENTRY("portable_storage::store_to_binary", false)
}
}
}

View File

@ -37,6 +37,7 @@
#include <boost/program_options/variables_map.hpp> #include <boost/program_options/variables_map.hpp>
#include <string> #include <string>
#include "byte_slice.h"
#include "math_helper.h" #include "math_helper.h"
#include "storages/levin_abstract_invoke2.h" #include "storages/levin_abstract_invoke2.h"
#include "warnings.h" #include "warnings.h"
@ -100,7 +101,7 @@ namespace cryptonote
void set_p2p_endpoint(nodetool::i_p2p_endpoint<connection_context>* p2p); void set_p2p_endpoint(nodetool::i_p2p_endpoint<connection_context>* p2p);
//bool process_handshake_data(const blobdata& data, cryptonote_connection_context& context); //bool process_handshake_data(const blobdata& data, cryptonote_connection_context& context);
bool process_payload_sync_data(const CORE_SYNC_DATA& hshd, cryptonote_connection_context& context, bool is_inital); bool process_payload_sync_data(const CORE_SYNC_DATA& hshd, cryptonote_connection_context& context, bool is_inital);
bool get_payload_sync_data(blobdata& data); bool get_payload_sync_data(epee::byte_slice& data);
bool get_payload_sync_data(CORE_SYNC_DATA& hshd); bool get_payload_sync_data(CORE_SYNC_DATA& hshd);
bool on_callback(cryptonote_connection_context& context); bool on_callback(cryptonote_connection_context& context);
t_core& get_core(){return m_core;} t_core& get_core(){return m_core;}
@ -191,10 +192,10 @@ namespace cryptonote
bool post_notify(typename t_parameter::request& arg, cryptonote_connection_context& context) bool post_notify(typename t_parameter::request& arg, cryptonote_connection_context& context)
{ {
LOG_PRINT_L2("[" << epee::net_utils::print_connection_context_short(context) << "] post " << typeid(t_parameter).name() << " -->"); LOG_PRINT_L2("[" << epee::net_utils::print_connection_context_short(context) << "] post " << typeid(t_parameter).name() << " -->");
std::string blob; epee::byte_slice blob;
epee::serialization::store_t_to_binary(arg, blob); epee::serialization::store_t_to_binary(arg, blob, 256 * 1024); // optimize for block responses
//handler_response_blocks_now(blob.size()); // XXX //handler_response_blocks_now(blob.size()); // XXX
return m_p2p->invoke_notify_to_peer(t_parameter::ID, epee::strspan<uint8_t>(blob), context); return m_p2p->invoke_notify_to_peer(t_parameter::ID, epee::to_span(blob), context);
} }
}; };

View File

@ -425,7 +425,7 @@ namespace cryptonote
} }
//------------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------------
template<class t_core> template<class t_core>
bool t_cryptonote_protocol_handler<t_core>::get_payload_sync_data(blobdata& data) bool t_cryptonote_protocol_handler<t_core>::get_payload_sync_data(epee::byte_slice& data)
{ {
CORE_SYNC_DATA hsd = {}; CORE_SYNC_DATA hsd = {};
get_payload_sync_data(hsd); get_payload_sync_data(hsd);
@ -2585,15 +2585,15 @@ skip:
// send fluffy ones first, we want to encourage people to run that // send fluffy ones first, we want to encourage people to run that
if (!fluffyConnections.empty()) if (!fluffyConnections.empty())
{ {
std::string fluffyBlob; epee::byte_slice fluffyBlob;
epee::serialization::store_t_to_binary(fluffy_arg, fluffyBlob); epee::serialization::store_t_to_binary(fluffy_arg, fluffyBlob, 32 * 1024);
m_p2p->relay_notify_to_list(NOTIFY_NEW_FLUFFY_BLOCK::ID, epee::strspan<uint8_t>(fluffyBlob), std::move(fluffyConnections)); m_p2p->relay_notify_to_list(NOTIFY_NEW_FLUFFY_BLOCK::ID, epee::to_span(fluffyBlob), std::move(fluffyConnections));
} }
if (!fullConnections.empty()) if (!fullConnections.empty())
{ {
std::string fullBlob; epee::byte_slice fullBlob;
epee::serialization::store_t_to_binary(arg, fullBlob); epee::serialization::store_t_to_binary(arg, fullBlob, 128 * 1024);
m_p2p->relay_notify_to_list(NOTIFY_NEW_BLOCK::ID, epee::strspan<uint8_t>(fullBlob), std::move(fullConnections)); m_p2p->relay_notify_to_list(NOTIFY_NEW_BLOCK::ID, epee::to_span(fullBlob), std::move(fullConnections));
} }
return true; return true;

View File

@ -36,6 +36,7 @@
#include <stdexcept> #include <stdexcept>
#include <utility> #include <utility>
#include "byte_slice.h"
#include "common/expect.h" #include "common/expect.h"
#include "common/varint.h" #include "common/varint.h"
#include "cryptonote_config.h" #include "cryptonote_config.h"
@ -52,7 +53,7 @@
namespace namespace
{ {
int get_command_from_message(const cryptonote::blobdata &msg) int get_command_from_message(const epee::byte_slice &msg)
{ {
return msg.size() >= sizeof(epee::levin::bucket_head2) ? SWAP32LE(((epee::levin::bucket_head2*)msg.data())->m_command) : 0; return msg.size() >= sizeof(epee::levin::bucket_head2) ? SWAP32LE(((epee::levin::bucket_head2*)msg.data())->m_command) : 0;
} }
@ -166,7 +167,7 @@ namespace levin
return get_out_connections(p2p, get_blockchain_height(p2p, core)); return get_out_connections(p2p, get_blockchain_height(p2p, core));
} }
std::string make_tx_payload(std::vector<blobdata>&& txs, const bool pad, const bool fluff) epee::byte_slice make_tx_payload(std::vector<blobdata>&& txs, const bool pad, const bool fluff)
{ {
NOTIFY_NEW_TRANSACTIONS::request request{}; NOTIFY_NEW_TRANSACTIONS::request request{};
request.txs = std::move(txs); request.txs = std::move(txs);
@ -188,7 +189,7 @@ namespace levin
padding -= overhead; padding -= overhead;
request._ = std::string(padding, ' '); request._ = std::string(padding, ' ');
std::string arg_buff; epee::byte_slice arg_buff;
epee::serialization::store_t_to_binary(request, arg_buff); epee::serialization::store_t_to_binary(request, arg_buff);
// we probably lowballed the payload size a bit, so added a but too much. Fix this now. // we probably lowballed the payload size a bit, so added a but too much. Fix this now.
@ -200,7 +201,7 @@ namespace levin
// if the size of _ moved enough, we might lose byte in size encoding, we don't care // if the size of _ moved enough, we might lose byte in size encoding, we don't care
} }
std::string fullBlob; epee::byte_slice fullBlob;
if (!epee::serialization::store_t_to_binary(request, fullBlob)) if (!epee::serialization::store_t_to_binary(request, fullBlob))
throw std::runtime_error{"Failed to serialize to epee binary format"}; throw std::runtime_error{"Failed to serialize to epee binary format"};
@ -209,12 +210,12 @@ namespace levin
bool make_payload_send_txs(connections& p2p, std::vector<blobdata>&& txs, const boost::uuids::uuid& destination, const bool pad, const bool fluff) bool make_payload_send_txs(connections& p2p, std::vector<blobdata>&& txs, const boost::uuids::uuid& destination, const bool pad, const bool fluff)
{ {
const cryptonote::blobdata blob = make_tx_payload(std::move(txs), pad, fluff); const epee::byte_slice blob = make_tx_payload(std::move(txs), pad, fluff);
p2p.for_connection(destination, [&blob](detail::p2p_context& context) { p2p.for_connection(destination, [&blob](detail::p2p_context& context) {
on_levin_traffic(context, true, true, false, blob.size(), get_command_from_message(blob)); on_levin_traffic(context, true, true, false, blob.size(), get_command_from_message(blob));
return true; return true;
}); });
return p2p.notify(NOTIFY_NEW_TRANSACTIONS::ID, epee::strspan<std::uint8_t>(blob), destination); return p2p.notify(NOTIFY_NEW_TRANSACTIONS::ID, epee::to_span(blob), destination);
} }
/* The current design uses `asio::strand`s. The documentation isn't as clear /* The current design uses `asio::strand`s. The documentation isn't as clear
@ -825,9 +826,9 @@ namespace levin
// Padding is not useful when using noise mode. Send as stem so receiver // Padding is not useful when using noise mode. Send as stem so receiver
// forwards in Dandelion++ mode. // forwards in Dandelion++ mode.
const std::string payload = make_tx_payload(std::move(txs), false, false); const epee::byte_slice payload = make_tx_payload(std::move(txs), false, false);
epee::byte_slice message = epee::levin::make_fragmented_notify( epee::byte_slice message = epee::levin::make_fragmented_notify(
zone_->noise, NOTIFY_NEW_TRANSACTIONS::ID, epee::strspan<std::uint8_t>(payload) zone_->noise, NOTIFY_NEW_TRANSACTIONS::ID, epee::to_span(payload)
); );
if (CRYPTONOTE_MAX_FRAGMENTS * zone_->noise.size() < message.size()) if (CRYPTONOTE_MAX_FRAGMENTS * zone_->noise.size() < message.size())
{ {

View File

@ -3788,7 +3788,7 @@ bool wallet2::store_keys(const std::string& keys_file_name, const epee::wipeable
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
boost::optional<wallet2::keys_file_data> wallet2::get_keys_file_data(const epee::wipeable_string& password, bool watch_only) boost::optional<wallet2::keys_file_data> wallet2::get_keys_file_data(const epee::wipeable_string& password, bool watch_only)
{ {
std::string account_data; epee::byte_slice account_data;
std::string multisig_signers; std::string multisig_signers;
std::string multisig_derivations; std::string multisig_derivations;
cryptonote::account_base account = m_account; cryptonote::account_base account = m_account;
@ -3815,7 +3815,7 @@ boost::optional<wallet2::keys_file_data> wallet2::get_keys_file_data(const epee:
rapidjson::Document json; rapidjson::Document json;
json.SetObject(); json.SetObject();
rapidjson::Value value(rapidjson::kStringType); rapidjson::Value value(rapidjson::kStringType);
value.SetString(account_data.c_str(), account_data.length()); value.SetString(reinterpret_cast<const char*>(account_data.data()), account_data.size());
json.AddMember("key_data", value, json.GetAllocator()); json.AddMember("key_data", value, json.GetAllocator());
if (!seed_language.empty()) if (!seed_language.empty())
{ {
@ -3989,13 +3989,12 @@ boost::optional<wallet2::keys_file_data> wallet2::get_keys_file_data(const epee:
rapidjson::StringBuffer buffer; rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
json.Accept(writer); json.Accept(writer);
account_data = buffer.GetString();
// Encrypt the entire JSON object. // Encrypt the entire JSON object.
std::string cipher; std::string cipher;
cipher.resize(account_data.size()); cipher.resize(buffer.GetSize());
keys_file_data.get().iv = crypto::rand<crypto::chacha_iv>(); keys_file_data.get().iv = crypto::rand<crypto::chacha_iv>();
crypto::chacha20(account_data.data(), account_data.size(), key, keys_file_data.get().iv, &cipher[0]); crypto::chacha20(buffer.GetString(), buffer.GetSize(), key, keys_file_data.get().iv, &cipher[0]);
keys_file_data.get().account_data = cipher; keys_file_data.get().account_data = cipher;
return keys_file_data; return keys_file_data;
} }

View File

@ -26,6 +26,7 @@
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <boost/utility/string_ref.hpp>
#include "include_base_utils.h" #include "include_base_utils.h"
#include "file_io_utils.h" #include "file_io_utils.h"
#include "net/http_client.h" #include "net/http_client.h"
@ -38,7 +39,7 @@ public:
bool connect(const std::string& addr, int port, std::chrono::milliseconds timeout, bool ssl = false, const std::string& bind_ip = "0.0.0.0") { return true; } bool connect(const std::string& addr, int port, std::chrono::milliseconds timeout, bool ssl = false, const std::string& bind_ip = "0.0.0.0") { return true; }
bool connect(const std::string& addr, const std::string& port, std::chrono::milliseconds timeout, bool ssl = false, const std::string& bind_ip = "0.0.0.0") { return true; } bool connect(const std::string& addr, const std::string& port, std::chrono::milliseconds timeout, bool ssl = false, const std::string& bind_ip = "0.0.0.0") { return true; }
bool disconnect() { return true; } bool disconnect() { return true; }
bool send(const std::string& buff, std::chrono::milliseconds timeout) { return true; } bool send(const boost::string_ref buff, std::chrono::milliseconds timeout) { return true; }
bool send(const void* data, size_t sz) { return true; } bool send(const void* data, size_t sz) { return true; }
bool is_connected() { return true; } bool is_connected() { return true; }
bool recv(std::string& buff, std::chrono::milliseconds timeout) bool recv(std::string& buff, std::chrono::milliseconds timeout)

View File

@ -65,13 +65,13 @@ namespace
{ {
} }
virtual int invoke(int command, const epee::span<const uint8_t> in_buff, std::string& buff_out, test_levin_connection_context& context) virtual int invoke(int command, const epee::span<const uint8_t> in_buff, epee::byte_slice& buff_out, test_levin_connection_context& context)
{ {
m_invoke_counter.inc(); m_invoke_counter.inc();
boost::unique_lock<boost::mutex> lock(m_mutex); boost::unique_lock<boost::mutex> lock(m_mutex);
m_last_command = command; m_last_command = command;
m_last_in_buf = std::string((const char*)in_buff.data(), in_buff.size()); m_last_in_buf = std::string((const char*)in_buff.data(), in_buff.size());
buff_out = m_invoke_out_buf; buff_out = m_invoke_out_buf.clone();
return m_return_code; return m_return_code;
} }
@ -111,8 +111,7 @@ namespace
int return_code() const { return m_return_code; } int return_code() const { return m_return_code; }
void return_code(int v) { m_return_code = v; } void return_code(int v) { m_return_code = v; }
const std::string& invoke_out_buf() const { return m_invoke_out_buf; } void invoke_out_buf(std::string v) { m_invoke_out_buf = epee::byte_slice{std::move(v)}; }
void invoke_out_buf(const std::string& v) { m_invoke_out_buf = v; }
int last_command() const { return m_last_command; } int last_command() const { return m_last_command; }
const std::string& last_in_buf() const { return m_last_in_buf; } const std::string& last_in_buf() const { return m_last_in_buf; }
@ -127,7 +126,7 @@ namespace
boost::mutex m_mutex; boost::mutex m_mutex;
int m_return_code; int m_return_code;
std::string m_invoke_out_buf; epee::byte_slice m_invoke_out_buf;
int m_last_command; int m_last_command;
std::string m_last_in_buf; std::string m_last_in_buf;

View File

@ -64,7 +64,7 @@ namespace net_load_tests
{ {
} }
virtual int invoke(int command, const epee::span<const uint8_t> in_buff, std::string& buff_out, test_connection_context& context) virtual int invoke(int command, const epee::span<const uint8_t> in_buff, epee::byte_slice& buff_out, test_connection_context& context)
{ {
//m_invoke_counter.inc(); //m_invoke_counter.inc();
//std::unique_lock<std::mutex> lock(m_mutex); //std::unique_lock<std::mutex> lock(m_mutex);

View File

@ -56,13 +56,13 @@ namespace
{ {
} }
virtual int invoke(int command, const epee::span<const uint8_t> in_buff, std::string& buff_out, test_levin_connection_context& context) virtual int invoke(int command, const epee::span<const uint8_t> in_buff, epee::byte_slice& buff_out, test_levin_connection_context& context)
{ {
m_invoke_counter.inc(); m_invoke_counter.inc();
boost::unique_lock<boost::mutex> lock(m_mutex); boost::unique_lock<boost::mutex> lock(m_mutex);
m_last_command = command; m_last_command = command;
m_last_in_buf = std::string((const char*)in_buff.data(), in_buff.size()); m_last_in_buf = std::string((const char*)in_buff.data(), in_buff.size());
buff_out = m_invoke_out_buf; buff_out = m_invoke_out_buf.clone();
return m_return_code; return m_return_code;
} }
@ -102,8 +102,7 @@ namespace
int return_code() const { return m_return_code; } int return_code() const { return m_return_code; }
void return_code(int v) { m_return_code = v; } void return_code(int v) { m_return_code = v; }
const std::string& invoke_out_buf() const { return m_invoke_out_buf; } void invoke_out_buf(std::string v) { m_invoke_out_buf = epee::byte_slice{std::move(v)}; }
void invoke_out_buf(const std::string& v) { m_invoke_out_buf = v; }
int last_command() const { return m_last_command; } int last_command() const { return m_last_command; }
const std::string& last_in_buf() const { return m_last_in_buf; } const std::string& last_in_buf() const { return m_last_in_buf; }
@ -118,7 +117,7 @@ namespace
boost::mutex m_mutex; boost::mutex m_mutex;
int m_return_code; int m_return_code;
std::string m_invoke_out_buf; epee::byte_slice m_invoke_out_buf;
int m_last_command; int m_last_command;
std::string m_last_in_buf; std::string m_last_in_buf;

View File

@ -238,9 +238,9 @@ namespace
return {connection, std::move(request)}; return {connection, std::move(request)};
} }
virtual int invoke(int command, const epee::span<const uint8_t> in_buff, std::string& buff_out, cryptonote::levin::detail::p2p_context& context) override final virtual int invoke(int command, const epee::span<const uint8_t> in_buff, epee::byte_slice& buff_out, cryptonote::levin::detail::p2p_context& context) override final
{ {
buff_out.clear(); buff_out = nullptr;
invoked_.push_back( invoked_.push_back(
{context.m_connection_id, command, std::string{reinterpret_cast<const char*>(in_buff.data()), in_buff.size()}} {context.m_connection_id, command, std::string{reinterpret_cast<const char*>(in_buff.data()), in_buff.size()}}
); );

View File

@ -245,7 +245,7 @@ namespace
TEST(tor_address, epee_serializev_v2) TEST(tor_address, epee_serializev_v2)
{ {
std::string buffer{}; epee::byte_slice buffer{};
{ {
test_command_tor command{MONERO_UNWRAP(net::tor_address::make(v2_onion, 10))}; test_command_tor command{MONERO_UNWRAP(net::tor_address::make(v2_onion, 10))};
EXPECT_FALSE(command.tor.is_unknown()); EXPECT_FALSE(command.tor.is_unknown());
@ -266,7 +266,7 @@ TEST(tor_address, epee_serializev_v2)
EXPECT_EQ(0u, command.tor.port()); EXPECT_EQ(0u, command.tor.port());
epee::serialization::portable_storage stg{}; epee::serialization::portable_storage stg{};
EXPECT_TRUE(stg.load_from_binary(buffer)); EXPECT_TRUE(stg.load_from_binary(epee::to_span(buffer)));
EXPECT_TRUE(command.load(stg)); EXPECT_TRUE(command.load(stg));
} }
EXPECT_FALSE(command.tor.is_unknown()); EXPECT_FALSE(command.tor.is_unknown());
@ -277,7 +277,7 @@ TEST(tor_address, epee_serializev_v2)
// make sure that exceeding max buffer doesn't destroy tor_address::_load // make sure that exceeding max buffer doesn't destroy tor_address::_load
{ {
epee::serialization::portable_storage stg{}; epee::serialization::portable_storage stg{};
stg.load_from_binary(buffer); stg.load_from_binary(epee::to_span(buffer));
std::string host{}; std::string host{};
ASSERT_TRUE(stg.get_value("host", host, stg.open_section("tor", nullptr, false))); ASSERT_TRUE(stg.get_value("host", host, stg.open_section("tor", nullptr, false)));
@ -296,7 +296,7 @@ TEST(tor_address, epee_serializev_v2)
TEST(tor_address, epee_serializev_v3) TEST(tor_address, epee_serializev_v3)
{ {
std::string buffer{}; epee::byte_slice buffer{};
{ {
test_command_tor command{MONERO_UNWRAP(net::tor_address::make(v3_onion, 10))}; test_command_tor command{MONERO_UNWRAP(net::tor_address::make(v3_onion, 10))};
EXPECT_FALSE(command.tor.is_unknown()); EXPECT_FALSE(command.tor.is_unknown());
@ -317,7 +317,7 @@ TEST(tor_address, epee_serializev_v3)
EXPECT_EQ(0u, command.tor.port()); EXPECT_EQ(0u, command.tor.port());
epee::serialization::portable_storage stg{}; epee::serialization::portable_storage stg{};
EXPECT_TRUE(stg.load_from_binary(buffer)); EXPECT_TRUE(stg.load_from_binary(epee::to_span(buffer)));
EXPECT_TRUE(command.load(stg)); EXPECT_TRUE(command.load(stg));
} }
EXPECT_FALSE(command.tor.is_unknown()); EXPECT_FALSE(command.tor.is_unknown());
@ -328,7 +328,7 @@ TEST(tor_address, epee_serializev_v3)
// make sure that exceeding max buffer doesn't destroy tor_address::_load // make sure that exceeding max buffer doesn't destroy tor_address::_load
{ {
epee::serialization::portable_storage stg{}; epee::serialization::portable_storage stg{};
stg.load_from_binary(buffer); stg.load_from_binary(epee::to_span(buffer));
std::string host{}; std::string host{};
ASSERT_TRUE(stg.get_value("host", host, stg.open_section("tor", nullptr, false))); ASSERT_TRUE(stg.get_value("host", host, stg.open_section("tor", nullptr, false)));
@ -347,7 +347,7 @@ TEST(tor_address, epee_serializev_v3)
TEST(tor_address, epee_serialize_unknown) TEST(tor_address, epee_serialize_unknown)
{ {
std::string buffer{}; epee::byte_slice buffer{};
{ {
test_command_tor command{net::tor_address::unknown()}; test_command_tor command{net::tor_address::unknown()};
EXPECT_TRUE(command.tor.is_unknown()); EXPECT_TRUE(command.tor.is_unknown());
@ -368,7 +368,7 @@ TEST(tor_address, epee_serialize_unknown)
EXPECT_EQ(0u, command.tor.port()); EXPECT_EQ(0u, command.tor.port());
epee::serialization::portable_storage stg{}; epee::serialization::portable_storage stg{};
EXPECT_TRUE(stg.load_from_binary(buffer)); EXPECT_TRUE(stg.load_from_binary(epee::to_span(buffer)));
EXPECT_TRUE(command.load(stg)); EXPECT_TRUE(command.load(stg));
} }
EXPECT_TRUE(command.tor.is_unknown()); EXPECT_TRUE(command.tor.is_unknown());
@ -379,7 +379,7 @@ TEST(tor_address, epee_serialize_unknown)
// make sure that exceeding max buffer doesn't destroy tor_address::_load // make sure that exceeding max buffer doesn't destroy tor_address::_load
{ {
epee::serialization::portable_storage stg{}; epee::serialization::portable_storage stg{};
stg.load_from_binary(buffer); stg.load_from_binary(epee::to_span(buffer));
std::string host{}; std::string host{};
ASSERT_TRUE(stg.get_value("host", host, stg.open_section("tor", nullptr, false))); ASSERT_TRUE(stg.get_value("host", host, stg.open_section("tor", nullptr, false)));
@ -700,7 +700,7 @@ namespace
TEST(i2p_address, epee_serializev_b32) TEST(i2p_address, epee_serializev_b32)
{ {
std::string buffer{}; epee::byte_slice buffer{};
{ {
test_command_i2p command{MONERO_UNWRAP(net::i2p_address::make(b32_i2p, 10))}; test_command_i2p command{MONERO_UNWRAP(net::i2p_address::make(b32_i2p, 10))};
EXPECT_FALSE(command.i2p.is_unknown()); EXPECT_FALSE(command.i2p.is_unknown());
@ -721,7 +721,7 @@ TEST(i2p_address, epee_serializev_b32)
EXPECT_EQ(0u, command.i2p.port()); EXPECT_EQ(0u, command.i2p.port());
epee::serialization::portable_storage stg{}; epee::serialization::portable_storage stg{};
EXPECT_TRUE(stg.load_from_binary(buffer)); EXPECT_TRUE(stg.load_from_binary(epee::to_span(buffer)));
EXPECT_TRUE(command.load(stg)); EXPECT_TRUE(command.load(stg));
} }
EXPECT_FALSE(command.i2p.is_unknown()); EXPECT_FALSE(command.i2p.is_unknown());
@ -732,7 +732,7 @@ TEST(i2p_address, epee_serializev_b32)
// make sure that exceeding max buffer doesn't destroy i2p_address::_load // make sure that exceeding max buffer doesn't destroy i2p_address::_load
{ {
epee::serialization::portable_storage stg{}; epee::serialization::portable_storage stg{};
stg.load_from_binary(buffer); stg.load_from_binary(epee::to_span(buffer));
std::string host{}; std::string host{};
ASSERT_TRUE(stg.get_value("host", host, stg.open_section("i2p", nullptr, false))); ASSERT_TRUE(stg.get_value("host", host, stg.open_section("i2p", nullptr, false)));
@ -751,7 +751,7 @@ TEST(i2p_address, epee_serializev_b32)
TEST(i2p_address, epee_serialize_unknown) TEST(i2p_address, epee_serialize_unknown)
{ {
std::string buffer{}; epee::byte_slice buffer{};
{ {
test_command_i2p command{net::i2p_address::unknown()}; test_command_i2p command{net::i2p_address::unknown()};
EXPECT_TRUE(command.i2p.is_unknown()); EXPECT_TRUE(command.i2p.is_unknown());
@ -772,7 +772,7 @@ TEST(i2p_address, epee_serialize_unknown)
EXPECT_EQ(0u, command.i2p.port()); EXPECT_EQ(0u, command.i2p.port());
epee::serialization::portable_storage stg{}; epee::serialization::portable_storage stg{};
EXPECT_TRUE(stg.load_from_binary(buffer)); EXPECT_TRUE(stg.load_from_binary(epee::to_span(buffer)));
EXPECT_TRUE(command.load(stg)); EXPECT_TRUE(command.load(stg));
} }
EXPECT_TRUE(command.i2p.is_unknown()); EXPECT_TRUE(command.i2p.is_unknown());
@ -783,7 +783,7 @@ TEST(i2p_address, epee_serialize_unknown)
// make sure that exceeding max buffer doesn't destroy i2p_address::_load // make sure that exceeding max buffer doesn't destroy i2p_address::_load
{ {
epee::serialization::portable_storage stg{}; epee::serialization::portable_storage stg{};
stg.load_from_binary(buffer); stg.load_from_binary(epee::to_span(buffer));
std::string host{}; std::string host{};
ASSERT_TRUE(stg.get_value("host", host, stg.open_section("i2p", nullptr, false))); ASSERT_TRUE(stg.get_value("host", host, stg.open_section("i2p", nullptr, false)));

View File

@ -36,7 +36,7 @@
TEST(protocol_pack, protocol_pack_command) TEST(protocol_pack, protocol_pack_command)
{ {
std::string buff; epee::byte_slice buff;
cryptonote::NOTIFY_RESPONSE_CHAIN_ENTRY::request r; cryptonote::NOTIFY_RESPONSE_CHAIN_ENTRY::request r;
r.start_height = 1; r.start_height = 1;
r.total_height = 3; r.total_height = 3;
@ -47,7 +47,7 @@ TEST(protocol_pack, protocol_pack_command)
ASSERT_TRUE(res); ASSERT_TRUE(res);
cryptonote::NOTIFY_RESPONSE_CHAIN_ENTRY::request r2; cryptonote::NOTIFY_RESPONSE_CHAIN_ENTRY::request r2;
res = epee::serialization::load_t_from_binary(r2, buff); res = epee::serialization::load_t_from_binary(r2, epee::to_span(buff));
ASSERT_TRUE(res); ASSERT_TRUE(res);
ASSERT_TRUE(r.m_block_ids.size() == i); ASSERT_TRUE(r.m_block_ids.size() == i);
ASSERT_TRUE(r.start_height == 1); ASSERT_TRUE(r.start_height == 1);