27 #include "../security/signature-sha256-with-rsa.hpp" 44 if (m_it != m_cache->get<byFullName>().end()) {
45 m_ptr = &((*m_it)->getData());
77 return m_it == rhs.m_it;
83 return m_it != rhs.m_it;
93 if (limit != std::numeric_limits<size_t>::max() && m_capacity > m_limit) {
97 for (
size_t i = 0; i < m_capacity; i++) {
106 while (it != m_cache.end()) {
110 BOOST_ASSERT(m_freeEntries.size() == m_capacity);
112 while (!m_freeEntries.empty()) {
113 delete m_freeEntries.top();
119 InMemoryStorage::setCapacity(
size_t capacity)
121 size_t oldCapacity = m_capacity;
122 m_capacity = capacity;
124 if (
size() > m_capacity) {
125 ssize_t nAllowedFailures =
size() - m_capacity;
126 while (
size() > m_capacity) {
127 if (!
evictItem() && --nAllowedFailures < 0) {
128 BOOST_THROW_EXCEPTION(
Error());
133 if (m_capacity >= oldCapacity) {
134 for (
size_t i = oldCapacity; i < m_capacity; i++) {
139 for (
size_t i = oldCapacity; i > m_capacity; i--) {
140 delete m_freeEntries.top();
145 BOOST_ASSERT(
size() + m_freeEntries.size() == m_capacity);
153 if (it != m_cache.get<byFullName>().end())
158 if (
isFull() && !doesReachLimit) {
161 setCapacity(newCapacity);
165 if (
isFull() && doesReachLimit) {
170 BOOST_ASSERT(m_freeEntries.size() > 0);
175 entry->setData(data);
176 m_cache.insert(entry);
182 shared_ptr<const Data>
188 if (it == m_cache.get<byFullName>().end()) {
189 return shared_ptr<const Data>();
194 return shared_ptr<const Data>();
198 return ((*it)->getData()).shared_from_this();
201 shared_ptr<const Data>
209 if (it != m_cache.get<byFullName>().end()) {
210 return ((*it)->getData()).shared_from_this();
215 it = m_cache.get<byFullName>().lower_bound(interest.
getName());
217 if (it == m_cache.get<byFullName>().end()) {
218 return shared_ptr<const Data>();
223 if (it != m_cache.get<byFullName>().begin())
230 return ret->
getData().shared_from_this();
233 return shared_ptr<const Data>();
241 BOOST_ASSERT(startingPoint != m_cache.get<byFullName>().end());
243 if (startingPoint != m_cache.get<byFullName>().begin())
245 BOOST_ASSERT((*startingPoint)->getFullName() < interest.
getName());
249 bool hasRightmostSelector = !hasLeftmostSelector;
251 if (hasLeftmostSelector)
253 if (interest.
matchesData((*startingPoint)->getData()))
255 return *startingPoint;
261 if (startingPoint != m_cache.get<byFullName>().end())
264 Name currentChildPrefix(
"");
268 ++rightmostCandidate;
270 bool isInBoundaries = (rightmostCandidate != m_cache.get<byFullName>().
end());
271 bool isInPrefix =
false;
274 isInPrefix = interest.
getName().
isPrefixOf((*rightmostCandidate)->getFullName());
279 if (interest.
matchesData((*rightmostCandidate)->getData()))
281 if (hasLeftmostSelector)
283 return *rightmostCandidate;
286 if (hasRightmostSelector)
289 const Name& childPrefix = (*rightmostCandidate)->getFullName()
292 if (currentChildPrefix.
empty() || (childPrefix != currentChildPrefix))
294 currentChildPrefix = childPrefix;
295 rightmost = rightmostCandidate;
305 if (rightmost != startingPoint)
310 if (hasRightmostSelector)
312 if (interest.
matchesData((*startingPoint)->getData()))
314 return *startingPoint;
326 m_freeEntries.push(*it);
328 return m_cache.erase(it);
337 while (it != m_cache.get<byFullName>().end() && prefix.
isPrefixOf((*it)->getName())) {
346 if (it == m_cache.get<byFullName>().end())
354 if (m_freeEntries.size() > (2 *
size()))
363 if (it == m_cache.get<byFullName>().end())
382 const Data* ptr = NULL;
406 const Cache::index<byFullName>::type& cacheIndex = m_cache.get<byFullName>();
408 it != cacheIndex.end(); it++)
409 os << (*it)->getFullName() << std::endl;
const Name & getName() const
Copyright (c) 2011-2015 Regents of the University of California.
const Data * operator->()
void insert(const Data &data)
Inserts a Data packet.
bool isFull() const
returns true if the in-memory storage uses up the current capacity, false otherwise ...
InMemoryStorage(size_t limit=std::numeric_limits< size_t >::max())
shared_ptr< const Data > find(const Interest &interest)
Finds the best match Data for an Interest.
Represents a self-defined const_iterator for the in-memory storage.
const Data & getData() const
Returns the Data packet stored in the in-memory storage entry.
represents an Interest packet
bool operator!=(const const_iterator &rhs)
InMemoryStorage::const_iterator end() const
Returns end iterator of the in-memory storage ordering by name with digest.
InMemoryStorage::const_iterator begin() const
Returns begin iterator of the in-memory storage ordering by name with digest.
virtual bool evictItem()=0
Removes one Data packet from in-memory storage based on derived class implemented replacement policy...
int getChildSelector() const
virtual void beforeErase(InMemoryStorageEntry *entry)
Update the entry or other data structures before a entry is successfully erased according to derived ...
void eraseImpl(const Name &name)
deletes in-memory storage entries by the Name with implicit digest.
Table::const_iterator iterator
const_iterator & operator++()
boost::multi_index_container< InMemoryStorageEntry *, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< byFullName >, boost::multi_index::const_mem_fun< InMemoryStorageEntry, const Name &,&InMemoryStorageEntry::getFullName >, std::less< Name > > > > Cache
size_t getCapacity() const
returns current capacity of in-memory storage (in packets)
size_t size() const
Get the number of components.
Represents an in-memory storage entry.
Name abstraction to represent an absolute name.
const_iterator(const Data *ptr, const Cache *cache, Cache::index< byFullName >::type::iterator it)
bool matchesData(const Data &data) const
Check if Interest can be satisfied by data.
virtual ~InMemoryStorage()
bool operator==(const const_iterator &rhs)
virtual void afterInsert(InMemoryStorageEntry *entry)
Update the entry or other data structures after a entry is successfully inserted according to derived...
bool empty() const
Check if name is emtpy.
bool isPrefixOf(const Name &name) const
Check if the N components of this name are the same as the first N components of the given name...
PartialName getPrefix(ssize_t nComponents) const
Extract a prefix (PartialName) of the name, containing first nComponents components.
InMemoryStorageEntry * selectChild(const Interest &interest, Cache::index< byFullName >::type::iterator startingPoint) const
Implements child selector (leftmost, rightmost, undeclared).
const Name & getFullName() const
Get full name of Data packet, including the implicit digest.
Represents an error might be thrown during reduce the current capacity of the in-memory storage throu...
void erase(const Name &prefix, const bool isPrefix=true)
Deletes in-memory storage entry by prefix by default.
void printCache(std::ostream &os) const
Prints contents of the in-memory storage.