mirror of
https://codeberg.org/wownero/wownero-lws
synced 2026-10-17 07:31:34 +02:00
Add constraints/limits to async rest responses (#229)
This commit is contained in:
committed by
Lee *!* Clagett
parent
6b3ec7c1b7
commit
97e0161cfd
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include "cryptonote_config.h"
|
#include "cryptonote_config.h"
|
||||||
|
|
||||||
namespace lws
|
namespace lws
|
||||||
@@ -7,5 +8,14 @@ namespace lws
|
|||||||
namespace config
|
namespace config
|
||||||
{
|
{
|
||||||
extern cryptonote::network_type network;
|
extern cryptonote::network_type network;
|
||||||
|
|
||||||
|
//! Max queued clients when waiting for cacheable daemon response
|
||||||
|
constexpr const std::size_t daemon_wait_queue_max = 25000;
|
||||||
|
|
||||||
|
//! Max queued clients for `get_random_outs`
|
||||||
|
constexpr const std::size_t get_random_outs_max = 10000;
|
||||||
|
|
||||||
|
//! Max memory allowed for `submit_raw_tx` buffering
|
||||||
|
constexpr const std::size_t submit_tx_max = 100 * 1024 * 1024;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,6 +91,8 @@ namespace lws
|
|||||||
return "Invalid subaddress range provided";
|
return "Invalid subaddress range provided";
|
||||||
case error::json_rpc:
|
case error::json_rpc:
|
||||||
return "Error returned by JSON-RPC server";
|
return "Error returned by JSON-RPC server";
|
||||||
|
case error::load:
|
||||||
|
return "Server load limits have been reached";
|
||||||
case error::exchange_rates_old:
|
case error::exchange_rates_old:
|
||||||
return "Exchange rates are older than cache interval";
|
return "Exchange rates are older than cache interval";
|
||||||
case error::max_subaddresses:
|
case error::max_subaddresses:
|
||||||
@@ -125,6 +127,7 @@ namespace lws
|
|||||||
case error::bad_view_key:
|
case error::bad_view_key:
|
||||||
return std::errc::bad_address;
|
return std::errc::bad_address;
|
||||||
case error::daemon_timeout:
|
case error::daemon_timeout:
|
||||||
|
case error::load:
|
||||||
return std::errc::timed_out;
|
return std::errc::timed_out;
|
||||||
case error::exceeded_blockchain_buffer:
|
case error::exceeded_blockchain_buffer:
|
||||||
return std::errc::no_buffer_space;
|
return std::errc::no_buffer_space;
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ namespace lws
|
|||||||
http_server, //!< HTTP server failure (init or run)
|
http_server, //!< HTTP server failure (init or run)
|
||||||
invalid_range, //!< Invalid subaddress range provided
|
invalid_range, //!< Invalid subaddress range provided
|
||||||
json_rpc, //!< Error returned by JSON-RPC server
|
json_rpc, //!< Error returned by JSON-RPC server
|
||||||
|
load, //!< Server load limits reached
|
||||||
max_subaddresses, //!< Max subaddresses exceeded
|
max_subaddresses, //!< Max subaddresses exceeded
|
||||||
not_enough_mixin, //!< Not enough outputs to meet mixin count
|
not_enough_mixin, //!< Not enough outputs to meet mixin count
|
||||||
not_enough_amount, //!< Not enough outputs to meet amount
|
not_enough_amount, //!< Not enough outputs to meet amount
|
||||||
|
|||||||
+18
-1
@@ -364,6 +364,9 @@ namespace lws
|
|||||||
auto active = cache.status.lock();
|
auto active = cache.status.lock();
|
||||||
if (active)
|
if (active)
|
||||||
{
|
{
|
||||||
|
if (config::daemon_wait_queue_max < active->resumers.size())
|
||||||
|
return {error::load};
|
||||||
|
|
||||||
active->resumers.push_back(std::move(resume));
|
active->resumers.push_back(std::move(resume));
|
||||||
return async_ready();
|
return async_ready();
|
||||||
}
|
}
|
||||||
@@ -757,6 +760,9 @@ namespace lws
|
|||||||
auto active = cache.status.lock();
|
auto active = cache.status.lock();
|
||||||
if (active)
|
if (active)
|
||||||
{
|
{
|
||||||
|
if (config::get_random_outs_max < active->resumers.size())
|
||||||
|
return {error::load};
|
||||||
|
|
||||||
active->resumers.emplace_back(std::move(req), std::move(resume));
|
active->resumers.emplace_back(std::move(req), std::move(resume));
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
@@ -1193,6 +1199,9 @@ namespace lws
|
|||||||
auto active = cache.status.lock();
|
auto active = cache.status.lock();
|
||||||
if (active)
|
if (active)
|
||||||
{
|
{
|
||||||
|
if (config::daemon_wait_queue_max < active->resumers.size())
|
||||||
|
return {error::load};
|
||||||
|
|
||||||
active->resumers.emplace_back(std::move(req), std::move(resume));
|
active->resumers.emplace_back(std::move(req), std::move(resume));
|
||||||
return async_ready();
|
return async_ready();
|
||||||
}
|
}
|
||||||
@@ -1587,6 +1596,7 @@ namespace lws
|
|||||||
boost::asio::steady_timer timer;
|
boost::asio::steady_timer timer;
|
||||||
boost::asio::io_context::strand strand;
|
boost::asio::io_context::strand strand;
|
||||||
std::deque<std::pair<epee::byte_slice, std::function<async_complete>>> resumers;
|
std::deque<std::pair<epee::byte_slice, std::function<async_complete>>> resumers;
|
||||||
|
std::size_t outstanding;
|
||||||
|
|
||||||
frame(rest_server_data& parent, net::zmq::async_client client)
|
frame(rest_server_data& parent, net::zmq::async_client client)
|
||||||
: parent(std::addressof(parent)),
|
: parent(std::addressof(parent)),
|
||||||
@@ -1594,7 +1604,8 @@ namespace lws
|
|||||||
client(std::move(client)),
|
client(std::move(client)),
|
||||||
timer(parent.io),
|
timer(parent.io),
|
||||||
strand(parent.io),
|
strand(parent.io),
|
||||||
resumers()
|
resumers(),
|
||||||
|
outstanding(0)
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1620,6 +1631,10 @@ namespace lws
|
|||||||
auto active = cache.status.lock();
|
auto active = cache.status.lock();
|
||||||
if (active)
|
if (active)
|
||||||
{
|
{
|
||||||
|
if (std::numeric_limits<std::size_t>::max() - msg.size() < active->outstanding || config::submit_tx_max < msg.size() + active->outstanding)
|
||||||
|
return {error::load};
|
||||||
|
|
||||||
|
active->outstanding += msg.size();
|
||||||
active->resumers.emplace_back(std::move(msg), std::move(resume));
|
active->resumers.emplace_back(std::move(msg), std::move(resume));
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
@@ -1709,6 +1724,7 @@ namespace lws
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
next = std::move(self_->resumers.front().first);
|
next = std::move(self_->resumers.front().first);
|
||||||
|
self_->outstanding -= std::min(self_->outstanding, next.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
set_timeout(std::chrono::seconds{10}, false);
|
set_timeout(std::chrono::seconds{10}, false);
|
||||||
@@ -1751,6 +1767,7 @@ namespace lws
|
|||||||
active = std::make_shared<frame>(*data.global, std::move(*client));
|
active = std::make_shared<frame>(*data.global, std::move(*client));
|
||||||
cache.status = active;
|
cache.status = active;
|
||||||
|
|
||||||
|
active->outstanding += msg.size();
|
||||||
active->resumers.emplace_back(std::move(msg), std::move(resume));
|
active->resumers.emplace_back(std::move(msg), std::move(resume));
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user