20 #ifndef RIPPLE_RESOURCE_LOGIC_H_INCLUDED
21 #define RIPPLE_RESOURCE_LOGIC_H_INCLUDED
23 #include <ripple/basics/Log.h>
24 #include <ripple/basics/UnorderedContainers.h>
25 #include <ripple/basics/chrono.h>
26 #include <ripple/beast/clock/abstract_clock.h>
27 #include <ripple/beast/insight/Insight.h>
28 #include <ripple/beast/utility/PropertyStream.h>
29 #include <ripple/json/json_value.h>
30 #include <ripple/protocol/jss.h>
31 #include <ripple/resource/Fees.h>
32 #include <ripple/resource/Gossip.h>
33 #include <ripple/resource/impl/Import.h>
52 warn = collector->make_meter(
"warn");
53 drop = collector->make_meter(
"drop");
112 Entry* entry(
nullptr);
117 std::piecewise_construct,
121 entry = &resultIt->second;
122 entry->
key = &resultIt->first;
142 Entry* entry(
nullptr);
147 std::piecewise_construct,
151 entry = &resultIt->second;
152 entry->
key = &resultIt->first;
175 Entry* entry(
nullptr);
180 std::piecewise_construct,
184 entry = &resultIt->second;
185 entry->
key = &resultIt->first;
217 int localBalance = inboundEntry.local_balance.value(now);
218 if ((localBalance + inboundEntry.remote_balance) >= threshold)
222 entry[jss::local] = localBalance;
223 entry[jss::remote] = inboundEntry.remote_balance;
224 entry[jss::type] =
"inbound";
229 int localBalance = outboundEntry.local_balance.value(now);
230 if ((localBalance + outboundEntry.remote_balance) >= threshold)
234 entry[jss::local] = localBalance;
235 entry[jss::remote] = outboundEntry.remote_balance;
236 entry[jss::type] =
"outbound";
239 for (
auto& adminEntry :
admin_)
241 int localBalance = adminEntry.local_balance.value(now);
242 if ((localBalance + adminEntry.remote_balance) >= threshold)
246 entry[jss::local] = localBalance;
247 entry[jss::remote] = adminEntry.remote_balance;
248 entry[jss::type] =
"admin";
268 item.
balance = inboundEntry.local_balance.value(now);
272 gossip.
items.push_back(item);
288 std::piecewise_construct,
296 Import& next(resultIt->second);
298 next.items.reserve(gossip.
items.size());
300 for (
auto const& gossipItem : gossip.
items)
303 item.
balance = gossipItem.balance;
306 next.items.push_back(item);
316 next.items.reserve(gossip.
items.size());
317 for (
auto const& gossipItem : gossip.
items)
320 item.
balance = gossipItem.balance;
323 next.items.push_back(item);
326 Import& prev(resultIt->second);
327 for (
auto& item : prev.items)
329 item.consumer.entry().remote_balance -= item.balance;
350 if (iter->whenExpires <= elapsed)
366 Import&
import(iter->second);
367 if (iter->second.whenExpires <= elapsed)
369 for (
auto item_iter(
import.items.begin());
370 item_iter !=
import.items.end();
373 item_iter->consumer.entry().remote_balance -=
391 return Disposition::drop;
394 return Disposition::warn;
396 return Disposition::ok;
403 Entry& entry(iter->second);
450 JLOG(
m_journal.
trace()) <<
"Charging " << entry <<
" for " << fee;
491 <<
"Consumer entry " << entry <<
" dropped with balance "
519 for (
auto& entry : list)
522 if (entry.refcount != 0)
523 item[
"count"] = entry.refcount;
524 item[
"name"] = entry.to_string();
525 item[
"balance"] = entry.balance(now);
526 if (entry.remote_balance != 0)
527 item[
"remote_balance"] = entry.remote_balance;
size_type size() const noexcept
Returns the number of elements in the list.
A set of imported consumer data from a gossip origin.
void onWrite(beast::PropertyStream::Map &map)
A metric for measuring an integral value.
std::recursive_mutex lock_
Stream trace() const
Severity stream access functions.
Data format for exchanging consumption information across peers.
EntryIntrusiveList inactive_
EntryIntrusiveList admin_
Consumer newInboundEndpoint(beast::IP::Endpoint const &address)
iterator iterator_to(T &element) const noexcept
Obtain an iterator from an element.
iterator end() noexcept
Obtain a iterator to the end of the list.
Address const & address() const
Returns the address portion of this endpoint.
bool disconnect(Entry &entry)
constexpr std::chrono::seconds secondsUntilExpiration
int balance(Entry &entry)
virtual time_point now() const =0
Returns the current time.
void acquire(Entry &entry)
int balance(clock_type::time_point const now)
Json::Value getJson(int threshold)
Returns a Json::objectValue.
constexpr std::chrono::seconds gossipExpirationSeconds
clock_type::time_point lastWarningTime
bool isUnlimited() const
Returns true if this connection should have no resource limits applied–it is still possible for certa...
@ objectValue
object value (collection of name/value pairs).
iterator begin() noexcept
Obtain an iterator to the beginning of the list.
clock_type::time_point whenExpires
void erase(Table::iterator iter)
void importConsumers(std::string const &origin, Gossip const &gossip)
std::vector< Item > items
EntryIntrusiveList outbound_
value_type cost() const
Return the cost of the charge in Resource::Manager units.
EntryIntrusiveList inbound_
void release(Entry &entry)
A generic endpoint for log messages.
Logic(beast::insight::Collector::ptr const &collector, clock_type &clock, beast::Journal journal)
Stats(beast::insight::Collector::ptr const &collector)
Describes a single consumer.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void writeList(clock_type::time_point const now, beast::PropertyStream::Set &items, EntryIntrusiveList &list)
Consumer newUnlimitedEndpoint(beast::IP::Endpoint const &address)
Create endpoint that should not have resource limits applied.
beast::IP::Endpoint address
An endpoint that consumes resources.
Disposition
The disposition of a consumer after applying a load charge.
beast::insight::Meter drop
A version-independent IP address and port combination.
iterator erase(iterator pos) noexcept
Remove an element.
Endpoint at_port(Port port) const
Returns a new Endpoint with a different port.
beast::abstract_clock< std::chrono::steady_clock > Stopwatch
A clock for measuring elapsed time.
typename std::chrono::steady_clock ::time_point time_point
int add(int charge, clock_type::time_point const now)
Consumer newOutboundEndpoint(beast::IP::Endpoint const &address)
Disposition charge(Entry &entry, Charge const &fee)
iterator push_back(T &element) noexcept
Append an element at the end of the list.
static Disposition disposition(int balance)
beast::insight::Meter warn