blob: 89f71f135d1d8231a0ce4f74fba3f2c89fdeaa42 [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/*
Davide Pesaventoe422f9e2022-06-03 01:30:23 -04003 * Copyright (c) 2014-2022, 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
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040031namespace nfd::cs {
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070032
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040033/** \brief A ContentStore entry.
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080034 */
Junxiao Shia9388182014-12-13 23:16:09 -070035class Entry
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070036{
Junxiao Shifc206962015-01-16 11:12:22 -070037public: // exposed through ContentStore enumeration
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040038 /** \brief Return the stored Data.
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040039 */
Junxiao Shifc206962015-01-16 11:12:22 -070040 const Data&
41 getData() const
42 {
Junxiao Shifc206962015-01-16 11:12:22 -070043 return *m_data;
44 }
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080045
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040046 /** \brief Return stored Data name.
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080047 */
Alexander Afanasyev4b3fc862014-06-19 14:57:57 -070048 const Name&
Junxiao Shifc206962015-01-16 11:12:22 -070049 getName() const
50 {
Junxiao Shifc206962015-01-16 11:12:22 -070051 return m_data->getName();
52 }
Junxiao Shi5640ec82015-01-07 21:51:19 -070053
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040054 /** \brief Return full name (including implicit digest) of the stored Data.
Junxiao Shifc206962015-01-16 11:12:22 -070055 */
Junxiao Shi5640ec82015-01-07 21:51:19 -070056 const Name&
Junxiao Shifc206962015-01-16 11:12:22 -070057 getFullName() const
58 {
Junxiao Shifc206962015-01-16 11:12:22 -070059 return m_data->getFullName();
60 }
Alexander Afanasyev4b3fc862014-06-19 14:57:57 -070061
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040062 /** \brief Return whether the stored Data is unsolicited.
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080063 */
64 bool
Junxiao Shifc206962015-01-16 11:12:22 -070065 isUnsolicited() const
66 {
Junxiao Shifc206962015-01-16 11:12:22 -070067 return m_isUnsolicited;
68 }
Junxiao Shia9388182014-12-13 23:16:09 -070069
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040070 /** \brief Check if the stored Data is fresh now.
Junxiao Shifc206962015-01-16 11:12:22 -070071 */
Junxiao Shia9388182014-12-13 23:16:09 -070072 bool
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000073 isFresh() const;
Junxiao Shia9388182014-12-13 23:16:09 -070074
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040075 /** \brief Determine whether Interest can be satisified by the stored Data.
Junxiao Shi5640ec82015-01-07 21:51:19 -070076 */
Junxiao Shia9388182014-12-13 23:16:09 -070077 bool
78 canSatisfy(const Interest& interest) const;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080079
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000080public: // used by ContentStore implementation
81 Entry(shared_ptr<const Data> data, bool isUnsolicited);
82
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040083 /** \brief Recalculate when the entry would become non-fresh, relative to current time.
Junxiao Shifc206962015-01-16 11:12:22 -070084 */
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000085 void
86 updateFreshUntil();
87
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040088 /** \brief Clear 'unsolicited' flag.
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000089 */
90 void
91 clearUnsolicited()
Junxiao Shifc206962015-01-16 11:12:22 -070092 {
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000093 m_isUnsolicited = false;
Junxiao Shifc206962015-01-16 11:12:22 -070094 }
95
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080096private:
Junxiao Shia9388182014-12-13 23:16:09 -070097 shared_ptr<const Data> m_data;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080098 bool m_isUnsolicited;
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040099 time::steady_clock::time_point m_freshUntil;
Junxiao Shi0fcb41e2014-01-24 10:29:43 -0700100};
101
Junxiao Shi5e4a02f2019-07-15 11:59:18 +0000102bool
103operator<(const Entry& entry, const Name& queryName);
104
105bool
106operator<(const Name& queryName, const Entry& entry);
107
108bool
109operator<(const Entry& lhs, const Entry& rhs);
110
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400111/** \brief An ordered container of ContentStore entries.
Junxiao Shi5e4a02f2019-07-15 11:59:18 +0000112 *
113 * This container uses std::less<> comparator to enable lookup with queryName.
114 */
115using Table = std::set<Entry, std::less<>>;
116
Junxiao Shi07f2e2f2019-07-22 09:10:06 -0600117inline bool
118operator<(Table::const_iterator lhs, Table::const_iterator rhs)
119{
120 return *lhs < *rhs;
121}
Junxiao Shi5e4a02f2019-07-15 11:59:18 +0000122
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400123} // namespace nfd::cs
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800124
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700125#endif // NFD_DAEMON_TABLE_CS_ENTRY_HPP