dead-nonce-list.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_DAEMON_TABLE_DEAD_NONCE_LIST_HPP
27 #define NFD_DAEMON_TABLE_DEAD_NONCE_LIST_HPP
28 
29 #include "core/common.hpp"
30 #include <boost/multi_index_container.hpp>
31 #include <boost/multi_index/sequenced_index.hpp>
32 #include <boost/multi_index/hashed_index.hpp>
33 #include "core/scheduler.hpp"
34 
35 namespace nfd {
36 
54 class DeadNonceList : noncopyable
55 {
56 public:
64  explicit
65  DeadNonceList(const time::nanoseconds& lifetime = DEFAULT_LIFETIME);
66 
68 
72  bool
73  has(const Name& name, uint32_t nonce) const;
74 
77  void
78  add(const Name& name, uint32_t nonce);
79 
83  size_t
84  size() const;
85 
88  const time::nanoseconds&
89  getLifetime() const;
90 
91 private: // Entry and Index
92  typedef uint64_t Entry;
93 
94  static Entry
95  makeEntry(const Name& name, uint32_t nonce);
96 
97  typedef boost::multi_index_container<
98  Entry,
99  boost::multi_index::indexed_by<
100  boost::multi_index::sequenced<>,
101  boost::multi_index::hashed_non_unique<
102  boost::multi_index::identity<Entry>
103  >
104  >
105  > Index;
106 
107  typedef Index::nth_index<0>::type Queue;
108  typedef Index::nth_index<1>::type Hashtable;
109 
110 private: // actual lifetime estimation and capacity control
113  size_t
114  countMarks() const;
115 
118  void
119  mark();
120 
126  void
127  adjustCapacity();
128 
131  void
132  evictEntries();
133 
134 public:
136  static const time::nanoseconds DEFAULT_LIFETIME;
137 
139  static const time::nanoseconds MIN_LIFETIME;
140 
141 private:
142  time::nanoseconds m_lifetime;
143  Index m_index;
144  Queue& m_queue;
145  Hashtable& m_ht;
146 
147 PUBLIC_WITH_TESTS_ELSE_PRIVATE: // actual lifetime estimation and capacity control
148 
149  // ---- current capacity and hard limits
150 
158  size_t m_capacity;
159 
160  static const size_t INITIAL_CAPACITY;
161 
166  static const size_t MIN_CAPACITY;
167 
172  static const size_t MAX_CAPACITY;
173 
174  // ---- actual entry lifetime estimation
175 
182  static const Entry MARK;
183 
186  static const size_t EXPECTED_MARK_COUNT;
187 
193  std::multiset<size_t> m_actualMarkCounts;
194 
195  time::nanoseconds m_markInterval;
196 
197  scheduler::EventId m_markEvent;
198 
199  // ---- capacity adjustments
200 
201  static const double CAPACITY_UP;
202 
203  static const double CAPACITY_DOWN;
204 
205  time::nanoseconds m_adjustCapacityInterval;
206 
207  scheduler::EventId m_adjustCapacityEvent;
208 
211  static const size_t EVICT_LIMIT;
212 };
213 
214 inline const time::nanoseconds&
216 {
217  return m_lifetime;
218 }
219 
220 } // namespace nfd
221 
222 #endif // NFD_DAEMON_TABLE_DEAD_NONCE_LIST_HPP
size_t size() const
const time::nanoseconds & getLifetime() const
void add(const Name &name, uint32_t nonce)
records name+nonce
bool has(const Name &name, uint32_t nonce) const
determines if name+nonce exists
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
represents the Dead Nonce list
DeadNonceList(const time::nanoseconds &lifetime=DEFAULT_LIFETIME)
constructs the Dead Nonce List
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40
static const time::nanoseconds MIN_LIFETIME
minimum entry lifetime
static const time::nanoseconds DEFAULT_LIFETIME
default entry lifetime