diff --git a/contrib/epee/include/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl index 2a4b10e4..403f5a3b 100644 --- a/contrib/epee/include/net/abstract_tcp_server2.inl +++ b/contrib/epee/include/net/abstract_tcp_server2.inl @@ -52,11 +52,11 @@ PRAGMA_WARNING_DISABLE_VS(4355) typename t_protocol_handler::config_type& config, volatile uint32_t& sock_count, i_connection_filter* &pfilter) : strand_(io_service), socket_(io_service), - m_protocol_handler(this, config, context), m_want_close_connection(0), m_was_shutdown(0), m_ref_sockets_count(sock_count), - m_pfilter(pfilter) + m_pfilter(pfilter), + m_protocol_handler(this, config, context) { boost::interprocess::ipcdetail::atomic_inc32(&m_ref_sockets_count); } diff --git a/contrib/epee/include/net/http_protocol_handler.h b/contrib/epee/include/net/http_protocol_handler.h index 4bf48750..aed90977 100644 --- a/contrib/epee/include/net/http_protocol_handler.h +++ b/contrib/epee/include/net/http_protocol_handler.h @@ -55,20 +55,20 @@ namespace net_utils /************************************************************************/ /* */ /************************************************************************/ - template + template class simple_http_connection_handler { public: - typedef t_connection_context connection_context;//t_connection_context net_utils::connection_context_base connection_context; + typedef t_connection_context connection_context;//t_connection_context net_utils::connection_context_base connection_context; typedef http_server_config config_type; simple_http_connection_handler(i_service_endpoint* psnd_hndlr, config_type& config); virtual ~simple_http_connection_handler(){} - bool release_protocol() - { - return true; - } + bool release_protocol() + { + return true; + } virtual bool thread_init() { @@ -85,10 +85,6 @@ namespace net_utils } virtual bool handle_recv(const void* ptr, size_t cb); virtual bool handle_request(const http::http_request_info& query_info, http_response_info& response); - - - //temporary here - //bool parse_uri(const std::string uri, uri_content& content); private: enum machine_state{ @@ -142,34 +138,37 @@ namespace net_utils i_service_endpoint* m_psnd_hndlr; }; - template + template struct i_http_server_handler { virtual ~i_http_server_handler(){} - virtual bool handle_http_request(const http_request_info& query_info, http_response_info& response, t_connection_context& m_conn_context)=0; - virtual bool init_server_thread(){return true;} + virtual bool handle_http_request(const http_request_info& query_info, + http_response_info& response, + t_connection_context& m_conn_context) = 0; + virtual bool init_server_thread(){return true;} virtual bool deinit_server_thread(){return true;} }; - template + template struct custum_handler_config: public http_server_config { i_http_server_handler* m_phandler; }; - /************************************************************************/ - /* */ - /************************************************************************/ + /************************************************************************/ + /* */ + /************************************************************************/ - template + template class http_custom_handler: public simple_http_connection_handler { public: typedef custum_handler_config config_type; - http_custom_handler(i_service_endpoint* psnd_hndlr, config_type& config, t_connection_context& conn_context):simple_http_connection_handler(psnd_hndlr, config), - m_config(config), - m_conn_context(conn_context) + http_custom_handler(i_service_endpoint* psnd_hndlr, config_type& config, t_connection_context& conn_context) + : simple_http_connection_handler(psnd_hndlr, config), + m_config(config), + m_conn_context(conn_context) {} inline bool handle_request(const http_request_info& query_info, http_response_info& response) { @@ -191,8 +190,8 @@ namespace net_utils { return m_config.m_phandler->deinit_server_thread(); } - void handle_qued_callback() - {} + void handle_qued_callback() + {} bool after_init_connection() { return true; diff --git a/contrib/epee/include/net/http_server_handlers_map2.h b/contrib/epee/include/net/http_server_handlers_map2.h index af4e035f..20146013 100644 --- a/contrib/epee/include/net/http_server_handlers_map2.h +++ b/contrib/epee/include/net/http_server_handlers_map2.h @@ -26,9 +26,10 @@ #pragma once -#include "serialization/keyvalue_serialization.h" -#include "storages/portable_storage_template_helper.h" #include "http_base.h" +#include "jsonrpc_structs.h" +#include "storages/portable_storage.h" +#include "storages/portable_storage_template_helper.h" #define CHAIN_HTTP_TO_MAP2(context_type) bool handle_http_request(const epee::net_utils::http::http_request_info& query_info, \ @@ -109,98 +110,6 @@ #define END_URI_MAP2() return handled;} - - -namespace epee -{ - namespace json_rpc - { - template - struct request - { - std::string jsonrpc; - std::string method; - epee::serialization::storage_entry id; - t_param params; - - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(jsonrpc) - KV_SERIALIZE(id) - KV_SERIALIZE(method) - KV_SERIALIZE(params) - END_KV_SERIALIZE_MAP() - }; - - struct error - { - int64_t code; - std::string message; - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(code) - KV_SERIALIZE(message) - END_KV_SERIALIZE_MAP() - }; - - struct dummy_error - { - BEGIN_KV_SERIALIZE_MAP() - END_KV_SERIALIZE_MAP() - }; - - struct dummy_result - { - BEGIN_KV_SERIALIZE_MAP() - END_KV_SERIALIZE_MAP() - }; - - template - struct response - { - std::string jsonrpc; - t_param result; - epee::serialization::storage_entry id; - t_error error; - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(jsonrpc) - KV_SERIALIZE(id) - KV_SERIALIZE(result) - KV_SERIALIZE(error) - END_KV_SERIALIZE_MAP() - }; - - template - struct response - { - std::string jsonrpc; - t_param result; - epee::serialization::storage_entry id; - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(jsonrpc) - KV_SERIALIZE(id) - KV_SERIALIZE(result) - END_KV_SERIALIZE_MAP() - }; - - template - struct response - { - std::string jsonrpc; - t_error error; - epee::serialization::storage_entry id; - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(jsonrpc) - KV_SERIALIZE(id) - KV_SERIALIZE(error) - END_KV_SERIALIZE_MAP() - }; - - typedef response error_response; - } -} - - - - #define BEGIN_JSON_RPC_MAP(uri) else if(query_info.m_URI == uri) \ { \ uint64_t ticks = epee::misc_utils::get_tick_count(); \ @@ -315,6 +224,6 @@ namespace epee rsp.error.message = "Method not found"; \ epee::serialization::store_t_to_json(static_cast(rsp), response_info.m_body); \ return true; \ - } +} diff --git a/contrib/epee/include/net/jsonrpc_protocol_handler.h b/contrib/epee/include/net/jsonrpc_protocol_handler.h new file mode 100644 index 00000000..b224c342 --- /dev/null +++ b/contrib/epee/include/net/jsonrpc_protocol_handler.h @@ -0,0 +1,167 @@ +#ifndef JSONRPC_PROTOCOL_HANDLER_H +#define JSONRPC_PROTOCOL_HANDLER_H + +#include +#include + +#include "net/net_utils_base.h" +#include "jsonrpc_structs.h" +#include "storages/portable_storage.h" +#include "storages/portable_storage_template_helper.h" + +namespace epee +{ +namespace net_utils +{ + namespace jsonrpc2 + { + inline + std::string& make_error_resp_json(int64_t code, const std::string& message, + std::string& response_data, + const epee::serialization::storage_entry& id = nullptr) + { + epee::json_rpc::error_response rsp; + rsp.id = id; + rsp.jsonrpc = "2.0"; + rsp.error.code = code; + rsp.error.message = message; + epee::serialization::store_t_to_json(static_cast(rsp), response_data, 0, false); + response_data += "\n"; + return response_data; + } + + template + struct i_jsonrpc2_server_handler + { + virtual ~i_jsonrpc2_server_handler() + {} + virtual bool handle_rpc_request(const std::string& req_data, + std::string& resp_data, + t_connection_context& conn_context) = 0; + virtual bool init_server_thread() + { return true; } + virtual bool deinit_server_thread() + { return true; } + }; + + template + struct jsonrpc2_server_config + { + i_jsonrpc2_server_handler* m_phandler; + critical_section m_lock; + }; + + template + class jsonrpc2_connection_handler + { + public: + typedef t_connection_context connection_context; + typedef jsonrpc2_server_config config_type; + + jsonrpc2_connection_handler(i_service_endpoint* psnd_hndlr, + config_type& config, + t_connection_context& conn_context) + : m_psnd_hndlr(psnd_hndlr), + m_config(config), + m_conn_context(conn_context), + m_is_stop_handling(false) + {} + virtual ~jsonrpc2_connection_handler() + {} + + bool release_protocol() + { + return true; + } + virtual bool thread_init() + { + return true; + } + virtual bool thread_deinit() + { + return true; + } + void handle_qued_callback() + {} + bool after_init_connection() + { + return true; + } + virtual bool handle_recv(const void* ptr, size_t cb) + { + std::string buf((const char*)ptr, cb); + LOG_PRINT_L0("JSONRPC2_RECV: " << ptr << "\r\n" << buf); + + bool res = handle_buff_in(buf); + return res; + } + private: + bool handle_buff_in(std::string& buf) + { + if(m_cache.size()) + m_cache += buf; + else + m_cache.swap(buf); + + m_is_stop_handling = false; + while (!m_is_stop_handling) { + std::string::size_type pos = match_end_of_request(m_cache); + if (std::string::npos == pos) { + m_is_stop_handling = true; + if (m_cache.size() > 4096) { + LOG_ERROR("jsonrpc2_connection_handler::handle_buff_in: Too long request"); + return false; + } + break; + } else { + extract_cached_request_and_handle(pos); + } + + if (!m_cache.size()) { + m_is_stop_handling = true; + } + } + + return true; + } + bool extract_cached_request_and_handle(std::string::size_type pos) + { + std::string request_data(m_cache.begin(), m_cache.begin() + pos); + m_cache.erase(0, pos); + return handle_request_and_send_response(request_data); + } + bool handle_request_and_send_response(const std::string& request_data) + { + CHECK_AND_ASSERT_MES(m_config.m_phandler, false, "m_config.m_phandler is NULL!!!!"); + std::string response_data; + + LOG_PRINT_L3("JSONRPC2_REQUEST: >> \r\n" << request_data); + bool rpc_result = m_config.m_phandler->handle_rpc_request(request_data, response_data, m_conn_context); + LOG_PRINT_L3("JSONRPC2_RESPONSE: << \r\n" << response_data); + + m_psnd_hndlr->do_send((void*)response_data.data(), response_data.size()); + return rpc_result; + } + std::string::size_type match_end_of_request(const std::string& buf) + { + std::string::size_type res = buf.find("\n"); + if(std::string::npos != res) { + return res + 2; + } + return res; + } + + protected: + i_service_endpoint* m_psnd_hndlr; + + private: + config_type& m_config; + t_connection_context& m_conn_context; + std::string m_cache; + bool m_is_stop_handling; + }; + } +} +} + +#endif /* JSONRPC_PROTOCOL_HANDLER_H */ diff --git a/contrib/epee/include/net/jsonrpc_server_handlers_map.h b/contrib/epee/include/net/jsonrpc_server_handlers_map.h new file mode 100644 index 00000000..8c747d1a --- /dev/null +++ b/contrib/epee/include/net/jsonrpc_server_handlers_map.h @@ -0,0 +1,86 @@ +#ifndef JSONRPC_SERVER_HANDLERS_MAP_H +#define JSONRPC_SERVER_HANDLERS_MAP_H + +#include +#include "serialization/keyvalue_serialization.h" +#include "storages/portable_storage_template_helper.h" +#include "storages/portable_storage_base.h" +#include "jsonrpc_structs.h" +#include "jsonrpc_protocol_handler.h" + +#define BEGIN_JSONRPC2_MAP(t_connection_context) \ +bool handle_rpc_request(const std::string& req_data, \ + std::string& resp_data, \ + t_connection_context& m_conn_context) \ +{ \ + bool handled = false; \ + uint64_t ticks = epee::misc_utils::get_tick_count(); \ + epee::serialization::portable_storage ps; \ + if (!ps.load_from_json(req_data)) \ + { \ + epee::net_utils::jsonrpc2::make_error_resp_json(-32700, "Parse error", resp_data); \ + return true; \ + } \ + epee::serialization::storage_entry id_; \ + id_ = epee::serialization::storage_entry(std::string()); \ + if (!ps.get_value("id", id_, nullptr)) \ + { \ + epee::net_utils::jsonrpc2::make_error_resp_json(-32600, "Invalid Request", resp_data); \ + return true; \ + } \ + std::string callback_name; \ + if (!ps.get_value("method", callback_name, nullptr)) \ + { \ + epee::net_utils::jsonrpc2::make_error_resp_json(-32600, "Invalid Request", resp_data, id_); \ + return true; \ + } \ + if (false) return true; //just a stub to have "else if" + + + +#define PREPARE_JSONRPC2_OBJECTS_FROM_JSON(command_type) \ + handled = true; \ + boost::value_initialized > req_; \ + epee::json_rpc::request& req = static_cast&>(req_);\ + if(!req.load(ps)) \ + { \ + epee::net_utils::jsonrpc2::make_error_resp_json(-32602, "Invalid params", resp_data, req.id); \ + return true; \ + } \ + uint64_t ticks1 = epee::misc_utils::get_tick_count(); \ + boost::value_initialized > resp_; \ + epee::json_rpc::response& resp = static_cast &>(resp_); \ + resp.jsonrpc = "2.0"; \ + resp.id = req.id; + +#define FINALIZE_JSONRPC2_OBJECTS_TO_JSON(method_name) \ + uint64_t ticks2 = epee::misc_utils::get_tick_count(); \ + epee::serialization::store_t_to_json(resp, resp_data, 0, false); \ + resp_data += "\n"; \ + uint64_t ticks3 = epee::misc_utils::get_tick_count(); \ + LOG_PRINT("[" << method_name << "] processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms", LOG_LEVEL_2); + + +#define MAP_JSONRPC2_WE(method_name, callback_f, command_type) \ + else if (callback_name == method_name) \ + { \ + PREPARE_JSONRPC2_OBJECTS_FROM_JSON(command_type) \ + epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \ + fail_resp.jsonrpc = "2.0"; \ + fail_resp.id = req.id; \ + if(!callback_f(req.params, resp.result, fail_resp.error, m_conn_context)) \ + { \ + epee::serialization::store_t_to_json(static_cast(fail_resp), resp_data, 0, false); \ + resp_data += "\n"; \ + return true; \ + } \ + FINALIZE_JSONRPC2_OBJECTS_TO_JSON(method_name) \ + return true; \ + } + +#define END_JSONRPC2_MAP() \ + epee::net_utils::jsonrpc2::make_error_resp_json(-32601, "Method not found", resp_data, id_); \ + return true; \ +} + +#endif /* JSONRPC_SERVER_HANDLERS_MAP_H */ diff --git a/contrib/epee/include/net/jsonrpc_server_impl_base.h b/contrib/epee/include/net/jsonrpc_server_impl_base.h new file mode 100644 index 00000000..8a5a9a5b --- /dev/null +++ b/contrib/epee/include/net/jsonrpc_server_impl_base.h @@ -0,0 +1,84 @@ +#ifndef JSONRPC_SERVER_IMPL_BASE_H +#define JSONRPC_SERVER_IMPL_BASE_H + +#include +#include + +#include "net/jsonrpc_protocol_handler.h" +#include "net/jsonrpc_server_handlers_map.h" +#include "net/abstract_tcp_server2.h" + +namespace epee +{ + +template + class jsonrpc_server_impl_base: public net_utils::jsonrpc2::i_jsonrpc2_server_handler + { + + public: + jsonrpc_server_impl_base() + : m_net_server() + {} + + explicit jsonrpc_server_impl_base(boost::asio::io_service& external_io_service) + : m_net_server(external_io_service) + {} + + bool init(const std::string& bind_port = "0", const std::string& bind_ip = "0.0.0.0") + { + //set self as callback handler + m_net_server.get_config_object().m_phandler = static_cast(this); + + LOG_PRINT_L0("Binding on " << bind_ip << ":" << bind_port); + bool res = m_net_server.init_server(bind_port, bind_ip); + if (!res) + { + LOG_ERROR("Failed to bind server"); + return false; + } + return true; + } + + bool run(size_t threads_count, bool wait = true) + { + //go to loop + LOG_PRINT("Run net_service loop( " << threads_count << " threads)...", LOG_LEVEL_0); + if(!m_net_server.run_server(threads_count, wait)) + { + LOG_ERROR("Failed to run net tcp server!"); + } + + if(wait) + LOG_PRINT("net_service loop stopped.", LOG_LEVEL_0); + return true; + } + + bool deinit() + { + return m_net_server.deinit_server(); + } + + bool timed_wait_server_stop(uint64_t ms) + { + return m_net_server.timed_wait_server_stop(ms); + } + + bool send_stop_signal() + { + m_net_server.send_stop_signal(); + return true; + } + + int get_binded_port() + { + return m_net_server.get_binded_port(); + } + + protected: + net_utils::boosted_tcp_server > m_net_server; + }; + +} + +#endif /* JSONRPC_SERVER_IMPL_BASE_H */ + diff --git a/contrib/epee/include/net/jsonrpc_structs.h b/contrib/epee/include/net/jsonrpc_structs.h new file mode 100644 index 00000000..9df9e259 --- /dev/null +++ b/contrib/epee/include/net/jsonrpc_structs.h @@ -0,0 +1,96 @@ +#ifndef JSONRPC_STRUCTS_H +#define JSONRPC_STRUCTS_H + +#include +#include +#include "serialization/keyvalue_serialization.h" +#include "storages/portable_storage_base.h" + +namespace epee +{ + namespace json_rpc + { + template + struct request + { + std::string jsonrpc; + std::string method; + epee::serialization::storage_entry id; + t_param params; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(jsonrpc) + KV_SERIALIZE(id) + KV_SERIALIZE(method) + KV_SERIALIZE(params) + END_KV_SERIALIZE_MAP() + }; + + struct error + { + int64_t code; + std::string message; + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(code) + KV_SERIALIZE(message) + END_KV_SERIALIZE_MAP() + }; + + struct dummy_error + { + BEGIN_KV_SERIALIZE_MAP() + END_KV_SERIALIZE_MAP() + }; + + struct dummy_result + { + BEGIN_KV_SERIALIZE_MAP() + END_KV_SERIALIZE_MAP() + }; + + template + struct response + { + std::string jsonrpc; + t_param result; + epee::serialization::storage_entry id; + t_error error; + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(jsonrpc) + KV_SERIALIZE(id) + KV_SERIALIZE(result) + KV_SERIALIZE(error) + END_KV_SERIALIZE_MAP() + }; + + template + struct response + { + std::string jsonrpc; + t_param result; + epee::serialization::storage_entry id; + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(jsonrpc) + KV_SERIALIZE(id) + KV_SERIALIZE(result) + END_KV_SERIALIZE_MAP() + }; + + template + struct response + { + std::string jsonrpc; + t_error error; + epee::serialization::storage_entry id; + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(jsonrpc) + KV_SERIALIZE(id) + KV_SERIALIZE(error) + END_KV_SERIALIZE_MAP() + }; + + typedef response error_response; + } +} + +#endif /* JSONRPC_STRUCTS_H */ diff --git a/contrib/epee/include/net/net_utils_base.h b/contrib/epee/include/net/net_utils_base.h index 793135b8..b5619bab 100644 --- a/contrib/epee/include/net/net_utils_base.h +++ b/contrib/epee/include/net/net_utils_base.h @@ -47,8 +47,8 @@ namespace net_utils struct connection_context_base { const boost::uuids::uuid m_connection_id; - const uint32_t m_remote_ip; - const uint32_t m_remote_port; + const uint32_t m_remote_ip; + const uint32_t m_remote_port; const bool m_is_income; const time_t m_started; time_t m_last_recv; @@ -56,27 +56,30 @@ namespace net_utils uint64_t m_recv_cnt; uint64_t m_send_cnt; - connection_context_base(boost::uuids::uuid connection_id, long remote_ip, int remote_port, bool is_income, time_t last_recv = 0, time_t last_send = 0, uint64_t recv_cnt = 0, uint64_t send_cnt = 0): + connection_context_base(boost::uuids::uuid connection_id, + long remote_ip, int remote_port, bool is_income, + time_t last_recv = 0, time_t last_send = 0, + uint64_t recv_cnt = 0, uint64_t send_cnt = 0): m_connection_id(connection_id), m_remote_ip(remote_ip), m_remote_port(remote_port), m_is_income(is_income), + m_started(time(NULL)), m_last_recv(last_recv), m_last_send(last_send), m_recv_cnt(recv_cnt), - m_send_cnt(send_cnt), - m_started(time(NULL)) + m_send_cnt(send_cnt) {} connection_context_base(): m_connection_id(), m_remote_ip(0), m_remote_port(0), m_is_income(false), + m_started(time(NULL)), m_last_recv(0), m_last_send(0), m_recv_cnt(0), - m_send_cnt(0), - m_started(time(NULL)) + m_send_cnt(0) {} connection_context_base& operator=(const connection_context_base& a) diff --git a/contrib/epee/include/profile_tools.h b/contrib/epee/include/profile_tools.h index be45feaf..0e1646f6 100644 --- a/contrib/epee/include/profile_tools.h +++ b/contrib/epee/include/profile_tools.h @@ -51,13 +51,13 @@ namespace epee #define PROFILE_FUNC_THIRD(immortal_ptr_str) #endif -#define START_WAY_POINTS() uint64_t _____way_point_time = misc_utils::get_tick_count(); -#define WAY_POINT(name) {uint64_t delta = misc_utils::get_tick_count()-_____way_point_time; LOG_PRINT("Way point " << name << ": " << delta, LOG_LEVEL_2);_____way_point_time = misc_utils::get_tick_count();} -#define WAY_POINT2(name, avrg_obj) {uint64_t delta = misc_utils::get_tick_count()-_____way_point_time; avrg_obj.push(delta); LOG_PRINT("Way point " << name << ": " << delta, LOG_LEVEL_2);_____way_point_time = misc_utils::get_tick_count();} +#define START_WAY_POINTS() uint64_t _____way_point_time = epee::misc_utils::get_tick_count(); +#define WAY_POINT(name) {uint64_t delta = epee::misc_utils::get_tick_count()-_____way_point_time; LOG_PRINT("Way point " << name << ": " << delta, LOG_LEVEL_2);_____way_point_time = misc_utils::get_tick_count();} +#define WAY_POINT2(name, avrg_obj) {uint64_t delta = epee::misc_utils::get_tick_count()-_____way_point_time; avrg_obj.push(delta); LOG_PRINT("Way point " << name << ": " << delta, LOG_LEVEL_2);_____way_point_time = misc_utils::get_tick_count();} -#define TIME_MEASURE_START(var_name) uint64_t var_name = misc_utils::get_tick_count(); -#define TIME_MEASURE_FINISH(var_name) var_name = misc_utils::get_tick_count() - var_name; +#define TIME_MEASURE_START(var_name) uint64_t var_name = epee::misc_utils::get_tick_count(); +#define TIME_MEASURE_FINISH(var_name) var_name = epee::misc_utils::get_tick_count() - var_name; namespace profile_tools { diff --git a/contrib/epee/include/serialization/keyvalue_serialization.h b/contrib/epee/include/serialization/keyvalue_serialization.h index 27fb0f1e..bf2c8dac 100644 --- a/contrib/epee/include/serialization/keyvalue_serialization.h +++ b/contrib/epee/include/serialization/keyvalue_serialization.h @@ -31,6 +31,8 @@ #include "misc_log_ex.h" #include "enableable.h" #include "keyvalue_serialization_overloads.h" +#include "serialization/serialization.h" + namespace epee { /************************************************************************/ @@ -41,12 +43,12 @@ public: \ template \ bool store( t_storage& st, typename t_storage::hsection hparent_section = nullptr) const\ {\ - return serialize_map(*this, st, hparent_section);\ + return serialize_map(*this, st, hparent_section);\ }\ template \ bool _load( t_storage& stg, typename t_storage::hsection hparent_section = nullptr)\ {\ - return serialize_map(*this, stg, hparent_section);\ + return serialize_map(*this, stg, hparent_section);\ }\ template \ bool load( t_storage& stg, typename t_storage::hsection hparent_section = nullptr)\ diff --git a/contrib/epee/include/storages/portable_storage.h b/contrib/epee/include/storages/portable_storage.h index c244dac1..bbfe5f85 100644 --- a/contrib/epee/include/storages/portable_storage.h +++ b/contrib/epee/include/storages/portable_storage.h @@ -83,7 +83,7 @@ namespace epee bool load_from_binary(const binarybuffer& target); 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 dump_as_json(std::string& targetObj, size_t indent = 0, bool insert_newlines = true); bool load_from_json(const std::string& source); private: @@ -106,17 +106,17 @@ namespace epee #pragma pack(pop) }; inline - bool portable_storage::dump_as_json(std::string& buff, size_t indent) + bool portable_storage::dump_as_json(std::string& buff, size_t indent, bool insert_newlines) { TRY_ENTRY(); std::stringstream ss; - epee::serialization::dump_as_json(ss, m_root, indent); + epee::serialization::dump_as_json(ss, m_root, indent, insert_newlines); buff = ss.str(); return true; CATCH_ENTRY("portable_storage::dump_as_json", false) } inline - bool portable_storage::load_from_json(const std::string& source) + bool portable_storage::load_from_json(const std::string& source) { TRY_ENTRY(); return json::load_from_json(source, *this); @@ -124,13 +124,13 @@ namespace epee } template - bool portable_storage::dump_as_xml(std::string& targetObj, const std::string& root_name) + bool portable_storage::dump_as_xml(std::string& targetObj, const std::string& root_name) { 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) + bool portable_storage::store_to_binary(binarybuffer& target) { TRY_ENTRY(); std::stringstream ss; @@ -145,7 +145,7 @@ namespace epee CATCH_ENTRY("portable_storage::store_to_binary", false) } inline - bool portable_storage::load_from_binary(const binarybuffer& source) + bool portable_storage::load_from_binary(const binarybuffer& source) { m_root.m_entries.clear(); if(source.size() < sizeof(storage_block_header)) @@ -174,7 +174,7 @@ namespace epee } //--------------------------------------------------------------------------------------------------------------- inline - hsection portable_storage::open_section(const std::string& section_name, hsection hparent_section, bool create_if_notexist) + hsection portable_storage::open_section(const std::string& section_name, hsection hparent_section, bool create_if_notexist) { TRY_ENTRY(); hparent_section = hparent_section ? hparent_section:&m_root; @@ -238,7 +238,7 @@ namespace epee } //--------------------------------------------------------------------------------------------------------------- template - bool portable_storage::set_value(const std::string& value_name, const t_value& v, hsection hparent_section) + bool portable_storage::set_value(const std::string& value_name, const t_value& v, hsection hparent_section) { BOOST_MPL_ASSERT(( boost::mpl::contains::type, t_value> )); TRY_ENTRY(); @@ -345,7 +345,7 @@ namespace epee template - bool portable_storage::get_next_value(harray hval_array, t_value& target) + bool portable_storage::get_next_value(harray hval_array, t_value& target) { BOOST_MPL_ASSERT(( boost::mpl::contains )); //TRY_ENTRY(); @@ -462,7 +462,7 @@ namespace epee } //--------------------------------------------------------------------------------------------------------------- inline - bool portable_storage::insert_next_section(harray hsec_array, hsection& hinserted_childsection) + bool portable_storage::insert_next_section(harray hsec_array, hsection& hinserted_childsection) { TRY_ENTRY(); CHECK_AND_ASSERT(hsec_array, false); @@ -476,4 +476,4 @@ namespace epee } //--------------------------------------------------------------------------------------------------------------- } -} \ No newline at end of file +} diff --git a/contrib/epee/include/storages/portable_storage_template_helper.h b/contrib/epee/include/storages/portable_storage_template_helper.h index 2163cb87..008f4432 100644 --- a/contrib/epee/include/storages/portable_storage_template_helper.h +++ b/contrib/epee/include/storages/portable_storage_template_helper.h @@ -25,6 +25,9 @@ // #pragma once + +#include + #include "parserse_base_utils.h" #include "portable_storage.h" #include "file_io_utils.h" @@ -56,19 +59,19 @@ namespace epee } //----------------------------------------------------------------------------------------------------------- template - bool store_t_to_json(t_struct& str_in, std::string& json_buff, size_t indent = 0) + bool store_t_to_json(t_struct& str_in, std::string& json_buff, size_t indent = 0, bool insert_newlines = true) { portable_storage ps; str_in.store(ps); - ps.dump_as_json(json_buff, indent); + ps.dump_as_json(json_buff, indent, insert_newlines); return true; } //----------------------------------------------------------------------------------------------------------- template - std::string store_t_to_json(t_struct& str_in, size_t indent = 0) + std::string store_t_to_json(t_struct& str_in, size_t indent = 0, bool insert_newlines = true) { std::string json_buff; - store_t_to_json(str_in, json_buff, indent); + store_t_to_json(str_in, json_buff, indent, insert_newlines); return std::move(json_buff); } //----------------------------------------------------------------------------------------------------------- diff --git a/contrib/epee/include/storages/portable_storage_to_json.h b/contrib/epee/include/storages/portable_storage_to_json.h index aff85b20..e3fdcec2 100644 --- a/contrib/epee/include/storages/portable_storage_to_json.h +++ b/contrib/epee/include/storages/portable_storage_to_json.h @@ -30,6 +30,7 @@ #include "misc_language.h" #include "portable_storage_base.h" +#include "parserse_base_utils.h" namespace epee { @@ -37,21 +38,21 @@ namespace epee { template - void dump_as_json(t_stream& strm, const array_entry& ae, size_t indent); + void dump_as_json(t_stream& strm, const array_entry& ae, size_t indent, bool insert_newlines); template - void dump_as_json(t_stream& strm, const storage_entry& se, size_t indent); + void dump_as_json(t_stream& strm, const storage_entry& se, size_t indent, bool insert_newlines); template - void dump_as_json(t_stream& strm, const std::string& v, size_t indent); + void dump_as_json(t_stream& strm, const std::string& v, size_t indent, bool insert_newlines); template - void dump_as_json(t_stream& strm, const int8_t& v, size_t indent); + void dump_as_json(t_stream& strm, const int8_t& v, size_t indent, bool insert_newlines); template - void dump_as_json(t_stream& strm, const uint8_t& v, size_t indent); + void dump_as_json(t_stream& strm, const uint8_t& v, size_t indent, bool insert_newlines); template - void dump_as_json(t_stream& strm, const bool& v, size_t indent); + void dump_as_json(t_stream& strm, const bool& v, size_t indent, bool insert_newlines); template - void dump_as_json(t_stream& strm, const t_type& v, size_t indent); + void dump_as_json(t_stream& strm, const t_type& v, size_t indent, bool insert_newlines); template - void dump_as_json(t_stream& strm, const section& sec, size_t indent); + void dump_as_json(t_stream& strm, const section& sec, size_t indent, bool insert_newlines); inline std::string make_indent(size_t indent) @@ -64,7 +65,11 @@ namespace epee { t_stream& m_strm; size_t m_indent; - array_entry_store_to_json_visitor(t_stream& strm, size_t indent):m_strm(strm), m_indent(indent){} + bool m_insert_newlines; + array_entry_store_to_json_visitor(t_stream& strm, size_t indent, + bool insert_newlines = true) + : m_strm(strm), m_indent(indent), m_insert_newlines(insert_newlines) + {} template void operator()(const array_entry_t& a) @@ -75,7 +80,7 @@ namespace epee auto last_it = --a.m_array.end(); for(auto it = a.m_array.begin(); it != a.m_array.end(); it++) { - dump_as_json(m_strm, *it, m_indent); + dump_as_json(m_strm, *it, m_indent, m_insert_newlines); if(it != last_it) m_strm << ","; } @@ -89,50 +94,53 @@ namespace epee { t_stream& m_strm; size_t m_indent; - storage_entry_store_to_json_visitor(t_stream& strm, size_t indent):m_strm(strm), m_indent(indent) + bool m_insert_newlines; + storage_entry_store_to_json_visitor(t_stream& strm, size_t indent, + bool insert_newlines = true) + : m_strm(strm), m_indent(indent), m_insert_newlines(insert_newlines) {} //section, array_entry template void operator()(const visited_type& v) { - dump_as_json(m_strm, v, m_indent); + dump_as_json(m_strm, v, m_indent, m_insert_newlines); } }; template - void dump_as_json(t_stream& strm, const array_entry& ae, size_t indent) + void dump_as_json(t_stream& strm, const array_entry& ae, size_t indent, bool insert_newlines) { - array_entry_store_to_json_visitor aesv(strm, indent); + array_entry_store_to_json_visitor aesv(strm, indent, insert_newlines); boost::apply_visitor(aesv, ae); } template - void dump_as_json(t_stream& strm, const storage_entry& se, size_t indent) + void dump_as_json(t_stream& strm, const storage_entry& se, size_t indent, bool insert_newlines) { - storage_entry_store_to_json_visitor sv(strm, indent); + storage_entry_store_to_json_visitor sv(strm, indent, insert_newlines); boost::apply_visitor(sv, se); } template - void dump_as_json(t_stream& strm, const std::string& v, size_t indent) + void dump_as_json(t_stream& strm, const std::string& v, size_t indent, bool insert_newlines) { strm << "\"" << misc_utils::parse::transform_to_escape_sequence(v) << "\""; } template - void dump_as_json(t_stream& strm, const int8_t& v, size_t indent) + void dump_as_json(t_stream& strm, const int8_t& v, size_t indent, bool insert_newlines) { strm << static_cast(v); } template - void dump_as_json(t_stream& strm, const uint8_t& v, size_t indent) + void dump_as_json(t_stream& strm, const uint8_t& v, size_t indent, bool insert_newlines) { strm << static_cast(v); } template - void dump_as_json(t_stream& strm, const bool& v, size_t indent) + void dump_as_json(t_stream& strm, const bool& v, size_t indent, bool insert_newlines) { if(v) strm << "true"; @@ -143,16 +151,17 @@ namespace epee template - void dump_as_json(t_stream& strm, const t_type& v, size_t indent) + void dump_as_json(t_stream& strm, const t_type& v, size_t indent, bool insert_newlines) { strm << v; } template - void dump_as_json(t_stream& strm, const section& sec, size_t indent) + void dump_as_json(t_stream& strm, const section& sec, size_t indent, bool insert_newlines) { size_t local_indent = indent + 1; - strm << "{\r\n"; + std::string newline = insert_newlines ? "\r\n" : ""; + strm << "{" << newline; std::string indent_str = make_indent(local_indent); if(sec.m_entries.size()) { @@ -160,10 +169,10 @@ namespace epee for(auto it = sec.m_entries.begin(); it!= sec.m_entries.end();it++) { strm << indent_str << "\"" << misc_utils::parse::transform_to_escape_sequence(it->first) << "\"" << ": "; - dump_as_json(strm, it->second, local_indent); + dump_as_json(strm, it->second, local_indent, insert_newlines); if(it_last != it) strm << ","; - strm << "\r\n"; + strm << newline; } } strm << make_indent(indent) << "}"; diff --git a/contrib/epee/include/string_tools.h b/contrib/epee/include/string_tools.h index 4cc88418..8289ee0b 100644 --- a/contrib/epee/include/string_tools.h +++ b/contrib/epee/include/string_tools.h @@ -32,6 +32,7 @@ //#include #include #include +#include //#include #include #include diff --git a/src/cryptonote_core/blockchain_storage.h b/src/cryptonote_core/blockchain_storage.h index 3a69d616..b1fb5df4 100644 --- a/src/cryptonote_core/blockchain_storage.h +++ b/src/cryptonote_core/blockchain_storage.h @@ -13,6 +13,8 @@ #include #include +#include "syncobj.h" +#include "string_tools.h" #include "tx_pool.h" #include "cryptonote_basic.h" #include "common/util.h" @@ -119,7 +121,7 @@ namespace cryptonote missed_bs.push_back(bl_id); else { - CHECK_AND_ASSERT_MES(it->second < m_blocks.size(), false, "Internal error: bl_id=" << string_tools::pod_to_hex(bl_id) + CHECK_AND_ASSERT_MES(it->second < m_blocks.size(), false, "Internal error: bl_id=" << epee::string_tools::pod_to_hex(bl_id) << " have index record with offset="<second<< ", bigger then m_blocks.size()=" << m_blocks.size()); blocks.push_back(m_blocks[it->second].bl); } @@ -163,7 +165,7 @@ namespace cryptonote typedef std::map>> outputs_container; //crypto::hash - tx hash, size_t - index of out in transaction tx_memory_pool& m_tx_pool; - critical_section m_blockchain_lock; // TODO: add here reader/writer lock + epee::critical_section m_blockchain_lock; // TODO: add here reader/writer lock // main chain blocks_container m_blocks; // height -> block_extended_info @@ -301,7 +303,7 @@ namespace cryptonote return false; } transactions_container::iterator tx_it = m_transactions.find(amount_outs_vec[i].first); - CHECK_AND_ASSERT_MES(tx_it != m_transactions.end(), false, "Wrong transaction id in output indexes: " <second.tx.vout.size(), false, "Wrong index in transaction outputs: " << amount_outs_vec[i].second << ", expected less then " << tx_it->second.tx.vout.size()); if(!vis.handle_output(tx_it->second.tx, tx_it->second.tx.vout[amount_outs_vec[i].second])) diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h index c298451e..cde52d5a 100644 --- a/src/cryptonote_core/cryptonote_core.h +++ b/src/cryptonote_core/cryptonote_core.h @@ -115,13 +115,13 @@ namespace cryptonote tx_memory_pool m_mempool; blockchain_storage m_blockchain_storage; i_cryptonote_protocol* m_pprotocol; - critical_section m_incoming_tx_lock; + epee::critical_section m_incoming_tx_lock; //m_miner and m_miner_addres are probably temporary here miner m_miner; account_public_address m_miner_address; std::string m_config_folder; cryptonote_protocol_stub m_protocol_stub; - math_helper::once_a_time_seconds<60*60*12, false> m_store_blockchain_interval; + epee::math_helper::once_a_time_seconds<60*60*12, false> m_store_blockchain_interval; friend class tx_validate_inputs; std::atomic m_starter_message_showed; }; diff --git a/src/cryptonote_core/miner.h b/src/cryptonote_core/miner.h index 84aa2788..61c063dd 100644 --- a/src/cryptonote_core/miner.h +++ b/src/cryptonote_core/miner.h @@ -63,7 +63,7 @@ namespace cryptonote volatile uint32_t m_stop; - ::critical_section m_template_lock; + epee::critical_section m_template_lock; block m_template; std::atomic m_template_no; std::atomic m_starter_nonce; @@ -72,21 +72,21 @@ namespace cryptonote volatile uint32_t m_thread_index; volatile uint32_t m_threads_total; std::atomic m_pausers_count; - ::critical_section m_miners_count_lock; + epee::critical_section m_miners_count_lock; std::list m_threads; - ::critical_section m_threads_lock; + epee::critical_section m_threads_lock; i_miner_handler* m_phandler; account_public_address m_mine_address; - math_helper::once_a_time_seconds<5> m_update_block_template_interval; - math_helper::once_a_time_seconds<2> m_update_merge_hr_interval; + epee::math_helper::once_a_time_seconds<5> m_update_block_template_interval; + epee::math_helper::once_a_time_seconds<2> m_update_merge_hr_interval; std::vector m_extra_messages; miner_config m_config; std::string m_config_folder_path; std::atomic m_last_hr_merge_time; std::atomic m_hashes; std::atomic m_current_hash_rate; - critical_section m_last_hash_rates_lock; + epee::critical_section m_last_hash_rates_lock; std::list m_last_hash_rates; bool m_do_print_hashrate; bool m_do_mining; diff --git a/src/cryptonote_core/tx_pool.h b/src/cryptonote_core/tx_pool.h index 3978dfb9..26d273aa 100644 --- a/src/cryptonote_core/tx_pool.h +++ b/src/cryptonote_core/tx_pool.h @@ -4,8 +4,6 @@ #pragma once #include "include_base_utils.h" -using namespace epee; - #include #include diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.h b/src/cryptonote_protocol/cryptonote_protocol_handler.h index 178ec2eb..80538677 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.h +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.h @@ -81,7 +81,7 @@ namespace cryptonote template bool post_notify(typename t_parametr::request& arg, cryptonote_connection_context& context) { - LOG_PRINT_L2("[" << net_utils::print_connection_context_short(context) << "] post " << typeid(t_parametr).name() << " -->"); + LOG_PRINT_L2("[" << epee::net_utils::print_connection_context_short(context) << "] post " << typeid(t_parametr).name() << " -->"); std::string blob; epee::serialization::store_t_to_binary(arg, blob); return m_p2p->invoke_notify_to_peer(t_parametr::ID, blob, context); @@ -90,7 +90,7 @@ namespace cryptonote template bool relay_post_notify(typename t_parametr::request& arg, cryptonote_connection_context& exlude_context) { - LOG_PRINT_L2("[" << net_utils::print_connection_context_short(exlude_context) << "] post relay " << typeid(t_parametr).name() << " -->"); + LOG_PRINT_L2("[" << epee::net_utils::print_connection_context_short(exlude_context) << "] post relay " << typeid(t_parametr).name() << " -->"); std::string arg_buff; epee::serialization::store_t_to_binary(arg, arg_buff); return m_p2p->relay_notify_to_all(t_parametr::ID, arg_buff, exlude_context); diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index b9f9a8fb..2584f109 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -81,7 +81,7 @@ namespace cryptonote m_p2p->for_each_connection([&](const connection_context& cntxt, nodetool::peerid_type peer_id) { ss << std::setw(25) << std::left << std::string(cntxt.m_is_income ? " [INC]":"[OUT]") + - string_tools::get_ip_string_from_int32(cntxt.m_remote_ip) + ":" + std::to_string(cntxt.m_remote_port) + epee::string_tools::get_ip_string_from_int32(cntxt.m_remote_ip) + ":" + std::to_string(cntxt.m_remote_port) << std::setw(20) << std::hex << peer_id << std::setw(25) << std::to_string(cntxt.m_recv_cnt)+ "(" + std::to_string(time(NULL) - cntxt.m_last_recv) + ")" + "/" + std::to_string(cntxt.m_send_cnt) + "(" + std::to_string(time(NULL) - cntxt.m_last_send) + ")" << std::setw(25) << get_protocol_state_string(cntxt.m_state) @@ -257,7 +257,7 @@ namespace cryptonote if(!parse_and_validate_block_from_blob(block_entry.block, b)) { LOG_ERROR_CCONTEXT("sent wrong block: failed to parse and validate block: \r\n" - << string_tools::buff_to_hex_nodelimer(block_entry.block) << "\r\n dropping connection"); + << epee::string_tools::buff_to_hex_nodelimer(block_entry.block) << "\r\n dropping connection"); m_p2p->drop_connection(context); return 1; } @@ -277,14 +277,14 @@ namespace cryptonote auto req_it = context.m_requested_objects.find(get_block_hash(b)); if(req_it == context.m_requested_objects.end()) { - LOG_ERROR_CCONTEXT("sent wrong NOTIFY_RESPONSE_GET_OBJECTS: block with id=" << string_tools::pod_to_hex(get_blob_hash(block_entry.block)) + LOG_ERROR_CCONTEXT("sent wrong NOTIFY_RESPONSE_GET_OBJECTS: block with id=" << epee::string_tools::pod_to_hex(get_blob_hash(block_entry.block)) << " wasn't requested, dropping connection"); m_p2p->drop_connection(context); return 1; } if(b.tx_hashes.size() != block_entry.txs.size()) { - LOG_ERROR_CCONTEXT("sent wrong NOTIFY_RESPONSE_GET_OBJECTS: block with id=" << string_tools::pod_to_hex(get_blob_hash(block_entry.block)) + LOG_ERROR_CCONTEXT("sent wrong NOTIFY_RESPONSE_GET_OBJECTS: block with id=" << epee::string_tools::pod_to_hex(get_blob_hash(block_entry.block)) << ", tx_hashes.size()=" << b.tx_hashes.size() << " mismatch with block_complete_entry.m_txs.size()=" << block_entry.txs.size() << ", dropping connection"); m_p2p->drop_connection(context); return 1; @@ -303,7 +303,7 @@ namespace cryptonote { m_core.pause_mine(); - misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler( + epee::misc_utils::auto_scope_leave_caller scope_exit_handler = epee::misc_utils::create_scope_leave_handler( boost::bind(&t_core::resume_mine, &m_core)); BOOST_FOREACH(const block_complete_entry& block_entry, arg.blocks) @@ -317,7 +317,7 @@ namespace cryptonote if(tvc.m_verifivation_failed) { LOG_ERROR_CCONTEXT("transaction verification failed on NOTIFY_RESPONSE_GET_OBJECTS, \r\ntx_id = " - << string_tools::pod_to_hex(get_blob_hash(tx_blob)) << ", dropping connection"); + << epee::string_tools::pod_to_hex(get_blob_hash(tx_blob)) << ", dropping connection"); m_p2p->drop_connection(context); return 1; } @@ -411,7 +411,7 @@ namespace cryptonote << "\r\nm_remote_blockchain_height=" << context.m_remote_blockchain_height << "\r\nm_needed_objects.size()=" << context.m_needed_objects.size() << "\r\nm_requested_objects.size()=" << context.m_requested_objects.size() - << "\r\non connection [" << net_utils::print_connection_context_short(context)<< "]"); + << "\r\non connection [" << epee::net_utils::print_connection_context_short(context)<< "]"); context.m_state = cryptonote_connection_context::state_normal; LOG_PRINT_CCONTEXT_GREEN(" SYNCHRONIZED OK", LOG_LEVEL_0); @@ -467,7 +467,7 @@ namespace cryptonote if(!m_core.have_block(arg.m_block_ids.front())) { LOG_ERROR_CCONTEXT("sent m_block_ids starting from unknown id: " - << string_tools::pod_to_hex(arg.m_block_ids.front()) << " , dropping connection"); + << epee::string_tools::pod_to_hex(arg.m_block_ids.front()) << " , dropping connection"); m_p2p->drop_connection(context); return 1; } diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h index 5cfdc765..5602a548 100644 --- a/src/p2p/net_node.h +++ b/src/p2p/net_node.h @@ -25,8 +25,6 @@ #include "math_helper.h" #include "net_node_common.h" -using namespace epee; - PUSH_WARNINGS DISABLE_VS_WARNINGS(4355) @@ -39,7 +37,7 @@ namespace nodetool }; template - class node_server: public levin::levin_commands_handler >, + class node_server: public epee::levin::levin_commands_handler >, public i_p2p_endpoint { struct by_conn_id{}; @@ -126,7 +124,7 @@ namespace nodetool bool parse_peer_from_string(nodetool::net_address& pe, const std::string& node_addr); bool handle_command_line(const boost::program_options::variables_map& vm); bool idle_worker(); - bool handle_remote_peerlist(const std::list& peerlist, time_t local_time, const net_utils::connection_context_base& context); + bool handle_remote_peerlist(const std::list& peerlist, time_t local_time, const epee::net_utils::connection_context_base& context); bool get_local_node_data(basic_node_data& node_data); //bool get_local_handshake_data(handshake_data& hshd); @@ -136,7 +134,7 @@ namespace nodetool bool connections_maker(); bool peer_sync_idle_maker(); bool do_handshake_with_peer(peerid_type& pi, p2p_connection_context& context, bool just_take_peerlist = false); - bool do_peer_timed_sync(const net_utils::connection_context_base& context, peerid_type peer_id); + bool do_peer_timed_sync(const epee::net_utils::connection_context_base& context, peerid_type peer_id); bool make_new_connection_from_peerlist(bool use_white_list); bool try_to_connect_and_handshake_with_new_peer(const net_address& na, bool just_take_peerlist = false, uint64_t last_seen_stamp = 0, bool white = true); @@ -152,7 +150,7 @@ namespace nodetool std::string print_connections_container(); - typedef net_utils::boosted_tcp_server > net_server; + typedef epee::net_utils::boosted_tcp_server > net_server; struct config { @@ -182,9 +180,9 @@ namespace nodetool t_payload_net_handler& m_payload_handler; peerlist_manager m_peerlist; - math_helper::once_a_time_seconds m_peer_handshake_idle_maker_interval; - math_helper::once_a_time_seconds<1> m_connections_maker_interval; - math_helper::once_a_time_seconds<60*30, false> m_peerlist_store_interval; + epee::math_helper::once_a_time_seconds m_peer_handshake_idle_maker_interval; + epee::math_helper::once_a_time_seconds<1> m_connections_maker_interval; + epee::math_helper::once_a_time_seconds<60*30, false> m_peerlist_store_interval; std::string m_bind_ip; std::string m_port; diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 479f1f79..401f48bb 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -98,7 +98,7 @@ namespace nodetool template bool node_server::parse_peer_from_string(nodetool::net_address& pe, const std::string& node_addr) { - return string_tools::parse_peer_from_string(pe.ip, pe.port, node_addr); + return epee::string_tools::parse_peer_from_string(pe.ip, pe.port, node_addr); } //----------------------------------------------------------------------------------- template @@ -363,23 +363,23 @@ namespace nodetool get_local_node_data(arg.node_data); m_payload_handler.get_payload_sync_data(arg.payload_data); - simple_event ev; + epee::simple_event ev; std::atomic hsh_result(false); - bool r = net_utils::async_invoke_remote_command2(context_.m_connection_id, COMMAND_HANDSHAKE::ID, arg, m_net_server.get_config_object(), + bool r = epee::net_utils::async_invoke_remote_command2(context_.m_connection_id, COMMAND_HANDSHAKE::ID, arg, m_net_server.get_config_object(), [this, &pi, &ev, &hsh_result, &just_take_peerlist](int code, const typename COMMAND_HANDSHAKE::response& rsp, p2p_connection_context& context) { - misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler([&](){ev.raise();}); + epee::misc_utils::auto_scope_leave_caller scope_exit_handler = epee::misc_utils::create_scope_leave_handler([&](){ev.raise();}); if(code < 0) { - LOG_PRINT_CC_RED(context, "COMMAND_HANDSHAKE invoke failed. (" << code << ", " << levin::get_err_descr(code) << ")", LOG_LEVEL_1); + LOG_PRINT_CC_RED(context, "COMMAND_HANDSHAKE invoke failed. (" << code << ", " << epee::levin::get_err_descr(code) << ")", LOG_LEVEL_1); return; } if(rsp.node_data.network_id != BYTECOIN_NETWORK) { - LOG_ERROR_CCONTEXT("COMMAND_HANDSHAKE Failed, wrong network! (" << string_tools::get_str_from_guid_a(rsp.node_data.network_id) << "), closing connection."); + LOG_ERROR_CCONTEXT("COMMAND_HANDSHAKE Failed, wrong network! (" << epee::string_tools::get_str_from_guid_a(rsp.node_data.network_id) << "), closing connection."); return; } @@ -429,17 +429,17 @@ namespace nodetool } //----------------------------------------------------------------------------------- template - bool node_server::do_peer_timed_sync(const net_utils::connection_context_base& context_, peerid_type peer_id) + bool node_server::do_peer_timed_sync(const epee::net_utils::connection_context_base& context_, peerid_type peer_id) { typename COMMAND_TIMED_SYNC::request arg = AUTO_VAL_INIT(arg); m_payload_handler.get_payload_sync_data(arg.payload_data); - bool r = net_utils::async_invoke_remote_command2(context_.m_connection_id, COMMAND_TIMED_SYNC::ID, arg, m_net_server.get_config_object(), + bool r = epee::net_utils::async_invoke_remote_command2(context_.m_connection_id, COMMAND_TIMED_SYNC::ID, arg, m_net_server.get_config_object(), [this](int code, const typename COMMAND_TIMED_SYNC::response& rsp, p2p_connection_context& context) { if(code < 0) { - LOG_PRINT_CC_RED(context, "COMMAND_TIMED_SYNC invoke failed. (" << code << ", " << levin::get_err_descr(code) << ")", LOG_LEVEL_1); + LOG_PRINT_CC_RED(context, "COMMAND_TIMED_SYNC invoke failed. (" << code << ", " << epee::levin::get_err_descr(code) << ")", LOG_LEVEL_1); return; } @@ -524,14 +524,14 @@ namespace nodetool template bool node_server::try_to_connect_and_handshake_with_new_peer(const net_address& na, bool just_take_peerlist, uint64_t last_seen_stamp, bool white) { - LOG_PRINT_L1("Connecting to " << string_tools::get_ip_string_from_int32(na.ip) << ":" - << string_tools::num_to_string_fast(na.port) << "(white=" << white << ", last_seen: " - << (last_seen_stamp?misc_utils::get_time_interval_string(time(NULL) - last_seen_stamp):"never") + LOG_PRINT_L1("Connecting to " << epee::string_tools::get_ip_string_from_int32(na.ip) << ":" + << epee::string_tools::num_to_string_fast(na.port) << "(white=" << white << ", last_seen: " + << (last_seen_stamp ? epee::misc_utils::get_time_interval_string(time(NULL) - last_seen_stamp):"never") << ")..."); typename net_server::t_connection_context con = AUTO_VAL_INIT(con); - bool res = m_net_server.connect(string_tools::get_ip_string_from_int32(na.ip), - string_tools::num_to_string_fast(na.port), + bool res = m_net_server.connect(epee::string_tools::get_ip_string_from_int32(na.ip), + epee::string_tools::num_to_string_fast(na.port), m_config.m_net_config.connection_timeout, con); @@ -539,8 +539,8 @@ namespace nodetool { bool is_priority = is_priority_node(na); LOG_PRINT_CC_PRIORITY_NODE(is_priority, con, "Connect failed to " - << string_tools::get_ip_string_from_int32(na.ip) - << ":" << string_tools::num_to_string_fast(na.port) + << epee::string_tools::get_ip_string_from_int32(na.ip) + << ":" << epee::string_tools::num_to_string_fast(na.port) /*<< ", try " << try_count*/); //m_peerlist.set_peer_unreachable(pe); return false; @@ -553,8 +553,8 @@ namespace nodetool { bool is_priority = is_priority_node(na); LOG_PRINT_CC_PRIORITY_NODE(is_priority, con, "Failed to HANDSHAKE with peer " - << string_tools::get_ip_string_from_int32(na.ip) - << ":" << string_tools::num_to_string_fast(na.port) + << epee::string_tools::get_ip_string_from_int32(na.ip) + << ":" << epee::string_tools::num_to_string_fast(na.port) /*<< ", try " << try_count*/); return false; } @@ -612,7 +612,10 @@ namespace nodetool if(is_peer_used(pe)) continue; - LOG_PRINT_L1("Selected peer: " << pe.id << " " << string_tools::get_ip_string_from_int32(pe.adr.ip) << ":" << boost::lexical_cast(pe.adr.port) << "[white=" << use_white_list << "] last_seen: " << (pe.last_seen ? misc_utils::get_time_interval_string(time(NULL) - pe.last_seen) : "never")); + LOG_PRINT_L1("Selected peer: " << pe.id << " " << epee::string_tools::get_ip_string_from_int32(pe.adr.ip) + << ":" << boost::lexical_cast(pe.adr.port) + << "[white=" << use_white_list + << "] last_seen: " << (pe.last_seen ? epee::misc_utils::get_time_interval_string(time(NULL) - pe.last_seen) : "never")); if(!try_to_connect_and_handshake_with_new_peer(pe.adr, false, pe.last_seen, use_white_list)) continue; @@ -728,7 +731,7 @@ namespace nodetool bool node_server::peer_sync_idle_maker() { LOG_PRINT_L2("STARTED PEERLIST IDLE HANDSHAKE"); - typedef std::list > local_connects_type; + typedef std::list > local_connects_type; local_connects_type cncts; m_net_server.get_config_object().foreach_connection([&](const p2p_connection_context& cntxt) { @@ -755,7 +758,7 @@ namespace nodetool { if(be.last_seen > local_time) { - LOG_PRINT_RED_L0("FOUND FUTURE peerlist for entry " << string_tools::get_ip_string_from_int32(be.adr.ip) << ":" << be.adr.port << " last_seen: " << be.last_seen << ", local_time(on remote node):" << local_time); + LOG_PRINT_RED_L0("FOUND FUTURE peerlist for entry " << epee::string_tools::get_ip_string_from_int32(be.adr.ip) << ":" << be.adr.port << " last_seen: " << be.last_seen << ", local_time(on remote node):" << local_time); return false; } be.last_seen += delta; @@ -764,7 +767,7 @@ namespace nodetool } //----------------------------------------------------------------------------------- template - bool node_server::handle_remote_peerlist(const std::list& peerlist, time_t local_time, const net_utils::connection_context_base& context) + bool node_server::handle_remote_peerlist(const std::list& peerlist, time_t local_time, const epee::net_utils::connection_context_base& context) { int64_t delta = 0; std::list peerlist_ = peerlist; @@ -812,7 +815,7 @@ namespace nodetool return false; } crypto::public_key pk = AUTO_VAL_INIT(pk); - string_tools::hex_to_pod(P2P_STAT_TRUSTED_PUB_KEY, pk); + epee::string_tools::hex_to_pod(P2P_STAT_TRUSTED_PUB_KEY, pk); crypto::hash h = tools::get_proof_of_trust_hash(tr); if(!crypto::check_signature(h, pk, tr.sign)) { @@ -933,8 +936,8 @@ namespace nodetool uint32_t actual_ip = context.m_remote_ip; if(!m_peerlist.is_ip_allowed(actual_ip)) return false; - std::string ip = string_tools::get_ip_string_from_int32(actual_ip); - std::string port = string_tools::num_to_string_fast(node_data.my_port); + std::string ip = epee::string_tools::get_ip_string_from_int32(actual_ip); + std::string port = epee::string_tools::num_to_string_fast(node_data.my_port); peerid_type pr = node_data.peer_id; bool r = m_net_server.connect_async(ip, port, m_config.m_net_config.ping_connection_timeout, [cb, /*context,*/ ip, port, pr, this]( const typename net_server::t_connection_context& ping_context, @@ -952,12 +955,12 @@ namespace nodetool std::string port_=port; peerid_type pr_ = pr; auto cb_ = cb;*/ - bool inv_call_res = net_utils::async_invoke_remote_command2(ping_context.m_connection_id, COMMAND_PING::ID, req, m_net_server.get_config_object(), + bool inv_call_res = epee::net_utils::async_invoke_remote_command2(ping_context.m_connection_id, COMMAND_PING::ID, req, m_net_server.get_config_object(), [=](int code, const COMMAND_PING::response& rsp, p2p_connection_context& context) { if(code <= 0) { - LOG_PRINT_CC_L2(ping_context, "Failed to invoke COMMAND_PING to " << ip << ":" << port << "(" << code << ", " << levin::get_err_descr(code) << ")"); + LOG_PRINT_CC_L2(ping_context, "Failed to invoke COMMAND_PING to " << ip << ":" << port << "(" << code << ", " << epee::levin::get_err_descr(code) << ")"); return; } @@ -1009,7 +1012,7 @@ namespace nodetool if(arg.node_data.network_id != BYTECOIN_NETWORK) { - LOG_PRINT_CCONTEXT_L0("WRONG NETWORK AGENT CONNECTED! id=" << string_tools::get_str_from_guid_a(arg.node_data.network_id)); + LOG_PRINT_CCONTEXT_L0("WRONG NETWORK AGENT CONNECTED! id=" << epee::string_tools::get_str_from_guid_a(arg.node_data.network_id)); drop_connection(context); return 1; } @@ -1051,7 +1054,7 @@ namespace nodetool time(&pe.last_seen); pe.id = peer_id_l; this->m_peerlist.append_with_peer_white(pe); - LOG_PRINT_CCONTEXT_L2("PING SUCCESS " << string_tools::get_ip_string_from_int32(context.m_remote_ip) << ":" << port_l); + LOG_PRINT_CCONTEXT_L2("PING SUCCESS " << epee::string_tools::get_ip_string_from_int32(context.m_remote_ip) << ":" << port_l); }); } @@ -1096,9 +1099,9 @@ namespace nodetool std::stringstream ss; m_net_server.get_config_object().foreach_connection([&](const p2p_connection_context& cntxt) { - ss << string_tools::get_ip_string_from_int32(cntxt.m_remote_ip) << ":" << cntxt.m_remote_port + ss << epee::string_tools::get_ip_string_from_int32(cntxt.m_remote_ip) << ":" << cntxt.m_remote_port << " \t\tpeer_id " << cntxt.peer_id - << " \t\tconn_id " << string_tools::get_str_from_guid_a(cntxt.m_connection_id) << (cntxt.m_is_income ? " INC":" OUT") + << " \t\tconn_id " << epee::string_tools::get_str_from_guid_a(cntxt.m_connection_id) << (cntxt.m_is_income ? " INC":" OUT") << std::endl; return true; }); @@ -1109,13 +1112,13 @@ namespace nodetool template void node_server::on_connection_new(p2p_connection_context& context) { - LOG_PRINT_L2("["<< net_utils::print_connection_context(context) << "] NEW CONNECTION"); + LOG_PRINT_L2("["<< epee::net_utils::print_connection_context(context) << "] NEW CONNECTION"); } //----------------------------------------------------------------------------------- template void node_server::on_connection_close(p2p_connection_context& context) { - LOG_PRINT_L2("["<< net_utils::print_connection_context(context) << "] CLOSE CONNECTION"); + LOG_PRINT_L2("["<< epee::net_utils::print_connection_context(context) << "] CLOSE CONNECTION"); } template diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 631fb5cf..f9e04bb8 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -383,7 +383,7 @@ namespace cryptonote return false; } res.blocktemplate_blob = string_tools::buff_to_hex_nodelimer(block_blob); - + res.status = CORE_RPC_STATUS_OK; return true; } //------------------------------------------------------------------------------------------------------------------------------ @@ -411,7 +411,7 @@ namespace cryptonote error_resp.message = "Block not accepted"; return false; } - res.status = "OK"; + res.status = CORE_RPC_STATUS_OK; return true; } //------------------------------------------------------------------------------------------------------------------------------ diff --git a/src/serialization/crypto.h b/src/serialization/crypto.h index 89d3c988..b7763ffe 100644 --- a/src/serialization/crypto.h +++ b/src/serialization/crypto.h @@ -2,6 +2,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include + #include "serialization.h" #include "debug_archive.h" #include "crypto/chacha8.h" diff --git a/src/serialization/serialization.h b/src/serialization/serialization.h index 62ea78a3..7024fdc0 100644 --- a/src/serialization/serialization.h +++ b/src/serialization/serialization.h @@ -10,6 +10,7 @@ #include #include #include +#include template struct is_blob_type { typedef boost::false_type type; }; diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 8b572a8e..4c6a7360 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -201,7 +201,7 @@ bool simple_wallet::set_log(const std::vector &args) return true; } uint16_t l = 0; - if(!string_tools::get_xtype_from_string(l, args[0])) + if(!epee::string_tools::get_xtype_from_string(l, args[0])) { fail_msg_writer() << "wrong number format, use: set_log "; return true; @@ -732,7 +732,7 @@ bool simple_wallet::transfer(const std::vector &args_) } size_t fake_outs_count; - if(!string_tools::get_xtype_from_string(fake_outs_count, local_args[0])) + if(!epee::string_tools::get_xtype_from_string(fake_outs_count, local_args[0])) { fail_msg_writer() << "mixin_count should be non-negative integer, got " << local_args[0]; return true; diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index a6c77180..2500553f 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -131,7 +131,7 @@ namespace cryptonote epee::console_handlers_binder m_cmd_binder; std::unique_ptr m_wallet; - net_utils::http::http_simple_client m_http_client; + epee::net_utils::http::http_simple_client m_http_client; refresh_progress_reporter_t m_refresh_progress_reporter; }; } diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index ecd9e51e..d2016f69 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -326,7 +326,7 @@ namespace tools req.amounts.push_back(it->amount()); } - bool r = net_utils::invoke_http_bin_remote_command2(m_daemon_address + "/getrandom_outs.bin", req, daemon_resp, m_http_client, 200000); + bool r = epee::net_utils::invoke_http_bin_remote_command2(m_daemon_address + "/getrandom_outs.bin", req, daemon_resp, m_http_client, 200000); THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "getrandom_outs.bin"); THROW_WALLET_EXCEPTION_IF(daemon_resp.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "getrandom_outs.bin"); THROW_WALLET_EXCEPTION_IF(daemon_resp.status != CORE_RPC_STATUS_OK, error::get_random_outs_error, daemon_resp.status); @@ -421,7 +421,7 @@ namespace tools COMMAND_RPC_SEND_RAW_TX::request req; req.tx_as_hex = epee::string_tools::buff_to_hex_nodelimer(tx_to_blob(tx)); COMMAND_RPC_SEND_RAW_TX::response daemon_send_resp; - r = net_utils::invoke_http_json_remote_command2(m_daemon_address + "/sendrawtransaction", req, daemon_send_resp, m_http_client, 200000); + r = epee::net_utils::invoke_http_json_remote_command2(m_daemon_address + "/sendrawtransaction", req, daemon_send_resp, m_http_client, 200000); THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "sendrawtransaction"); THROW_WALLET_EXCEPTION_IF(daemon_send_resp.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "sendrawtransaction"); THROW_WALLET_EXCEPTION_IF(daemon_send_resp.status != CORE_RPC_STATUS_OK, error::tx_rejected, tx, daemon_send_resp.status); diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index c575f927..e6f287d7 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -21,15 +21,15 @@ namespace int main(int argc, char* argv[]) { TRY_ENTRY(); - string_tools::set_module_name_and_folder(argv[0]); + epee::string_tools::set_module_name_and_folder(argv[0]); //set up logging options - log_space::get_set_log_detalisation_level(true, LOG_LEVEL_3); - log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_2); + epee::log_space::get_set_log_detalisation_level(true, LOG_LEVEL_3); + epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_2); - log_space::log_singletone::add_logger(LOGGER_FILE, - log_space::log_singletone::get_default_log_file().c_str(), - log_space::log_singletone::get_default_log_folder().c_str()); + epee::log_space::log_singletone::add_logger(LOGGER_FILE, + epee::log_space::log_singletone::get_default_log_file().c_str(), + epee::log_space::log_singletone::get_default_log_folder().c_str()); po::options_description desc_options("Allowed options"); command_line::add_arg(desc_options, command_line::arg_help);