aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contrib/epee/src/mlog.cpp6
-rw-r--r--external/easylogging++/easylogging++.h6
-rw-r--r--src/p2p/net_node.h2
-rw-r--r--src/p2p/net_node.inl30
4 files changed, 41 insertions, 3 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 688648452..8042392a0 100644
--- a/external/easylogging++/easylogging++.h
+++ b/external/easylogging++/easylogging++.h
@@ -1001,7 +1001,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/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;
+ }
}