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 | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014 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 |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 9 | * |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 11 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 12 | * |
| 13 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 14 | * of the GNU General Public License as published by the Free Software Foundation, |
| 15 | * either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE. See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 23 | * |
| 24 | * \author Ilya Moiseenko <iliamo@ucla.edu> |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 25 | */ |
| 26 | |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 27 | #ifndef NFD_TABLE_CS_ENTRY_HPP |
| 28 | #define NFD_TABLE_CS_ENTRY_HPP |
| 29 | |
| 30 | #include "common.hpp" |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 31 | #include <ndn-cpp-dev/util/crypto.hpp> |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 32 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 33 | namespace nfd { |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 34 | |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 35 | namespace cs { |
| 36 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 37 | class Entry; |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 38 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 39 | /** \brief represents a CS entry |
| 40 | */ |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 41 | class Entry : noncopyable |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 42 | { |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 43 | public: |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 44 | typedef std::map<int, std::list<Entry*>::iterator > LayerIterators; |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 45 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 46 | Entry(); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 47 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 48 | /** \brief releases reference counts on shared objects |
| 49 | */ |
| 50 | void |
| 51 | release(); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 52 | |
| 53 | /** \brief returns the name of the Data packet stored in the CS entry |
| 54 | * \return{ NDN name } |
| 55 | */ |
| 56 | const Name& |
| 57 | getName() const; |
| 58 | |
| 59 | /** \brief Data packet is unsolicited if this particular NDN node |
| 60 | * did not receive an Interest packet for it, or the Interest packet has already expired |
| 61 | * \return{ True if the Data packet is unsolicited; otherwise False } |
| 62 | */ |
| 63 | bool |
| 64 | isUnsolicited() const; |
| 65 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 66 | /** \brief returns the absolute time when Data becomes expired |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 67 | * \return{ Time (resolution up to time::milliseconds) } |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 68 | */ |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 69 | const time::steady_clock::TimePoint& |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 70 | getStaleTime() const; |
| 71 | |
| 72 | /** \brief returns the Data packet stored in the CS entry |
| 73 | */ |
| 74 | const Data& |
| 75 | getData() const; |
| 76 | |
| 77 | /** \brief changes the content of CS entry and recomputes digest |
| 78 | */ |
| 79 | void |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 80 | setData(const Data& data, bool isUnsolicited); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 81 | |
| 82 | /** \brief changes the content of CS entry and modifies digest |
| 83 | */ |
| 84 | void |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 85 | setData(const Data& data, bool isUnsolicited, const ndn::ConstBufferPtr& digest); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 86 | |
| 87 | /** \brief refreshes the time when Data becomes expired |
| 88 | * according to the current absolute time. |
| 89 | */ |
| 90 | void |
| 91 | updateStaleTime(); |
| 92 | |
| 93 | /** \brief returns the digest of the Data packet stored in the CS entry. |
| 94 | */ |
| 95 | const ndn::ConstBufferPtr& |
| 96 | getDigest() const; |
| 97 | |
| 98 | /** \brief saves the iterator pointing to the CS entry on a specific layer of skip list |
| 99 | */ |
| 100 | void |
| 101 | setIterator(int layer, const LayerIterators::mapped_type& layerIterator); |
| 102 | |
| 103 | /** \brief removes the iterator pointing to the CS entry on a specific layer of skip list |
| 104 | */ |
| 105 | void |
| 106 | removeIterator(int layer); |
| 107 | |
| 108 | /** \brief returns the table containing <layer, iterator> pairs. |
| 109 | */ |
| 110 | const LayerIterators& |
| 111 | getIterators() const; |
| 112 | |
| 113 | private: |
| 114 | /** \brief prints <layer, iterator> pairs. |
| 115 | */ |
| 116 | void |
| 117 | printIterators() const; |
| 118 | |
| 119 | private: |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 120 | time::steady_clock::TimePoint m_staleAt; |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 121 | shared_ptr<const Data> m_dataPacket; |
| 122 | |
| 123 | bool m_isUnsolicited; |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 124 | Name m_nameWithDigest; |
| 125 | |
| 126 | mutable ndn::ConstBufferPtr m_digest; |
| 127 | |
| 128 | LayerIterators m_layerIterators; |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 129 | }; |
| 130 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 131 | inline |
| 132 | Entry::Entry() |
| 133 | { |
| 134 | } |
| 135 | |
| 136 | inline const Name& |
| 137 | Entry::getName() const |
| 138 | { |
| 139 | return m_nameWithDigest; |
| 140 | } |
| 141 | |
| 142 | inline const Data& |
| 143 | Entry::getData() const |
| 144 | { |
| 145 | return *m_dataPacket; |
| 146 | } |
| 147 | |
| 148 | inline bool |
| 149 | Entry::isUnsolicited() const |
| 150 | { |
| 151 | return m_isUnsolicited; |
| 152 | } |
| 153 | |
| 154 | inline const time::steady_clock::TimePoint& |
| 155 | Entry::getStaleTime() const |
| 156 | { |
| 157 | return m_staleAt; |
| 158 | } |
| 159 | |
| 160 | inline const Entry::LayerIterators& |
| 161 | Entry::getIterators() const |
| 162 | { |
| 163 | return m_layerIterators; |
| 164 | } |
| 165 | |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 166 | } // namespace cs |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 167 | } // namespace nfd |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 168 | |
| 169 | #endif // NFD_TABLE_CS_ENTRY_HPP |