blob: eadb9f6aadc7c8a653d66eba2ac1f48356df2361 [file] [log] [blame]
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
* Washington University in St. Louis,
* Beijing Institute of Technology,
* The University of Memphis.
*
* This file is part of NFD (Named Data Networking Forwarding Daemon).
* See AUTHORS.md for complete list of NFD authors and contributors.
*
* NFD is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef NFD_DAEMON_TABLE_CS_ENTRY_HPP
#define NFD_DAEMON_TABLE_CS_ENTRY_HPP
#include "core/common.hpp"
namespace nfd {
namespace cs {
/** \brief a ContentStore entry
*/
class Entry
{
public: // exposed through ContentStore enumeration
/** \brief return the stored Data
*/
const Data&
getData() const
{
return *m_data;
}
/** \brief return stored Data name
*/
const Name&
getName() const
{
return m_data->getName();
}
/** \brief return full name (including implicit digest) of the stored Data
*/
const Name&
getFullName() const
{
return m_data->getFullName();
}
/** \brief return whether the stored Data is unsolicited
*/
bool
isUnsolicited() const
{
return m_isUnsolicited;
}
/** \brief check if the stored Data is fresh now
*/
bool
isFresh() const;
/** \brief determine whether Interest can be satisified by the stored Data
*/
bool
canSatisfy(const Interest& interest) const;
public: // used by ContentStore implementation
Entry(shared_ptr<const Data> data, bool isUnsolicited);
/** \brief recalculate when the entry would become non-fresh, relative to current time
*/
void
updateFreshUntil();
/** \brief clear 'unsolicited' flag
*/
void
clearUnsolicited()
{
m_isUnsolicited = false;
}
private:
shared_ptr<const Data> m_data;
bool m_isUnsolicited;
time::steady_clock::TimePoint m_freshUntil;
};
bool
operator<(const Entry& entry, const Name& queryName);
bool
operator<(const Name& queryName, const Entry& entry);
bool
operator<(const Entry& lhs, const Entry& rhs);
/** \brief an ordered container of ContentStore entries
*
* This container uses std::less<> comparator to enable lookup with queryName.
*/
using Table = std::set<Entry, std::less<>>;
using iterator = Table::const_iterator;
} // namespace cs
} // namespace nfd
#endif // NFD_DAEMON_TABLE_CS_ENTRY_HPP