interim checkin of the rebased code

This commit is contained in:
Some Random Crypto Guy
2025-03-13 17:57:28 +00:00
parent 9570c7a910
commit 9baeb750ac
81 changed files with 1232 additions and 766 deletions
+52 -1
View File
@@ -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;
@@ -2835,6 +2856,12 @@ namespace cryptonote
}
else
{
if (!i->ip)
{
error_resp.code = CORE_RPC_ERROR_CODE_WRONG_PARAM;
error_resp.message = "No ip/host supplied";
return false;
}
na = epee::net_utils::ipv4_network_address{i->ip, 0};
}
if (i->ban)
@@ -3829,4 +3856,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
+4 -5
View File
@@ -47,10 +47,6 @@
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "daemon.rpc"
// yes, epee doesn't properly use its full namespace when calling its
// functions from macros. *sigh*
using namespace epee;
namespace cryptonote
{
/************************************************************************/
@@ -60,7 +56,6 @@ namespace cryptonote
{
public:
static const command_line::arg_descriptor<bool> arg_public_node;
static const command_line::arg_descriptor<std::string, false, true, 2> arg_rpc_bind_port;
static const command_line::arg_descriptor<std::string> arg_rpc_restricted_bind_port;
static const command_line::arg_descriptor<bool> arg_restricted_rpc;
@@ -77,6 +72,10 @@ namespace cryptonote
static const command_line::arg_descriptor<uint64_t> arg_rpc_payment_difficulty;
static const command_line::arg_descriptor<uint64_t> arg_rpc_payment_credits;
static const command_line::arg_descriptor<bool> arg_rpc_payment_allow_free_loopback;
static const command_line::arg_descriptor<std::size_t> arg_rpc_max_connections_per_public_ip;
static const command_line::arg_descriptor<std::size_t> arg_rpc_max_connections_per_private_ip;
static const command_line::arg_descriptor<std::size_t> arg_rpc_max_connections;
static const command_line::arg_descriptor<std::size_t> arg_rpc_response_soft_limit;
typedef epee::net_utils::connection_context_base connection_context;
+2
View File
@@ -536,6 +536,8 @@ namespace rpc
res.info.target_height = res.info.height;
}
m_core.get_blockchain_top(res.info.top_block_height, res.info.top_block_hash);
auto& chain = m_core.get_blockchain_storage();
res.info.wide_difficulty = chain.get_difficulty_for_next_block();
+1
View File
@@ -180,6 +180,7 @@ namespace rpc
{
uint64_t height;
uint64_t target_height;
uint64_t top_block_height;
cryptonote::difficulty_type wide_difficulty;
uint64_t difficulty;
uint64_t target;
+4 -4
View File
@@ -149,7 +149,7 @@ namespace cryptonote
{
// always parse IP here for error consistency
boost::system::error_code ec{};
const auto parsed_ip = boost::asio::ip::address::from_string(config.bind_ip, ec);
const auto parsed_ip = boost::asio::ip::make_address(config.bind_ip, ec);
if (ec)
{
LOG_ERROR(tr("Invalid IP address given for --") << arg.rpc_bind_ip.name);
@@ -177,7 +177,7 @@ namespace cryptonote
// always parse IP here for error consistency
boost::system::error_code ec{};
const auto parsed_ip = boost::asio::ip::address::from_string(config.bind_ipv6_address, ec);
const auto parsed_ip = boost::asio::ip::make_address(config.bind_ipv6_address, ec);
if (ec)
{
LOG_ERROR(tr("Invalid IP address given for --") << arg.rpc_bind_ipv6_address.name);
@@ -198,7 +198,7 @@ namespace cryptonote
{
// always parse IP here for error consistency
boost::system::error_code ec{};
boost::asio::ip::address::from_string(config.restricted_bind_ip, ec);
boost::asio::ip::make_address(config.restricted_bind_ip, ec);
if (ec)
{
LOG_ERROR(tr("Invalid IP address given for --") << arg.rpc_restricted_bind_ip.name);
@@ -215,7 +215,7 @@ namespace cryptonote
// always parse IP here for error consistency
boost::system::error_code ec{};
boost::asio::ip::address::from_string(config.restricted_bind_ipv6_address, ec);
boost::asio::ip::make_address(config.restricted_bind_ipv6_address, ec);
if (ec)
{
LOG_ERROR(tr("Invalid IP address given for --") << arg.rpc_restricted_bind_ipv6_address.name);