aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/epee')
-rw-r--r--contrib/epee/include/math_helper.h39
-rw-r--r--contrib/epee/include/misc_log_ex.h23
-rw-r--r--contrib/epee/include/net/levin_client_async.h2
-rw-r--r--contrib/epee/include/net/levin_protocol_handler_async.h2
-rw-r--r--contrib/epee/include/storages/parserse_base_utils.h8
-rw-r--r--contrib/epee/include/string_tools.h48
-rw-r--r--contrib/epee/src/mlocker.cpp4
-rw-r--r--contrib/epee/src/mlog.cpp2
-rw-r--r--contrib/epee/tests/src/CMakeLists.txt4
9 files changed, 71 insertions, 61 deletions
diff --git a/contrib/epee/include/math_helper.h b/contrib/epee/include/math_helper.h
index ef839f609..e22e8ee6e 100644
--- a/contrib/epee/include/math_helper.h
+++ b/contrib/epee/include/math_helper.h
@@ -230,35 +230,56 @@ namespace math_helper
}
}
- template<int default_interval, bool start_immediate = true>
- class once_a_time_seconds
+ template<uint64_t scale, int default_interval, bool start_immediate = true>
+ class once_a_time
{
+ uint64_t get_time() const
+ {
+#ifdef _WIN32
+ FILETIME fileTime;
+ GetSystemTimeAsFileTime(&fileTime);
+ unsigned __int64 present = 0;
+ present |= fileTime.dwHighDateTime;
+ present = present << 32;
+ present |= fileTime.dwLowDateTime;
+ present /= 10; // mic-sec
+#else
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return tv.tv_sec * 1000000 + tv.tv_usec;
+#endif
+ }
+
public:
- once_a_time_seconds():m_interval(default_interval)
+ once_a_time():m_interval(default_interval * scale)
{
m_last_worked_time = 0;
if(!start_immediate)
- time(&m_last_worked_time);
+ m_last_worked_time = get_time();
}
template<class functor_t>
bool do_call(functor_t functr)
{
- time_t current_time = 0;
- time(&current_time);
+ uint64_t current_time = get_time();
if(current_time - m_last_worked_time > m_interval)
{
bool res = functr();
- time(&m_last_worked_time);
+ m_last_worked_time = get_time();
return res;
}
return true;
}
private:
- time_t m_last_worked_time;
- time_t m_interval;
+ uint64_t m_last_worked_time;
+ uint64_t m_interval;
};
+
+ template<int default_interval, bool start_immediate = true>
+ class once_a_time_seconds: public once_a_time<1000000, default_interval, start_immediate> {};
+ template<int default_interval, bool start_immediate = true>
+ class once_a_time_milliseconds: public once_a_time<1000, default_interval, start_immediate> {};
}
}
diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h
index 9100a8db3..1ff9da3a7 100644
--- a/contrib/epee/include/misc_log_ex.h
+++ b/contrib/epee/include/misc_log_ex.h
@@ -38,14 +38,21 @@
#define MAX_LOG_FILE_SIZE 104850000 // 100 MB - 7600 bytes
#define MAX_LOG_FILES 50
-#define MCFATAL(cat,x) CLOG(FATAL,cat) << x
-#define MCERROR(cat,x) CLOG(ERROR,cat) << x
-#define MCWARNING(cat,x) CLOG(WARNING,cat) << x
-#define MCINFO(cat,x) CLOG(INFO,cat) << x
-#define MCDEBUG(cat,x) CLOG(DEBUG,cat) << x
-#define MCTRACE(cat,x) CLOG(TRACE,cat) << x
-#define MCLOG(level,cat,x) ELPP_WRITE_LOG(el::base::Writer, level, el::base::DispatchAction::NormalLog, cat) << x
-#define MCLOG_FILE(level,cat,x) ELPP_WRITE_LOG(el::base::Writer, level, el::base::DispatchAction::FileOnlyLog, cat) << x
+#define MCLOG_TYPE(level, cat, type, x) do { \
+ if (ELPP->vRegistry()->allowed(level, cat)) { \
+ el::base::Writer(level, __FILE__, __LINE__, ELPP_FUNC, type).construct(cat) << x; \
+ } \
+ } while (0)
+
+#define MCLOG(level, cat, x) MCLOG_TYPE(level, cat, el::base::DispatchAction::NormalLog, x)
+#define MCLOG_FILE(level, cat, x) MCLOG_TYPE(level, cat, el::base::DispatchAction::FileOnlyLog, x)
+
+#define MCFATAL(cat,x) MCLOG(el::Level::Fatal,cat, x)
+#define MCERROR(cat,x) MCLOG(el::Level::Error,cat, x)
+#define MCWARNING(cat,x) MCLOG(el::Level::Warning,cat, x)
+#define MCINFO(cat,x) MCLOG(el::Level::Info,cat, x)
+#define MCDEBUG(cat,x) MCLOG(el::Level::Debug,cat, x)
+#define MCTRACE(cat,x) MCLOG(el::Level::Trace,cat, x)
#define MCLOG_COLOR(level,cat,color,x) MCLOG(level,cat,"\033[1;" color "m" << x << "\033[0m")
#define MCLOG_RED(level,cat,x) MCLOG_COLOR(level,cat,"31",x)
diff --git a/contrib/epee/include/net/levin_client_async.h b/contrib/epee/include/net/levin_client_async.h
index b3a46465b..ed92f4b95 100644
--- a/contrib/epee/include/net/levin_client_async.h
+++ b/contrib/epee/include/net/levin_client_async.h
@@ -431,7 +431,7 @@ namespace levin
}
CRITICAL_REGION_END();
- LOG_PRINT_L4("LEVIN_PACKET_RECIEVED. [len=" << head.m_cb << ", flags=" << head.m_flags << ", is_cmd=" << head.m_have_to_return_data <<", cmd_id = " << head.m_command << ", pr_v=" << head.m_protocol_version << ", uid=" << string_tools::get_str_from_guid_a(head.m_id) << "]");
+ LOG_PRINT_L4("LEVIN_PACKET_RECEIVED. [len=" << head.m_cb << ", flags=" << head.m_flags << ", is_cmd=" << head.m_have_to_return_data <<", cmd_id = " << head.m_command << ", pr_v=" << head.m_protocol_version << ", uid=" << string_tools::get_str_from_guid_a(head.m_id) << "]");
if(is_request)
{
diff --git a/contrib/epee/include/net/levin_protocol_handler_async.h b/contrib/epee/include/net/levin_protocol_handler_async.h
index 6b1528caf..11649febe 100644
--- a/contrib/epee/include/net/levin_protocol_handler_async.h
+++ b/contrib/epee/include/net/levin_protocol_handler_async.h
@@ -416,7 +416,7 @@ public:
bool is_response = (m_oponent_protocol_ver == LEVIN_PROTOCOL_VER_1 && m_current_head.m_flags&LEVIN_PACKET_RESPONSE);
- MDEBUG(m_connection_context << "LEVIN_PACKET_RECIEVED. [len=" << m_current_head.m_cb
+ MDEBUG(m_connection_context << "LEVIN_PACKET_RECEIVED. [len=" << m_current_head.m_cb
<< ", flags" << m_current_head.m_flags
<< ", r?=" << m_current_head.m_have_to_return_data
<<", cmd = " << m_current_head.m_command
diff --git a/contrib/epee/include/storages/parserse_base_utils.h b/contrib/epee/include/storages/parserse_base_utils.h
index 31495ae13..d73fbde3a 100644
--- a/contrib/epee/include/storages/parserse_base_utils.h
+++ b/contrib/epee/include/storages/parserse_base_utils.h
@@ -91,11 +91,15 @@ namespace misc_utils
*/
inline void match_string2(std::string::const_iterator& star_end_string, std::string::const_iterator buf_end, std::string& val)
{
- val.clear();
- val.reserve(std::distance(star_end_string, buf_end));
bool escape_mode = false;
std::string::const_iterator it = star_end_string;
++it;
+ std::string::const_iterator fi = it;
+ while (fi != buf_end && *fi != '\\' && *fi != '\"')
+ ++fi;
+ val.assign(it, fi);
+ val.reserve(std::distance(star_end_string, buf_end));
+ it = fi;
for(;it != buf_end;it++)
{
if(escape_mode/*prev_ch == '\\'*/)
diff --git a/contrib/epee/include/string_tools.h b/contrib/epee/include/string_tools.h
index 6a063cc36..0d8eca727 100644
--- a/contrib/epee/include/string_tools.h
+++ b/contrib/epee/include/string_tools.h
@@ -117,16 +117,12 @@ namespace string_tools
return to_hex::string(to_byte_span(to_span(src)));
}
//----------------------------------------------------------------------------
- template<class CharT>
- bool parse_hexstr_to_binbuff(const std::basic_string<CharT>& s, std::basic_string<CharT>& res)
+ inline bool parse_hexstr_to_binbuff(const epee::span<const char> s, epee::span<char>& res)
{
- res.clear();
- if (s.size() & 1)
- return false;
- try
- {
- res.resize(s.size() / 2);
- unsigned char *dst = (unsigned char *)res.data();
+ if (s.size() != res.size() * 2)
+ return false;
+
+ unsigned char *dst = (unsigned char *)&res[0];
const unsigned char *src = (const unsigned char *)s.data();
for(size_t i = 0; i < s.size(); i += 2)
{
@@ -140,28 +136,15 @@ namespace string_tools
}
return true;
- }
- catch(...)
- {
- return false;
- }
}
//----------------------------------------------------------------------------
- template<class t_pod_type>
- bool parse_tpod_from_hex_string(const std::string& str_hash, t_pod_type& t_pod)
+ inline bool parse_hexstr_to_binbuff(const std::string& s, std::string& res)
{
- static_assert(std::is_pod<t_pod_type>::value, "expected pod type");
- std::string buf;
- bool res = epee::string_tools::parse_hexstr_to_binbuff(str_hash, buf);
- if (!res || buf.size() != sizeof(t_pod_type))
- {
+ if (s.size() & 1)
return false;
- }
- else
- {
- buf.copy(reinterpret_cast<char *>(&t_pod), sizeof(t_pod_type));
- return true;
- }
+ res.resize(s.size() / 2);
+ epee::span<char> rspan((char*)&res[0], res.size());
+ return parse_hexstr_to_binbuff(epee::to_span(s), rspan);
}
//----------------------------------------------------------------------------
PUSH_WARNINGS
@@ -360,17 +343,10 @@ POP_WARNINGS
bool hex_to_pod(const std::string& hex_str, t_pod_type& s)
{
static_assert(std::is_pod<t_pod_type>::value, "expected pod type");
- std::string hex_str_tr = trim(hex_str);
if(sizeof(s)*2 != hex_str.size())
return false;
- std::string bin_buff;
- if(!parse_hexstr_to_binbuff(hex_str_tr, bin_buff))
- return false;
- if(bin_buff.size()!=sizeof(s))
- return false;
-
- s = *(t_pod_type*)bin_buff.data();
- return true;
+ epee::span<char> rspan((char*)&s, sizeof(s));
+ return parse_hexstr_to_binbuff(epee::to_span(hex_str), rspan);
}
//----------------------------------------------------------------------------
template<class t_pod_type>
diff --git a/contrib/epee/src/mlocker.cpp b/contrib/epee/src/mlocker.cpp
index 0b41c36bf..446fa3315 100644
--- a/contrib/epee/src/mlocker.cpp
+++ b/contrib/epee/src/mlocker.cpp
@@ -40,6 +40,9 @@
#include <atomic>
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "mlocker"
+
// did an mlock operation previously fail? we only
// want to log an error once and be done with it
static std::atomic<bool> previously_failed{ false };
@@ -53,7 +56,6 @@ static size_t query_page_size()
MERROR("Failed to determine page size");
return 0;
}
- MINFO("Page size: " << ret);
return ret;
#else
#warning Missing query_page_size implementation
diff --git a/contrib/epee/src/mlog.cpp b/contrib/epee/src/mlog.cpp
index 00d848388..9b6b832d1 100644
--- a/contrib/epee/src/mlog.cpp
+++ b/contrib/epee/src/mlog.cpp
@@ -103,7 +103,7 @@ static const char *get_default_categories(int level)
categories = "*:WARNING,net:FATAL,net.http:FATAL,net.p2p:FATAL,net.cn:FATAL,global:INFO,verify:FATAL,stacktrace:INFO,logging:INFO,msgwriter:INFO";
break;
case 1:
- categories = "*:INFO,global:INFO,stacktrace:INFO,logging:INFO,msgwriter:INFO";
+ categories = "*:INFO,global:INFO,stacktrace:INFO,logging:INFO,msgwriter:INFO,perf.*:DEBUG";
break;
case 2:
categories = "*:DEBUG";
diff --git a/contrib/epee/tests/src/CMakeLists.txt b/contrib/epee/tests/src/CMakeLists.txt
index c7d31735b..4807fa7ea 100644
--- a/contrib/epee/tests/src/CMakeLists.txt
+++ b/contrib/epee/tests/src/CMakeLists.txt
@@ -14,8 +14,8 @@ IF (MSVC)
include_directories(SYSTEM platform/msvc)
ELSE()
# set stuff for other systems
- SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -Wall -Werror")
- SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Werror -Wno-reorder")
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -Wall")
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wno-reorder")
ENDIF()