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: |
| 44 | typedef std::map<int, std::list< shared_ptr<Entry> >::iterator> LayerIterators; |
| 45 | |
| 46 | Entry(const Data& data, bool isUnsolicited = false); |
| 47 | |
| 48 | ~Entry(); |
| 49 | |
| 50 | /** \brief returns the name of the Data packet stored in the CS entry |
| 51 | * \return{ NDN name } |
| 52 | */ |
| 53 | const Name& |
| 54 | getName() const; |
| 55 | |
| 56 | /** \brief Data packet is unsolicited if this particular NDN node |
| 57 | * did not receive an Interest packet for it, or the Interest packet has already expired |
| 58 | * \return{ True if the Data packet is unsolicited; otherwise False } |
| 59 | */ |
| 60 | bool |
| 61 | isUnsolicited() const; |
| 62 | |
| 63 | /** \brief Returns True if CS entry was refreshed by a duplicate Data packet |
| 64 | */ |
| 65 | bool |
| 66 | wasRefreshedByDuplicate() const; |
| 67 | |
| 68 | /** \brief returns the absolute time when Data becomes expired |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 69 | * \return{ Time (resolution up to time::milliseconds) } |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 70 | */ |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 71 | const time::steady_clock::TimePoint& |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 72 | getStaleTime() const; |
| 73 | |
| 74 | /** \brief returns the Data packet stored in the CS entry |
| 75 | */ |
| 76 | const Data& |
| 77 | getData() const; |
| 78 | |
| 79 | /** \brief changes the content of CS entry and recomputes digest |
| 80 | */ |
| 81 | void |
| 82 | setData(const Data& data); |
| 83 | |
| 84 | /** \brief changes the content of CS entry and modifies digest |
| 85 | */ |
| 86 | void |
| 87 | setData(const Data& data, const ndn::ConstBufferPtr& digest); |
| 88 | |
| 89 | /** \brief refreshes the time when Data becomes expired |
| 90 | * according to the current absolute time. |
| 91 | */ |
| 92 | void |
| 93 | updateStaleTime(); |
| 94 | |
| 95 | /** \brief returns the digest of the Data packet stored in the CS entry. |
| 96 | */ |
| 97 | const ndn::ConstBufferPtr& |
| 98 | getDigest() const; |
| 99 | |
| 100 | /** \brief saves the iterator pointing to the CS entry on a specific layer of skip list |
| 101 | */ |
| 102 | void |
| 103 | setIterator(int layer, const LayerIterators::mapped_type& layerIterator); |
| 104 | |
| 105 | /** \brief removes the iterator pointing to the CS entry on a specific layer of skip list |
| 106 | */ |
| 107 | void |
| 108 | removeIterator(int layer); |
| 109 | |
| 110 | /** \brief returns the table containing <layer, iterator> pairs. |
| 111 | */ |
| 112 | const LayerIterators& |
| 113 | getIterators() const; |
| 114 | |
| 115 | private: |
| 116 | /** \brief prints <layer, iterator> pairs. |
| 117 | */ |
| 118 | void |
| 119 | printIterators() const; |
| 120 | |
| 121 | private: |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 122 | time::steady_clock::TimePoint m_staleAt; |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 123 | shared_ptr<const Data> m_dataPacket; |
| 124 | |
| 125 | bool m_isUnsolicited; |
| 126 | bool m_wasRefreshedByDuplicate; |
| 127 | |
| 128 | Name m_nameWithDigest; |
| 129 | |
| 130 | mutable ndn::ConstBufferPtr m_digest; |
| 131 | |
| 132 | LayerIterators m_layerIterators; |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 133 | }; |
| 134 | |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 135 | } // namespace cs |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 136 | } // namespace nfd |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 137 | |
| 138 | #endif // NFD_TABLE_CS_ENTRY_HPP |