From 690ce560b0f7eb806573d1f96d19b5e6c7d3673e Mon Sep 17 00:00:00 2001 From: Jeffrey Date: Mon, 7 Mar 2022 17:49:11 -0600 Subject: Boring Old Deletes Here lies dozens of unused files. This commit is ONLY file deletions except for the removing of a couple of #includes and removing filenames from CmakeLists where appropriate. --- src/daemon/command_parser_executor.h | 1 - src/daemon/command_server.h | 1 - src/daemon/rpc_command_executor.h | 1 - src/p2p/stdafx.h | 53 ------------------------------------ 4 files changed, 56 deletions(-) delete mode 100644 src/p2p/stdafx.h (limited to 'src') diff --git a/src/daemon/command_parser_executor.h b/src/daemon/command_parser_executor.h index ac95c3afc..cd9e6544e 100644 --- a/src/daemon/command_parser_executor.h +++ b/src/daemon/command_parser_executor.h @@ -40,7 +40,6 @@ #include "daemon/rpc_command_executor.h" #include "common/common_fwd.h" -#include "net/net_fwd.h" #include "rpc/core_rpc_server.h" namespace daemonize { diff --git a/src/daemon/command_server.h b/src/daemon/command_server.h index 113f99cbc..babb8e85a 100644 --- a/src/daemon/command_server.h +++ b/src/daemon/command_server.h @@ -43,7 +43,6 @@ Passing RPC commands: #include "common/common_fwd.h" #include "console_handler.h" #include "daemon/command_parser_executor.h" -#include "net/net_fwd.h" namespace daemonize { diff --git a/src/daemon/rpc_command_executor.h b/src/daemon/rpc_command_executor.h index 8cbb59716..ebd7eda85 100644 --- a/src/daemon/rpc_command_executor.h +++ b/src/daemon/rpc_command_executor.h @@ -43,7 +43,6 @@ #include "common/common_fwd.h" #include "common/rpc_client.h" #include "cryptonote_basic/cryptonote_basic.h" -#include "net/net_fwd.h" #include "rpc/core_rpc_server.h" #undef MONERO_DEFAULT_LOG_CATEGORY diff --git a/src/p2p/stdafx.h b/src/p2p/stdafx.h deleted file mode 100644 index 27157c8cd..000000000 --- a/src/p2p/stdafx.h +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) 2014-2022, The Monero Project -// -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, are -// permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, this list of -// conditions and the following disclaimer. -// -// 2. 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. -// -// 3. Neither the name of the copyright holder 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 HOLDER OR CONTRIBUTORS 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. -// -// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers - -#pragma once - -#include "targetver.h" - - -#if !defined(__GNUC__) -#define _CRTDBG_MAP_ALLOC -#include -#include -#endif - - - -#include - - -#define BOOST_FILESYSTEM_VERSION 3 -#define ENABLE_RELEASE_LOGGING -#include "log_opt_defs.h" -#include "misc_log_ex.h" - - - -- cgit v1.2.3 From 12b1b74d322f9933bb5d2ccbccd2566ee44cd3fc Mon Sep 17 00:00:00 2001 From: Jeffrey Date: Mon, 7 Mar 2022 18:27:28 -0600 Subject: Trimming Fat Remove unused include statements or unused definitions. --- contrib/epee/include/file_io_utils.h | 3 -- contrib/epee/include/misc_language.h | 52 ---------------------- contrib/epee/include/net/local_ip.h | 1 - .../epee/include/storages/levin_abstract_invoke2.h | 48 -------------------- contrib/epee/src/connection_basic.cpp | 1 - contrib/epee/src/file_io_utils.cpp | 43 ------------------ contrib/epee/src/network_throttle-detail.cpp | 1 - .../cryptonote_protocol_handler-base.cpp | 1 - src/p2p/net_node.inl | 1 - 9 files changed, 151 deletions(-) (limited to 'src') diff --git a/contrib/epee/include/file_io_utils.h b/contrib/epee/include/file_io_utils.h index 84dc79266..da05520c1 100644 --- a/contrib/epee/include/file_io_utils.h +++ b/contrib/epee/include/file_io_utils.h @@ -36,10 +36,7 @@ namespace file_io_utils { bool is_file_exist(const std::string& path); bool save_string_to_file(const std::string& path_to_file, const std::string& str); - bool get_file_time(const std::string& path_to_file, time_t& ft); - bool set_file_time(const std::string& path_to_file, const time_t& ft); bool load_file_to_string(const std::string& path_to_file, std::string& target_str, size_t max_size = 1000000000); - bool append_string_to_file(const std::string& path_to_file, const std::string& str); bool get_file_size(const std::string& path_to_file, uint64_t &size); } } diff --git a/contrib/epee/include/misc_language.h b/contrib/epee/include/misc_language.h index 5ccfe6fcc..bf75da23f 100644 --- a/contrib/epee/include/misc_language.h +++ b/contrib/epee/include/misc_language.h @@ -30,47 +30,13 @@ #include #include -#include -#include #include namespace epee { -#define STD_TRY_BEGIN() try { - -#define STD_TRY_CATCH(where_, ret_val) \ - } \ - catch (const std::exception &e) \ - { \ - LOG_ERROR("EXCEPTION: " << where_ << ", mes: "<< e.what()); \ - return ret_val; \ - } \ - catch (...) \ - { \ - LOG_ERROR("EXCEPTION: " << where_ ); \ - return ret_val; \ - } - - - #define AUTO_VAL_INIT(v) boost::value_initialized() namespace misc_utils { - template - t_type get_max_t_val(t_type t) - { - return (std::numeric_limits::max)(); - } - - - template - t_iterator move_it_forward(t_iterator it, size_t count) - { - while(count--) - it++; - return it; - } - template t_iterator move_it_backward(t_iterator it, size_t count) { @@ -79,24 +45,6 @@ namespace misc_utils return it; } - - // TEMPLATE STRUCT less - template - struct less_as_pod - : public std::binary_function<_Ty, _Ty, bool> - { // functor for operator< - bool operator()(const _Ty& _Left, const _Ty& _Right) const - { // apply operator< to operands - return memcmp(&_Left, &_Right, sizeof(_Left)) < 0; - } - }; - - template - bool is_less_as_pod(const _Ty& _Left, const _Ty& _Right) - { // apply operator< to operands - return memcmp(&_Left, &_Right, sizeof(_Left)) < 0; - } - bool sleep_no_w(long ms ); template diff --git a/contrib/epee/include/net/local_ip.h b/contrib/epee/include/net/local_ip.h index 1eeab2dc5..1c501d24b 100644 --- a/contrib/epee/include/net/local_ip.h +++ b/contrib/epee/include/net/local_ip.h @@ -27,7 +27,6 @@ #pragma once -#include #include "int-util.h" // IP addresses are kept in network byte order diff --git a/contrib/epee/include/storages/levin_abstract_invoke2.h b/contrib/epee/include/storages/levin_abstract_invoke2.h index 383d67cc2..7fd786a53 100644 --- a/contrib/epee/include/storages/levin_abstract_invoke2.h +++ b/contrib/epee/include/storages/levin_abstract_invoke2.h @@ -56,54 +56,6 @@ namespace epee { namespace net_utils { -#if 0 - template - bool invoke_remote_command2(int command, const t_arg& out_struct, t_result& result_struct, t_transport& transport) - { - if(!transport.is_connected()) - return false; - - serialization::portable_storage stg; - out_struct.store(stg); - std::string buff_to_send, buff_to_recv; - stg.store_to_binary(buff_to_send); - - int res = transport.invoke(command, buff_to_send, buff_to_recv); - if( res <=0 ) - { - MERROR("Failed to invoke command " << command << " return code " << res); - return false; - } - serialization::portable_storage stg_ret; - if(!stg_ret.load_from_binary(buff_to_recv, &default_levin_limits)) - { - LOG_ERROR("Failed to load_from_binary on command " << command); - return false; - } - return result_struct.load(stg_ret); - } - - template - bool notify_remote_command2(int command, const t_arg& out_struct, t_transport& transport) - { - if(!transport.is_connected()) - return false; - - serialization::portable_storage stg; - out_struct.store(&stg); - std::string buff_to_send; - stg.store_to_binary(buff_to_send); - - int res = transport.notify(command, buff_to_send); - if(res <=0 ) - { - LOG_ERROR("Failed to notify command " << command << " return code " << res); - return false; - } - return true; - } -#endif - template bool invoke_remote_command2(const epee::net_utils::connection_context_base context, int command, const t_arg& out_struct, t_result& result_struct, t_transport& transport) { diff --git a/contrib/epee/src/connection_basic.cpp b/contrib/epee/src/connection_basic.cpp index 85ff55587..b0a30f47f 100644 --- a/contrib/epee/src/connection_basic.cpp +++ b/contrib/epee/src/connection_basic.cpp @@ -39,7 +39,6 @@ #include #include #include "misc_language.h" -#include "pragma_comp_defs.h" #include #include diff --git a/contrib/epee/src/file_io_utils.cpp b/contrib/epee/src/file_io_utils.cpp index 5072adcbc..a8348431c 100644 --- a/contrib/epee/src/file_io_utils.cpp +++ b/contrib/epee/src/file_io_utils.cpp @@ -102,29 +102,6 @@ namespace file_io_utils } - bool get_file_time(const std::string& path_to_file, time_t& ft) - { - boost::system::error_code ec; - ft = boost::filesystem::last_write_time(boost::filesystem::path(path_to_file), ec); - if(!ec) - return true; - else - return false; - } - - - bool set_file_time(const std::string& path_to_file, const time_t& ft) - { - boost::system::error_code ec; - boost::filesystem::last_write_time(boost::filesystem::path(path_to_file), ft, ec); - if(!ec) - return true; - else - return false; - } - - - bool load_file_to_string(const std::string& path_to_file, std::string& target_str, size_t max_size) { #ifdef WIN32 @@ -174,26 +151,6 @@ namespace file_io_utils } - bool append_string_to_file(const std::string& path_to_file, const std::string& str) - { - // No special Windows implementation because so far not used in Monero code - try - { - std::ofstream fstream; - fstream.exceptions(std::ifstream::failbit | std::ifstream::badbit); - fstream.open(path_to_file.c_str(), std::ios_base::binary | std::ios_base::out | std::ios_base::app); - fstream << str; - fstream.close(); - return true; - } - - catch(...) - { - return false; - } - } - - bool get_file_size(const std::string& path_to_file, uint64_t &size) { #ifdef WIN32 diff --git a/contrib/epee/src/network_throttle-detail.cpp b/contrib/epee/src/network_throttle-detail.cpp index 0374a449c..978572120 100644 --- a/contrib/epee/src/network_throttle-detail.cpp +++ b/contrib/epee/src/network_throttle-detail.cpp @@ -46,7 +46,6 @@ #include "misc_log_ex.h" #include #include "misc_language.h" -#include "pragma_comp_defs.h" #include #include #include diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp b/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp index 4c21de7a5..92ee08054 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp +++ b/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp @@ -43,7 +43,6 @@ #include #include #include "misc_language.h" -#include "pragma_comp_defs.h" #include diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 5c61ede3f..a3bc3bf24 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -55,7 +55,6 @@ #include "math_helper.h" #include "misc_log_ex.h" #include "p2p_protocol_defs.h" -#include "net/local_ip.h" #include "crypto/crypto.h" #include "storages/levin_abstract_invoke2.h" #include "cryptonote_core/cryptonote_core.h" -- cgit v1.2.3 From 40f02f9d739a207f124bf07c590b9e7c94244eaf Mon Sep 17 00:00:00 2001 From: Jeffrey Date: Mon, 7 Mar 2022 18:34:39 -0600 Subject: Add Include statements --- src/p2p/p2p_protocol_defs.h | 1 + src/rpc/core_rpc_server.cpp | 1 + tests/unit_tests/epee_utils.cpp | 1 + 3 files changed, 3 insertions(+) (limited to 'src') diff --git a/src/p2p/p2p_protocol_defs.h b/src/p2p/p2p_protocol_defs.h index fbeef6e62..8b9cd0f09 100644 --- a/src/p2p/p2p_protocol_defs.h +++ b/src/p2p/p2p_protocol_defs.h @@ -30,6 +30,7 @@ #pragma once +#include #include #include #include "serialization/keyvalue_serialization.h" diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index b28583e37..bbcfa6168 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -48,6 +48,7 @@ using namespace epee; #include "cryptonote_basic/merge_mining.h" #include "cryptonote_core/tx_sanity_check.h" #include "misc_language.h" +#include "net/local_ip.h" #include "net/parse.h" #include "storages/http_abstract_invoke.h" #include "crypto/hash.h" diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp index 1ba0e49ab..1c756e77c 100644 --- a/tests/unit_tests/epee_utils.cpp +++ b/tests/unit_tests/epee_utils.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include -- cgit v1.2.3 From 441c86073869c5df55e91c39fd4b331212512022 Mon Sep 17 00:00:00 2001 From: Jeffrey Date: Mon, 7 Mar 2022 19:16:26 -0600 Subject: Merge functionality of misc_os_dependent into time_helper.h Actions: 1. Remove unused functions from misc_os_dependent.h 2. Move three remaining functions, get_gmt_time, get_ns_count, and get_tick_count into time_helper.h 3. Remove unused functions from time_helper.h 4. Refactor get_ns_count and get_internet_time_str and get_time_interval_string 5. Remove/add includes as needed Relevant commits on the old PR: a9fbe52b02ffab451e90c977459fea4642731cd1 9a59b131c4ed1be8afe238fff3780fe203c65a46 7fa9e2817df9b9ef3f0290f7f86357939829e588 --- contrib/epee/include/math_helper.h | 2 +- contrib/epee/include/misc_os_dependent.h | 129 -------------------- .../include/net/levin_protocol_handler_async.h | 2 +- contrib/epee/include/profile_tools.h | 2 +- contrib/epee/include/time_helper.h | 130 +++++---------------- contrib/epee/src/CMakeLists.txt | 1 - contrib/epee/src/misc_os_dependent.cpp | 44 ------- contrib/epee/src/mlog.cpp | 2 +- src/common/perf_timer.cpp | 2 +- src/common/util.cpp | 2 +- 10 files changed, 35 insertions(+), 281 deletions(-) delete mode 100644 contrib/epee/include/misc_os_dependent.h delete mode 100644 contrib/epee/src/misc_os_dependent.cpp (limited to 'src') diff --git a/contrib/epee/include/math_helper.h b/contrib/epee/include/math_helper.h index 29acffaea..6a759b515 100644 --- a/contrib/epee/include/math_helper.h +++ b/contrib/epee/include/math_helper.h @@ -37,8 +37,8 @@ #include #include -#include "misc_os_dependent.h" #include "syncobj.h" +#include "time_helper.h" namespace epee { diff --git a/contrib/epee/include/misc_os_dependent.h b/contrib/epee/include/misc_os_dependent.h deleted file mode 100644 index 522cdf263..000000000 --- a/contrib/epee/include/misc_os_dependent.h +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright (c) 2006-2013, 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. -// -#ifdef _WIN32 -#include -#endif - -#ifdef WIN32 - #ifndef WIN32_LEAN_AND_MEAN - #define WIN32_LEAN_AND_MEAN - #endif - - //#ifdef _WIN32_WINNT - // #undef _WIN32_WINNT - // #define _WIN32_WINNT 0x0600 - //#endif - - -#include -#endif - -#ifdef __MACH__ -#include -#include -#endif - -#include -#include - -#pragma once -namespace epee -{ -namespace misc_utils -{ - - inline uint64_t get_ns_count() - { -#if defined(_MSC_VER) - return ::GetTickCount64() * 1000000; -#elif defined(WIN32) - static LARGE_INTEGER pcfreq = {0}; - LARGE_INTEGER ticks; - if (!pcfreq.QuadPart) - QueryPerformanceFrequency(&pcfreq); - QueryPerformanceCounter(&ticks); - ticks.QuadPart *= 1000000000; /* we want nsec */ - return ticks.QuadPart / pcfreq.QuadPart; -#elif defined(__MACH__) - clock_serv_t cclock; - mach_timespec_t mts; - - host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock); - clock_get_time(cclock, &mts); - mach_port_deallocate(mach_task_self(), cclock); - - return ((uint64_t)mts.tv_sec * 1000000000) + (mts.tv_nsec); -#else - struct timespec ts; - if(clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { - return 0; - } - return ((uint64_t)ts.tv_sec * 1000000000) + (ts.tv_nsec); -#endif - } - - inline uint64_t get_tick_count() - { - return get_ns_count() / 1000000; - } - - - inline int call_sys_cmd(const std::string& cmd) - { - std::cout << "# " << cmd << std::endl; - - FILE * fp ; - //char tstCommand[] ="ls *"; - char path[1000] = {0}; -#if !defined(__GNUC__) - fp = _popen(cmd.c_str(), "r"); -#else - fp = popen(cmd.c_str(), "r"); -#endif - while ( fgets( path, 1000, fp ) != NULL ) - std::cout << path; - -#if !defined(__GNUC__) - _pclose(fp); -#else - pclose(fp); -#endif - return 0; - - } - - std::string get_thread_string_id(); - - inline bool get_gmt_time(time_t t, struct tm &tm) - { -#ifdef _WIN32 - return gmtime_s(&tm, &t); -#else - return gmtime_r(&t, &tm); -#endif - } -} -} diff --git a/contrib/epee/include/net/levin_protocol_handler_async.h b/contrib/epee/include/net/levin_protocol_handler_async.h index 7cc42b5c4..bd6ffe930 100644 --- a/contrib/epee/include/net/levin_protocol_handler_async.h +++ b/contrib/epee/include/net/levin_protocol_handler_async.h @@ -37,7 +37,7 @@ #include "buffer.h" #include "misc_language.h" #include "syncobj.h" -#include "misc_os_dependent.h" +#include "time_helper.h" #include "int-util.h" #include diff --git a/contrib/epee/include/profile_tools.h b/contrib/epee/include/profile_tools.h index a0b5f77f4..76f794a36 100644 --- a/contrib/epee/include/profile_tools.h +++ b/contrib/epee/include/profile_tools.h @@ -28,7 +28,7 @@ #ifndef _PROFILE_TOOLS_H_ #define _PROFILE_TOOLS_H_ -#include "misc_os_dependent.h" +#include "time_helper.h" namespace epee { diff --git a/contrib/epee/include/time_helper.h b/contrib/epee/include/time_helper.h index 244b35800..632996bc5 100644 --- a/contrib/epee/include/time_helper.h +++ b/contrib/epee/include/time_helper.h @@ -28,132 +28,60 @@ #pragma once -//#include -//#include -#include -#include -#include "pragma_comp_defs.h" +#include +#include +#include +#include namespace epee { namespace misc_utils { - -#ifdef __ATLTIME_H__ - - inline - bool get_time_t_from_ole_date(DATE src, time_t& res) + inline bool get_gmt_time(time_t t, struct tm &tm) { - SYSTEMTIME st = {0}; - if(TRUE != ::VariantTimeToSystemTime(src, &st)) - return false; - ATL::CTime ss(st); - res = ss.GetTime(); - return true; - } +#ifdef _WIN32 + return gmtime_s(&tm, &t); +#else + return gmtime_r(&t, &tm); #endif - inline - std::string get_time_str(const time_t& time_) - { - - - char tmpbuf[200] = {0}; - tm* pt = NULL; -PRAGMA_WARNING_PUSH -PRAGMA_WARNING_DISABLE_VS(4996) - pt = localtime(&time_); -PRAGMA_WARNING_POP - - if(pt) - strftime( tmpbuf, 199, "%d.%m.%Y %H:%M:%S", pt ); - else - { - std::stringstream strs; - strs << "[wrong_time: " << std::hex << time_ << "]"; - return strs.str(); - } - return tmpbuf; } - inline - std::string get_time_str_v2(const time_t& time_) - { - - char tmpbuf[200] = {0}; - tm* pt = NULL; -PRAGMA_WARNING_PUSH -PRAGMA_WARNING_DISABLE_VS(4996) - pt = localtime(&time_); -PRAGMA_WARNING_POP - - if(pt) - strftime( tmpbuf, 199, "%Y_%m_%d %H_%M_%S", pt ); - else - { - std::stringstream strs; - strs << "[wrong_time: " << std::hex << time_ << "]"; - return strs.str(); - } - return tmpbuf; - } - - inline - std::string get_time_str_v3(const boost::posix_time::ptime& time_) - { - return boost::posix_time::to_simple_string(time_); - } - - - inline std::string get_internet_time_str(const time_t& time_) { char tmpbuf[200] = {0}; - tm* pt = NULL; -PRAGMA_WARNING_PUSH -PRAGMA_WARNING_DISABLE_VS(4996) - pt = gmtime(&time_); -PRAGMA_WARNING_POP - strftime( tmpbuf, 199, "%a, %d %b %Y %H:%M:%S GMT", pt ); + struct tm pt; + get_gmt_time(time_, pt); + strftime(tmpbuf, 199, "%a, %d %b %Y %H:%M:%S GMT", &pt); return tmpbuf; } inline std::string get_time_interval_string(const time_t& time_) { - std::string res; time_t tail = time_; -PRAGMA_WARNING_PUSH -PRAGMA_WARNING_DISABLE_VS(4244) - int days = tail/(60*60*24); + const int days = (int) (tail/(60*60*24)); tail = tail%(60*60*24); - int hours = tail/(60*60); + const int hours = (int) (tail/(60*60)); tail = tail%(60*60); - int minutes = tail/(60); + const int minutes = (int) (tail/(60)); tail = tail%(60); - int seconds = tail; -PRAGMA_WARNING_POP - res = std::string() + "d" + boost::lexical_cast(days) + ".h" + boost::lexical_cast(hours) + ".m" + boost::lexical_cast(minutes) + ".s" + boost::lexical_cast(seconds); - return res; + const int seconds = (int) tail; + + char tmpbuf[64] = {0}; + snprintf(tmpbuf, sizeof(tmpbuf) - 1, "d%d.h%d.m%d.s%d", days, hours, minutes, seconds); + + return tmpbuf; } -#ifdef __SQLEXT - inline - bool odbc_time_to_oledb_taime(const SQL_TIMESTAMP_STRUCT& odbc_timestamp, DATE& oledb_date) + inline uint64_t get_ns_count() { - - SYSTEMTIME st = {0}; - st.wYear = odbc_timestamp.year; - st.wDay = odbc_timestamp.day; - st.wHour = odbc_timestamp.hour ; - st.wMilliseconds = (WORD)odbc_timestamp.fraction ; - st.wMinute = odbc_timestamp.minute ; - st.wMonth = odbc_timestamp.month ; - st.wSecond = odbc_timestamp.second ; - - if(TRUE != ::SystemTimeToVariantTime(&st, &oledb_date)) - return false; - return true; + typedef std::chrono::duration ns_duration; + const ns_duration ns_since_epoch = std::chrono::steady_clock::now().time_since_epoch(); + return ns_since_epoch.count(); } -#endif + inline uint64_t get_tick_count() + { + return get_ns_count() / 1000000; + } } } diff --git a/contrib/epee/src/CMakeLists.txt b/contrib/epee/src/CMakeLists.txt index 13d8154f3..808b9f09e 100644 --- a/contrib/epee/src/CMakeLists.txt +++ b/contrib/epee/src/CMakeLists.txt @@ -35,7 +35,6 @@ monero_add_library(epee byte_slice.cpp byte_stream.cpp hex.cpp abstract_http_cli wipeable_string.cpp levin_base.cpp memwipe.c connection_basic.cpp network_throttle.cpp network_throttle-detail.cpp mlocker.cpp buffer.cpp net_ssl.cpp int-util.cpp portable_storage.cpp misc_language.cpp - misc_os_dependent.cpp file_io_utils.cpp net_parse_helpers.cpp http_base.cpp diff --git a/contrib/epee/src/misc_os_dependent.cpp b/contrib/epee/src/misc_os_dependent.cpp deleted file mode 100644 index cd4967131..000000000 --- a/contrib/epee/src/misc_os_dependent.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2006-2013, 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. -// - -#include "misc_os_dependent.h" -#include - -namespace epee -{ -namespace misc_utils -{ - // TODO: (vtnerd) This function is weird since boost::this_thread::get_id() exists but returns a different value. - std::string get_thread_string_id() - { -#if defined(_WIN32) - return boost::lexical_cast(GetCurrentThreadId()); -#elif defined(__GNUC__) - return boost::lexical_cast(pthread_self()); -#endif - } -} -} diff --git a/contrib/epee/src/mlog.cpp b/contrib/epee/src/mlog.cpp index bcde215be..092d41777 100644 --- a/contrib/epee/src/mlog.cpp +++ b/contrib/epee/src/mlog.cpp @@ -40,7 +40,7 @@ #include #include #include "string_tools.h" -#include "misc_os_dependent.h" +#include "time_helper.h" #include "misc_log_ex.h" #undef MONERO_DEFAULT_LOG_CATEGORY diff --git a/src/common/perf_timer.cpp b/src/common/perf_timer.cpp index 1152bf25a..30164a557 100644 --- a/src/common/perf_timer.cpp +++ b/src/common/perf_timer.cpp @@ -27,7 +27,7 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -#include "misc_os_dependent.h" +#include "time_helper.h" #include "perf_timer.h" #undef MONERO_DEFAULT_LOG_CATEGORY diff --git a/src/common/util.cpp b/src/common/util.cpp index d607d8f7f..89dcf4fef 100644 --- a/src/common/util.cpp +++ b/src/common/util.cpp @@ -59,7 +59,7 @@ #include "include_base_utils.h" #include "file_io_utils.h" #include "wipeable_string.h" -#include "misc_os_dependent.h" +#include "time_helper.h" using namespace epee; #include "crypto/crypto.h" -- cgit v1.2.3 From 7764d69782510071f7b2b28ce839945de3fc195c Mon Sep 17 00:00:00 2001 From: Jeffrey Date: Mon, 7 Mar 2022 20:29:22 -0600 Subject: Move copyable_atomic into connection_context Relevant commit from old PR: bd0a5119957d3ef9130a0b82599e1696995ef235 --- contrib/epee/include/copyable_atomic.h | 56 ------------------------------- src/cryptonote_basic/connection_context.h | 39 ++++++++++++++++++--- 2 files changed, 35 insertions(+), 60 deletions(-) delete mode 100644 contrib/epee/include/copyable_atomic.h (limited to 'src') diff --git a/contrib/epee/include/copyable_atomic.h b/contrib/epee/include/copyable_atomic.h deleted file mode 100644 index 00a5f484b..000000000 --- a/contrib/epee/include/copyable_atomic.h +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2006-2013, 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 - -namespace epee -{ - class copyable_atomic: public std::atomic - { - public: - copyable_atomic() - {}; - copyable_atomic(uint32_t value) - { store(value); } - copyable_atomic(const copyable_atomic& a):std::atomic(a.load()) - {} - copyable_atomic& operator= (const copyable_atomic& a) - { - store(a.load()); - return *this; - } - uint32_t operator++() - { - return std::atomic::operator++(); - } - uint32_t operator++(int fake) - { - return std::atomic::operator++(fake); - } - }; -} diff --git a/src/cryptonote_basic/connection_context.h b/src/cryptonote_basic/connection_context.h index 11e54b479..818999a60 100644 --- a/src/cryptonote_basic/connection_context.h +++ b/src/cryptonote_basic/connection_context.h @@ -27,6 +27,7 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers +// Parts of this file are originally copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net #pragma once #include @@ -34,7 +35,6 @@ #include #include #include "net/net_utils_base.h" -#include "copyable_atomic.h" #include "crypto/hash.h" namespace cryptonote @@ -55,6 +55,37 @@ namespace cryptonote state_normal }; + /* + This class was originally from the EPEE module. It is identical in function to std::atomic except + that it has copy-construction and copy-assignment defined, which means that earliers devs didn't have to write + custom copy-contructors and copy-assingment operators for the outer class, cryptonote_connection_context. + cryptonote_connection_context should probably be refactored because it is both trying to be POD-like while + also (very loosely) controlling access to its atomic members. + */ + class copyable_atomic: public std::atomic + { + public: + copyable_atomic() + {}; + copyable_atomic(uint32_t value) + { store(value); } + copyable_atomic(const copyable_atomic& a):std::atomic(a.load()) + {} + copyable_atomic& operator= (const copyable_atomic& a) + { + store(a.load()); + return *this; + } + uint32_t operator++() + { + return std::atomic::operator++(); + } + uint32_t operator++(int fake) + { + return std::atomic::operator++(fake); + } + }; + static constexpr int handshake_command() noexcept { return 1001; } bool handshake_complete() const noexcept { return m_state != state_before_handshake; } @@ -67,7 +98,7 @@ namespace cryptonote uint64_t m_remote_blockchain_height; uint64_t m_last_response_height; boost::posix_time::ptime m_last_request_time; - epee::copyable_atomic m_callback_request_count; //in debug purpose: problem with double callback rise + copyable_atomic m_callback_request_count; //in debug purpose: problem with double callback rise crypto::hash m_last_known_hash; uint32_t m_pruning_seed; uint16_t m_rpc_port; @@ -77,8 +108,8 @@ namespace cryptonote int m_expect_response; uint64_t m_expect_height; size_t m_num_requested; - epee::copyable_atomic m_new_stripe_notification{0}; - epee::copyable_atomic m_idle_peer_notification{0}; + copyable_atomic m_new_stripe_notification{0}; + copyable_atomic m_idle_peer_notification{0}; }; inline std::string get_protocol_state_string(cryptonote_connection_context::state s) -- cgit v1.2.3 From 1f25aa27c5cf83afd8e332bd5fe84c88c3dd7ffd Mon Sep 17 00:00:00 2001 From: Jeffrey Date: Mon, 7 Mar 2022 20:49:19 -0600 Subject: Factor out move_it_backward from misc_language.h Relevant commit from old PR: 330df2952cb2863a591158b984c0fb7f652887ac --- contrib/epee/include/misc_language.h | 10 +--------- src/p2p/net_peerlist.h | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/contrib/epee/include/misc_language.h b/contrib/epee/include/misc_language.h index bf75da23f..ee07bbe8f 100644 --- a/contrib/epee/include/misc_language.h +++ b/contrib/epee/include/misc_language.h @@ -37,15 +37,7 @@ namespace epee namespace misc_utils { - template - t_iterator move_it_backward(t_iterator it, size_t count) - { - while(count--) - it--; - return it; - } - - bool sleep_no_w(long ms ); + bool sleep_no_w(long ms); template T get_mid(const T &a, const T &b) diff --git a/src/p2p/net_peerlist.h b/src/p2p/net_peerlist.h index 2cb85d270..8a56bb378 100644 --- a/src/p2p/net_peerlist.h +++ b/src/p2p/net_peerlist.h @@ -31,6 +31,7 @@ #pragma once #include +#include #include #include #include @@ -46,7 +47,6 @@ #include "crypto/crypto.h" #include "cryptonote_config.h" #include "net/enums.h" -#include "net/local_ip.h" #include "p2p_protocol_defs.h" #include "syncobj.h" @@ -184,6 +184,7 @@ namespace nodetool private: void trim_white_peerlist(); void trim_gray_peerlist(); + static peerlist_entry get_nth_latest_peer(peers_indexed& peerlist, size_t n); friend class boost::serialization::access; epee::critical_section m_peerlist_lock; @@ -214,6 +215,16 @@ namespace nodetool } } //-------------------------------------------------------------------------------------------------- + inline + peerlist_entry peerlist_manager::get_nth_latest_peer(peers_indexed& peerlist, const size_t n) + { + // Is not thread-safe nor does it check bounds. Do this before calling. Indexing starts at 0. + peers_indexed::index::type& by_time_index = peerlist.get(); + auto by_time_it = --by_time_index.end(); + std::advance(by_time_it, -((long long) n)); + return *by_time_it; + } + //-------------------------------------------------------------------------------------------------- inline bool peerlist_manager::merge_peerlist(const std::vector& outer_bs, const std::function &f) { @@ -235,8 +246,7 @@ namespace nodetool if(i >= m_peers_white.size()) return false; - peers_indexed::index::type& by_time_index = m_peers_white.get(); - p = *epee::misc_utils::move_it_backward(--by_time_index.end(), i); + p = peerlist_manager::get_nth_latest_peer(m_peers_white, i); return true; } //-------------------------------------------------------------------------------------------------- @@ -247,8 +257,7 @@ namespace nodetool if(i >= m_peers_gray.size()) return false; - peers_indexed::index::type& by_time_index = m_peers_gray.get(); - p = *epee::misc_utils::move_it_backward(--by_time_index.end(), i); + p = peerlist_manager::get_nth_latest_peer(m_peers_gray, i); return true; } //-------------------------------------------------------------------------------------------------- @@ -437,9 +446,7 @@ namespace nodetool } size_t random_index = crypto::rand_idx(m_peers_gray.size()); - - peers_indexed::index::type& by_time_index = m_peers_gray.get(); - pe = *epee::misc_utils::move_it_backward(--by_time_index.end(), random_index); + pe = peerlist_manager::get_nth_latest_peer(m_peers_gray, random_index); return true; -- cgit v1.2.3 From 11371425f562f7202aff74004776489b93973af8 Mon Sep 17 00:00:00 2001 From: Jeffrey Date: Thu, 10 Mar 2022 10:46:21 -0600 Subject: "Change C-cast to static_cast in net_peerlist.h" Thanks @mj-xmr: https://github.com/monero-project/monero/pull/8211#discussion_r823870855 --- src/p2p/net_peerlist.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/p2p/net_peerlist.h b/src/p2p/net_peerlist.h index 8a56bb378..dc480462d 100644 --- a/src/p2p/net_peerlist.h +++ b/src/p2p/net_peerlist.h @@ -221,7 +221,7 @@ namespace nodetool // Is not thread-safe nor does it check bounds. Do this before calling. Indexing starts at 0. peers_indexed::index::type& by_time_index = peerlist.get(); auto by_time_it = --by_time_index.end(); - std::advance(by_time_it, -((long long) n)); + std::advance(by_time_it, -static_cast(n)); return *by_time_it; } //-------------------------------------------------------------------------------------------------- -- cgit v1.2.3