diff options
author | Alexander Blair <snipa@jagtech.io> | 2020-12-10 17:34:50 -0800 |
---|---|---|
committer | Alexander Blair <snipa@jagtech.io> | 2020-12-10 17:34:50 -0800 |
commit | 1e9483a2d585d4ce4c2bf001862132ca46185c16 (patch) | |
tree | b9a58d5cd7de6b8ed5da9df1c869449f0623611b /src | |
parent | Merge pull request #7003 (diff) | |
parent | Change epee binary output from std::stringstream to byte_stream (diff) | |
download | monero-1e9483a2d585d4ce4c2bf001862132ca46185c16.tar.xz |
Merge pull request #7009
7414e2bac Change epee binary output from std::stringstream to byte_stream (Lee Clagett)
Diffstat (limited to 'src')
-rw-r--r-- | src/cryptonote_protocol/cryptonote_protocol_handler.h | 9 | ||||
-rw-r--r-- | src/cryptonote_protocol/cryptonote_protocol_handler.inl | 14 | ||||
-rw-r--r-- | src/cryptonote_protocol/levin_notify.cpp | 17 | ||||
-rw-r--r-- | src/wallet/wallet2.cpp | 9 |
4 files changed, 25 insertions, 24 deletions
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.h b/src/cryptonote_protocol/cryptonote_protocol_handler.h index ee3a67198..7093f7826 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.h +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.h @@ -37,6 +37,7 @@ #include <boost/program_options/variables_map.hpp> #include <string> +#include "byte_slice.h" #include "math_helper.h" #include "storages/levin_abstract_invoke2.h" #include "warnings.h" @@ -100,7 +101,7 @@ namespace cryptonote void set_p2p_endpoint(nodetool::i_p2p_endpoint<connection_context>* p2p); //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 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 on_callback(cryptonote_connection_context& context); 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) { LOG_PRINT_L2("[" << epee::net_utils::print_connection_context_short(context) << "] post " << typeid(t_parameter).name() << " -->"); - std::string blob; - epee::serialization::store_t_to_binary(arg, blob); + epee::byte_slice blob; + epee::serialization::store_t_to_binary(arg, blob, 256 * 1024); // optimize for block responses //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); } }; diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index c62a0cd31..f25f9e134 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -425,7 +425,7 @@ namespace cryptonote } //------------------------------------------------------------------------------------------------------------------------ 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 = {}; get_payload_sync_data(hsd); @@ -2585,15 +2585,15 @@ skip: // send fluffy ones first, we want to encourage people to run that if (!fluffyConnections.empty()) { - std::string fluffyBlob; - epee::serialization::store_t_to_binary(fluffy_arg, fluffyBlob); - m_p2p->relay_notify_to_list(NOTIFY_NEW_FLUFFY_BLOCK::ID, epee::strspan<uint8_t>(fluffyBlob), std::move(fluffyConnections)); + epee::byte_slice fluffyBlob; + epee::serialization::store_t_to_binary(fluffy_arg, fluffyBlob, 32 * 1024); + m_p2p->relay_notify_to_list(NOTIFY_NEW_FLUFFY_BLOCK::ID, epee::to_span(fluffyBlob), std::move(fluffyConnections)); } if (!fullConnections.empty()) { - std::string fullBlob; - epee::serialization::store_t_to_binary(arg, fullBlob); - m_p2p->relay_notify_to_list(NOTIFY_NEW_BLOCK::ID, epee::strspan<uint8_t>(fullBlob), std::move(fullConnections)); + epee::byte_slice fullBlob; + epee::serialization::store_t_to_binary(arg, fullBlob, 128 * 1024); + m_p2p->relay_notify_to_list(NOTIFY_NEW_BLOCK::ID, epee::to_span(fullBlob), std::move(fullConnections)); } return true; diff --git a/src/cryptonote_protocol/levin_notify.cpp b/src/cryptonote_protocol/levin_notify.cpp index 2d04dffb6..318bcf4e1 100644 --- a/src/cryptonote_protocol/levin_notify.cpp +++ b/src/cryptonote_protocol/levin_notify.cpp @@ -36,6 +36,7 @@ #include <stdexcept> #include <utility> +#include "byte_slice.h" #include "common/expect.h" #include "common/varint.h" #include "cryptonote_config.h" @@ -52,7 +53,7 @@ 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; } @@ -166,7 +167,7 @@ namespace levin 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{}; request.txs = std::move(txs); @@ -188,7 +189,7 @@ namespace levin padding -= overhead; request._ = std::string(padding, ' '); - std::string arg_buff; + epee::byte_slice 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. @@ -200,7 +201,7 @@ namespace levin // 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)) 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) { - 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) { on_levin_traffic(context, true, true, false, blob.size(), get_command_from_message(blob)); 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 @@ -825,9 +826,9 @@ namespace levin // Padding is not useful when using noise mode. Send as stem so receiver // 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( - 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()) { diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 920e0413c..91b3c0535 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -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) { - std::string account_data; + epee::byte_slice account_data; std::string multisig_signers; std::string multisig_derivations; 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; json.SetObject(); 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()); 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::Writer<rapidjson::StringBuffer> writer(buffer); json.Accept(writer); - account_data = buffer.GetString(); // Encrypt the entire JSON object. std::string cipher; - cipher.resize(account_data.size()); + cipher.resize(buffer.GetSize()); 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; return keys_file_data; } |