rippled
Loading...
Searching...
No Matches
libxrpl
resource
Consumer.cpp
1
#include <xrpl/basics/Log.h>
2
#include <xrpl/beast/utility/Journal.h>
3
#include <xrpl/beast/utility/instrumentation.h>
4
#include <xrpl/resource/Charge.h>
5
#include <xrpl/resource/Consumer.h>
6
#include <xrpl/resource/Disposition.h>
7
#include <xrpl/resource/detail/Entry.h>
8
#include <xrpl/resource/detail/Logic.h>
9
10
#include <
ostream
>
11
#include <
string
>
12
13
namespace
ripple
{
14
namespace
Resource {
15
16
Consumer::Consumer
(
Logic
& logic,
Entry
& entry)
17
: m_logic(&logic), m_entry(&entry)
18
{
19
}
20
21
Consumer::Consumer
() : m_logic(nullptr), m_entry(nullptr)
22
{
23
}
24
25
Consumer::Consumer
(
Consumer
const
& other)
26
: m_logic(other.m_logic), m_entry(nullptr)
27
{
28
if
(
m_logic
&& other.
m_entry
)
29
{
30
m_entry
= other.
m_entry
;
31
m_logic
->
acquire
(*
m_entry
);
32
}
33
}
34
35
Consumer::~Consumer
()
36
{
37
if
(
m_logic
&&
m_entry
)
38
m_logic
->
release
(*
m_entry
);
39
}
40
41
Consumer
&
42
Consumer::operator=
(
Consumer
const
& other)
43
{
44
// remove old ref
45
if
(
m_logic
&&
m_entry
)
46
m_logic
->
release
(*
m_entry
);
47
48
m_logic
= other.
m_logic
;
49
m_entry
= other.
m_entry
;
50
51
// add new ref
52
if
(
m_logic
&&
m_entry
)
53
m_logic
->
acquire
(*
m_entry
);
54
55
return
*
this
;
56
}
57
58
std::string
59
Consumer::to_string
()
const
60
{
61
if
(
m_logic
==
nullptr
)
62
return
"(none)"
;
63
64
return
m_entry
->
to_string
();
65
}
66
67
bool
68
Consumer::isUnlimited
()
const
69
{
70
if
(
m_entry
)
71
return
m_entry
->
isUnlimited
();
72
73
return
false
;
74
}
75
76
Disposition
77
Consumer::disposition
()
const
78
{
79
Disposition
d =
ok
;
80
if
(
m_logic
&&
m_entry
)
81
d =
m_logic
->
charge
(*
m_entry
,
Charge
(0));
82
83
return
d;
84
}
85
86
Disposition
87
Consumer::charge
(
Charge
const
& what,
std::string
const
& context)
88
{
89
Disposition
d =
ok
;
90
91
if
(
m_logic
&&
m_entry
&& !
m_entry
->
isUnlimited
())
92
d =
m_logic
->
charge
(*
m_entry
, what, context);
93
94
return
d;
95
}
96
97
bool
98
Consumer::warn
()
99
{
100
XRPL_ASSERT(
m_entry
,
"ripple::Resource::Consumer::warn : non-null entry"
);
101
return
m_logic
->
warn
(*
m_entry
);
102
}
103
104
bool
105
Consumer::disconnect
(
beast::Journal
const
& j)
106
{
107
XRPL_ASSERT(
108
m_entry
,
"ripple::Resource::Consumer::disconnect : non-null entry"
);
109
bool
const
d =
m_logic
->
disconnect
(*
m_entry
);
110
if
(d)
111
{
112
JLOG(j.
debug
()) <<
"disconnecting "
<<
m_entry
->
to_string
();
113
}
114
return
d;
115
}
116
117
int
118
Consumer::balance
()
119
{
120
XRPL_ASSERT(
121
m_entry
,
"ripple::Resource::Consumer::balance : non-null entry"
);
122
return
m_logic
->
balance
(*
m_entry
);
123
}
124
125
Entry
&
126
Consumer::entry
()
127
{
128
XRPL_ASSERT(
m_entry
,
"ripple::Resource::Consumer::entry : non-null entry"
);
129
return
*
m_entry
;
130
}
131
132
void
133
Consumer::setPublicKey
(
PublicKey
const
& publicKey)
134
{
135
m_entry
->
publicKey
= publicKey;
136
}
137
138
std::ostream
&
139
operator<<
(
std::ostream
& os,
Consumer
const
& v)
140
{
141
os << v.
to_string
();
142
return
os;
143
}
144
145
}
// namespace Resource
146
}
// namespace ripple
std::ostream
std::string
beast::Journal
A generic endpoint for log messages.
Definition
Journal.h:41
beast::Journal::debug
Stream debug() const
Definition
Journal.h:309
ripple::PublicKey
A public key.
Definition
PublicKey.h:43
ripple::Resource::Charge
A consumption charge.
Definition
Charge.h:11
ripple::Resource::Consumer
An endpoint that consumes resources.
Definition
Consumer.h:17
ripple::Resource::Consumer::m_entry
Entry * m_entry
Definition
Consumer.h:77
ripple::Resource::Consumer::warn
bool warn()
Returns true if the consumer should be warned.
Definition
Consumer.cpp:98
ripple::Resource::Consumer::operator=
Consumer & operator=(Consumer const &other)
Definition
Consumer.cpp:42
ripple::Resource::Consumer::balance
int balance()
Returns the credit balance representing consumption.
Definition
Consumer.cpp:118
ripple::Resource::Consumer::Consumer
Consumer()
Definition
Consumer.cpp:21
ripple::Resource::Consumer::to_string
std::string to_string() const
Return a human readable string uniquely identifying this consumer.
Definition
Consumer.cpp:59
ripple::Resource::Consumer::disconnect
bool disconnect(beast::Journal const &j)
Returns true if the consumer should be disconnected.
Definition
Consumer.cpp:105
ripple::Resource::Consumer::entry
Entry & entry()
Definition
Consumer.cpp:126
ripple::Resource::Consumer::charge
Disposition charge(Charge const &fee, std::string const &context={})
Apply a load charge to the consumer.
Definition
Consumer.cpp:87
ripple::Resource::Consumer::setPublicKey
void setPublicKey(PublicKey const &publicKey)
Definition
Consumer.cpp:133
ripple::Resource::Consumer::m_logic
Logic * m_logic
Definition
Consumer.h:76
ripple::Resource::Consumer::isUnlimited
bool isUnlimited() const
Returns true if this is a privileged endpoint.
Definition
Consumer.cpp:68
ripple::Resource::Consumer::disposition
Disposition disposition() const
Returns the current disposition of this consumer.
Definition
Consumer.cpp:77
ripple::Resource::Consumer::~Consumer
~Consumer()
Definition
Consumer.cpp:35
ripple::Resource::Logic
Definition
include/xrpl/resource/detail/Logic.h:23
ripple::Resource::Logic::acquire
void acquire(Entry &entry)
Definition
include/xrpl/resource/detail/Logic.h:394
ripple::Resource::Logic::warn
bool warn(Entry &entry)
Definition
include/xrpl/resource/detail/Logic.h:465
ripple::Resource::Logic::disconnect
bool disconnect(Entry &entry)
Definition
include/xrpl/resource/detail/Logic.h:489
ripple::Resource::Logic::charge
Disposition charge(Entry &entry, Charge const &fee, std::string context={})
Definition
include/xrpl/resource/detail/Logic.h:433
ripple::Resource::Logic::balance
int balance(Entry &entry)
Definition
include/xrpl/resource/detail/Logic.h:515
ripple::Resource::Logic::release
void release(Entry &entry)
Definition
include/xrpl/resource/detail/Logic.h:401
ripple::Resource::operator<<
std::ostream & operator<<(std::ostream &os, Charge const &v)
Definition
Charge.cpp:37
ripple::Resource::Disposition
Disposition
The disposition of a consumer after applying a load charge.
Definition
Disposition.h:8
ripple::Resource::ok
@ ok
No action required.
Definition
Disposition.h:10
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:6
ostream
string
ripple::Resource::Entry
Definition
Entry.h:19
ripple::Resource::Entry::to_string
std::string to_string() const
Definition
Entry.h:35
ripple::Resource::Entry::publicKey
std::optional< PublicKey > publicKey
Definition
Entry.h:67
ripple::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:46
Generated by
1.9.8