blob: 5dd931d39e293e5a2b6add525e47c398dfc6b4e5 [file] [log] [blame]
Junxiao Shi0fcb41e2014-01-24 10:29:43 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi14b39182019-04-29 19:19:18 +00002/*
3 * Copyright (c) 2014-2019, Regents of the University of California,
Junxiao Shi5640ec82015-01-07 21:51:19 -07004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080010 *
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070011 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070024 */
25
Alexander Afanasyev613e2a92014-04-15 13:36:58 -070026#ifndef NFD_DAEMON_TABLE_CS_ENTRY_HPP
27#define NFD_DAEMON_TABLE_CS_ENTRY_HPP
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080028
Junxiao Shi9f5b01d2016-08-05 03:54:28 +000029#include "core/common.hpp"
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080030
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080031namespace nfd {
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070032namespace cs {
33
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000034/** \brief a ContentStore entry
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080035 */
Junxiao Shia9388182014-12-13 23:16:09 -070036class Entry
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070037{
Junxiao Shifc206962015-01-16 11:12:22 -070038public: // exposed through ContentStore enumeration
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000039 /** \brief return the stored Data
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040040 */
Junxiao Shifc206962015-01-16 11:12:22 -070041 const Data&
42 getData() const
43 {
Junxiao Shifc206962015-01-16 11:12:22 -070044 return *m_data;
45 }
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080046
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000047 /** \brief return stored Data name
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080048 */
Alexander Afanasyev4b3fc862014-06-19 14:57:57 -070049 const Name&
Junxiao Shifc206962015-01-16 11:12:22 -070050 getName() const
51 {
Junxiao Shifc206962015-01-16 11:12:22 -070052 return m_data->getName();
53 }
Junxiao Shi5640ec82015-01-07 21:51:19 -070054
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000055 /** \brief return full name (including implicit digest) of the stored Data
Junxiao Shifc206962015-01-16 11:12:22 -070056 */
Junxiao Shi5640ec82015-01-07 21:51:19 -070057 const Name&
Junxiao Shifc206962015-01-16 11:12:22 -070058 getFullName() const
59 {
Junxiao Shifc206962015-01-16 11:12:22 -070060 return m_data->getFullName();
61 }
Alexander Afanasyev4b3fc862014-06-19 14:57:57 -070062
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000063 /** \brief return whether the stored Data is unsolicited
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080064 */
65 bool
Junxiao Shifc206962015-01-16 11:12:22 -070066 isUnsolicited() const
67 {
Junxiao Shifc206962015-01-16 11:12:22 -070068 return m_isUnsolicited;
69 }
Junxiao Shia9388182014-12-13 23:16:09 -070070
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000071 /** \brief check if the stored Data is fresh now
Junxiao Shifc206962015-01-16 11:12:22 -070072 */
Junxiao Shia9388182014-12-13 23:16:09 -070073 bool
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000074 isFresh() const;
Junxiao Shia9388182014-12-13 23:16:09 -070075
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000076 /** \brief determine whether Interest can be satisified by the stored Data
Junxiao Shi5640ec82015-01-07 21:51:19 -070077 */
Junxiao Shia9388182014-12-13 23:16:09 -070078 bool
79 canSatisfy(const Interest& interest) const;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080080
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000081public: // used by ContentStore implementation
82 Entry(shared_ptr<const Data> data, bool isUnsolicited);
83
84 /** \brief recalculate when the entry would become non-fresh, relative to current time
Junxiao Shifc206962015-01-16 11:12:22 -070085 */
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000086 void
87 updateFreshUntil();
88
89 /** \brief clear 'unsolicited' flag
90 */
91 void
92 clearUnsolicited()
Junxiao Shifc206962015-01-16 11:12:22 -070093 {
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000094 m_isUnsolicited = false;
Junxiao Shifc206962015-01-16 11:12:22 -070095 }
96
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080097private:
Junxiao Shia9388182014-12-13 23:16:09 -070098 shared_ptr<const Data> m_data;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080099 bool m_isUnsolicited;
Junxiao Shi5e4a02f2019-07-15 11:59:18 +0000100 time::steady_clock::TimePoint m_freshUntil;
Junxiao Shi0fcb41e2014-01-24 10:29:43 -0700101};
102
Junxiao Shi5e4a02f2019-07-15 11:59:18 +0000103bool
104operator<(const Entry& entry, const Name& queryName);
105
106bool
107operator<(const Name& queryName, const Entry& entry);
108
109bool
110operator<(const Entry& lhs, const Entry& rhs);
111
112/** \brief an ordered container of ContentStore entries
113 *
114 * This container uses std::less<> comparator to enable lookup with queryName.
115 */
116using Table = std::set<Entry, std::less<>>;
117
Junxiao Shi07f2e2f2019-07-22 09:10:06 -0600118inline bool
119operator<(Table::const_iterator lhs, Table::const_iterator rhs)
120{
121 return *lhs < *rhs;
122}
Junxiao Shi5e4a02f2019-07-15 11:59:18 +0000123
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800124} // namespace cs
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800125} // namespace nfd
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800126
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700127#endif // NFD_DAEMON_TABLE_CS_ENTRY_HPP