xrpld
Loading...
Searching...
No Matches
Entry.h
1#pragma once
2
3#include <xrpl/basics/DecayingSample.h>
4#include <xrpl/beast/clock/abstract_clock.h>
5#include <xrpl/beast/core/List.h>
6#include <xrpl/protocol/PublicKey.h>
7#include <xrpl/resource/detail/Key.h>
8#include <xrpl/resource/detail/Tuning.h>
9
10#include <chrono>
11#include <optional>
12#include <ostream>
13#include <string>
14
15namespace xrpl::resource {
16
18
19// An entry in the table
20// VFALCO DEPRECATED using boost::intrusive list
21struct Entry : public beast::List<Entry>::Node
22{
23 Entry() = delete;
24
28 explicit Entry(clock_type::time_point const now)
30 {
31 }
32
33 [[nodiscard]] std::string
34 toString() const
35 {
36 return getFingerprint(key->address, publicKey);
37 }
38
44 [[nodiscard]] bool
46 {
47 return key->kind == Kind::Unlimited;
48 }
49
50 // Balance including remote contributions
51 int
53 {
54 return localBalance.value(now) + remoteBalance;
55 }
56
57 // Add a charge and return normalized balance
58 // including contributions from imports.
59 int
60 add(int charge, clock_type::time_point const now)
61 {
62 return localBalance.add(charge, now) + remoteBalance;
63 }
64
65 // The public key of the peer
67
68 // Back pointer to the map key (bit of a hack here)
69 Key const* key{};
70
71 // Number of Consumer references
73
74 // Exponentially decaying balance of resource consumption
76
77 // Normalized balance contribution from imports
79
80 // Time of the last warning
82
83 // For inactive entries, time after which this entry will be erased
85};
86
88operator<<(std::ostream& os, Entry const& v)
89{
90 os << v.toString();
91 return os;
92}
93
94} // namespace xrpl::resource
Abstract interface to a clock.
std::chrono::steady_clock::time_point time_point
Intrusive doubly linked list.
Definition List.h:258
Sampling function using exponential decay to provide a continuous value.
beast::AbstractClock< std::chrono::steady_clock > clock_type
Definition Entry.h:17
std::ostream & operator<<(std::ostream &os, Charge const &v)
Definition Charge.cpp:36
std::string getFingerprint(beast::ip::Endpoint const &address, std::optional< PublicKey > const &publicKey=std::nullopt, std::optional< std::string > const &id=std::nullopt)
Definition PublicKey.h:262
clock_type::time_point lastWarningTime
Definition Entry.h:81
clock_type::time_point whenExpires
Definition Entry.h:84
Entry(clock_type::time_point const now)
Definition Entry.h:28
bool isUnlimited() const
Returns true if this connection should have no resource limits applied–it is still possible for certa...
Definition Entry.h:45
std::optional< PublicKey > publicKey
Definition Entry.h:66
Key const * key
Definition Entry.h:69
int balance(clock_type::time_point const now)
Definition Entry.h:52
std::string toString() const
Definition Entry.h:34
DecayingSample< kDecayWindowSeconds, clock_type > localBalance
Definition Entry.h:75
int add(int charge, clock_type::time_point const now)
Definition Entry.h:60