blob: 0b58395c7a247c063e909f5f3d515956d46c2606 [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 Pesavento2c9d2ca2024-01-27 16:36:51 -05003 * Copyright (c) 2014-2024, 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 Pesavento2c9d2ca2024-01-27 16:36:51 -050031#include <set>
32
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040033namespace nfd::cs {
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070034
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040035/** \brief A ContentStore entry.
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080036 */
Junxiao Shia9388182014-12-13 23:16:09 -070037class Entry
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070038{
Junxiao Shifc206962015-01-16 11:12:22 -070039public: // exposed through ContentStore enumeration
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040040 /** \brief Return the stored Data.
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040041 */
Junxiao Shifc206962015-01-16 11:12:22 -070042 const Data&
43 getData() const
44 {
Junxiao Shifc206962015-01-16 11:12:22 -070045 return *m_data;
46 }
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080047
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040048 /** \brief Return stored Data name.
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080049 */
Alexander Afanasyev4b3fc862014-06-19 14:57:57 -070050 const Name&
Junxiao Shifc206962015-01-16 11:12:22 -070051 getName() const
52 {
Junxiao Shifc206962015-01-16 11:12:22 -070053 return m_data->getName();
54 }
Junxiao Shi5640ec82015-01-07 21:51:19 -070055
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040056 /** \brief Return full name (including implicit digest) of the stored Data.
Junxiao Shifc206962015-01-16 11:12:22 -070057 */
Junxiao Shi5640ec82015-01-07 21:51:19 -070058 const Name&
Junxiao Shifc206962015-01-16 11:12:22 -070059 getFullName() const
60 {
Junxiao Shifc206962015-01-16 11:12:22 -070061 return m_data->getFullName();
62 }
Alexander Afanasyev4b3fc862014-06-19 14:57:57 -070063
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040064 /** \brief Return whether the stored Data is unsolicited.
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080065 */
66 bool
Junxiao Shifc206962015-01-16 11:12:22 -070067 isUnsolicited() const
68 {
Junxiao Shifc206962015-01-16 11:12:22 -070069 return m_isUnsolicited;
70 }
Junxiao Shia9388182014-12-13 23:16:09 -070071
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040072 /** \brief Check if the stored Data is fresh now.
Junxiao Shifc206962015-01-16 11:12:22 -070073 */
Junxiao Shia9388182014-12-13 23:16:09 -070074 bool
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000075 isFresh() const;
Junxiao Shia9388182014-12-13 23:16:09 -070076
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040077 /** \brief Determine whether Interest can be satisified by the stored Data.
Junxiao Shi5640ec82015-01-07 21:51:19 -070078 */
Junxiao Shia9388182014-12-13 23:16:09 -070079 bool
80 canSatisfy(const Interest& interest) const;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080081
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000082public: // used by ContentStore implementation
83 Entry(shared_ptr<const Data> data, bool isUnsolicited);
84
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040085 /** \brief Recalculate when the entry would become non-fresh, relative to current time.
Junxiao Shifc206962015-01-16 11:12:22 -070086 */
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000087 void
88 updateFreshUntil();
89
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -040090 /** \brief Clear 'unsolicited' flag.
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000091 */
92 void
93 clearUnsolicited()
Junxiao Shifc206962015-01-16 11:12:22 -070094 {
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000095 m_isUnsolicited = false;
Junxiao Shifc206962015-01-16 11:12:22 -070096 }
97
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080098private:
Junxiao Shia9388182014-12-13 23:16:09 -070099 shared_ptr<const Data> m_data;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800100 bool m_isUnsolicited;
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400101 time::steady_clock::time_point m_freshUntil;
Junxiao Shi0fcb41e2014-01-24 10:29:43 -0700102};
103
Junxiao Shi5e4a02f2019-07-15 11:59:18 +0000104bool
105operator<(const Entry& entry, const Name& queryName);
106
107bool
108operator<(const Name& queryName, const Entry& entry);
109
110bool
111operator<(const Entry& lhs, const Entry& rhs);
112
Davide Pesaventoaa9e3b22022-10-21 17:00:07 -0400113/** \brief An ordered container of ContentStore entries.
Junxiao Shi5e4a02f2019-07-15 11:59:18 +0000114 *
115 * This container uses std::less<> comparator to enable lookup with queryName.
116 */
117using Table = std::set<Entry, std::less<>>;
118
Junxiao Shi07f2e2f2019-07-22 09:10:06 -0600119inline bool
120operator<(Table::const_iterator lhs, Table::const_iterator rhs)
121{
122 return *lhs < *rhs;
123}
Junxiao Shi5e4a02f2019-07-15 11:59:18 +0000124
Davide Pesaventoe422f9e2022-06-03 01:30:23 -0400125} // namespace nfd::cs
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800126
Alexander Afanasyev613e2a92014-04-15 13:36:58 -0700127#endif // NFD_DAEMON_TABLE_CS_ENTRY_HPP