always append clio warning (#186)

* appends a warning stating that this is a clio server to every response
This commit is contained in:
CJ Cobb
2022-06-17 17:01:33 -04:00
committed by GitHub
parent 54669420bf
commit 7d5415e8b0
3 changed files with 24 additions and 33 deletions

View File

@@ -88,9 +88,6 @@ doServerInfo(Context const& context)
response["etl"] = context.etl->getInfo();
response["note"] =
"This is a clio server. If you want to talk to rippled, include "
"\"ledger_index\":\"current\" in your request";
return response;
}
} // namespace RPC

View File

@@ -402,7 +402,6 @@ handle_request(
result = error;
responseStr = boost::json::serialize(response);
BOOST_LOG_TRIVIAL(debug)
<< __func__ << " Encountered error: " << responseStr;
}
@@ -416,27 +415,23 @@ handle_request(
if (!result.contains("error"))
result["status"] = "success";
responseStr = boost::json::serialize(response);
}
auto warningFlag = false;
boost::json::array warnings;
warnings.emplace_back(
"This is a clio server. clio only serves validated data. If you "
"want to talk to rippled, include 'ledger_index':'current' in your "
"request");
auto lastPublishAge = context->etl->lastPublishAgeSeconds();
if (lastPublishAge >= 60)
warnings.emplace_back("This server may be out of date");
result["warnings"] = warnings;
responseStr = boost::json::serialize(response);
if (!dosGuard.add(ip, responseStr.size()))
{
warnings.emplace_back("Too many requests");
warningFlag = true;
}
auto lastPublishAge = context->etl->lastPublishAgeSeconds();
if (lastPublishAge >= 60)
{
warnings.emplace_back("This server may be out of date");
warningFlag = true;
}
// reserialize only if a warning was appended.
if (warningFlag)
{
response["warning"] = warnings;
response["warnings"] = warnings;
// reserialize when we need to include this warning
responseStr = boost::json::serialize(response);
}
return send(

View File

@@ -326,25 +326,24 @@ public:
return sendError(RPC::Error::rpcINTERNAL);
}
std::string responseStr = boost::json::serialize(response);
boost::json::array warnings;
auto warningFlag = false;
warnings.emplace_back(
"This is a clio server. clio only serves validated data. If you "
"want to talk to rippled, include 'ledger_index':'current' in your "
"request");
auto lastPublishAge = etl_->lastPublishAgeSeconds();
if (lastPublishAge >= 60)
warnings.emplace_back("This server may be out of date");
auto& result = response["result"].as_object();
result["warnings"] = warnings;
std::string responseStr = boost::json::serialize(response);
if (!dosGuard_.add(*ip, responseStr.size()))
{
warnings.emplace_back("Too many requests");
warningFlag = true;
}
auto lastPublishAge = etl_->lastPublishAgeSeconds();
if (lastPublishAge >= 60)
{
warnings.emplace_back("This server may be out of date");
warningFlag = true;
}
// reserialize if a warning was appended
if (warningFlag)
{
response["warning"] = warnings;
response["warnings"] = warnings;
// reserialize if we need to include this warning
responseStr = boost::json::serialize(response);
}
send(std::move(responseStr));