Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contrib/epee/include/net/http_server_handlers_map2.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
} \
uint64_t ticks2 = misc_utils::get_tick_count(); \
epee::byte_slice buffer; \
epee::serialization::store_t_to_binary(static_cast<command_type::response&>(resp), buffer, 64 * 1024); \
epee::serialization::store_t_to_binary(static_cast<command_type::response&>(resp), buffer); \
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"; \
Expand Down
9 changes: 2 additions & 7 deletions contrib/epee/include/storages/http_abstract_invoke.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace epee
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")
{
byte_slice req_param;
if(!serialization::store_t_to_binary(out_struct, req_param, 16 * 1024))
if(!serialization::store_t_to_binary(out_struct, req_param))
return false;

const http::http_response_info* pri = NULL;
Expand All @@ -98,12 +98,7 @@ namespace epee
return false;
}

static const constexpr epee::serialization::portable_storage::limits_t default_http_bin_limits = {
65536 * 3, // objects
65536 * 3, // fields
65536 * 3, // strings
};
return serialization::load_t_from_binary(result_struct, epee::strspan<uint8_t>(pri->m_body), &default_http_bin_limits);
return serialization::load_t_from_binary(result_struct, epee::strspan<uint8_t>(pri->m_body));
}

template<class t_request, class t_response, class t_transport>
Expand Down
64 changes: 12 additions & 52 deletions contrib/epee/include/storages/levin_abstract_invoke2.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#pragma once

#include "portable_storage_template_helper.h"
#include "p2p/portable_scheme/load_store_wrappers.h"
#include <boost/utility/string_ref.hpp>
#include <boost/utility/value_init.hpp>
#include <functional>
Expand All @@ -43,15 +44,6 @@ void on_levin_traffic(const context_t &context, bool initiator, bool sent, bool
template<typename context_t>
void on_levin_traffic(const context_t &context, bool initiator, bool sent, bool error, size_t bytes, int command);

namespace
{
static const constexpr epee::serialization::portable_storage::limits_t default_levin_limits = {
8192, // objects
16384, // fields
16384, // strings
};
}

namespace epee
{
namespace net_utils
Expand Down Expand Up @@ -108,37 +100,32 @@ namespace epee
bool invoke_remote_command2(const epee::net_utils::connection_context_base context, int command, const t_arg& out_struct, t_result& result_struct, t_transport& transport)
{
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};
std::string buff_to_recv;
stg.store_to_binary(to_send.buffer);
portable_scheme::store_to_binary(out_struct, to_send.buffer);

int res = transport.invoke(command, std::move(to_send), buff_to_recv, conn_id);
if( res <=0 )
{
LOG_PRINT_L1("Failed to invoke command " << command << " return code " << res);
return false;
}
typename serialization::portable_storage stg_ret;
if(!stg_ret.load_from_binary(buff_to_recv, &default_levin_limits))
if(!portable_scheme::load_from_binary(result_struct, buff_to_recv))
{
on_levin_traffic(context, true, false, true, buff_to_recv.size(), command);
LOG_ERROR("Failed to load_from_binary on command " << command);
return false;
}
on_levin_traffic(context, true, false, false, buff_to_recv.size(), command);
return result_struct.load(stg_ret);
return true;
}

template<class t_result, class t_arg, class callback_t, class t_transport>
bool async_invoke_remote_command2(const epee::net_utils::connection_context_base &context, int command, const t_arg& out_struct, t_transport& transport, const callback_t &cb, size_t inv_timeout = LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED)
{
const boost::uuids::uuid &conn_id = context.m_connection_id;
typename serialization::portable_storage stg;
const_cast<t_arg&>(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);
portable_scheme::store_to_binary(out_struct, to_send.buffer);
int res = transport.invoke_async(command, std::move(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);
Expand All @@ -150,21 +137,13 @@ namespace epee
cb(code, result_struct, context);
return false;
}
serialization::portable_storage stg_ret;
if(!stg_ret.load_from_binary(buff, &default_levin_limits))
if(!portable_scheme::load_from_binary(result_struct, buff))
{
on_levin_traffic(context, true, false, true, buff.size(), command);
LOG_ERROR("Failed to load_from_binary on command " << command);
cb(LEVIN_ERROR_FORMAT, result_struct, context);
return false;
}
if (!result_struct.load(stg_ret))
{
on_levin_traffic(context, true, false, true, buff.size(), command);
LOG_ERROR("Failed to load result struct on command " << command);
cb(LEVIN_ERROR_FORMAT, result_struct, context);
return false;
}
on_levin_traffic(context, true, false, false, buff.size(), command);
cb(code, result_struct, context);
return true;
Expand All @@ -181,10 +160,8 @@ namespace epee
bool notify_remote_command2(const typename t_transport::connection_context &context, int command, const t_arg& out_struct, t_transport& transport)
{
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);
portable_scheme::store_to_binary(out_struct, to_send.buffer);

int res = transport.send(to_send.finalize_notify(command), conn_id);
if(res <=0 )
Expand All @@ -199,28 +176,18 @@ namespace epee
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, byte_stream& buff_out, callback_t cb, t_context& context )
{
serialization::portable_storage strg;
if(!strg.load_from_binary(in_buff, &default_levin_limits))
boost::value_initialized<t_in_type> in_struct;
if(!portable_scheme::load_from_binary(static_cast<t_in_type &>(in_struct), in_buff))
{
on_levin_traffic(context, false, false, true, in_buff.size(), command);
LOG_ERROR("Failed to load_from_binary in command " << command);
return -1;
}
boost::value_initialized<t_in_type> in_struct;
boost::value_initialized<t_out_type> out_struct;

if (!static_cast<t_in_type&>(in_struct).load(strg))
{
on_levin_traffic(context, false, false, true, in_buff.size(), command);
LOG_ERROR("Failed to load in_struct in command " << command);
return -1;
}
on_levin_traffic(context, false, false, false, in_buff.size(), command);
int res = cb(command, static_cast<t_in_type&>(in_struct), static_cast<t_out_type&>(out_struct), context);
serialization::portable_storage strg_out;
static_cast<t_out_type&>(out_struct).store(strg_out);

if(!strg_out.store_to_binary(buff_out))
if(!portable_scheme::store_to_binary(static_cast<t_out_type &>(out_struct), buff_out))
{
LOG_ERROR("Failed to store_to_binary in command" << command);
return -1;
Expand All @@ -232,18 +199,11 @@ namespace epee
template<class t_owner, class t_in_type, class t_context, class callback_t>
int buff_to_t_adapter(t_owner* powner, int command, const epee::span<const uint8_t> in_buff, callback_t cb, t_context& context)
{
serialization::portable_storage strg;
if(!strg.load_from_binary(in_buff, &default_levin_limits))
{
on_levin_traffic(context, false, false, true, in_buff.size(), command);
LOG_ERROR("Failed to load_from_binary in notify " << command);
return -1;
}
boost::value_initialized<t_in_type> in_struct;
if (!static_cast<t_in_type&>(in_struct).load(strg))
if(!portable_scheme::load_from_binary(static_cast<t_in_type &>(in_struct), in_buff))
{
on_levin_traffic(context, false, false, true, in_buff.size(), command);
LOG_ERROR("Failed to load in_struct in notify " << command);
LOG_ERROR("Failed to load_from_binary in notify " << command);
return -1;
}
on_levin_traffic(context, false, false, false, in_buff.size(), command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "byte_slice.h"
#include "parserse_base_utils.h" /// TODO: (mj-xmr) This will be reduced in an another PR
#include "p2p/portable_scheme/load_store_wrappers.h"
#include "portable_storage.h"
#include "file_io_utils.h"
#include "span.h"
Expand Down Expand Up @@ -88,14 +89,9 @@ namespace epee
}
//-----------------------------------------------------------------------------------------------------------
template<class t_struct>
bool load_t_from_binary(t_struct& out, const epee::span<const uint8_t> binary_buff, const epee::serialization::portable_storage::limits_t *limits = NULL)
bool load_t_from_binary(t_struct& out, const epee::span<const uint8_t> binary_buff)
{
portable_storage ps;
bool rs = ps.load_from_binary(binary_buff, limits);
if(!rs)
return false;

return out.load(ps);
return portable_scheme::load_from_binary(out, binary_buff);
}
//-----------------------------------------------------------------------------------------------------------
template<class t_struct>
Expand All @@ -115,27 +111,23 @@ namespace epee
}
//-----------------------------------------------------------------------------------------------------------
template<class t_struct>
bool store_t_to_binary(t_struct& str_in, byte_slice& binary_buff, size_t initial_buffer_size = 8192)
bool store_t_to_binary(t_struct& str_in, byte_slice& binary_buff)
{
portable_storage ps;
str_in.store(ps);
return ps.store_to_binary(binary_buff, initial_buffer_size);
return portable_scheme::store_to_binary(str_in, binary_buff);
}
//-----------------------------------------------------------------------------------------------------------
template<class t_struct>
byte_slice store_t_to_binary(t_struct& str_in, size_t initial_buffer_size = 8192)
byte_slice store_t_to_binary(t_struct& str_in)
{
byte_slice binary_buff;
store_t_to_binary(str_in, binary_buff, initial_buffer_size);
store_t_to_binary(str_in, binary_buff);
return binary_buff;
}
//-----------------------------------------------------------------------------------------------------------
template<class t_struct>
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);
return portable_scheme::store_to_binary(str_in, binary_buff);
}

}
Expand Down
1 change: 1 addition & 0 deletions src/cryptonote_basic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ target_link_libraries(cryptonote_format_utils_basic

set(cryptonote_basic_sources
account.cpp
account_epee_serialization.cpp
connection_context.cpp
cryptonote_basic_impl.cpp
cryptonote_format_utils.cpp
Expand Down
6 changes: 6 additions & 0 deletions src/cryptonote_basic/account_epee_serialization.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "account_epee_serialization.h"
#include "p2p/portable_scheme/load_store_wrappers_impl.h"

PORTABLE_SCHEME_LOAD_STORE_INSTANCE(cryptonote::account_public_address)
PORTABLE_SCHEME_LOAD_STORE_INSTANCE(cryptonote::account_keys)
PORTABLE_SCHEME_LOAD_STORE_INSTANCE(cryptonote::account_base)
100 changes: 100 additions & 0 deletions src/cryptonote_basic/account_epee_serialization.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#pragma once

#include "account.h"
#include "p2p/portable_scheme/scheme.h"

namespace portable_scheme {

namespace scheme_space {

template<>
struct scheme<cryptonote::account_public_address> {
using T = cryptonote::account_public_address;
using tags = map_tag<
field_tag<KEY("m_spend_public_key"), span_tag<>>,
field_tag<KEY("m_view_public_key"), span_tag<>>
>;
BEGIN_READ(T)
READ_FIELD_POD(m_spend_public_key)
READ_FIELD_POD(m_view_public_key)
END_READ()
BEGIN_WRITE(T)
WRITE_FIELD_POD(m_spend_public_key)
WRITE_FIELD_POD(m_view_public_key)
END_WRITE()
};

template<>
struct scheme<cryptonote::account_keys> {
using T = cryptonote::account_keys;
using tags = map_tag<
field_tag<KEY("m_account_address"), scheme<decltype(T::m_account_address)>::tags>,
field_tag<KEY("m_encryption_iv"), span_tag<>>,
field_tag<KEY("m_multisig_keys"), span_tag<>>,
field_tag<KEY("m_spend_secret_key"), span_tag<>>,
field_tag<KEY("m_view_secret_key"), span_tag<>>
>;
BEGIN_READ(T)
READ_FIELD(m_account_address)
READ_FIELD_CUSTOM(m_spend_secret_key, scheme<pod_tag<crypto::ec_scalar>>)
READ_FIELD_CUSTOM(m_view_secret_key, scheme<pod_tag<crypto::ec_scalar>>)
READ_FIELD_LIST_CUSTOM(m_multisig_keys, scheme<container_pod_tag<decltype(T::m_multisig_keys), false, crypto::ec_scalar>>)
READ_FIELD_POD(m_encryption_iv)
END_READ()
BEGIN_WRITE(T)
WRITE_FIELD(m_account_address)
WRITE_FIELD_CUSTOM(m_spend_secret_key, scheme<pod_tag<crypto::ec_scalar>>)
WRITE_FIELD_CUSTOM(m_view_secret_key, scheme<pod_tag<crypto::ec_scalar>>)
WRITE_FIELD_LIST_CUSTOM(m_multisig_keys, scheme<container_pod_tag<decltype(T::m_multisig_keys), false, crypto::ec_scalar>>)
WRITE_FIELD_POD_WITH_DEFAULT(m_encryption_iv, crypto::chacha_iv{{}})
END_WRITE()
};

template<>
struct scheme<cryptonote::account_base> {
using T = cryptonote::account_base;
using tags = map_tag<
field_tag<KEY("m_creation_timestamp"), base_tag<std::uint64_t>>,
field_tag<KEY("m_keys"), scheme<cryptonote::account_keys>::tags>
>;
BEGIN_READ_RAW(
private:
const T &t;
uint64_t m_creation_timestamp;
public:
read_t(const T &t): t(t), m_creation_timestamp(t.get_createtime()) {}
)
READ_FIELD_NAME("m_keys", t.get_keys())
READ_FIELD_NAME("m_creation_timestamp", m_creation_timestamp)
END_READ()
BEGIN_WRITE_RAW(
private:
T &t;
cryptonote::account_keys m_keys{};
uint64_t m_creation_timestamp{};
public:
write_t(T &t): t(t) {}
)
WRITE_FIELD_NAME("m_keys", m_keys);
WRITE_FIELD_NAME("m_creation_timestamp", m_creation_timestamp);
WRITE_CHECK(
struct archive_t {
const cryptonote::account_keys &m_keys;
const uint64_t &m_creation_timestamp;
void operator&(cryptonote::account_keys& m_keys) const {
m_keys = this->m_keys;
}
void operator&(std::uint64_t &m_creation_timestamp) const {
m_creation_timestamp = this->m_creation_timestamp;
}
};
archive_t archive{m_keys, m_creation_timestamp};
t.serialize(archive, 0);
return true;
)
END_WRITE()
};

}

}
13 changes: 13 additions & 0 deletions src/cryptonote_protocol/cryptonote_protocol_serialization.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "cryptonote_protocol/cryptonote_protocol_serialization.h"
#include "p2p/portable_scheme/load_store_wrappers_impl.h"

PORTABLE_SCHEME_LOAD_STORE_INSTANCE(cryptonote::NOTIFY_NEW_BLOCK::request)
PORTABLE_SCHEME_LOAD_STORE_INSTANCE(cryptonote::NOTIFY_NEW_TRANSACTIONS::request)
PORTABLE_SCHEME_LOAD_STORE_INSTANCE(cryptonote::NOTIFY_REQUEST_GET_OBJECTS::request)
PORTABLE_SCHEME_LOAD_STORE_INSTANCE(cryptonote::NOTIFY_RESPONSE_GET_OBJECTS::request)
PORTABLE_SCHEME_LOAD_STORE_INSTANCE(cryptonote::CORE_SYNC_DATA)
PORTABLE_SCHEME_LOAD_STORE_INSTANCE(cryptonote::NOTIFY_REQUEST_CHAIN::request)
PORTABLE_SCHEME_LOAD_STORE_INSTANCE(cryptonote::NOTIFY_RESPONSE_CHAIN_ENTRY::request)
PORTABLE_SCHEME_LOAD_STORE_INSTANCE(cryptonote::NOTIFY_NEW_FLUFFY_BLOCK::request)
PORTABLE_SCHEME_LOAD_STORE_INSTANCE(cryptonote::NOTIFY_REQUEST_FLUFFY_MISSING_TX::request)
PORTABLE_SCHEME_LOAD_STORE_INSTANCE(cryptonote::NOTIFY_GET_TXPOOL_COMPLEMENT::request)
Loading