Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Weights.hpp
1#pragma once
2
3#include "util/StringHash.hpp"
4#include "util/config/ConfigDefinition.hpp"
5#include "web/dosguard/WeightsInterface.hpp"
6
7#include <boost/json/object.hpp>
8
9#include <cstddef>
10#include <functional>
11#include <optional>
12#include <string>
13#include <unordered_map>
14
15namespace web::dosguard {
16
24class Weights : public WeightsInterface {
25public:
32 struct Entry {
33 size_t weight;
34 std::optional<size_t> weightLedgerCurrent;
35 std::optional<size_t> weightLedgerValidated;
36 };
37
38private:
39 size_t defaultWeight_;
40 std::unordered_map<std::string, Entry, util::StringHash, std::equal_to<>> weights_;
41
42public:
49 Weights(size_t defaultWeight, std::unordered_map<std::string, Entry> weights);
50
57 static Weights
59
66 size_t
67 requestWeight(boost::json::object const& request) const override;
68};
69
70} // namespace web::dosguard
All the config data will be stored and extracted from this class.
Definition ConfigDefinition.hpp:31
Interface for determining request weights in DOS protection.
Definition WeightsInterface.hpp:15
static Weights make(util::config::ClioConfigDefinition const &config)
Create a Weights object from configuration.
Definition Weights.cpp:27
Weights(size_t defaultWeight, std::unordered_map< std::string, Entry > weights)
Construct a new Weights object.
Definition Weights.cpp:20
size_t requestWeight(boost::json::object const &request) const override
Get the weight assigned to a specific command.
Definition Weights.cpp:44
Structure representing weight configuration for a command.
Definition Weights.hpp:32