blob: ce3d5388a3efa649da1a6850189fd0c53bb59778 [file] [log] [blame]
Junxiao Shi0fcb41e2014-01-24 10:29:43 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -07003 * 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 Moiseenko76cf77a2014-03-05 14:35:51 -08009 *
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 * 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 Shi0fcb41e2014-01-24 10:29:43 -070025 */
26
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080027#ifndef NFD_TABLE_CS_ENTRY_HPP
28#define NFD_TABLE_CS_ENTRY_HPP
29
30#include "common.hpp"
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080031#include <ndn-cpp-dev/util/crypto.hpp>
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080032
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080033namespace nfd {
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080034
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070035namespace cs {
36
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080037class Entry;
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070038
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080039/** \brief represents a CS entry
40 */
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -080041class Entry : noncopyable
Junxiao Shi0fcb41e2014-01-24 10:29:43 -070042{
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080043public:
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040044 typedef std::map<int, std::list<Entry*>::iterator > LayerIterators;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080045
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040046 Entry();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080047
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040048 /** \brief releases reference counts on shared objects
49 */
50 void
51 release();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080052
53 /** \brief returns the name of the Data packet stored in the CS entry
54 * \return{ NDN name }
55 */
56 const Name&
57 getName() const;
58
59 /** \brief Data packet is unsolicited if this particular NDN node
60 * did not receive an Interest packet for it, or the Interest packet has already expired
61 * \return{ True if the Data packet is unsolicited; otherwise False }
62 */
63 bool
64 isUnsolicited() const;
65
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080066 /** \brief returns the absolute time when Data becomes expired
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070067 * \return{ Time (resolution up to time::milliseconds) }
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080068 */
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070069 const time::steady_clock::TimePoint&
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080070 getStaleTime() const;
71
72 /** \brief returns the Data packet stored in the CS entry
73 */
74 const Data&
75 getData() const;
76
77 /** \brief changes the content of CS entry and recomputes digest
78 */
79 void
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040080 setData(const Data& data, bool isUnsolicited);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080081
82 /** \brief changes the content of CS entry and modifies digest
83 */
84 void
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040085 setData(const Data& data, bool isUnsolicited, const ndn::ConstBufferPtr& digest);
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080086
87 /** \brief refreshes the time when Data becomes expired
88 * according to the current absolute time.
89 */
90 void
91 updateStaleTime();
92
93 /** \brief returns the digest of the Data packet stored in the CS entry.
94 */
95 const ndn::ConstBufferPtr&
96 getDigest() const;
97
98 /** \brief saves the iterator pointing to the CS entry on a specific layer of skip list
99 */
100 void
101 setIterator(int layer, const LayerIterators::mapped_type& layerIterator);
102
103 /** \brief removes the iterator pointing to the CS entry on a specific layer of skip list
104 */
105 void
106 removeIterator(int layer);
107
108 /** \brief returns the table containing <layer, iterator> pairs.
109 */
110 const LayerIterators&
111 getIterators() const;
112
113private:
114 /** \brief prints <layer, iterator> pairs.
115 */
116 void
117 printIterators() const;
118
119private:
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700120 time::steady_clock::TimePoint m_staleAt;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800121 shared_ptr<const Data> m_dataPacket;
122
123 bool m_isUnsolicited;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800124 Name m_nameWithDigest;
125
126 mutable ndn::ConstBufferPtr m_digest;
127
128 LayerIterators m_layerIterators;
Junxiao Shi0fcb41e2014-01-24 10:29:43 -0700129};
130
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400131inline
132Entry::Entry()
133{
134}
135
136inline const Name&
137Entry::getName() const
138{
139 return m_nameWithDigest;
140}
141
142inline const Data&
143Entry::getData() const
144{
145 return *m_dataPacket;
146}
147
148inline bool
149Entry::isUnsolicited() const
150{
151 return m_isUnsolicited;
152}
153
154inline const time::steady_clock::TimePoint&
155Entry::getStaleTime() const
156{
157 return m_staleAt;
158}
159
160inline const Entry::LayerIterators&
161Entry::getIterators() const
162{
163 return m_layerIterators;
164}
165
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800166} // namespace cs
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800167} // namespace nfd
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800168
169#endif // NFD_TABLE_CS_ENTRY_HPP