From e45619e61e4831eea70a43fe6985f4d57ea02e9e Mon Sep 17 00:00:00 2001 From: luigi1111 Date: Fri, 16 Apr 2021 13:52:44 -0500 Subject: Revert "Merge pull request #7136" This reverts commit 63c7ca07fba2f063c760f786a986fb3e02fb040e, reversing changes made to 2218e23e84a89e9a1e4c0be5d50f891ab836754f. --- .../epee/include/storages/levin_abstract_invoke2.h | 55 +++++++++++++--------- contrib/epee/include/storages/portable_storage.h | 10 +--- .../storages/portable_storage_template_helper.h | 11 ----- 3 files changed, 35 insertions(+), 41 deletions(-) (limited to 'contrib/epee/include/storages') diff --git a/contrib/epee/include/storages/levin_abstract_invoke2.h b/contrib/epee/include/storages/levin_abstract_invoke2.h index 383d67cc2..802e16c1b 100644 --- a/contrib/epee/include/storages/levin_abstract_invoke2.h +++ b/contrib/epee/include/storages/levin_abstract_invoke2.h @@ -37,14 +37,21 @@ #undef MONERO_DEFAULT_LOG_CATEGORY #define MONERO_DEFAULT_LOG_CATEGORY "net" -template -void on_levin_traffic(const context_t &context, bool initiator, bool sent, bool error, size_t bytes, const char *category); - -template -void on_levin_traffic(const context_t &context, bool initiator, bool sent, bool error, size_t bytes, int command); - namespace { + template + void on_levin_traffic(const context_t &context, bool initiator, bool sent, bool error, size_t bytes, const char *category) + { + MCINFO("net.p2p.traffic", context << bytes << " bytes " << (sent ? "sent" : "received") << (error ? "/corrupt" : "") + << " for category " << category << " initiated by " << (initiator ? "us" : "peer")); + } + template + void on_levin_traffic(const context_t &context, bool initiator, bool sent, bool error, size_t bytes, int command) + { + char buf[32]; + snprintf(buf, sizeof(buf), "command-%u", command); + return on_levin_traffic(context, initiator, sent, error, bytes, buf); + } static const constexpr epee::serialization::portable_storage::limits_t default_levin_limits = { 8192, // objects 16384, // fields @@ -110,11 +117,12 @@ namespace epee const boost::uuids::uuid &conn_id = context.m_connection_id; typename serialization::portable_storage stg; out_struct.store(stg); - levin::message_writer to_send{16 * 1024}; + byte_slice buff_to_send; std::string buff_to_recv; - stg.store_to_binary(to_send.buffer); + stg.store_to_binary(buff_to_send, 16 * 1024); - int res = transport.invoke(command, std::move(to_send), buff_to_recv, conn_id); + on_levin_traffic(context, true, true, false, buff_to_send.size(), command); + int res = transport.invoke(command, boost::string_ref{reinterpret_cast(buff_to_send.data()), buff_to_send.size()}, buff_to_recv, conn_id); if( res <=0 ) { LOG_PRINT_L1("Failed to invoke command " << command << " return code " << res); @@ -137,9 +145,10 @@ namespace epee const boost::uuids::uuid &conn_id = context.m_connection_id; typename serialization::portable_storage stg; const_cast(out_struct).store(stg);//TODO: add true const support to searilzation - levin::message_writer to_send{16 * 1024}; - stg.store_to_binary(to_send.buffer); - int res = transport.invoke_async(command, std::move(to_send), conn_id, [cb, command](int code, const epee::span buff, typename t_transport::connection_context& context)->bool + byte_slice buff_to_send; + stg.store_to_binary(buff_to_send, 16 * 1024); + on_levin_traffic(context, true, true, false, buff_to_send.size(), command); + int res = transport.invoke_async(command, epee::to_span(buff_to_send), conn_id, [cb, command](int code, const epee::span buff, typename t_transport::connection_context& context)->bool { t_result result_struct = AUTO_VAL_INIT(result_struct); if( code <=0 ) @@ -183,10 +192,11 @@ namespace epee const boost::uuids::uuid &conn_id = context.m_connection_id; serialization::portable_storage stg; out_struct.store(stg); - levin::message_writer to_send; - stg.store_to_binary(to_send.buffer); + byte_slice buff_to_send; + stg.store_to_binary(buff_to_send); - int res = transport.send(to_send.finalize_notify(command), conn_id); + on_levin_traffic(context, true, true, false, buff_to_send.size(), command); + int res = transport.notify(command, epee::to_span(buff_to_send), conn_id); if(res <=0 ) { MERROR("Failed to notify command " << command << " return code " << res); @@ -197,7 +207,7 @@ namespace epee //---------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------- template - int buff_to_t_adapter(int command, const epee::span in_buff, byte_stream& buff_out, callback_t cb, t_context& context ) + int buff_to_t_adapter(int command, const epee::span in_buff, byte_slice& buff_out, callback_t cb, t_context& context ) { serialization::portable_storage strg; if(!strg.load_from_binary(in_buff, &default_levin_limits)) @@ -220,11 +230,12 @@ namespace epee serialization::portable_storage strg_out; static_cast(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); return -1; } + on_levin_traffic(context, false, true, false, buff_out.size(), command); return res; } @@ -251,7 +262,7 @@ namespace epee } #define CHAIN_LEVIN_INVOKE_MAP2(context_type) \ - int invoke(int command, const epee::span in_buff, epee::byte_stream& buff_out, context_type& context) \ + int invoke(int command, const epee::span in_buff, epee::byte_slice& buff_out, context_type& context) \ { \ bool handled = false; \ return handle_invoke_map(false, command, in_buff, buff_out, context, handled); \ @@ -260,13 +271,13 @@ namespace epee #define CHAIN_LEVIN_NOTIFY_MAP2(context_type) \ int notify(int command, const epee::span in_buff, context_type& context) \ { \ - bool handled = false; epee::byte_stream fake_str; \ - return handle_invoke_map(true, command, in_buff, fake_str, context, handled); \ + bool handled = false; epee::byte_slice fake_str; \ + return handle_invoke_map(true, command, in_buff, fake_str, context, handled); \ } #define CHAIN_LEVIN_INVOKE_MAP() \ - int invoke(int command, const epee::span in_buff, epee::byte_stream& buff_out, epee::net_utils::connection_context_base& context) \ + int invoke(int command, const epee::span in_buff, epee::byte_slice& buff_out, epee::net_utils::connection_context_base& context) \ { \ bool handled = false; \ return handle_invoke_map(false, command, in_buff, buff_out, context, handled); \ @@ -286,7 +297,7 @@ namespace epee } #define BEGIN_INVOKE_MAP2(owner_type) \ - template int handle_invoke_map(bool is_notify, int command, const epee::span in_buff, epee::byte_stream& buff_out, t_context& context, bool& handled) \ + template int handle_invoke_map(bool is_notify, int command, const epee::span in_buff, epee::byte_slice& buff_out, t_context& context, bool& handled) \ { \ try { \ typedef owner_type internal_owner_type_name; diff --git a/contrib/epee/include/storages/portable_storage.h b/contrib/epee/include/storages/portable_storage.h index 655a2eb12..c5d0c48ee 100644 --- a/contrib/epee/include/storages/portable_storage.h +++ b/contrib/epee/include/storages/portable_storage.h @@ -34,7 +34,6 @@ namespace epee { class byte_slice; - class byte_stream; namespace serialization { /************************************************************************/ @@ -84,13 +83,8 @@ namespace epee //------------------------------------------------------------------------------- bool store_to_binary(byte_slice& target, std::size_t initial_buffer_size = 8192); - bool store_to_binary(byte_stream& ss); - bool load_from_binary(const epee::span target, const limits_t *limits = nullptr); - bool load_from_binary(const std::string& target, const limits_t *limits = nullptr) - { - return load_from_binary(epee::strspan(target), limits); - } - + bool load_from_binary(const epee::span target, const limits_t *limits = NULL); + bool load_from_binary(const std::string& target, const limits_t *limits = NULL); template bool dump_as_xml(std::string& targetObj, const std::string& root_name = ""); bool dump_as_json(std::string& targetObj, size_t indent = 0, bool insert_newlines = true); diff --git a/contrib/epee/include/storages/portable_storage_template_helper.h b/contrib/epee/include/storages/portable_storage_template_helper.h index 7f6596f36..00ad15e9d 100644 --- a/contrib/epee/include/storages/portable_storage_template_helper.h +++ b/contrib/epee/include/storages/portable_storage_template_helper.h @@ -36,8 +36,6 @@ namespace epee { - class byte_stream; - namespace serialization { //----------------------------------------------------------------------------------------------------------- @@ -129,14 +127,5 @@ namespace epee store_t_to_binary(str_in, binary_buff, initial_buffer_size); return binary_buff; } - //----------------------------------------------------------------------------------------------------------- - template - bool store_t_to_binary(t_struct& str_in, byte_stream& binary_buff) - { - portable_storage ps; - str_in.store(ps); - return ps.store_to_binary(binary_buff); - } - } } -- cgit v1.2.3