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