blob: 062e7f12db1eb70431af4f7f18ffee17aa15e4d2 [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 <ndn-cpp-dev/util/crypto.hpp>
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080014
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080015namespace nfd {
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080016
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070017namespace cs {
18
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080019class Entry;
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070020
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080021/** \brief represents a CS entry
22 */
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080023class Entry : noncopyable
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070024{
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080025public:
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 Afanasyeveb3197f2014-03-17 19:28:18 -070051 * \return{ Time (resolution up to time::milliseconds) }
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080052 */
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070053 const time::steady_clock::TimePoint&
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080054 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
97private:
98 /** \brief prints <layer, iterator> pairs.
99 */
100 void
101 printIterators() const;
102
103private:
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700104 time::steady_clock::TimePoint m_staleAt;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800105 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 Shi0fcb41e2014-01-24 10:29:43 -0700115};
116
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800117} // namespace cs
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800118} // namespace nfd
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800119
120#endif // NFD_TABLE_CS_ENTRY_HPP