blob: a04f9f7d07e61e20b4811ea2895361059bb00155 [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
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000033/** \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
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000038 /** \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
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000046 /** \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
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000054 /** \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
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000062 /** \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
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000070 /** \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
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000075 /** \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
83 /** \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
88 /** \brief clear 'unsolicited' flag
89 */
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;
Junxiao Shi5e4a02f2019-07-15 11:59:18 +000099 time::steady_clock::TimePoint 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
111/** \brief an ordered container of ContentStore entries
112 *
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