diff options
-rw-r--r-- | contrib/epee/src/mlog.cpp | 6 | ||||
-rw-r--r-- | external/easylogging++/easylogging++.h | 6 | ||||
-rw-r--r-- | src/blockchain_db/lmdb/db_lmdb.cpp | 24 | ||||
-rw-r--r-- | src/p2p/net_node.h | 2 | ||||
-rw-r--r-- | src/p2p/net_node.inl | 30 | ||||
-rw-r--r-- | src/p2p/net_peerlist.h | 6 | ||||
-rw-r--r-- | src/simplewallet/simplewallet.cpp | 2 | ||||
-rw-r--r-- | src/wallet/api/wallet_manager.cpp | 5 | ||||
-rw-r--r-- | src/wallet/wallet2_api.h | 1 |
9 files changed, 65 insertions, 17 deletions
diff --git a/contrib/epee/src/mlog.cpp b/contrib/epee/src/mlog.cpp index 37a15bbd5..f1d74a2a3 100644 --- a/contrib/epee/src/mlog.cpp +++ b/contrib/epee/src/mlog.cpp @@ -33,7 +33,6 @@ INITIALIZE_EASYLOGGINGPP -//#define MLOG_BASE_FORMAT "%datetime{%Y-%M-%d %H:%m:%s.%g}\t%thread\t%level\t%logger\t%fbase:%line\t%msg" #define MLOG_BASE_FORMAT "%datetime{%Y-%M-%d %H:%m:%s.%g}\t%thread\t%level\t%logger\t%loc\t%msg" using namespace epee; @@ -83,7 +82,10 @@ void mlog_configure(const std::string &filename_base, bool console) el::Configurations c; c.setGlobally(el::ConfigurationType::Filename, filename_base); c.setGlobally(el::ConfigurationType::ToFile, "true"); - c.setGlobally(el::ConfigurationType::Format, MLOG_BASE_FORMAT); + const char *log_format = getenv("MONERO_LOG_FORMAT"); + if (!log_format) + log_format = MLOG_BASE_FORMAT; + c.setGlobally(el::ConfigurationType::Format, log_format); c.setGlobally(el::ConfigurationType::ToStandardOutput, console ? "true" : "false"); c.setGlobally(el::ConfigurationType::MaxLogFileSize, "104850000"); // 100 MB - 7600 bytes el::Loggers::setDefaultConfigurations(c, true); diff --git a/external/easylogging++/easylogging++.h b/external/easylogging++/easylogging++.h index 4a378923a..3395c2cb2 100644 --- a/external/easylogging++/easylogging++.h +++ b/external/easylogging++/easylogging++.h @@ -1006,7 +1006,11 @@ namespace el { public: Mutex(void) { # if ELPP_OS_UNIX - pthread_mutex_init(&m_underlyingMutex, nullptr); + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&m_underlyingMutex, &attr); + pthread_mutexattr_destroy(&attr); # elif ELPP_OS_WINDOWS InitializeCriticalSection(&m_underlyingMutex); # endif // ELPP_OS_UNIX diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index 343fd1fa4..7d548afed 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -441,7 +441,7 @@ void BlockchainLMDB::do_resize(uint64_t increase_size) if (result) throw0(DB_ERROR(lmdb_error("Failed to set new mapsize: ", result).c_str())); - MINFO("LMDB Mapsize increased." << " Old: " << mei.me_mapsize / (1024 * 1024) << "MiB" << ", New: " << new_mapsize / (1024 * 1024) << "MiB"); + MGINFO("LMDB Mapsize increased." << " Old: " << mei.me_mapsize / (1024 * 1024) << "MiB" << ", New: " << new_mapsize / (1024 * 1024) << "MiB"); mdb_txn_safe::allow_new_txns(); } @@ -525,7 +525,7 @@ void BlockchainLMDB::check_and_resize_for_batch(uint64_t batch_num_blocks) // size-based check if (need_resize(threshold_size)) { - LOG_PRINT_L0("[batch] DB resize needed"); + MGINFO("[batch] DB resize needed"); do_resize(increase_size); } } @@ -1172,7 +1172,7 @@ void BlockchainLMDB::open(const std::string& filename, const int mdb_flags) { if (*(const uint32_t*)v.mv_data > VERSION) { - MINFO("Existing lmdb database was made by a later version. We don't know how it will change yet."); + MWARNING("Existing lmdb database was made by a later version. We don't know how it will change yet."); compatible = false; } #if VERSION > 0 @@ -2301,11 +2301,11 @@ void BlockchainLMDB::batch_commit() if (! m_batch_transactions) throw0(DB_ERROR("batch transactions not enabled")); if (! m_batch_active) - throw0(DB_ERROR("batch transaction not in progress")); + throw1(DB_ERROR("batch transaction not in progress")); if (m_write_batch_txn == nullptr) - throw0(DB_ERROR("batch transaction not in progress")); + throw1(DB_ERROR("batch transaction not in progress")); if (m_writer != boost::this_thread::get_id()) - return; // batch txn owned by other thread + throw1(DB_ERROR("batch transaction owned by other thread")); check_open(); @@ -2328,11 +2328,11 @@ void BlockchainLMDB::batch_stop() if (! m_batch_transactions) throw0(DB_ERROR("batch transactions not enabled")); if (! m_batch_active) - throw0(DB_ERROR("batch transaction not in progress")); + throw1(DB_ERROR("batch transaction not in progress")); if (m_write_batch_txn == nullptr) - throw0(DB_ERROR("batch transaction not in progress")); + throw1(DB_ERROR("batch transaction not in progress")); if (m_writer != boost::this_thread::get_id()) - return; // batch txn owned by other thread + throw1(DB_ERROR("batch transaction owned by other thread")); check_open(); LOG_PRINT_L3("batch transaction: committing..."); TIME_MEASURE_START(time1); @@ -2354,9 +2354,11 @@ void BlockchainLMDB::batch_abort() if (! m_batch_transactions) throw0(DB_ERROR("batch transactions not enabled")); if (! m_batch_active) - throw0(DB_ERROR("batch transaction not in progress")); + throw1(DB_ERROR("batch transaction not in progress")); + if (m_write_batch_txn == nullptr) + throw1(DB_ERROR("batch transaction not in progress")); if (m_writer != boost::this_thread::get_id()) - return; // batch txn owned by other thread + throw1(DB_ERROR("batch transaction owned by other thread")); check_open(); // for destruction of batch transaction m_write_txn = nullptr; diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h index cc6a486d3..3f5a5ad93 100644 --- a/src/p2p/net_node.h +++ b/src/p2p/net_node.h @@ -227,6 +227,8 @@ namespace nodetool bool set_rate_down_limit(const boost::program_options::variables_map& vm, int64_t limit); bool set_rate_limit(const boost::program_options::variables_map& vm, int64_t limit); + bool has_too_many_connections(const uint32_t ip); + void kill() { ///< will be called e.g. from deinit() _info("Killing the net_node"); is_closing = true; diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 34a3f9363..60e51c222 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -1456,6 +1456,14 @@ namespace nodetool drop_connection(context); return 1; } + + if(has_too_many_connections(context.m_remote_ip)) + { + LOG_PRINT_CCONTEXT_L1("CONNECTION FROM " << epee::string_tools::get_ip_string_from_int32(context.m_remote_ip) << " REFUSED, too many connections from the same address"); + drop_connection(context); + return 1; + } + //associate peer_id with this connection context.peer_id = arg.node_data.peer_id; @@ -1674,4 +1682,26 @@ namespace nodetool return true; } + + template<class t_payload_net_handler> + bool node_server<t_payload_net_handler>::has_too_many_connections(const uint32_t ip) + { + const uint8_t max_connections = 1; + uint8_t count = 0; + + m_net_server.get_config_object().foreach_connection([&](const p2p_connection_context& cntxt) + { + if (cntxt.m_is_income && cntxt.m_remote_ip == ip) { + count++; + + if (count > max_connections) { + return false; + } + } + + return true; + }); + + return count > max_connections; + } } diff --git a/src/p2p/net_peerlist.h b/src/p2p/net_peerlist.h index fa69abd6e..db9387ceb 100644 --- a/src/p2p/net_peerlist.h +++ b/src/p2p/net_peerlist.h @@ -285,9 +285,11 @@ namespace nodetool { if(!vl.last_seen) continue; - bs_head.push_back(vl); - if(cnt++ > depth) + + if(cnt++ >= depth) break; + + bs_head.push_back(vl); } return true; } diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 68781dd73..bbdf6a4a7 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -1958,7 +1958,7 @@ bool simple_wallet::print_ring_members(const std::vector<tools::wallet2::pending return false; } // available for RPC version 1.4 or higher - if (version < 0x10004) + if (version < MAKE_CORE_RPC_VERSION(1, 4)) return true; std::string err; uint64_t blockchain_height = get_daemon_blockchain_height(err); diff --git a/src/wallet/api/wallet_manager.cpp b/src/wallet/api/wallet_manager.cpp index 12bce0285..904338a72 100644 --- a/src/wallet/api/wallet_manager.cpp +++ b/src/wallet/api/wallet_manager.cpp @@ -448,6 +448,11 @@ void WalletManagerFactory::setLogLevel(int level) mlog_set_log_level(level); } +void WalletManagerFactory::setLogCategories(const std::string &categories) +{ + mlog_set_categories(categories.c_str()); +} + } diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h index 5a13205c5..78caddc0b 100644 --- a/src/wallet/wallet2_api.h +++ b/src/wallet/wallet2_api.h @@ -708,6 +708,7 @@ struct WalletManagerFactory static WalletManager * getWalletManager(); static void setLogLevel(int level); + static void setLogCategories(const std::string &categories); }; |