mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-20 11:45:53 +00:00
Make DOSGuard config loading more resilient (#103)
This commit is contained in:
@@ -29,8 +29,14 @@ class DOSGuard
|
||||
std::string const& key,
|
||||
std::uint32_t const fallback) const
|
||||
{
|
||||
if (auto const c = getConfig(config); c)
|
||||
try
|
||||
{
|
||||
if (auto const c = getConfig(config))
|
||||
return c->at(key).as_int64();
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
}
|
||||
|
||||
return fallback;
|
||||
}
|
||||
@@ -40,13 +46,12 @@ class DOSGuard
|
||||
{
|
||||
using T = std::unordered_set<std::string> const;
|
||||
|
||||
try
|
||||
{
|
||||
auto const& c = getConfig(config);
|
||||
if (!c)
|
||||
return T();
|
||||
|
||||
if (!c->contains("whitelist"))
|
||||
return T();
|
||||
|
||||
auto const& w = c->at("whitelist").as_array();
|
||||
|
||||
auto const transform = [](auto const& elem) {
|
||||
@@ -57,6 +62,11 @@ class DOSGuard
|
||||
boost::transform_iterator(w.begin(), transform),
|
||||
boost::transform_iterator(w.end(), transform));
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
return T();
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
DOSGuard(boost::json::object const& config, boost::asio::io_context& ctx)
|
||||
|
||||
Reference in New Issue
Block a user