Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
DOSGuardInterface.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2024, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include <cstdint>
23#include <string>
24#include <string_view>
25namespace web::dosguard {
26
31public:
32 virtual ~BaseDOSGuard() = default;
33
37 virtual void
38 clear() noexcept = 0;
39};
40
45public:
53 [[nodiscard]] virtual bool
54 isWhiteListed(std::string_view const ip) const noexcept = 0;
55
63 [[nodiscard]] virtual bool
64 isOk(std::string const& ip) const noexcept = 0;
65
71 virtual void
72 increment(std::string const& ip) noexcept = 0;
73
79 virtual void
80 decrement(std::string const& ip) noexcept = 0;
81
94 [[maybe_unused]] virtual bool
95 add(std::string const& ip, uint32_t numObjects) noexcept = 0;
96
106 [[maybe_unused]] virtual bool
107 request(std::string const& ip) noexcept = 0;
108};
109
110} // namespace web::dosguard
The interface of a denial of service guard.
Definition DOSGuardInterface.hpp:30
virtual void clear() noexcept=0
Clears implementation-defined counters.
The interface of a denial of service guard.
Definition DOSGuardInterface.hpp:44
virtual bool isWhiteListed(std::string_view const ip) const noexcept=0
Check whether an ip address is in the whitelist or not.
virtual void decrement(std::string const &ip) noexcept=0
Decrement connection count for the given ip address.
virtual void increment(std::string const &ip) noexcept=0
Increment connection count for the given ip address.
virtual bool add(std::string const &ip, uint32_t numObjects) noexcept=0
Adds numObjects of usage for the given ip address.
virtual bool request(std::string const &ip) noexcept=0
Adds one request for the given ip address.
virtual bool isOk(std::string const &ip) const noexcept=0
Check whether an ip address is currently rate limited or not.