Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 319f2c8 | 2015-01-07 14:56:53 -0800 | [diff] [blame^] | 3 | * Copyright (c) 2014-2015, Regents of the University of California, |
| 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/>. |
| 24 | * |
Alexander Afanasyev | 4b3fc86 | 2014-06-19 14:57:57 -0700 | [diff] [blame] | 25 | * \author Ilya Moiseenko <http://ilyamoiseenko.com/> |
| 26 | * \author Junxiao Shi <http://www.cs.arizona.edu/people/shijunxiao/> |
| 27 | * \author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html> |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 28 | */ |
| 29 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 30 | #ifndef NFD_DAEMON_TABLE_CS_ENTRY_HPP |
| 31 | #define NFD_DAEMON_TABLE_CS_ENTRY_HPP |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 32 | |
| 33 | #include "common.hpp" |
| 34 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 35 | namespace nfd { |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 36 | namespace cs { |
| 37 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 38 | class Entry; |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 39 | |
Alexander Afanasyev | c91ebfa | 2015-01-03 18:09:57 -0800 | [diff] [blame] | 40 | /** \brief represents a base class for CS entry |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 41 | */ |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 42 | class Entry : noncopyable |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 43 | { |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 44 | public: |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 45 | Entry(); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 46 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 47 | /** \brief returns the name of the Data packet stored in the CS entry |
| 48 | * \return{ NDN name } |
| 49 | */ |
| 50 | const Name& |
| 51 | getName() const; |
| 52 | |
Alexander Afanasyev | 4b3fc86 | 2014-06-19 14:57:57 -0700 | [diff] [blame] | 53 | /** \brief returns the full name (including implicit digest) of the Data packet stored |
| 54 | * in the CS entry |
| 55 | * \return{ NDN name } |
| 56 | */ |
| 57 | const Name& |
| 58 | getFullName() const; |
| 59 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 60 | /** \brief Data packet is unsolicited if this particular NDN node |
| 61 | * did not receive an Interest packet for it, or the Interest packet has already expired |
| 62 | * \return{ True if the Data packet is unsolicited; otherwise False } |
| 63 | */ |
| 64 | bool |
| 65 | isUnsolicited() const; |
| 66 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 67 | /** \brief returns the Data packet stored in the CS entry |
| 68 | */ |
| 69 | const Data& |
| 70 | getData() const; |
| 71 | |
| 72 | /** \brief changes the content of CS entry and recomputes digest |
| 73 | */ |
| 74 | void |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 75 | setData(const Data& data, bool isUnsolicited); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 76 | |
Alexander Afanasyev | c91ebfa | 2015-01-03 18:09:57 -0800 | [diff] [blame] | 77 | /** \brief returns the absolute time when Data becomes expired |
| 78 | * \return{ Time (resolution up to time::milliseconds) } |
| 79 | */ |
| 80 | const time::steady_clock::TimePoint& |
| 81 | getStaleTime() const; |
| 82 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 83 | /** \brief refreshes the time when Data becomes expired |
| 84 | * according to the current absolute time. |
| 85 | */ |
| 86 | void |
| 87 | updateStaleTime(); |
| 88 | |
Alexander Afanasyev | c91ebfa | 2015-01-03 18:09:57 -0800 | [diff] [blame] | 89 | /** \brief checks if the stored Data is stale |
| 90 | */ |
| 91 | bool |
| 92 | isStale() const; |
| 93 | |
| 94 | /** \brief clears CS entry |
| 95 | * After reset, *this == Entry() |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 96 | */ |
| 97 | void |
Alexander Afanasyev | c91ebfa | 2015-01-03 18:09:57 -0800 | [diff] [blame] | 98 | reset(); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 99 | |
| 100 | private: |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 101 | time::steady_clock::TimePoint m_staleAt; |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 102 | shared_ptr<const Data> m_dataPacket; |
| 103 | |
| 104 | bool m_isUnsolicited; |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 107 | inline const Name& |
| 108 | Entry::getName() const |
| 109 | { |
Alexander Afanasyev | c91ebfa | 2015-01-03 18:09:57 -0800 | [diff] [blame] | 110 | BOOST_ASSERT(m_dataPacket != nullptr); |
Alexander Afanasyev | 4b3fc86 | 2014-06-19 14:57:57 -0700 | [diff] [blame] | 111 | return m_dataPacket->getName(); |
| 112 | } |
| 113 | |
| 114 | inline const Name& |
| 115 | Entry::getFullName() const |
| 116 | { |
Alexander Afanasyev | c91ebfa | 2015-01-03 18:09:57 -0800 | [diff] [blame] | 117 | BOOST_ASSERT(m_dataPacket != nullptr); |
Alexander Afanasyev | 4b3fc86 | 2014-06-19 14:57:57 -0700 | [diff] [blame] | 118 | return m_dataPacket->getFullName(); |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | inline const Data& |
| 122 | Entry::getData() const |
| 123 | { |
Alexander Afanasyev | c91ebfa | 2015-01-03 18:09:57 -0800 | [diff] [blame] | 124 | BOOST_ASSERT(m_dataPacket != nullptr); |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 125 | return *m_dataPacket; |
| 126 | } |
| 127 | |
| 128 | inline bool |
| 129 | Entry::isUnsolicited() const |
| 130 | { |
| 131 | return m_isUnsolicited; |
| 132 | } |
| 133 | |
| 134 | inline const time::steady_clock::TimePoint& |
| 135 | Entry::getStaleTime() const |
| 136 | { |
| 137 | return m_staleAt; |
| 138 | } |
| 139 | |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 140 | } // namespace cs |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 141 | } // namespace nfd |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 142 | |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 143 | #endif // NFD_DAEMON_TABLE_CS_ENTRY_HPP |