blob: be26645ec5b81b516b23cb408bac1091e952bed4 [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:
44 typedef std::map<int, std::list< shared_ptr<Entry> >::iterator> LayerIterators;
45
46 Entry(const Data& data, bool isUnsolicited = false);
47
48 ~Entry();
49
50 /** \brief returns the name of the Data packet stored in the CS entry
51 * \return{ NDN name }
52 */
53 const Name&
54 getName() const;
55
56 /** \brief Data packet is unsolicited if this particular NDN node
57 * did not receive an Interest packet for it, or the Interest packet has already expired
58 * \return{ True if the Data packet is unsolicited; otherwise False }
59 */
60 bool
61 isUnsolicited() const;
62
63 /** \brief Returns True if CS entry was refreshed by a duplicate Data packet
64 */
65 bool
66 wasRefreshedByDuplicate() const;
67
68 /** \brief returns the absolute time when Data becomes expired
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070069 * \return{ Time (resolution up to time::milliseconds) }
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080070 */
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070071 const time::steady_clock::TimePoint&
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080072 getStaleTime() const;
73
74 /** \brief returns the Data packet stored in the CS entry
75 */
76 const Data&
77 getData() const;
78
79 /** \brief changes the content of CS entry and recomputes digest
80 */
81 void
82 setData(const Data& data);
83
84 /** \brief changes the content of CS entry and modifies digest
85 */
86 void
87 setData(const Data& data, const ndn::ConstBufferPtr& digest);
88
89 /** \brief refreshes the time when Data becomes expired
90 * according to the current absolute time.
91 */
92 void
93 updateStaleTime();
94
95 /** \brief returns the digest of the Data packet stored in the CS entry.
96 */
97 const ndn::ConstBufferPtr&
98 getDigest() const;
99
100 /** \brief saves the iterator pointing to the CS entry on a specific layer of skip list
101 */
102 void
103 setIterator(int layer, const LayerIterators::mapped_type& layerIterator);
104
105 /** \brief removes the iterator pointing to the CS entry on a specific layer of skip list
106 */
107 void
108 removeIterator(int layer);
109
110 /** \brief returns the table containing <layer, iterator> pairs.
111 */
112 const LayerIterators&
113 getIterators() const;
114
115private:
116 /** \brief prints <layer, iterator> pairs.
117 */
118 void
119 printIterators() const;
120
121private:
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -0700122 time::steady_clock::TimePoint m_staleAt;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800123 shared_ptr<const Data> m_dataPacket;
124
125 bool m_isUnsolicited;
126 bool m_wasRefreshedByDuplicate;
127
128 Name m_nameWithDigest;
129
130 mutable ndn::ConstBufferPtr m_digest;
131
132 LayerIterators m_layerIterators;
Junxiao Shi0fcb41e2014-01-24 10:29:43 -0700133};
134
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800135} // namespace cs
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800136} // namespace nfd
Alexander Afanasyevb927a3a2014-01-24 10:41:47 -0800137
138#endif // NFD_TABLE_CS_ENTRY_HPP