xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
resource
detail
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
15
namespace
xrpl::resource
{
16
17
using
ClockType
=
beast::AbstractClock<std::chrono::steady_clock>
;
18
19
// An entry in the table
20
// VFALCO DEPRECATED using boost::intrusive list
21
struct
Entry
:
public
beast::List
<Entry>::Node
22
{
23
Entry
() =
delete
;
24
28
explicit
Entry
(
ClockType::time_point
const
now)
29
:
refcount
(0),
localBalance
(now),
remoteBalance
(0)
30
{
31
}
32
33
[[nodiscard]]
std::string
34
toString
()
const
35
{
36
return
getFingerprint
(
key
->address,
publicKey
);
37
}
38
44
[[nodiscard]]
bool
45
isUnlimited
()
const
46
{
47
return
key
->kind ==
Kind::Unlimited
;
48
}
49
50
// Balance including remote contributions
51
int
52
balance
(
ClockType::time_point
const
now)
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,
ClockType::time_point
const
now)
61
{
62
return
localBalance
.add(charge, now) +
remoteBalance
;
63
}
64
65
// The public key of the peer
66
std::optional<PublicKey>
publicKey
;
67
68
// Back pointer to the map key (bit of a hack here)
69
Key
const
*
key
{};
70
71
// Number of Consumer references
72
int
refcount
;
73
74
// Exponentially decaying balance of resource consumption
75
DecayingSample<kDecayWindowSeconds, ClockType>
localBalance
;
76
77
// Normalized balance contribution from imports
78
int
remoteBalance
;
79
80
// Time of the last warning
81
ClockType::time_point
lastWarningTime
;
82
83
// For inactive entries, time after which this entry will be erased
84
ClockType::time_point
whenExpires
;
85
};
86
87
inline
std::ostream
&
88
operator<<
(
std::ostream
& os,
Entry
const
& v)
89
{
90
os << v.
toString
();
91
return
os;
92
}
93
94
}
// namespace xrpl::resource
std::ostream
std::string
chrono
beast::AbstractClock
Abstract interface to a clock.
Definition
abstract_clock.h:36
beast::AbstractClock< std::chrono::steady_clock >::time_point
std::chrono::steady_clock::time_point time_point
Definition
abstract_clock.h:41
beast::List
Intrusive doubly linked list.
Definition
List.h:258
xrpl::DecayingSample
Sampling function using exponential decay to provide a continuous value.
Definition
DecayingSample.h:15
xrpl::resource
Definition
ServiceRegistry.h:21
xrpl::resource::ClockType
beast::AbstractClock< std::chrono::steady_clock > ClockType
Definition
Entry.h:17
xrpl::resource::operator<<
std::ostream & operator<<(std::ostream &os, Charge const &v)
Definition
Charge.cpp:36
xrpl::resource::Kind::Unlimited
@ Unlimited
Definition
Kind.h:13
xrpl::getFingerprint
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
optional
ostream
string
xrpl::resource::Entry
Definition
Entry.h:22
xrpl::resource::Entry::remoteBalance
int remoteBalance
Definition
Entry.h:78
xrpl::resource::Entry::refcount
int refcount
Definition
Entry.h:72
xrpl::resource::Entry::whenExpires
ClockType::time_point whenExpires
Definition
Entry.h:84
xrpl::resource::Entry::add
int add(int charge, ClockType::time_point const now)
Definition
Entry.h:60
xrpl::resource::Entry::isUnlimited
bool isUnlimited() const
Returns true if this connection should have no resource limits applied–it is still possible for certa...
Definition
Entry.h:45
xrpl::resource::Entry::publicKey
std::optional< PublicKey > publicKey
Definition
Entry.h:66
xrpl::resource::Entry::Entry
Entry()=delete
xrpl::resource::Entry::key
Key const * key
Definition
Entry.h:69
xrpl::resource::Entry::lastWarningTime
ClockType::time_point lastWarningTime
Definition
Entry.h:81
xrpl::resource::Entry::balance
int balance(ClockType::time_point const now)
Definition
Entry.h:52
xrpl::resource::Entry::toString
std::string toString() const
Definition
Entry.h:34
xrpl::resource::Entry::localBalance
DecayingSample< kDecayWindowSeconds, ClockType > localBalance
Definition
Entry.h:75
xrpl::resource::Entry::Entry
Entry(ClockType::time_point const now)
Definition
Entry.h:28
xrpl::resource::Key
Definition
Key.h:14
Generated by
1.17.0