rippled
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 <ripple/basics/DecayingSample.h>
24 #include <ripple/beast/clock/abstract_clock.h>
25 #include <ripple/beast/core/List.h>
26 #include <ripple/resource/impl/Key.h>
27 #include <ripple/resource/impl/Tuning.h>
28 #include <cassert>
29 
30 namespace ripple {
31 namespace Resource {
32 
34 
35 // An entry in the table
36 // VFALCO DEPRECATED using boost::intrusive list
37 struct 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)
47  , remote_balance(0)
48  , lastWarningTime()
49  , whenExpires()
50  {
51  }
52 
54  to_string() const
55  {
56  return key->address.to_string();
57  }
58 
64  bool
65  isUnlimited() const
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  // Back pointer to the map key (bit of a hack here)
86  Key const* key;
87 
88  // Number of Consumer references
89  int refcount;
90 
91  // Exponentially decaying balance of resource consumption
93 
94  // Normalized balance contribution from imports
96 
97  // Time of the last warning
99 
100  // For inactive entries, time after which this entry will be erased
102 };
103 
104 inline std::ostream&
106 {
107  os << v.to_string();
108  return os;
109 }
110 
111 } // namespace Resource
112 } // namespace ripple
113 
114 #endif
std::string
STL class.
beast::IP::Endpoint::to_string
std::string to_string() const
Returns a string representing the endpoint.
Definition: IPEndpoint.cpp:57
ripple::Resource::Key::kind
Kind kind
Definition: Key.h:33
ripple::Resource::Entry::to_string
std::string to_string() const
Definition: Entry.h:54
ripple::Resource::Entry::local_balance
DecayingSample< decayWindowSeconds, clock_type > local_balance
Definition: Entry.h:92
ripple::Resource::Entry::Entry
Entry(clock_type::time_point const now)
Definition: Entry.h:44
ripple::Resource::operator<<
std::ostream & operator<<(std::ostream &os, Charge const &v)
Definition: Charge.cpp:52
ripple::Resource::Entry::balance
int balance(clock_type::time_point const now)
Definition: Entry.h:72
ripple::Resource::Key
Definition: Key.h:31
ripple::Resource::kindUnlimited
@ kindUnlimited
Definition: Kind.h:34
ripple::Resource::Entry::lastWarningTime
clock_type::time_point lastWarningTime
Definition: Entry.h:98
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:65
ripple::Resource::Entry::whenExpires
clock_type::time_point whenExpires
Definition: Entry.h:101
std::ostream
STL class.
beast::abstract_clock< std::chrono::steady_clock >
ripple::Resource::Key::address
beast::IP::Endpoint address
Definition: Key.h:34
ripple::Resource::Entry::refcount
int refcount
Definition: Entry.h:89
ripple::Resource::Entry
Definition: Entry.h:37
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::Resource::Entry::Entry
Entry()=delete
cassert
ripple::DecayingSample
Sampling function using exponential decay to provide a continuous value.
Definition: DecayingSample.h:32
ripple::Resource::Entry::remote_balance
int remote_balance
Definition: Entry.h:95
ripple::Resource::Entry::key
Key const * key
Definition: Entry.h:86
beast::abstract_clock< std::chrono::steady_clock >::time_point
typename std::chrono::steady_clock ::time_point time_point
Definition: abstract_clock.h:63
ripple::Resource::Entry::add
int add(int charge, clock_type::time_point const now)
Definition: Entry.h:80
beast::List
Intrusive doubly linked list.
Definition: List.h:29