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/beast/utility/instrumentation.h>
7#include <xrpl/resource/detail/Key.h>
8#include <xrpl/resource/detail/Tuning.h>
9
10namespace xrpl::Resource {
11
13
14// An entry in the table
15// VFALCO DEPRECATED using boost::intrusive list
16struct Entry : public beast::List<Entry>::Node
17{
18 Entry() = delete;
19
23 explicit Entry(clock_type::time_point const now)
25 {
26 }
27
28 [[nodiscard]] std::string
29 toString() const
30 {
31 return getFingerprint(key->address, publicKey);
32 }
33
39 [[nodiscard]] bool
41 {
42 return key->kind == Kind::Unlimited;
43 }
44
45 // Balance including remote contributions
46 int
48 {
49 return localBalance.value(now) + remoteBalance;
50 }
51
52 // Add a charge and return normalized balance
53 // including contributions from imports.
54 int
55 add(int charge, clock_type::time_point const now)
56 {
57 return localBalance.add(charge, now) + remoteBalance;
58 }
59
60 // The public key of the peer
62
63 // Back pointer to the map key (bit of a hack here)
64 Key const* key{};
65
66 // Number of Consumer references
68
69 // Exponentially decaying balance of resource consumption
71
72 // Normalized balance contribution from imports
74
75 // Time of the last warning
77
78 // For inactive entries, time after which this entry will be erased
80};
81
83operator<<(std::ostream& os, Entry const& v)
84{
85 os << v.toString();
86 return os;
87}
88
89} // namespace xrpl::Resource
Abstract interface to a clock.
std::chrono::steady_clock::time_point time_point
Intrusive doubly linked list.
Definition List.h:260
Sampling function using exponential decay to provide a continuous value.
std::ostream & operator<<(std::ostream &os, Charge const &v)
Definition Charge.cpp:36
beast::AbstractClock< std::chrono::steady_clock > clock_type
Definition Entry.h:12
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:242
int add(int charge, clock_type::time_point const now)
Definition Entry.h:55
Entry(clock_type::time_point const now)
Definition Entry.h:23
int balance(clock_type::time_point const now)
Definition Entry.h:47
clock_type::time_point whenExpires
Definition Entry.h:79
Key const * key
Definition Entry.h:64
bool isUnlimited() const
Returns true if this connection should have no resource limits applied–it is still possible for certa...
Definition Entry.h:40
std::optional< PublicKey > publicKey
Definition Entry.h:61
std::string toString() const
Definition Entry.h:29
DecayingSample< kDecayWindowSeconds, clock_type > localBalance
Definition Entry.h:70
clock_type::time_point lastWarningTime
Definition Entry.h:76