Skip to content

Commit

Permalink
Merge branch 'release'
Browse files Browse the repository at this point in the history
  • Loading branch information
sowle committed Dec 27, 2019
2 parents 9a55a0b + 31d824a commit a819fce
Show file tree
Hide file tree
Showing 97 changed files with 5,727 additions and 1,323 deletions.
2 changes: 1 addition & 1 deletion contrib/db/libmdbx
116 changes: 116 additions & 0 deletions contrib/epee/include/misc_helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// Copyright (c) 2019, Zano Project
// Copyright (c) 2006-2019, Andrey N. Sabelnikov, www.sabelnikov.net
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Andrey N. Sabelnikov nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#pragma once

#define COMBINE1(X,Y) X##Y // helper macro
#define COMBINE(X,Y) COMBINE1(X,Y)
#define _STR(X) #X
#define STR(X) _STR(X)

#if defined(_MSC_VER)
#define LOCAL_FUNCTION_DEF__ __FUNCTION__
#define UNUSED_ATTRIBUTE
#else
#define LOCAL_FUNCTION_DEF__ __FUNCTION__
#define UNUSED_ATTRIBUTE __attribute__((unused))
#endif

#define LOCATION_SS "[" << LOCAL_FUNCTION_DEF__ << ("] @ " __FILE__ ":" STR(__LINE__))
#define LOCATION_STR (std::string("[") + LOCAL_FUNCTION_DEF__ + "] @ " __FILE__ ":" STR(__LINE__))


//
// Try-catch helpers
//

#define TRY_ENTRY() try {
#define CATCH_ALL_DO_NOTHING() }catch(...) {}

#define CATCH_ENTRY_CUSTOM(location, custom_code, return_val) } \
catch(const std::exception& ex) \
{ \
(void)(ex); \
LOG_ERROR("Exception at [" << location << "], what=" << ex.what()); \
custom_code; \
return return_val; \
} \
catch(...) \
{ \
LOG_ERROR("Exception at [" << location << "], generic exception \"...\""); \
custom_code; \
return return_val; \
}
#define CATCH_ENTRY(location, return_val) CATCH_ENTRY_CUSTOM(location, (void)0, return_val)
#define CATCH_ENTRY2(return_val) CATCH_ENTRY_CUSTOM(LOCATION_SS, (void)0, return_val)

#define CATCH_ENTRY_L0(location, return_val) CATCH_ENTRY(location, return_val)
#define CATCH_ENTRY_L1(location, return_val) CATCH_ENTRY(location, return_val)
#define CATCH_ENTRY_L2(location, return_val) CATCH_ENTRY(location, return_val)
#define CATCH_ENTRY_L3(location, return_val) CATCH_ENTRY(location, return_val)
#define CATCH_ENTRY_L4(location, return_val) CATCH_ENTRY(location, return_val)

/// @brief Catches TRY_ENTRY without returning
/// @details Useful within a dtor - but only if nested within another try block
/// (since we can still potentially throw here). See NESTED_*ENTRY()
/// @todo Exception dispatcher class
#define CATCH_ENTRY_NO_RETURN_CUSTOM(location, custom_code) } \
catch(const std::exception& ex) \
{ \
(void)(ex); \
LOG_ERROR("Exception at [" << location << "], what=" << ex.what()); \
custom_code; \
} \
catch(...) \
{ \
LOG_ERROR("Exception at [" << location << "], generic exception \"...\""); \
custom_code; \
}

#define CATCH_ENTRY_NO_RETURN() CATCH_ENTRY_NO_RETURN_CUSTOM(LOCATION_SS, (void)0)

#define CATCH_ENTRY_WITH_FORWARDING_EXCEPTION() } \
catch(const std::exception& ex) \
{ \
LOG_ERROR("Exception at [" << LOCATION_SS << "], what=" << ex.what()); \
throw std::runtime_error(std::string("[EXCEPTION FORWARDED]: ") + ex.what()); \
} \
catch(...) \
{ \
LOG_ERROR("Exception at [" << LOCATION_SS << "], generic unknown exception \"...\""); \
throw std::runtime_error("[EXCEPTION FORWARDED]"); \
}



#define NESTED_TRY_ENTRY() try { TRY_ENTRY();

#define NESTED_CATCH_ENTRY(location) \
CATCH_ENTRY_NO_RETURN_CUSTOM(location, {}); \
} catch (...) {}



16 changes: 15 additions & 1 deletion contrib/epee/include/misc_language.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,21 @@ namespace misc_utils

auto res = container.insert(typename t_container_type::value_type(key, AUTO_VAL_INIT(typename t_container_type::mapped_type())));
return res.first->second;
}
}

template<class t_container_type>
typename t_container_type::iterator it_get_or_insert_value_initialized(t_container_type& container, const typename t_container_type::key_type& key)
{
auto it = container.find(key);
if (it != container.end())
{
return it;
}

auto res = container.insert(typename t_container_type::value_type(key, AUTO_VAL_INIT(typename t_container_type::mapped_type())));
return res.first;
}

} // namespace misc_utils
} // namespace epee

Expand Down
93 changes: 10 additions & 83 deletions contrib/epee/include/misc_log_ex.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (c) 2019, Zano Project
// Copyright (c) 2019, anonimal <[email protected]>
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
// All rights reserved.
Expand Down Expand Up @@ -59,6 +60,7 @@ PUSH_VS_WARNINGS
DISABLE_VS_WARNINGS(4100)


#include "misc_helpers.h"
#include "static_initializer.h"
#include "string_tools.h"
#include "time_helper.h"
Expand Down Expand Up @@ -106,21 +108,6 @@ DISABLE_VS_WARNINGS(4100)
#endif


#define COMBINE1(X,Y) X##Y // helper macro
#define COMBINE(X,Y) COMBINE1(X,Y)
#define _STR(X) #X
#define STR(X) _STR(X)

#if defined(_MSC_VER)
#define LOCAL_FUNCTION_DEF__ __FUNCTION__
#define UNUSED_ATTRIBUTE
#else
#define LOCAL_FUNCTION_DEF__ __PRETTY_FUNCTION__
#define UNUSED_ATTRIBUTE __attribute__((unused))
#endif

#define LOCATION_SS "[" << LOCAL_FUNCTION_DEF__ << ("] @ " __FILE__ ":" STR(__LINE__))

#if !defined(DISABLE_RELEASE_LOGGING)
#define ENABLE_LOGGING_INTERNAL
#endif
Expand All @@ -131,28 +118,29 @@ DISABLE_VS_WARNINGS(4100)
epee::log_space::log_singletone::enable_channel(ch_name); return true; \
});


#if defined(ENABLE_LOGGING_INTERNAL)

#define LOG_PRINT_CHANNEL_NO_PREFIX2(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\
{std::stringstream ss________; ss________ << x << std::endl; epee::log_space::log_singletone::do_log_message(ss________.str() , y, epee::log_space::console_color_default, false, log_name);}}
{TRY_ENTRY();std::stringstream ss________; ss________ << x << std::endl; epee::log_space::log_singletone::do_log_message(ss________.str() , y, epee::log_space::console_color_default, false, log_name);CATCH_ALL_DO_NOTHING();}}

#define LOG_PRINT_CHANNEL_NO_PREFIX_NO_POSTFIX2(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\
{std::stringstream ss________; ss________ << x; epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, false, log_name);}}
{TRY_ENTRY();std::stringstream ss________; ss________ << x; epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, false, log_name);CATCH_ALL_DO_NOTHING();}}

#define LOG_PRINT_CHANNEL_NO_POSTFIX2(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\
{std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x; epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, false, log_name);}}
{TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x; epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, false, log_name);CATCH_ALL_DO_NOTHING();}}

#define LOG_PRINT_CHANNEL2(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\
{std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, false, log_name);}}
{TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, false, log_name);CATCH_ALL_DO_NOTHING();}}

#define LOG_PRINT_CHANNEL_COLOR2(log_channel, log_name, x, y, color) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\
{std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, color, false, log_name);}}
{TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, color, false, log_name);CATCH_ALL_DO_NOTHING();}}

#define LOG_PRINT_CHANNEL_2_JORNAL(log_channel, log_name, x, y) {if ( y <= epee::log_space::log_singletone::get_log_detalisation_level() && epee::log_space::log_singletone::channel_enabled(log_channel))\
{std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, true, log_name);}}
{TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << x << std::endl;epee::log_space::log_singletone::do_log_message(ss________.str(), y, epee::log_space::console_color_default, true, log_name);CATCH_ALL_DO_NOTHING();}}

#define LOG_ERROR2(log_name, x) { \
std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << "[ERROR] Location: " << std::endl << LOCATION_SS << epee::misc_utils::get_callstack() << " Message:" << std::endl << x << std::endl; epee::log_space::log_singletone::do_log_message(ss________.str(), LOG_LEVEL_0, epee::log_space::console_color_red, true, log_name); LOCAL_ASSERT(0); epee::log_space::increase_error_count(LOG_DEFAULT_CHANNEL); }
TRY_ENTRY();std::stringstream ss________; ss________ << epee::log_space::log_singletone::get_prefix_entry() << "[ERROR] Location: " << std::endl << LOCATION_SS << epee::misc_utils::get_callstack() << " Message:" << std::endl << x << std::endl; epee::log_space::log_singletone::do_log_message(ss________.str(), LOG_LEVEL_0, epee::log_space::console_color_red, true, log_name); LOCAL_ASSERT(0); epee::log_space::increase_error_count(LOG_DEFAULT_CHANNEL);CATCH_ALL_DO_NOTHING();}

#define LOG_FRAME2(log_name, x, y) epee::log_space::log_frame frame(x, y, log_name)

Expand Down Expand Up @@ -212,67 +200,6 @@ DISABLE_VS_WARNINGS(4100)

#define ENDL std::endl

#define TRY_ENTRY() try {
#define CATCH_ENTRY_CUSTOM(location, custom_code, return_val) } \
catch(const std::exception& ex) \
{ \
(void)(ex); \
LOG_ERROR("Exception at [" << location << "], what=" << ex.what()); \
custom_code; \
return return_val; \
} \
catch(...) \
{ \
LOG_ERROR("Exception at [" << location << "], generic exception \"...\""); \
custom_code; \
return return_val; \
}
#define CATCH_ENTRY(location, return_val) CATCH_ENTRY_CUSTOM(location, (void)0, return_val)
#define CATCH_ENTRY2(return_val) CATCH_ENTRY_CUSTOM(LOCATION_SS, (void)0, return_val)

#define CATCH_ENTRY_L0(location, return_val) CATCH_ENTRY(location, return_val)
#define CATCH_ENTRY_L1(location, return_val) CATCH_ENTRY(location, return_val)
#define CATCH_ENTRY_L2(location, return_val) CATCH_ENTRY(location, return_val)
#define CATCH_ENTRY_L3(location, return_val) CATCH_ENTRY(location, return_val)
#define CATCH_ENTRY_L4(location, return_val) CATCH_ENTRY(location, return_val)

/// @brief Catches TRY_ENTRY without returning
/// @details Useful within a dtor - but only if nested within another try block
/// (since we can still potentially throw here). See NESTED_*ENTRY()
/// @todo Exception dispatcher class
#define CATCH_ENTRY_NO_RETURN(location, custom_code) } \
catch(const std::exception& ex) \
{ \
(void)(ex); \
LOG_ERROR("Exception at [" << location << "], what=" << ex.what()); \
custom_code; \
} \
catch(...) \
{ \
LOG_ERROR("Exception at [" << location << "], generic exception \"...\""); \
custom_code; \
}


#define CATCH_ENTRY_WITH_FORWARDING_EXCEPTION() } \
catch(const std::exception& ex) \
{ \
LOG_ERROR("Exception at [" << LOCATION_SS << "], what=" << ex.what()); \
throw std::runtime_error(std::string("[EXCEPTION FORWARDED]: ") + ex.what()); \
} \
catch(...) \
{ \
LOG_ERROR("Exception at [" << LOCATION_SS << "], generic unknown exception \"...\""); \
throw std::runtime_error("[EXCEPTION FORWARDED]"); \
}



#define NESTED_TRY_ENTRY() try { TRY_ENTRY();

#define NESTED_CATCH_ENTRY(location) \
CATCH_ENTRY_NO_RETURN(location, {}); \
} catch (...) {}

#define ASSERT_MES_AND_THROW(message) {LOG_ERROR(message); std::stringstream ss; ss << message; throw std::runtime_error(ss.str());}

Expand Down
13 changes: 10 additions & 3 deletions contrib/epee/include/net/abstract_tcp_server2.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ class boosted_tcp_server
return true;
}

idle_callback_conext_base(boost::asio::io_service& io_serice)
: m_timer(io_serice)
idle_callback_conext_base(boost::asio::io_service& io_serice): m_timer(io_serice),
m_period(0)
{
}
boost::asio::deadline_timer m_timer;
Expand Down Expand Up @@ -254,7 +254,14 @@ class boosted_tcp_server
if(!ptr->call_handler())
return true;
}
catch(...) {
catch(std::exception& e)
{
LOG_ERROR("exeption caught in boosted_tcp_server::global_timer_handler: " << e.what() << ENDL << "won't be called anymore");
return true;
}
catch(...)
{
LOG_ERROR("unknown exeption caught in boosted_tcp_server::global_timer_handler, it won't be called anymore");
return true;
}

Expand Down
6 changes: 4 additions & 2 deletions contrib/epee/include/net/http_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,10 @@ using namespace std;
if(!u_c.port)
u_c.port = 80;//default for http

res = tr.connect(u_c.host, static_cast<int>(u_c.port), timeout);
CHECK_AND_ASSERT_MES(res, false, "failed to connect " << u_c.host << ":" << u_c.port);
if (!tr.connect(u_c.host, static_cast<int>(u_c.port), timeout))
{
LOG_PRINT_L2("invoke_request: cannot connect to " << u_c.host << ":" << u_c.port);
}
}

return tr.invoke(u_c.uri, method, body, ppresponse_info, additional_params);
Expand Down
4 changes: 3 additions & 1 deletion contrib/epee/include/serialization/keyvalue_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace epee
}
};


//basic helpers for pod-to-hex serialization
template<class t_pod_type>
std::string transform_t_pod_to_str(const t_pod_type & a)
Expand All @@ -61,7 +62,8 @@ namespace epee
t_pod_type transform_str_to_t_pod(const std::string& a)
{
t_pod_type res = AUTO_VAL_INIT(res);
epee::string_tools::hex_to_pod(a, res);
if (!epee::string_tools::hex_to_pod(a, res))
throw std::runtime_error(std::string("Unable to transform \"") + a + "\" to pod type " + typeid(t_pod_type).name());
return res;
}

Expand Down
41 changes: 41 additions & 0 deletions contrib/epee/include/serialization/keyvalue_hexemizer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) 2006-2019, Andrey N. Sabelnikov, www.sabelnikov.net
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Andrey N. Sabelnikov nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//

#pragma once
#include "keyvalue_serialization.h"
namespace epee
{

struct hexemizer
{
std::string blob;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_BLOB_AS_HEX_STRING(blob)
END_KV_SERIALIZE_MAP()
};


}
Loading

0 comments on commit a819fce

Please sign in to comment.