Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
web::dosguard::DOSGuard Class Reference

A simple denial of service guard used for rate limiting. More...

#include <DOSGuard.hpp>

Inheritance diagram for web::dosguard::DOSGuard:
Collaboration diagram for web::dosguard::DOSGuard:

Public Member Functions

 DOSGuard (util::config::ClioConfigDefinition const &config, WhitelistHandlerInterface const &whitelistHandler)
 Constructs a new DOS guard.
 
bool isWhiteListed (std::string_view const ip) const noexcept override
 Check whether an ip address is in the whitelist or not.
 
bool isOk (std::string const &ip) const noexcept override
 Check whether an ip address is currently rate limited or not.
 
void increment (std::string const &ip) noexcept override
 Increment connection count for the given ip address.
 
void decrement (std::string const &ip) noexcept override
 Decrement connection count for the given ip address.
 
bool add (std::string const &ip, uint32_t numObjects) noexcept override
 Adds numObjects of usage for the given ip address.
 
bool request (std::string const &ip) noexcept override
 Adds one request for the given ip address.
 
void clear () noexcept override
 Instantly clears all fetch counters added by.
 
- Public Member Functions inherited from web::dosguard::DOSGuardInterface
- Public Member Functions inherited from web::dosguard::BaseDOSGuard

Detailed Description

A simple denial of service guard used for rate limiting.

Template Parameters
WhitelistHandlerTypeThe type of the whitelist handler

Constructor & Destructor Documentation

◆ DOSGuard()

web::dosguard::DOSGuard::DOSGuard ( util::config::ClioConfigDefinition const & config,
WhitelistHandlerInterface const & whitelistHandler )

Constructs a new DOS guard.

Parameters
configClio config
whitelistHandlerWhitelist handler that checks whitelist for IP addresses

Member Function Documentation

◆ add()

bool web::dosguard::DOSGuard::add ( std::string const & ip,
uint32_t numObjects )
overridevirtualnoexcept

Adds numObjects of usage for the given ip address.

If the total sums up to a value equal or larger than maxFetches_ the operation is no longer allowed and false is returned; true is returned otherwise.

Parameters
ip
numObjects
Returns
true
false

Implements web::dosguard::DOSGuardInterface.

◆ clear()

void web::dosguard::DOSGuard::clear ( )
overridevirtualnoexcept

Instantly clears all fetch counters added by.

See also
add(std::string const&, uint32_t).

Implements web::dosguard::BaseDOSGuard.

◆ decrement()

void web::dosguard::DOSGuard::decrement ( std::string const & ip)
overridevirtualnoexcept

Decrement connection count for the given ip address.

Parameters
ip

Implements web::dosguard::DOSGuardInterface.

◆ increment()

void web::dosguard::DOSGuard::increment ( std::string const & ip)
overridevirtualnoexcept

Increment connection count for the given ip address.

Parameters
ip

Implements web::dosguard::DOSGuardInterface.

◆ isOk()

bool web::dosguard::DOSGuard::isOk ( std::string const & ip) const
nodiscardoverridevirtualnoexcept

Check whether an ip address is currently rate limited or not.

Parameters
ipThe ip address to check
Returns
true If not rate limited
false If rate limited and the request should not be processed

Implements web::dosguard::DOSGuardInterface.

◆ isWhiteListed()

bool web::dosguard::DOSGuard::isWhiteListed ( std::string_view const ip) const
nodiscardoverridevirtualnoexcept

Check whether an ip address is in the whitelist or not.

Parameters
ipThe ip address to check
Returns
true
false

Implements web::dosguard::DOSGuardInterface.

◆ request()

bool web::dosguard::DOSGuard::request ( std::string const & ip)
overridevirtualnoexcept

Adds one request for the given ip address.

If the total sums up to a value equal or larger than maxRequestCount_ the operation is no longer allowed and false is returned; true is returned otherwise.

Parameters
ip
Returns
true
false

Implements web::dosguard::DOSGuardInterface.


The documentation for this class was generated from the following files: