diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2017-01-01 16:34:23 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2017-01-16 00:25:46 +0000 |
commit | 5833d66f6540e7b34e10ddef37c2b67bd501994b (patch) | |
tree | e4d312059948a0528583e7ea58d2c0b40307a494 /src/p2p | |
parent | easylogging++: fix logging with static const header only data members (diff) | |
download | monero-5833d66f6540e7b34e10ddef37c2b67bd501994b.tar.xz |
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
Diffstat (limited to 'src/p2p')
-rw-r--r-- | src/p2p/connection_basic.cpp | 32 | ||||
-rw-r--r-- | src/p2p/data_logger.cpp | 202 | ||||
-rw-r--r-- | src/p2p/data_logger.hpp | 105 | ||||
-rw-r--r-- | src/p2p/net_node.inl | 163 | ||||
-rw-r--r-- | src/p2p/network_throttle-detail.cpp | 16 |
5 files changed, 91 insertions, 427 deletions
diff --git a/src/p2p/connection_basic.cpp b/src/p2p/connection_basic.cpp index 981a02882..80915e9a3 100644 --- a/src/p2p/connection_basic.cpp +++ b/src/p2p/connection_basic.cpp @@ -77,14 +77,13 @@ #include <boost/asio/ip/unicast.hpp> #include "../../contrib/epee/include/net/abstract_tcp_server2.h" -#include "../../contrib/otshell_utils/utils.hpp" -#include "data_logger.hpp" -using namespace nOT::nUtils; - // TODO: #include "../../src/p2p/network_throttle-detail.hpp" #include "../../src/cryptonote_core/cryptonote_core.h" +#undef MONERO_DEFAULT_LOG_CATEGORY +#define MONERO_DEFAULT_LOG_CATEGORY "net.p2p" + // ################################################################################################ // local (TU local) headers // ################################################################################################ @@ -219,19 +218,6 @@ uint64_t connection_basic::get_rate_down_limit() { } void connection_basic::save_limit_to_file(int limit) { - // saving limit to file - if (!epee::net_utils::data_logger::m_save_graph) - return; - - { - CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_out ); - epee::net_utils::data_logger::get_instance().add_data("upload_limit", network_throttle_manager::get_global_throttle_out().get_target_speed() / 1024); - } - - { - CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_in ); - epee::net_utils::data_logger::get_instance().add_data("download_limit", network_throttle_manager::get_global_throttle_in().get_target_speed() / 1024); - } } void connection_basic::set_tos_flag(int tos) { @@ -259,9 +245,8 @@ void connection_basic::sleep_before_packet(size_t packet_size, int phase, int q delay *= 0.50; if (delay > 0) { long int ms = (long int)(delay * 1000); - _info_c("net/sleep", "Sleeping in " << __FUNCTION__ << " for " << ms << " ms before packet_size="<<packet_size); // debug sleep + MDEBUG("Sleeping in " << __FUNCTION__ << " for " << ms << " ms before packet_size="<<packet_size); // debug sleep _dbg1("sleep in sleep_before_packet"); - epee::net_utils::data_logger::get_instance().add_data("sleep_up", ms); boost::this_thread::sleep(boost::posix_time::milliseconds( ms ) ); } } while(delay > 0); @@ -280,25 +265,21 @@ void connection_basic::set_start_time() { void connection_basic::do_send_handler_write(const void* ptr , size_t cb ) { sleep_before_packet(cb,1,-1); - _info_c("net/out/size", "handler_write (direct) - before ASIO write, for packet="<<cb<<" B (after sleep)"); + MDEBUG("handler_write (direct) - before ASIO write, for packet="<<cb<<" B (after sleep)"); set_start_time(); } void connection_basic::do_send_handler_write_from_queue( const boost::system::error_code& e, size_t cb, int q_len ) { sleep_before_packet(cb,2,q_len); - _info_c("net/out/size", "handler_write (after write, from queue="<<q_len<<") - before ASIO write, for packet="<<cb<<" B (after sleep)"); + MDEBUG("handler_write (after write, from queue="<<q_len<<") - before ASIO write, for packet="<<cb<<" B (after sleep)"); set_start_time(); } void connection_basic::logger_handle_net_read(size_t size) { // network data read - size /= 1024; - epee::net_utils::data_logger::get_instance().add_data("download", size); } void connection_basic::logger_handle_net_write(size_t size) { - size /= 1024; - epee::net_utils::data_logger::get_instance().add_data("upload", size); } double connection_basic::get_sleep_time(size_t cb) { @@ -308,7 +289,6 @@ double connection_basic::get_sleep_time(size_t cb) { } void connection_basic::set_save_graph(bool save_graph) { - epee::net_utils::data_logger::m_save_graph = save_graph; } diff --git a/src/p2p/data_logger.cpp b/src/p2p/data_logger.cpp deleted file mode 100644 index fe54aef63..000000000 --- a/src/p2p/data_logger.cpp +++ /dev/null @@ -1,202 +0,0 @@ -// Copyright (c) 2014-2016, 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. - -#include "data_logger.hpp" -#include <stdexcept> - -#include <boost/chrono.hpp> -#include <boost/filesystem.hpp> -#include <boost/thread.hpp> -#include <chrono> -#include "../../contrib/otshell_utils/utils.hpp" - -namespace epee -{ -namespace net_utils -{ - data_logger &data_logger::get_instance() { - boost::call_once(m_singleton, - [] { - _info_c("dbg/data","Creating singleton of data_logger"); - if (m_state != data_logger_state::state_before_init) { _erro_c("dbg/data","Internal error in singleton"); throw std::runtime_error("data_logger singleton"); } - m_state = data_logger_state::state_during_init; - m_obj.reset(new data_logger()); - m_state = data_logger_state::state_ready_to_use; - } - ); - - if (m_state != data_logger_state::state_ready_to_use) { - _erro ("trying to use not working data_logger"); - throw std::runtime_error("data_logger ctor state"); - } - - return * m_obj; - } - - data_logger::data_logger() { - _note_c("dbg/data","Starting data logger (for graphs data)"); - if (m_state != data_logger_state::state_during_init) { _erro_c("dbg/data","Singleton ctor state"); throw std::runtime_error("data_logger ctor state"); } - boost::lock_guard<boost::mutex> lock(mMutex); // lock - - // prepare all the files for given data channels: - mFilesMap["peers"] = data_logger::fileData("log/dr-monero/peers.data"); - mFilesMap["download"] = data_logger::fileData("log/dr-monero/net/in-all.data"); - mFilesMap["upload"] = data_logger::fileData("log/dr-monero/net/out-all.data"); - mFilesMap["request"] = data_logger::fileData("log/dr-monero/net/req-all.data"); - mFilesMap["sleep_down"] = data_logger::fileData("log/dr-monero/down_sleep_log.data"); - mFilesMap["sleep_up"] = data_logger::fileData("log/dr-monero/up_sleep_log.data"); - mFilesMap["calc_time"] = data_logger::fileData("log/dr-monero/get_objects_calc_time.data"); - mFilesMap["blockchain_processing_time"] = data_logger::fileData("log/dr-monero/blockchain_log.data"); - mFilesMap["block_processing"] = data_logger::fileData("log/dr-monero/block_proc.data"); - - mFilesMap["peers_limit"] = data_logger::fileData("log/dr-monero/peers_limit.info"); - mFilesMap["download_limit"] = data_logger::fileData("log/dr-monero/limit_down.info"); - mFilesMap["upload_limit"] = data_logger::fileData("log/dr-monero/limit_up.info"); - - mFilesMap["peers_limit"].mLimitFile = true; - mFilesMap["download_limit"].mLimitFile = true; - mFilesMap["upload_limit"].mLimitFile = true; - - // do NOT modify mFilesMap below this point, since there is no locking for this used (yet) - - _info_c("dbg/data","Creating thread for data logger"); // create timer thread - m_thread_maybe_running=true; - std::shared_ptr<boost::thread> logger_thread(new boost::thread([&]() { - _info_c("dbg/data","Inside thread for data logger"); - while (m_state == data_logger_state::state_during_init) { // wait for creation to be done (in other thread, in singleton) before actually running - boost::this_thread::sleep_for(boost::chrono::seconds(1)); - } - _info_c("dbg/data","Inside thread for data logger - going into main loop"); - while (m_state == data_logger_state::state_ready_to_use) { // run as long as we are not closing the single object - boost::this_thread::sleep_for(boost::chrono::seconds(1)); - saveToFile(); // save all the pending data - } - _info_c("dbg/data","Inside thread for data logger - done the main loop"); - m_thread_maybe_running=false; - })); - logger_thread->detach(); - _info_c("dbg/data","Data logger constructed"); - } - - data_logger::~data_logger() noexcept(false) { - _note_c("dbg/data","Destructor of the data logger"); - { - boost::lock_guard<boost::mutex> lock(mMutex); - m_state = data_logger_state::state_dying; - } - _info_c("dbg/data","State was set to dying"); - while(m_thread_maybe_running) { // wait for the thread to exit - boost::this_thread::sleep_for(boost::chrono::seconds(1)); - _info_c("dbg/data","Waiting for background thread to exit"); - } - _info_c("dbg/data","Thread exited"); - } - - void data_logger::kill_instance() { - m_state = data_logger_state::state_dying; - m_obj.reset(); - } - - void data_logger::add_data(std::string filename, unsigned int data) { - boost::lock_guard<boost::mutex> lock(mMutex); - if (m_state != data_logger_state::state_ready_to_use) { _info_c("dbg/data","Data logger is not ready, returning."); return; } - - if (mFilesMap.find(filename) == mFilesMap.end()) { // no such file/counter - _erro_c("dbg/data","Trying to use not opened data file filename="<<filename); - _erro_c("dbg/data","Disabling saving of graphs due to error"); - m_save_graph=false; // <--- disabling saving graphs - return; - } - - if (mFilesMap[filename].mLimitFile) { // this holds a number (that is not additive) - e.g. the limit setting - mFilesMap[filename].mDataToSave = data; - } else { - mFilesMap[filename].mDataToSave += data; // this holds a number that should be sum of all accumulated samples - } - } - - bool data_logger::is_dying() { - if (m_state == data_logger_state::state_dying) { - return true; - } - else { - return false; - } - } - - void data_logger::saveToFile() { - _dbg2_c("dbg/data","saving to files"); - boost::lock_guard<boost::mutex> lock(mMutex); - if (m_state != data_logger_state::state_ready_to_use) { _info_c("dbg/data","Data logger is not ready, returning."); return; } - nOT::nUtils::cFilesystemUtils::CreateDirTree("log/dr-monero/net/"); - for (auto &element : mFilesMap) - { - element.second.save(); - if (!element.second.mLimitFile) element.second.mDataToSave = 0; - } - } - - // the inner class: - - double data_logger::fileData::get_current_time() { - #if defined(__APPLE__) - auto point = std::chrono::system_clock::now(); - #else - auto point = std::chrono::steady_clock::now(); - #endif - auto time_from_epoh = point.time_since_epoch(); - auto ms = std::chrono::duration_cast< std::chrono::milliseconds >( time_from_epoh ).count(); - double ms_f = ms; - return ms_f / 1000.; - } - - data_logger::fileData::fileData(std::string pFile) { - _dbg3_c("dbg/data","opening data file named pFile="<<pFile<<" for this="<<this); - mFile = std::make_shared<std::ofstream> (pFile); - _dbg1_c("dbg/data","opened data file named pFile="<<pFile<<" in mFile="<<mFile<<" for this="<<this); - mPath = pFile; - } - - void data_logger::fileData::save() { - if (!data_logger::m_save_graph) return; // <--- disabled - _dbg2_c("dbg/data","saving to the file now, mFile="<<mFile); - mFile->open(mPath, std::ios::app); - *mFile << static_cast<int>(get_current_time()) << " " << mDataToSave << std::endl; - mFile->close(); - } - - -data_logger_state data_logger::m_state(data_logger_state::state_before_init); ///< (static) state of the singleton object -std::atomic<bool> data_logger::m_save_graph(false); // (static) -std::atomic<bool> data_logger::m_thread_maybe_running(false); // (static) -boost::once_flag data_logger::m_singleton; // (static) -std::unique_ptr<data_logger> data_logger::m_obj; // (static) - -} // namespace -} // namespace - diff --git a/src/p2p/data_logger.hpp b/src/p2p/data_logger.hpp deleted file mode 100644 index 278d08bfc..000000000 --- a/src/p2p/data_logger.hpp +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright (c) 2014-2016, 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. - -#ifndef INCLUDED_p2p_data_logger_hpp -#define INCLUDED_p2p_data_logger_hpp - -#include <string> -#include <map> -#include <fstream> -#include <memory> -#include <boost/thread/thread.hpp> -#include <boost/thread/mutex.hpp> -#include <boost/thread/once.hpp> -#include <atomic> - -namespace epee -{ -namespace net_utils -{ - -enum class data_logger_state { state_before_init, state_during_init, state_ready_to_use, state_dying }; - -/*** -@note: use it ONLY via singleton! It will be spawned then, and will auto destruct on program exit. -@note: do call ::kill_instance() before exiting main, at end of main. But before make sure no one else (e.g. no other threads) will try to use this/singleton -@note: it is not allowed to use this class from code "runnig before or after main", e.g. from ctors of static objects, because of static-creation-order races -@note: on creation (e.g. from singleton), it spawns a thread that saves all data in background -*/ - class data_logger { - public: - static data_logger &get_instance(); ///< singleton - static void kill_instance(); ///< call this before ending main to allow more gracefull shutdown of the main singleton and it's background thread - ~data_logger() noexcept(false); ///< destr, will be called when singleton is killed when global m_obj dies. will kill theads etc - - private: - data_logger(); ///< constructor is private, use only via singleton get_instance - - public: - data_logger(const data_logger &ob) = delete; // use only one per program - data_logger(data_logger &&ob) = delete; - data_logger & operator=(const data_logger&) = delete; - data_logger & operator=(data_logger&&) = delete; - - void add_data(std::string filename, unsigned int data); ///< use this to append data here. Use it only the singleton. It locks itself. - - static std::atomic<bool> m_save_graph; ///< global setting flag, should we save all the data or not (can disable logging graphs data) - static bool is_dying(); - - private: - static boost::once_flag m_singleton; ///< to guarantee singleton creates the object exactly once - static data_logger_state m_state; ///< state of the singleton object - static std::atomic<bool> m_thread_maybe_running; ///< is the background thread (more or less) running, or is it fully finished - static std::unique_ptr<data_logger> m_obj; ///< the singleton object. Only use it via get_instance(). Can be killed by kill_instance() - - /*** - * one graph/file with data - */ - class fileData { - public: - fileData() = default; - fileData(const fileData &ob) = delete; - fileData(std::string pFile); - - std::shared_ptr<std::ofstream> mFile; - long int mDataToSave = 0; ///< sum of the data (in current interval, will be counted from 0 on next interval) - static double get_current_time(); - void save(); - std::string mPath; - bool mLimitFile = false; ///< this holds a number (that is not additive) - e.g. the limit setting - }; - - std::map<std::string, fileData> mFilesMap; - boost::mutex mMutex; - void saveToFile(); ///< write data to the target files. do not use this directly - }; - -} // namespace -} // namespace - -#endif diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index f32e7a435..34a3f9363 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -48,7 +48,6 @@ #include "net/local_ip.h" #include "crypto/crypto.h" #include "storages/levin_abstract_invoke2.h" -#include "data_logger.hpp" // We have to look for miniupnpc headers in different places, dependent on if its compiled or external #ifdef UPNP_STATIC @@ -61,6 +60,9 @@ #include "upnperrors.h" #endif +#undef MONERO_DEFAULT_LOG_CATEGORY +#define MONERO_DEFAULT_LOG_CATEGORY "net.p2p" + #define NET_MAKE_IP(b1,b2,b3,b4) ((LPARAM)(((DWORD)(b1)<<24)+((DWORD)(b2)<<16)+((DWORD)(b3)<<8)+((DWORD)(b4)))) @@ -203,7 +205,7 @@ namespace nodetool if(time(nullptr) >= it->second) { m_blocked_ips.erase(it); - LOG_PRINT_CYAN("IP " << epee::string_tools::get_ip_string_from_int32(addr) << " unblocked.", LOG_LEVEL_0); + MLOG_CYAN(el::Level::Info, "IP " << epee::string_tools::get_ip_string_from_int32(addr) << " unblocked."); return true; } return false; @@ -235,7 +237,7 @@ namespace nodetool for (const auto &c: conns) m_net_server.get_config_object().close(c); - LOG_PRINT_CYAN("IP " << epee::string_tools::get_ip_string_from_int32(addr) << " blocked.", LOG_LEVEL_0); + MLOG_CYAN(el::Level::Info, "IP " << epee::string_tools::get_ip_string_from_int32(addr) << " blocked."); return true; } //----------------------------------------------------------------------------------- @@ -247,7 +249,7 @@ namespace nodetool if (i == m_blocked_ips.end()) return false; m_blocked_ips.erase(i); - LOG_PRINT_CYAN("IP " << epee::string_tools::get_ip_string_from_int32(addr) << " unblocked.", LOG_LEVEL_0); + MLOG_CYAN(el::Level::Info, "IP " << epee::string_tools::get_ip_string_from_int32(addr) << " unblocked."); return true; } //----------------------------------------------------------------------------------- @@ -256,7 +258,7 @@ namespace nodetool { CRITICAL_REGION_LOCAL(m_ip_fails_score_lock); uint64_t fails = ++m_ip_fails_score[address]; - LOG_PRINT_CYAN("IP " << epee::string_tools::get_ip_string_from_int32(address) << " fail score=" << fails, LOG_LEVEL_1); + MDEBUG("IP " << epee::string_tools::get_ip_string_from_int32(address) << " fail score=" << fails); if(fails > P2P_IP_FAILS_BEFORE_BLOCK) { auto it = m_ip_fails_score.find(address); @@ -376,11 +378,11 @@ namespace nodetool na.ip = boost::asio::detail::socket_ops::host_to_network_long(endpoint.address().to_v4().to_ulong()); na.port = endpoint.port(); seed_nodes.push_back(na); - LOG_PRINT_L4("Added seed node: " << endpoint.address().to_v4().to_string(ec) << ':' << na.port); + MINFO("Added seed node: " << endpoint.address().to_v4().to_string(ec) << ':' << na.port); } else { - LOG_PRINT_L2("IPv6 doesn't supported, skip '" << host << "' -> " << endpoint.address().to_v6().to_string(ec)); + MDEBUG("IPv6 doesn't supported, skip '" << host << "' -> " << endpoint.address().to_v6().to_string(ec)); } } } @@ -416,7 +418,7 @@ namespace nodetool { boost::thread* th = new boost::thread([=, &dns_results, &addr_str] { - LOG_PRINT_L4("dns_threads[" << result_index << "] created for: " << addr_str); + MDEBUG("dns_threads[" << result_index << "] created for: " << addr_str); // TODO: care about dnssec avail/valid bool avail, valid; std::vector<std::string> addr_list; @@ -424,7 +426,7 @@ namespace nodetool try { addr_list = tools::DNSResolver::instance().get_ipv4(addr_str, avail, valid); - LOG_PRINT_L4("dns_threads[" << result_index << "] DNS resolve done"); + MDEBUG("dns_threads[" << result_index << "] DNS resolve done"); boost::this_thread::interruption_point(); } catch(const boost::thread_interrupted&) @@ -432,11 +434,11 @@ namespace nodetool // thread interruption request // even if we now have results, finish thread without setting // result variables, which are now out of scope in main thread - LOG_PRINT_L4("dns_threads[" << result_index << "] interrupted"); + MWARNING("dns_threads[" << result_index << "] interrupted"); return; } - LOG_PRINT_L4("dns_threads[" << result_index << "] addr_str: " << addr_str << " number of results: " << addr_list.size()); + MINFO("dns_threads[" << result_index << "] addr_str: " << addr_str << " number of results: " << addr_list.size()); dns_results[result_index] = addr_list; }); @@ -444,14 +446,14 @@ namespace nodetool ++result_index; } - LOG_PRINT_L4("dns_threads created, now waiting for completion or timeout of " << CRYPTONOTE_DNS_TIMEOUT_MS << "ms"); + MDEBUG("dns_threads created, now waiting for completion or timeout of " << CRYPTONOTE_DNS_TIMEOUT_MS << "ms"); boost::chrono::system_clock::time_point deadline = boost::chrono::system_clock::now() + boost::chrono::milliseconds(CRYPTONOTE_DNS_TIMEOUT_MS); uint64_t i = 0; for (boost::thread* th : dns_threads) { if (! th->try_join_until(deadline)) { - LOG_PRINT_L4("dns_threads[" << i << "] timed out, sending interrupt"); + MWARNING("dns_threads[" << i << "] timed out, sending interrupt"); th->interrupt(); } ++i; @@ -460,7 +462,7 @@ namespace nodetool i = 0; for (const auto& result : dns_results) { - LOG_PRINT_L4("DNS lookup for " << m_seed_nodes_list[i] << ": " << result.size() << " results"); + MDEBUG("DNS lookup for " << m_seed_nodes_list[i] << ": " << result.size() << " results"); // if no results for node, thread's lookup likely timed out if (result.size()) { @@ -472,7 +474,7 @@ namespace nodetool if (!full_addrs.size()) { - LOG_PRINT_L0("DNS seed node lookup either timed out or failed, falling back to defaults"); + MINFO("DNS seed node lookup either timed out or failed, falling back to defaults"); full_addrs.insert("198.74.231.92:18080"); full_addrs.insert("161.67.132.39:18080"); full_addrs.insert("163.172.182.165:18080"); @@ -483,10 +485,10 @@ namespace nodetool for (const auto& full_addr : full_addrs) { - LOG_PRINT_L2("Seed node: " << full_addr); + MDEBUG("Seed node: " << full_addr); append_net_address(m_seed_nodes, full_addr); } - LOG_PRINT_L1("Number of seed nodes: " << m_seed_nodes.size()); + MDEBUG("Number of seed nodes: " << m_seed_nodes.size()); bool res = handle_command_line(vm, testnet); CHECK_AND_ASSERT_MES(res, false, "Failed to handle command line"); @@ -520,18 +522,18 @@ namespace nodetool return res; //try to bind - LOG_PRINT_L0("Binding on " << m_bind_ip << ":" << m_port); + MINFO("Binding on " << m_bind_ip << ":" << m_port); res = m_net_server.init_server(m_port, m_bind_ip); CHECK_AND_ASSERT_MES(res, false, "Failed to bind server"); m_listenning_port = m_net_server.get_binded_port(); - LOG_PRINT_GREEN("Net service bound to " << m_bind_ip << ":" << m_listenning_port, LOG_LEVEL_0); + MLOG_GREEN(el::Level::Info, "Net service bound to " << m_bind_ip << ":" << m_listenning_port); if(m_external_port) - LOG_PRINT_L0("External port defined as " << m_external_port); + MDEBUG("External port defined as " << m_external_port); // Add UPnP port mapping if(m_no_igd == false) { - LOG_PRINT_L0("Attempting to add IGD port mapping."); + MDEBUG("Attempting to add IGD port mapping."); int result; #if MINIUPNPC_API_VERSION > 13 // default according to miniupnpc.h @@ -558,19 +560,19 @@ namespace nodetool if (portMappingResult != 0) { LOG_ERROR("UPNP_AddPortMapping failed, error: " << strupnperror(portMappingResult)); } else { - LOG_PRINT_GREEN("Added IGD port mapping.", LOG_LEVEL_0); + MLOG_GREEN(el::Level::Info, "Added IGD port mapping."); } } else if (result == 2) { - LOG_PRINT_L0("IGD was found but reported as not connected."); + MWARNING("IGD was found but reported as not connected."); } else if (result == 3) { - LOG_PRINT_L0("UPnP device was found but not recognized as IGD."); + MWARNING("UPnP device was found but not recognized as IGD."); } else { - LOG_ERROR("UPNP_GetValidIGD returned an unknown result code."); + MWARNING("UPNP_GetValidIGD returned an unknown result code."); } FreeUPNPUrls(&urls); } else { - LOG_PRINT_L0("No IGD was found."); + MINFO("No IGD was found."); } } return res; @@ -600,9 +602,6 @@ namespace nodetool }); // lambda m_current_number_of_out_peers = number_of_peers; - if (epee::net_utils::data_logger::is_dying()) - break; - epee::net_utils::data_logger::get_instance().add_data("peers", number_of_peers); boost::this_thread::sleep_for(boost::chrono::seconds(1)); } // main loop of thread @@ -619,13 +618,13 @@ namespace nodetool attrs.set_stack_size(THREAD_STACK_SIZE); //go to loop - LOG_PRINT("Run net_service loop( " << thrds_count << " threads)...", LOG_LEVEL_0); + MINFO("Run net_service loop( " << thrds_count << " threads)..."); if(!m_net_server.run_server(thrds_count, true, attrs)) { LOG_ERROR("Failed to run net tcp server!"); } - LOG_PRINT("net_service loop stopped.", LOG_LEVEL_0); + MINFO("net_service loop stopped."); return true; } @@ -652,7 +651,7 @@ namespace nodetool TRY_ENTRY(); if (!tools::create_directories_if_necessary(m_config_folder)) { - LOG_PRINT_L0("Failed to create data directory: " << m_config_folder); + MWARNING("Failed to create data directory: " << m_config_folder); return false; } @@ -661,7 +660,7 @@ namespace nodetool p2p_data.open( state_file_path , std::ios_base::binary | std::ios_base::out| std::ios::trunc); if(p2p_data.fail()) { - LOG_PRINT_L0("Failed to save config to file " << state_file_path); + MWARNING("Failed to save config to file " << state_file_path); return false; }; @@ -678,7 +677,7 @@ namespace nodetool { m_payload_handler.stop(); m_net_server.send_stop_signal(); - LOG_PRINT_L0("[node] Stop signal sent"); + MDEBUG("[node] Stop signal sent"); return true; } //----------------------------------------------------------------------------------- @@ -702,19 +701,19 @@ namespace nodetool if(code < 0) { - LOG_PRINT_CC_RED(context, "COMMAND_HANDSHAKE invoke failed. (" << code << ", " << epee::levin::get_err_descr(code) << ")", LOG_LEVEL_1); + LOG_ERROR_CC(context, "COMMAND_HANDSHAKE invoke failed. (" << code << ", " << epee::levin::get_err_descr(code) << ")"); return; } if(rsp.node_data.network_id != m_network_id) { - LOG_ERROR_CCONTEXT("COMMAND_HANDSHAKE Failed, wrong network! (" << epee::string_tools::get_str_from_guid_a(rsp.node_data.network_id) << "), closing connection."); + LOG_ERROR_CC(context, "COMMAND_HANDSHAKE Failed, wrong network! (" << epee::string_tools::get_str_from_guid_a(rsp.node_data.network_id) << "), closing connection."); return; } if(!handle_remote_peerlist(rsp.local_peerlist, rsp.node_data.local_time, context)) { - LOG_ERROR_CCONTEXT("COMMAND_HANDSHAKE: failed to handle_remote_peerlist(...), closing connection."); + LOG_ERROR_CC(context, "COMMAND_HANDSHAKE: failed to handle_remote_peerlist(...), closing connection."); add_ip_fail(context.m_remote_ip); return; } @@ -723,7 +722,7 @@ namespace nodetool { if(!m_payload_handler.process_payload_sync_data(rsp.payload_data, context, true)) { - LOG_ERROR_CCONTEXT("COMMAND_HANDSHAKE invoked, but process_payload_sync_data returned false, dropping connection."); + LOG_ERROR_CC(context, "COMMAND_HANDSHAKE invoked, but process_payload_sync_data returned false, dropping connection."); hsh_result = false; return; } @@ -733,14 +732,14 @@ namespace nodetool if(rsp.node_data.peer_id == m_config.m_peer_id) { - LOG_PRINT_CCONTEXT_L2("Connection to self detected, dropping connection"); + LOG_DEBUG_CC(context, "Connection to self detected, dropping connection"); hsh_result = false; return; } - LOG_PRINT_CCONTEXT_L1(" COMMAND_HANDSHAKE INVOKED OK"); + LOG_DEBUG_CC(context, " COMMAND_HANDSHAKE INVOKED OK"); }else { - LOG_PRINT_CCONTEXT_L1(" COMMAND_HANDSHAKE(AND CLOSE) INVOKED OK"); + LOG_DEBUG_CC(context, " COMMAND_HANDSHAKE(AND CLOSE) INVOKED OK"); } }, P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT); @@ -751,7 +750,7 @@ namespace nodetool if(!hsh_result) { - LOG_PRINT_CC_L1(context_, "COMMAND_HANDSHAKE Failed"); + LOG_ERROR_CC(context_, "COMMAND_HANDSHAKE Failed"); m_net_server.get_config_object().close(context_.m_connection_id); } else @@ -776,13 +775,13 @@ namespace nodetool { if(code < 0) { - LOG_PRINT_CC_RED(context, "COMMAND_TIMED_SYNC invoke failed. (" << code << ", " << epee::levin::get_err_descr(code) << ")", LOG_LEVEL_1); + LOG_ERROR_CC(context, "COMMAND_TIMED_SYNC invoke failed. (" << code << ", " << epee::levin::get_err_descr(code) << ")"); return; } if(!handle_remote_peerlist(rsp.local_peerlist, rsp.local_time, context)) { - LOG_ERROR_CCONTEXT("COMMAND_TIMED_SYNC: failed to handle_remote_peerlist(...), closing connection."); + LOG_WARNING_CC(context, "COMMAND_TIMED_SYNC: failed to handle_remote_peerlist(...), closing connection."); m_net_server.get_config_object().close(context.m_connection_id ); add_ip_fail(context.m_remote_ip); } @@ -793,7 +792,7 @@ namespace nodetool if(!r) { - LOG_PRINT_CC_L2(context_, "COMMAND_TIMED_SYNC Failed"); + LOG_ERROR_CC(context_, "COMMAND_TIMED_SYNC Failed"); return false; } return true; @@ -808,7 +807,7 @@ namespace nodetool size_t x = crypto::rand<size_t>()%(max_index+1); size_t res = (x*x*x)/(max_index*max_index); //parabola \/ - LOG_PRINT_L3("Random connection index=" << res << "(x="<< x << ", max_index=" << max_index << ")"); + MDEBUG("Random connection index=" << res << "(x="<< x << ", max_index=" << max_index << ")"); return res; } //----------------------------------------------------------------------------------- @@ -853,9 +852,9 @@ namespace nodetool #define LOG_PRINT_CC_PRIORITY_NODE(priority, con, msg) \ do { \ if (priority) {\ - LOG_PRINT_CC_L1(con, msg); \ + LOG_INFO_CC(con, "[priority]" << msg); \ } else {\ - LOG_PRINT_CC_L1(con, msg); \ + LOG_INFO_CC(con, msg); \ } \ } while(0) @@ -872,7 +871,7 @@ namespace nodetool m_current_number_of_out_peers --; // atomic variable, update time = 1s return false; } - LOG_PRINT_L1("Connecting to " << epee::string_tools::get_ip_string_from_int32(na.ip) << ":" + MDEBUG("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") << ")..."); @@ -910,7 +909,7 @@ namespace nodetool if(just_take_peerlist) { m_net_server.get_config_object().close(con.m_connection_id); - LOG_PRINT_CC_GREEN(con, "CONNECTION HANDSHAKED OK AND CLOSED.", LOG_LEVEL_2); + LOG_DEBUG_CC(con, "CONNECTION HANDSHAKED OK AND CLOSED."); return true; } @@ -923,7 +922,7 @@ namespace nodetool m_peerlist.append_with_peer_white(pe_local); //update last seen and push it to peerlist manager - LOG_PRINT_CC_GREEN(con, "CONNECTION HANDSHAKED OK.", LOG_LEVEL_2); + LOG_DEBUG_CC(con, "CONNECTION HANDSHAKED OK."); return true; } @@ -986,7 +985,7 @@ namespace nodetool if(is_addr_recently_failed(pe.adr)) continue; - LOG_PRINT_L2("Selected peer: " << pe.id << " " << epee::string_tools::get_ip_string_from_int32(pe.adr.ip) + MDEBUG("Selected peer: " << pe.id << " " << epee::string_tools::get_ip_string_from_int32(pe.adr.ip) << ":" << boost::lexical_cast<std::string>(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")); @@ -1021,7 +1020,7 @@ namespace nodetool break; if(++try_count > m_seed_nodes.size()) { - LOG_PRINT_RED_L0("Failed to connect to any of seed peers, continuing without seeds"); + MWARNING("Failed to connect to any of seed peers, continuing without seeds"); break; } if(++current_index >= m_seed_nodes.size()) @@ -1105,7 +1104,7 @@ namespace nodetool template<class t_payload_net_handler> bool node_server<t_payload_net_handler>::peer_sync_idle_maker() { - LOG_PRINT_L2("STARTED PEERLIST IDLE HANDSHAKE"); + MDEBUG("STARTED PEERLIST IDLE HANDSHAKE"); typedef std::list<std::pair<epee::net_utils::connection_context_base, peerid_type> > local_connects_type; local_connects_type cncts; m_net_server.get_config_object().foreach_connection([&](const p2p_connection_context& cntxt) @@ -1117,7 +1116,7 @@ namespace nodetool std::for_each(cncts.begin(), cncts.end(), [&](const typename local_connects_type::value_type& vl){do_peer_timed_sync(vl.first, vl.second);}); - LOG_PRINT_L2("FINISHED PEERLIST IDLE HANDSHAKE"); + MDEBUG("FINISHED PEERLIST IDLE HANDSHAKE"); return true; } //----------------------------------------------------------------------------------- @@ -1133,7 +1132,7 @@ namespace nodetool { if(be.last_seen > local_time) { - LOG_PRINT_RED_L1("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); + MWARNING("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; @@ -1148,8 +1147,8 @@ namespace nodetool std::list<peerlist_entry> peerlist_ = peerlist; if(!fix_time_delta(peerlist_, local_time, delta)) return false; - LOG_PRINT_CCONTEXT_L2("REMOTE PEERLIST: TIME_DELTA: " << delta << ", remote peerlist size=" << peerlist_.size()); - LOG_PRINT_CCONTEXT_L3("REMOTE PEERLIST: " << print_peerlist_to_string(peerlist_)); + LOG_DEBUG_CC(context, "REMOTE PEERLIST: TIME_DELTA: " << delta << ", remote peerlist size=" << peerlist_.size()); + LOG_DEBUG_CC(context, "REMOTE PEERLIST: " << print_peerlist_to_string(peerlist_)); return m_peerlist.merge_peerlist(peerlist_); } //----------------------------------------------------------------------------------- @@ -1332,7 +1331,7 @@ namespace nodetool { if(ec) { - LOG_PRINT_CC_L2(ping_context, "back ping connect failed to " << ip << ":" << port); + LOG_WARNING_CC(ping_context, "back ping connect failed to " << ip << ":" << port); return false; } COMMAND_PING::request req; @@ -1351,13 +1350,13 @@ namespace nodetool { if(code <= 0) { - LOG_PRINT_CC_L2(ping_context, "Failed to invoke COMMAND_PING to " << ip << ":" << port << "(" << code << ", " << epee::levin::get_err_descr(code) << ")"); + LOG_ERROR_CC(ping_context, "Failed to invoke COMMAND_PING to " << ip << ":" << port << "(" << code << ", " << epee::levin::get_err_descr(code) << ")"); return; } if(rsp.status != PING_OK_RESPONSE_STATUS_TEXT || pr != rsp.peer_id) { - LOG_PRINT_CC_L2(ping_context, "back ping invoke wrong response \"" << rsp.status << "\" from" << ip << ":" << port << ", hsh_peer_id=" << pr_ << ", rsp.peer_id=" << rsp.peer_id); + LOG_ERROR_CC(ping_context, "back ping invoke wrong response \"" << rsp.status << "\" from" << ip << ":" << port << ", hsh_peer_id=" << pr_ << ", rsp.peer_id=" << rsp.peer_id); m_net_server.get_config_object().close(ping_context.m_connection_id); return; } @@ -1367,7 +1366,7 @@ namespace nodetool if(!inv_call_res) { - LOG_PRINT_CC_L2(ping_context, "back ping invoke failed to " << ip << ":" << port); + LOG_ERROR_CC(ping_context, "back ping invoke failed to " << ip << ":" << port); m_net_server.get_config_object().close(ping_context.m_connection_id); return false; } @@ -1375,7 +1374,7 @@ namespace nodetool }); if(!r) { - LOG_ERROR("Failed to call connect_async, network error."); + LOG_ERROR_CC(context, "Failed to call connect_async, network error."); } return r; } @@ -1394,7 +1393,7 @@ namespace nodetool { if(code < 0) { - LOG_PRINT_CC_RED(context_, "COMMAND_REQUEST_SUPPORT_FLAGS invoke failed. (" << code << ", " << epee::levin::get_err_descr(code) << ")", LOG_LEVEL_1); + LOG_ERROR_CC(context_, "COMMAND_REQUEST_SUPPORT_FLAGS invoke failed. (" << code << ", " << epee::levin::get_err_descr(code) << ")"); return; } @@ -1411,7 +1410,7 @@ namespace nodetool { if(!m_payload_handler.process_payload_sync_data(arg.payload_data, context, false)) { - LOG_ERROR_CCONTEXT("Failed to process_payload_sync_data(), dropping connection"); + LOG_ERROR_CC(context, "Failed to process_payload_sync_data(), dropping connection"); drop_connection(context); return 1; } @@ -1420,7 +1419,7 @@ namespace nodetool rsp.local_time = time(NULL); m_peerlist.get_peerlist_head(rsp.local_peerlist); m_payload_handler.get_payload_sync_data(rsp.payload_data); - LOG_PRINT_CCONTEXT_L2("COMMAND_TIMED_SYNC"); + LOG_DEBUG_CC(context, "COMMAND_TIMED_SYNC"); return 1; } //----------------------------------------------------------------------------------- @@ -1430,7 +1429,7 @@ namespace nodetool if(arg.node_data.network_id != m_network_id) { - LOG_PRINT_CCONTEXT_L1("WRONG NETWORK AGENT CONNECTED! id=" << epee::string_tools::get_str_from_guid_a(arg.node_data.network_id)); + LOG_INFO_CC(context, "WRONG NETWORK AGENT CONNECTED! id=" << epee::string_tools::get_str_from_guid_a(arg.node_data.network_id)); drop_connection(context); add_ip_fail(context.m_remote_ip); return 1; @@ -1438,7 +1437,7 @@ namespace nodetool if(!context.m_is_income) { - LOG_ERROR_CCONTEXT("COMMAND_HANDSHAKE came not from incoming connection"); + LOG_ERROR_CC(context, "COMMAND_HANDSHAKE came not from incoming connection"); drop_connection(context); add_ip_fail(context.m_remote_ip); return 1; @@ -1446,14 +1445,14 @@ namespace nodetool if(context.peer_id) { - LOG_ERROR_CCONTEXT("COMMAND_HANDSHAKE came, but seems that connection already have associated peer_id (double COMMAND_HANDSHAKE?)"); + LOG_ERROR_CC(context, "COMMAND_HANDSHAKE came, but seems that connection already have associated peer_id (double COMMAND_HANDSHAKE?)"); drop_connection(context); return 1; } if(!m_payload_handler.process_payload_sync_data(arg.payload_data, context, true)) { - LOG_ERROR_CCONTEXT("COMMAND_HANDSHAKE came, but process_payload_sync_data returned false, dropping connection."); + LOG_ERROR_CC(context, "COMMAND_HANDSHAKE came, but process_payload_sync_data returned false, dropping connection."); drop_connection(context); return 1; } @@ -1476,7 +1475,7 @@ namespace nodetool pe.last_seen = static_cast<int64_t>(last_seen); pe.id = peer_id_l; this->m_peerlist.append_with_peer_white(pe); - LOG_PRINT_CCONTEXT_L2("PING SUCCESS " << epee::string_tools::get_ip_string_from_int32(context.m_remote_ip) << ":" << port_l); + LOG_DEBUG_CC(context, "PING SUCCESS " << epee::string_tools::get_ip_string_from_int32(context.m_remote_ip) << ":" << port_l); }); } @@ -1489,14 +1488,14 @@ namespace nodetool m_peerlist.get_peerlist_head(rsp.local_peerlist); get_local_node_data(rsp.node_data); m_payload_handler.get_payload_sync_data(rsp.payload_data); - LOG_PRINT_CCONTEXT_GREEN("COMMAND_HANDSHAKE", LOG_LEVEL_1); + LOG_DEBUG_CC(context, "COMMAND_HANDSHAKE"); return 1; } //----------------------------------------------------------------------------------- template<class t_payload_net_handler> int node_server<t_payload_net_handler>::handle_ping(int command, COMMAND_PING::request& arg, COMMAND_PING::response& rsp, p2p_connection_context& context) { - LOG_PRINT_CCONTEXT_L2("COMMAND_PING"); + LOG_DEBUG_CC(context, "COMMAND_PING"); rsp.status = PING_OK_RESPONSE_STATUS_TEXT; rsp.peer_id = m_config.m_peer_id; return 1; @@ -1508,14 +1507,14 @@ namespace nodetool std::list<peerlist_entry> pl_white; std::list<peerlist_entry> pl_gray; m_peerlist.get_peerlist_full(pl_gray, pl_white); - LOG_PRINT_L0(ENDL << "Peerlist white:" << ENDL << print_peerlist_to_string(pl_white) << ENDL << "Peerlist gray:" << ENDL << print_peerlist_to_string(pl_gray) ); + MINFO(ENDL << "Peerlist white:" << ENDL << print_peerlist_to_string(pl_white) << ENDL << "Peerlist gray:" << ENDL << print_peerlist_to_string(pl_gray) ); return true; } //----------------------------------------------------------------------------------- template<class t_payload_net_handler> bool node_server<t_payload_net_handler>::log_connections() { - LOG_PRINT_L0("Connections: \r\n" << print_connections_container() ); + MINFO("Connections: \r\n" << print_connections_container() ); return true; } //----------------------------------------------------------------------------------- @@ -1539,13 +1538,13 @@ namespace nodetool template<class t_payload_net_handler> void node_server<t_payload_net_handler>::on_connection_new(p2p_connection_context& context) { - LOG_PRINT_L2("["<< epee::net_utils::print_connection_context(context) << "] NEW CONNECTION"); + MINFO("["<< epee::net_utils::print_connection_context(context) << "] NEW CONNECTION"); } //----------------------------------------------------------------------------------- template<class t_payload_net_handler> void node_server<t_payload_net_handler>::on_connection_close(p2p_connection_context& context) { - LOG_PRINT_L2("["<< epee::net_utils::print_connection_context(context) << "] CLOSE CONNECTION"); + MINFO("["<< epee::net_utils::print_connection_context(context) << "] CLOSE CONNECTION"); } template<class t_payload_net_handler> @@ -1595,10 +1594,8 @@ namespace nodetool { if(max == -1) { m_config.m_net_config.connections_count = P2P_DEFAULT_CONNECTIONS_COUNT; - epee::net_utils::data_logger::get_instance().add_data("peers_limit", m_config.m_net_config.connections_count); return true; } - epee::net_utils::data_logger::get_instance().add_data("peers_limit", max); m_config.m_net_config.connections_count = max; return true; } @@ -1632,7 +1629,7 @@ namespace nodetool limit *= 1024; epee::net_utils::connection<epee::levin::async_protocol_handler<p2p_connection_context> >::set_rate_up_limit( limit ); - LOG_PRINT_L0("Set limit-up to " << limit/1024 << " kB/s"); + MINFO("Set limit-up to " << limit/1024 << " kB/s"); return true; } @@ -1646,7 +1643,7 @@ namespace nodetool } limit *= 1024; epee::net_utils::connection<epee::levin::async_protocol_handler<p2p_connection_context> >::set_rate_down_limit( limit ); - LOG_PRINT_L0("Set limit-down to " << limit/1024 << " kB/s"); + MINFO("Set limit-down to " << limit/1024 << " kB/s"); return true; } @@ -1668,11 +1665,11 @@ namespace nodetool } if(!this->islimitup) { epee::net_utils::connection<epee::levin::async_protocol_handler<p2p_connection_context> >::set_rate_up_limit(limit_up); - LOG_PRINT_L0("Set limit-up to " << limit_up/1024 << " kB/s"); + MINFO("Set limit-up to " << limit_up/1024 << " kB/s"); } if(!this->islimitdown) { epee::net_utils::connection<epee::levin::async_protocol_handler<p2p_connection_context> >::set_rate_down_limit(limit_down); - LOG_PRINT_L0("Set limit-down to " << limit_down/1024 << " kB/s"); + MINFO("Set limit-down to " << limit_down/1024 << " kB/s"); } return true; diff --git a/src/p2p/network_throttle-detail.cpp b/src/p2p/network_throttle-detail.cpp index ed3c8e7b4..9efaaf95a 100644 --- a/src/p2p/network_throttle-detail.cpp +++ b/src/p2p/network_throttle-detail.cpp @@ -77,9 +77,8 @@ // TODO: #include "../../src/p2p/network_throttle-detail.hpp" -#include "../../contrib/otshell_utils/utils.hpp" -#include "data_logger.hpp" -using namespace nOT::nUtils; +#undef MONERO_DEFAULT_LOG_CATEGORY +#define MONERO_DEFAULT_LOG_CATEGORY "net.throttle" // ################################################################################################ // ################################################################################################ @@ -89,8 +88,6 @@ using namespace nOT::nUtils; // ################################################################################################ // ################################################################################################ -using namespace nOT::nUtils; - namespace epee { namespace net_utils @@ -163,7 +160,7 @@ void network_throttle::set_name(const std::string &name) void network_throttle::set_target_speed( network_speed_kbps target ) { m_target_speed = target * 1024; - _note_c("net/"+m_nameshort, "Setting LIMIT: " << target << " kbps"); + MINFO("Setting LIMIT: " << target << " kbps"); set_real_target_speed(target); } @@ -220,7 +217,7 @@ void network_throttle::_handle_trafic_exact(size_t packet_size, size_t orginal_s std::ostringstream oss; oss << "["; for (auto sample: m_history) oss << sample.m_size << " "; oss << "]" << std::ends; std::string history_str = oss.str(); - _dbg2_c( "net/" + m_nameshort , "Throttle " << m_name << ": packet of ~"<<packet_size<<"b " << " (from "<<orginal_size<<" b)" + MDEBUG("Throttle " << m_name << ": packet of ~"<<packet_size<<"b " << " (from "<<orginal_size<<" b)" << " Speed AVG=" << std::setw(4) << ((long int)(cts .average/1024)) <<"[w="<<cts .window<<"]" << " " << std::setw(4) << ((long int)(cts2.average/1024)) <<"[w="<<cts2.window<<"]" <<" / " << " Limit="<< ((long int)(m_target_speed/1024)) <<" KiB/sec " @@ -241,8 +238,6 @@ network_time_seconds network_throttle::get_sleep_time_after_tick(size_t packet_s } void network_throttle::logger_handle_net(const std::string &filename, double time, size_t size) { - if (! epee::net_utils::data_logger::m_save_graph) - return; boost::mutex mutex; mutex.lock(); { std::fstream file; @@ -312,8 +307,7 @@ void network_throttle::calculate_times(size_t packet_size, calculate_times_struc if (dbg) { std::ostringstream oss; oss << "["; for (auto sample: m_history) oss << sample.m_size << " "; oss << "]" << std::ends; std::string history_str = oss.str(); - _dbg1_c( "net/"+m_nameshort+"_c" , - (cts.delay > 0 ? "SLEEP" : "") + MDEBUG((cts.delay > 0 ? "SLEEP" : "") << "dbg " << m_name << ": " << "speed is A=" << std::setw(8) <<cts.average<<" vs " << "Max=" << std::setw(8) <<M<<" " |