rippled
Loading...
Searching...
No Matches
Entry.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_RESOURCE_ENTRY_H_INCLUDED
21#define RIPPLE_RESOURCE_ENTRY_H_INCLUDED
22
23#include <xrpl/basics/DecayingSample.h>
24#include <xrpl/beast/clock/abstract_clock.h>
25#include <xrpl/beast/core/List.h>
26#include <xrpl/beast/utility/instrumentation.h>
27#include <xrpl/resource/detail/Key.h>
28#include <xrpl/resource/detail/Tuning.h>
29
30namespace ripple {
31namespace Resource {
32
34
35// An entry in the table
36// VFALCO DEPRECATED using boost::intrusive list
37struct Entry : public beast::List<Entry>::Node
38{
39 Entry() = delete;
40
44 explicit Entry(clock_type::time_point const now)
45 : refcount(0)
46 , local_balance(now)
49 , whenExpires()
50 {
51 }
52
54 to_string() const
55 {
57 }
58
64 bool
66 {
67 return key->kind == kindUnlimited;
68 }
69
70 // Balance including remote contributions
71 int
73 {
74 return local_balance.value(now) + remote_balance;
75 }
76
77 // Add a charge and return normalized balance
78 // including contributions from imports.
79 int
80 add(int charge, clock_type::time_point const now)
81 {
82 return local_balance.add(charge, now) + remote_balance;
83 }
84
85 // The public key of the peer
87
88 // Back pointer to the map key (bit of a hack here)
89 Key const* key;
90
91 // Number of Consumer references
93
94 // Exponentially decaying balance of resource consumption
96
97 // Normalized balance contribution from imports
99
100 // Time of the last warning
102
103 // For inactive entries, time after which this entry will be erased
105};
106
108operator<<(std::ostream& os, Entry const& v)
109{
110 os << v.to_string();
111 return os;
112}
113
114} // namespace Resource
115} // namespace ripple
116
117#endif
Intrusive doubly linked list.
Definition List.h:279
Sampling function using exponential decay to provide a continuous value.
std::ostream & operator<<(std::ostream &os, Charge const &v)
Definition Charge.cpp:56
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
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:269
std::string to_string() const
Definition Entry.h:54
Key const * key
Definition Entry.h:89
Entry(clock_type::time_point const now)
Definition Entry.h:44
std::optional< PublicKey > publicKey
Definition Entry.h:86
bool isUnlimited() const
Returns true if this connection should have no resource limits applied–it is still possible for certa...
Definition Entry.h:65
int add(int charge, clock_type::time_point const now)
Definition Entry.h:80
int balance(clock_type::time_point const now)
Definition Entry.h:72
clock_type::time_point whenExpires
Definition Entry.h:104
clock_type::time_point lastWarningTime
Definition Entry.h:101
DecayingSample< decayWindowSeconds, clock_type > local_balance
Definition Entry.h:95
beast::IP::Endpoint address
Definition Key.h:34