Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 14b3918 | 2019-04-29 19:19:18 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Junxiao Shi | 5640ec8 | 2015-01-07 21:51:19 -0700 | [diff] [blame] | 4 | * 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 Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 10 | * |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 11 | * 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 Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 24 | */ |
| 25 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 26 | #ifndef NFD_DAEMON_TABLE_CS_ENTRY_HPP |
| 27 | #define NFD_DAEMON_TABLE_CS_ENTRY_HPP |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 28 | |
Junxiao Shi | 9f5b01d | 2016-08-05 03:54:28 +0000 | [diff] [blame] | 29 | #include "core/common.hpp" |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 30 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 31 | namespace nfd::cs { |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 32 | |
Junxiao Shi | 5e4a02f | 2019-07-15 11:59:18 +0000 | [diff] [blame] | 33 | /** \brief a ContentStore entry |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 34 | */ |
Junxiao Shi | a938818 | 2014-12-13 23:16:09 -0700 | [diff] [blame] | 35 | class Entry |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 36 | { |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 37 | public: // exposed through ContentStore enumeration |
Junxiao Shi | 5e4a02f | 2019-07-15 11:59:18 +0000 | [diff] [blame] | 38 | /** \brief return the stored Data |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 39 | */ |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 40 | const Data& |
| 41 | getData() const |
| 42 | { |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 43 | return *m_data; |
| 44 | } |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 45 | |
Junxiao Shi | 5e4a02f | 2019-07-15 11:59:18 +0000 | [diff] [blame] | 46 | /** \brief return stored Data name |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 47 | */ |
Alexander Afanasyev | 4b3fc86 | 2014-06-19 14:57:57 -0700 | [diff] [blame] | 48 | const Name& |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 49 | getName() const |
| 50 | { |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 51 | return m_data->getName(); |
| 52 | } |
Junxiao Shi | 5640ec8 | 2015-01-07 21:51:19 -0700 | [diff] [blame] | 53 | |
Junxiao Shi | 5e4a02f | 2019-07-15 11:59:18 +0000 | [diff] [blame] | 54 | /** \brief return full name (including implicit digest) of the stored Data |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 55 | */ |
Junxiao Shi | 5640ec8 | 2015-01-07 21:51:19 -0700 | [diff] [blame] | 56 | const Name& |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 57 | getFullName() const |
| 58 | { |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 59 | return m_data->getFullName(); |
| 60 | } |
Alexander Afanasyev | 4b3fc86 | 2014-06-19 14:57:57 -0700 | [diff] [blame] | 61 | |
Junxiao Shi | 5e4a02f | 2019-07-15 11:59:18 +0000 | [diff] [blame] | 62 | /** \brief return whether the stored Data is unsolicited |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 63 | */ |
| 64 | bool |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 65 | isUnsolicited() const |
| 66 | { |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 67 | return m_isUnsolicited; |
| 68 | } |
Junxiao Shi | a938818 | 2014-12-13 23:16:09 -0700 | [diff] [blame] | 69 | |
Junxiao Shi | 5e4a02f | 2019-07-15 11:59:18 +0000 | [diff] [blame] | 70 | /** \brief check if the stored Data is fresh now |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 71 | */ |
Junxiao Shi | a938818 | 2014-12-13 23:16:09 -0700 | [diff] [blame] | 72 | bool |
Junxiao Shi | 5e4a02f | 2019-07-15 11:59:18 +0000 | [diff] [blame] | 73 | isFresh() const; |
Junxiao Shi | a938818 | 2014-12-13 23:16:09 -0700 | [diff] [blame] | 74 | |
Junxiao Shi | 5e4a02f | 2019-07-15 11:59:18 +0000 | [diff] [blame] | 75 | /** \brief determine whether Interest can be satisified by the stored Data |
Junxiao Shi | 5640ec8 | 2015-01-07 21:51:19 -0700 | [diff] [blame] | 76 | */ |
Junxiao Shi | a938818 | 2014-12-13 23:16:09 -0700 | [diff] [blame] | 77 | bool |
| 78 | canSatisfy(const Interest& interest) const; |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 79 | |
Junxiao Shi | 5e4a02f | 2019-07-15 11:59:18 +0000 | [diff] [blame] | 80 | public: // 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 Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 84 | */ |
Junxiao Shi | 5e4a02f | 2019-07-15 11:59:18 +0000 | [diff] [blame] | 85 | void |
| 86 | updateFreshUntil(); |
| 87 | |
| 88 | /** \brief clear 'unsolicited' flag |
| 89 | */ |
| 90 | void |
| 91 | clearUnsolicited() |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 92 | { |
Junxiao Shi | 5e4a02f | 2019-07-15 11:59:18 +0000 | [diff] [blame] | 93 | m_isUnsolicited = false; |
Junxiao Shi | fc20696 | 2015-01-16 11:12:22 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 96 | private: |
Junxiao Shi | a938818 | 2014-12-13 23:16:09 -0700 | [diff] [blame] | 97 | shared_ptr<const Data> m_data; |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 98 | bool m_isUnsolicited; |
Junxiao Shi | 5e4a02f | 2019-07-15 11:59:18 +0000 | [diff] [blame] | 99 | time::steady_clock::TimePoint m_freshUntil; |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 100 | }; |
| 101 | |
Junxiao Shi | 5e4a02f | 2019-07-15 11:59:18 +0000 | [diff] [blame] | 102 | bool |
| 103 | operator<(const Entry& entry, const Name& queryName); |
| 104 | |
| 105 | bool |
| 106 | operator<(const Name& queryName, const Entry& entry); |
| 107 | |
| 108 | bool |
| 109 | operator<(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 | */ |
| 115 | using Table = std::set<Entry, std::less<>>; |
| 116 | |
Junxiao Shi | 07f2e2f | 2019-07-22 09:10:06 -0600 | [diff] [blame] | 117 | inline bool |
| 118 | operator<(Table::const_iterator lhs, Table::const_iterator rhs) |
| 119 | { |
| 120 | return *lhs < *rhs; |
| 121 | } |
Junxiao Shi | 5e4a02f | 2019-07-15 11:59:18 +0000 | [diff] [blame] | 122 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 123 | } // namespace nfd::cs |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 124 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 125 | #endif // NFD_DAEMON_TABLE_CS_ENTRY_HPP |