aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/core_rpc_server.cpp
diff options
context:
space:
mode:
authortobtoht <tob@featherwallet.org>2025-02-14 07:49:40 +0000
committertobtoht <tob@featherwallet.org>2025-02-14 07:49:40 +0000
commit23a11d851adef30aea1888da0a7dd23936c81ec1 (patch)
treec498e2dd419125e3ea617733e45f5fa4bd2bb0f6 /src/rpc/core_rpc_server.cpp
parent70afa6b7bcdea59ec3eec446f6bf39d24174f3c5 (diff)
parent13ff355cf6081776fd7379080c17246e35c1236d (diff)
downloadmonzero-core-23a11d851adef30aea1888da0a7dd23936c81ec1.tar.gz
monzero-core-23a11d851adef30aea1888da0a7dd23936c81ec1.tar.xz
monzero-core-23a11d851adef30aea1888da0a7dd23936c81ec1.zip
Merge pull request #9775
13ff355cf Set response limits on http server connections (Lee *!* Clagett) 89fa3ed68 epee: update 'http_server_handlers_map2.h' macros to use fully qualified names (Jeffrey Ryan)
Diffstat (limited to 'src/rpc/core_rpc_server.cpp')
-rw-r--r--src/rpc/core_rpc_server.cpp47
1 files changed, 46 insertions, 1 deletions
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index 1b0e3f261..95f3ddd40 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -163,6 +163,10 @@ namespace cryptonote
command_line::add_arg(desc, arg_rpc_payment_difficulty);
command_line::add_arg(desc, arg_rpc_payment_credits);
command_line::add_arg(desc, arg_rpc_payment_allow_free_loopback);
+ command_line::add_arg(desc, arg_rpc_max_connections_per_public_ip);
+ command_line::add_arg(desc, arg_rpc_max_connections_per_private_ip);
+ command_line::add_arg(desc, arg_rpc_max_connections);
+ command_line::add_arg(desc, arg_rpc_response_soft_limit);
}
//------------------------------------------------------------------------------------------------------------------------------
core_rpc_server::core_rpc_server(
@@ -369,11 +373,28 @@ namespace cryptonote
}
}
+ const auto max_connections_public = command_line::get_arg(vm, arg_rpc_max_connections_per_public_ip);
+ const auto max_connections_private = command_line::get_arg(vm, arg_rpc_max_connections_per_private_ip);
+ const auto max_connections = command_line::get_arg(vm, arg_rpc_max_connections);
+
+ if (max_connections < max_connections_public)
+ {
+ MFATAL(arg_rpc_max_connections_per_public_ip.name << " is bigger than " << arg_rpc_max_connections.name);
+ return false;
+ }
+ if (max_connections < max_connections_private)
+ {
+ MFATAL(arg_rpc_max_connections_per_private_ip.name << " is bigger than " << arg_rpc_max_connections.name);
+ return false;
+ }
+
auto rng = [](size_t len, uint8_t *ptr){ return crypto::rand(len, ptr); };
const bool inited = epee::http_server_impl_base<core_rpc_server, connection_context>::init(
rng, std::move(port), std::move(bind_ip_str),
std::move(bind_ipv6_str), std::move(rpc_config->use_ipv6), std::move(rpc_config->require_ipv4),
- std::move(rpc_config->access_control_origins), std::move(http_login), std::move(rpc_config->ssl_options)
+ std::move(rpc_config->access_control_origins), std::move(http_login), std::move(rpc_config->ssl_options),
+ max_connections_public, max_connections_private, max_connections,
+ command_line::get_arg(vm, arg_rpc_response_soft_limit)
);
m_net_server.get_config_object().m_max_content_length = MAX_RPC_CONTENT_LENGTH;
@@ -3748,4 +3769,28 @@ namespace cryptonote
, "Allow free access from the loopback address (ie, the local host)"
, false
};
+
+ const command_line::arg_descriptor<std::size_t> core_rpc_server::arg_rpc_max_connections_per_public_ip = {
+ "rpc-max-connections-per-public-ip"
+ , "Max RPC connections per public IP permitted"
+ , DEFAULT_RPC_MAX_CONNECTIONS_PER_PUBLIC_IP
+ };
+
+ const command_line::arg_descriptor<std::size_t> core_rpc_server::arg_rpc_max_connections_per_private_ip = {
+ "rpc-max-connections-per-private-ip"
+ , "Max RPC connections per private and localhost IP permitted"
+ , DEFAULT_RPC_MAX_CONNECTIONS_PER_PRIVATE_IP
+ };
+
+ const command_line::arg_descriptor<std::size_t> core_rpc_server::arg_rpc_max_connections = {
+ "rpc-max-connections"
+ , "Max RPC connections permitted"
+ , DEFAULT_RPC_MAX_CONNECTIONS
+ };
+
+ const command_line::arg_descriptor<std::size_t> core_rpc_server::arg_rpc_response_soft_limit = {
+ "rpc-response-soft-limit"
+ , "Max response bytes that can be queued, enforced at next response attempt"
+ , DEFAULT_RPC_SOFT_LIMIT_SIZE
+ };
} // namespace cryptonote