Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 5 | * |
| 6 | * Author: Ilya Moiseenko <iliamo@ucla.edu> |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 9 | #ifndef NFD_TABLE_CS_ENTRY_HPP |
| 10 | #define NFD_TABLE_CS_ENTRY_HPP |
| 11 | |
| 12 | #include "common.hpp" |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 13 | #include <ndn-cpp-dev/util/crypto.hpp> |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 14 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 15 | namespace nfd { |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 16 | |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 17 | namespace cs { |
| 18 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 19 | class Entry; |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 20 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 21 | /** \brief represents a CS entry |
| 22 | */ |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 23 | class Entry : noncopyable |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 24 | { |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 25 | public: |
| 26 | typedef std::map<int, std::list< shared_ptr<Entry> >::iterator> LayerIterators; |
| 27 | |
| 28 | Entry(const Data& data, bool isUnsolicited = false); |
| 29 | |
| 30 | ~Entry(); |
| 31 | |
| 32 | /** \brief returns the name of the Data packet stored in the CS entry |
| 33 | * \return{ NDN name } |
| 34 | */ |
| 35 | const Name& |
| 36 | getName() const; |
| 37 | |
| 38 | /** \brief Data packet is unsolicited if this particular NDN node |
| 39 | * did not receive an Interest packet for it, or the Interest packet has already expired |
| 40 | * \return{ True if the Data packet is unsolicited; otherwise False } |
| 41 | */ |
| 42 | bool |
| 43 | isUnsolicited() const; |
| 44 | |
| 45 | /** \brief Returns True if CS entry was refreshed by a duplicate Data packet |
| 46 | */ |
| 47 | bool |
| 48 | wasRefreshedByDuplicate() const; |
| 49 | |
| 50 | /** \brief returns the absolute time when Data becomes expired |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 51 | * \return{ Time (resolution up to time::milliseconds) } |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 52 | */ |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 53 | const time::steady_clock::TimePoint& |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 54 | getStaleTime() const; |
| 55 | |
| 56 | /** \brief returns the Data packet stored in the CS entry |
| 57 | */ |
| 58 | const Data& |
| 59 | getData() const; |
| 60 | |
| 61 | /** \brief changes the content of CS entry and recomputes digest |
| 62 | */ |
| 63 | void |
| 64 | setData(const Data& data); |
| 65 | |
| 66 | /** \brief changes the content of CS entry and modifies digest |
| 67 | */ |
| 68 | void |
| 69 | setData(const Data& data, const ndn::ConstBufferPtr& digest); |
| 70 | |
| 71 | /** \brief refreshes the time when Data becomes expired |
| 72 | * according to the current absolute time. |
| 73 | */ |
| 74 | void |
| 75 | updateStaleTime(); |
| 76 | |
| 77 | /** \brief returns the digest of the Data packet stored in the CS entry. |
| 78 | */ |
| 79 | const ndn::ConstBufferPtr& |
| 80 | getDigest() const; |
| 81 | |
| 82 | /** \brief saves the iterator pointing to the CS entry on a specific layer of skip list |
| 83 | */ |
| 84 | void |
| 85 | setIterator(int layer, const LayerIterators::mapped_type& layerIterator); |
| 86 | |
| 87 | /** \brief removes the iterator pointing to the CS entry on a specific layer of skip list |
| 88 | */ |
| 89 | void |
| 90 | removeIterator(int layer); |
| 91 | |
| 92 | /** \brief returns the table containing <layer, iterator> pairs. |
| 93 | */ |
| 94 | const LayerIterators& |
| 95 | getIterators() const; |
| 96 | |
| 97 | private: |
| 98 | /** \brief prints <layer, iterator> pairs. |
| 99 | */ |
| 100 | void |
| 101 | printIterators() const; |
| 102 | |
| 103 | private: |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 104 | time::steady_clock::TimePoint m_staleAt; |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 105 | shared_ptr<const Data> m_dataPacket; |
| 106 | |
| 107 | bool m_isUnsolicited; |
| 108 | bool m_wasRefreshedByDuplicate; |
| 109 | |
| 110 | Name m_nameWithDigest; |
| 111 | |
| 112 | mutable ndn::ConstBufferPtr m_digest; |
| 113 | |
| 114 | LayerIterators m_layerIterators; |
Junxiao Shi | 0fcb41e | 2014-01-24 10:29:43 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 117 | } // namespace cs |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 118 | } // namespace nfd |
Alexander Afanasyev | b927a3a | 2014-01-24 10:41:47 -0800 | [diff] [blame] | 119 | |
| 120 | #endif // NFD_TABLE_CS_ENTRY_HPP |