feat: Dosguard API weights (#2082)

Experimental support for Dosguard API weights.
This commit is contained in:
Sergey Kuznetsov
2025-05-13 15:02:21 +01:00
committed by GitHub
parent d02da5d28a
commit b87b32db86
42 changed files with 1653 additions and 329 deletions

View File

@@ -240,19 +240,7 @@ public:
return sender_(httpResponse(http::status::bad_request, "text/html", "Expected a POST request"));
}
// to avoid overwhelm work queue, the request limit check should be
// before posting to queue the web socket creation will be guarded via
// connection limit
if (!dosGuard_.get().request(clientIp)) {
// TODO: this looks like it could be useful to count too in the future
return sender_(httpResponse(
http::status::service_unavailable,
"text/plain",
boost::json::serialize(rpc::makeError(rpc::RippledError::rpcSLOW_DOWN))
));
}
LOG(log_.info()) << tag() << "Received request from ip = " << clientIp << " - posting to WorkQueue";
LOG(log_.info()) << tag() << "Received request from ip = " << clientIp;
try {
(*handler_)(req_.body(), derived().shared_from_this());
@@ -265,6 +253,16 @@ public:
}
}
void
sendSlowDown(std::string const&) override
{
sender_(httpResponse(
http::status::service_unavailable,
"text/plain",
boost::json::serialize(rpc::makeError(rpc::RippledError::rpcSLOW_DOWN))
));
}
/**
* @brief Send a response to the client
* The message length will be added to the DOSGuard, if the limit is reached, a warning will be added to the