Monero
Loading...
Searching...
No Matches
levin_abstract_invoke2.h File Reference
#include "portable_storage_template_helper.h"
#include <boost/utility/string_ref.hpp>
#include <boost/utility/value_init.hpp>
#include <functional>
#include "byte_slice.h"
#include "span.h"
#include "net/levin_base.h"
Include dependency graph for levin_abstract_invoke2.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  epee
 TODO: (mj-xmr) This will be reduced in an another PR.
namespace  epee::net_utils

Macros

#define MONERO_DEFAULT_LOG_CATEGORY   "net"
#define CHAIN_LEVIN_INVOKE_MAP2(context_type)
#define CHAIN_LEVIN_NOTIFY_MAP2(context_type)
#define CHAIN_LEVIN_INVOKE_MAP()
#define CHAIN_LEVIN_NOTIFY_MAP()
#define CHAIN_LEVIN_NOTIFY_STUB()
#define BEGIN_INVOKE_MAP2(owner_type)
#define HANDLE_INVOKE2(command_id, func, type_name_in, typename_out)
#define HANDLE_INVOKE_T2(COMMAND, func)
#define HANDLE_NOTIFY2(command_id, func, type_name_in)
#define HANDLE_NOTIFY_T2(NOTIFY, func)
#define CHAIN_INVOKE_MAP2(func)
#define CHAIN_INVOKE_MAP_TO_OBJ2(obj)
#define CHAIN_INVOKE_MAP_TO_OBJ_FORCE_CONTEXT(obj, context_type)
#define END_INVOKE_MAP2()

Functions

template<typename context_t>
void on_levin_traffic (const context_t &context, bool initiator, bool sent, bool error, size_t bytes, const char *category)
template<typename context_t>
void on_levin_traffic (const context_t &context, bool initiator, bool sent, bool error, size_t bytes, int command)
template<class t_arg, class t_result, class t_transport>
bool epee::net_utils::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)
template<class t_result, class t_arg, class callback_t, class t_transport>
bool epee::net_utils::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)
template<class t_arg, class t_transport>
bool epee::net_utils::notify_remote_command2 (const typename t_transport::connection_context &context, int command, const t_arg &out_struct, t_transport &transport)
template<class t_owner, class t_in_type, class t_out_type, class t_context, class callback_t>
int epee::net_utils::buff_to_t_adapter (int command, const epee::span< const uint8_t > in_buff, byte_stream &buff_out, callback_t cb, t_context &context)
template<class t_owner, class t_in_type, class t_context, class callback_t>
int epee::net_utils::buff_to_t_adapter (t_owner *powner, int command, const epee::span< const uint8_t > in_buff, callback_t cb, t_context &context)

Macro Definition Documentation

◆ BEGIN_INVOKE_MAP2

#define BEGIN_INVOKE_MAP2 ( owner_type)
Value:
template <class t_context> int handle_invoke_map(bool is_notify, int command, const epee::span<const uint8_t> in_buff, epee::byte_stream& buff_out, t_context& context, bool& handled) \
{ \
try { \
typedef owner_type internal_owner_type_name;
A partial drop-in replacement for std::ostream.
Definition byte_stream.h:58
Non-owning sequence of data. Does not deep copy.
Definition span.h:55

◆ CHAIN_INVOKE_MAP2

#define CHAIN_INVOKE_MAP2 ( func)
Value:
{ \
int res = func(is_notify, command, in_buff, buff_out, context, handled); \
if(handled) \
return res; \
}
const char * res
Definition hmac_keccak.cpp:42

◆ CHAIN_INVOKE_MAP_TO_OBJ2

#define CHAIN_INVOKE_MAP_TO_OBJ2 ( obj)
Value:
{ \
int res = obj.handle_invoke_map(is_notify, command, in_buff, buff_out, context, handled); \
if(handled) \
return res; \
}

◆ CHAIN_INVOKE_MAP_TO_OBJ_FORCE_CONTEXT

#define CHAIN_INVOKE_MAP_TO_OBJ_FORCE_CONTEXT ( obj,
context_type )
Value:
{ \
int res = obj.handle_invoke_map(is_notify, command, in_buff, buff_out, static_cast<context_type>(context), handled); \
if(handled) return res; \
}

◆ CHAIN_LEVIN_INVOKE_MAP

#define CHAIN_LEVIN_INVOKE_MAP ( )
Value:
int invoke(int command, const epee::span<const uint8_t> in_buff, epee::byte_stream& buff_out, epee::net_utils::connection_context_base& context) \
{ \
bool handled = false; \
return handle_invoke_map(false, command, in_buff, buff_out, context, handled); \
}
Definition net_utils_base.h:367

◆ CHAIN_LEVIN_INVOKE_MAP2

#define CHAIN_LEVIN_INVOKE_MAP2 ( context_type)
Value:
int invoke(int command, const epee::span<const uint8_t> in_buff, epee::byte_stream& buff_out, context_type& context) \
{ \
bool handled = false; \
return handle_invoke_map(false, command, in_buff, buff_out, context, handled); \
}

◆ CHAIN_LEVIN_NOTIFY_MAP

#define CHAIN_LEVIN_NOTIFY_MAP ( )
Value:
int notify(int command, const epee::span<const uint8_t> in_buff, epee::net_utils::connection_context_base& context) \
{ \
bool handled = false; std::string fake_str;\
return handle_invoke_map(true, command, in_buff, fake_str, context, handled); \
}

◆ CHAIN_LEVIN_NOTIFY_MAP2

#define CHAIN_LEVIN_NOTIFY_MAP2 ( context_type)
Value:
int notify(int command, const epee::span<const uint8_t> 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); \
}

◆ CHAIN_LEVIN_NOTIFY_STUB

#define CHAIN_LEVIN_NOTIFY_STUB ( )
Value:
int notify(int command, const epee::span<const uint8_t> in_buff, epee::net_utils::connection_context_base& context) \
{ \
return -1; \
}

◆ END_INVOKE_MAP2

#define END_INVOKE_MAP2 ( )
Value:
LOG_ERROR("Unknown command:" << command); \
on_levin_traffic(context, false, false, true, in_buff.size(), "invalid-command"); \
} \
catch (const std::exception &e) { \
MERROR("Error in handle_invoke_map: " << e.what()); \
return LEVIN_ERROR_CONNECTION_TIMEDOUT; /* seems kinda appropriate */ \
} \
}
#define LEVIN_ERROR_CONNECTION_HANDLER_NOT_DEFINED
Definition levin_base.h:108
#define LEVIN_ERROR_CONNECTION_TIMEDOUT
Definition levin_base.h:106

◆ HANDLE_INVOKE2

#define HANDLE_INVOKE2 ( command_id,
func,
type_name_in,
typename_out )
Value:
if(!is_notify && command_id == command) \
{handled=true;return epee::net_utils::buff_to_t_adapter<internal_owner_type_name, type_name_in, typename_out>(this, command, in_buff, buff_out, std::bind(func, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4), context);}
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)
Definition levin_abstract_invoke2.h:152

◆ HANDLE_INVOKE_T2

#define HANDLE_INVOKE_T2 ( COMMAND,
func )
Value:
if(!is_notify && COMMAND::ID == command) \
{handled=true;return epee::net_utils::buff_to_t_adapter<internal_owner_type_name, typename COMMAND::request, typename COMMAND::response>(command, in_buff, buff_out, std::bind(func, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4), context);}

◆ HANDLE_NOTIFY2

#define HANDLE_NOTIFY2 ( command_id,
func,
type_name_in )
Value:
if(is_notify && command_id == command) \
{handled=true;return epee::net_utils::buff_to_t_adapter<internal_owner_type_name, type_name_in>(this, command, in_buff, std::bind(func, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), context);}

◆ HANDLE_NOTIFY_T2

#define HANDLE_NOTIFY_T2 ( NOTIFY,
func )
Value:
if(is_notify && NOTIFY::ID == command) \
{handled=true;return epee::net_utils::buff_to_t_adapter<internal_owner_type_name, typename NOTIFY::request>(this, command, in_buff, std::bind(func, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), context);}

◆ MONERO_DEFAULT_LOG_CATEGORY

#define MONERO_DEFAULT_LOG_CATEGORY   "net"

Function Documentation

◆ on_levin_traffic() [1/2]

template<typename context_t>
void on_levin_traffic ( const context_t & context,
bool initiator,
bool sent,
bool error,
size_t bytes,
const char * category )

◆ on_levin_traffic() [2/2]

template<typename context_t>
void on_levin_traffic ( const context_t & context,
bool initiator,
bool sent,
bool error,
size_t bytes,
int command )