aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp24
-rw-r--r--src/p2p/net_node.h2
-rw-r--r--src/p2p/net_node.inl30
3 files changed, 45 insertions, 11 deletions
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;
+ }
}