blob: 7d31442f38bd7e33f914065333c89be6a8674053 [file] [log] [blame]
Junxiao Shi0fcb41e2014-01-24 10:29:43 -07001/* -*- 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 Moiseenko76cf77a2014-03-05 14:35:51 -08005 *
6 * Author: Ilya Moiseenko <iliamo@ucla.edu>
Junxiao Shi0fcb41e2014-01-24 10:29:43 -07007 */
8
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -08009#ifndef NFD_TABLE_CS_ENTRY_HPP
10#define NFD_TABLE_CS_ENTRY_HPP
11
12#include "common.hpp"
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080013#include "core/time.hpp"
14#include <ndn-cpp-dev/util/crypto.hpp>
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080015
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080016namespace nfd {
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080017
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070018namespace cs {
19
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080020class Entry;
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070021
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080022/** \brief represents a CS entry
23 */
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080024class Entry : noncopyable
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070025{
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080026public:
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
98private:
99 /** \brief prints <layer, iterator> pairs.
100 */
101 void
102 printIterators() const;
103
104private:
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 Shi0fcb41e2014-01-24 10:29:43 -0700116};
117
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800118} // namespace cs
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800119} // namespace nfd
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800120
121#endif // NFD_TABLE_CS_ENTRY_HPP