Clio
develop
The XRP Ledger API server.
Theme:
Default
Round
Robot
Toggle main menu visibility
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
15
namespace
web::dosguard
{
16
24
class
Weights
:
public
WeightsInterface
{
25
public
:
32
struct
Entry
{
33
size_t
weight
;
34
std::optional<size_t>
weightLedgerCurrent
;
35
std::optional<size_t>
weightLedgerValidated
;
36
};
37
38
private
:
39
size_t
defaultWeight_;
40
std::unordered_map<std::string, Entry, util::StringHash, std::equal_to<>> weights_;
41
42
public
:
49
Weights
(
size_t
defaultWeight, std::unordered_map<std::string, Entry> weights);
50
57
static
Weights
58
make
(
util::config::ClioConfigDefinition
const
& config);
59
66
[[nodiscard]]
size_t
67
requestWeight
(boost::json::object
const
& request)
const override
;
68
};
69
70
}
// namespace web::dosguard
util::config::ClioConfigDefinition
All the config data will be stored and extracted from this class.
Definition
ConfigDefinition.hpp:31
web::dosguard::WeightsInterface
Interface for determining request weights in DOS protection.
Definition
WeightsInterface.hpp:15
web::dosguard::Weights::make
static Weights make(util::config::ClioConfigDefinition const &config)
Create a Weights object from configuration.
Definition
Weights.cpp:26
web::dosguard::Weights::Weights
Weights(size_t defaultWeight, std::unordered_map< std::string, Entry > weights)
Construct a new Weights object.
Definition
Weights.cpp:19
web::dosguard::Weights::requestWeight
size_t requestWeight(boost::json::object const &request) const override
Get the weight assigned to a specific command.
Definition
Weights.cpp:43
web::dosguard
Denial of service protection: rate limiting, IP whitelisting and request weighting.
Definition
DOSGuard.cpp:22
web::dosguard::Weights::Entry
Structure representing weight configuration for a command.
Definition
Weights.hpp:32
web::dosguard::Weights::Entry::weightLedgerCurrent
std::optional< size_t > weightLedgerCurrent
Weight if ledger_index is "current".
Definition
Weights.hpp:34
web::dosguard::Weights::Entry::weight
size_t weight
Base weight of the command.
Definition
Weights.hpp:33
web::dosguard::Weights::Entry::weightLedgerValidated
std::optional< size_t > weightLedgerValidated
Weight if ledger_index is "validated".
Definition
Weights.hpp:35
src
web
dosguard
Weights.hpp
Generated by
1.17.0