blob: 447c7106f8340cab9079e9f82112f071ee987ce2 [file] [log] [blame]
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -08001/* -*- 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>
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080025 */
26
27#include "cs-entry.hpp"
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060028#include "core/logger.hpp"
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080029
30namespace nfd {
31namespace cs {
32
33NFD_LOG_INIT("CsEntry");
34
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040035void
36Entry::release()
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080037{
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040038 BOOST_ASSERT(m_layerIterators.empty());
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080039
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040040 m_dataPacket.reset();
41 m_digest.reset();
42 m_nameWithDigest.clear();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080043}
44
45void
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040046Entry::setData(const Data& data, bool isUnsolicited)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080047{
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040048 m_isUnsolicited = isUnsolicited;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080049 m_dataPacket = data.shared_from_this();
50 m_digest.reset();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080051
52 updateStaleTime();
53
54 m_nameWithDigest = data.getName();
55 m_nameWithDigest.append(ndn::name::Component(getDigest()));
56}
57
58void
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040059Entry::setData(const Data& data, bool isUnsolicited, const ndn::ConstBufferPtr& digest)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080060{
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080061 m_dataPacket = data.shared_from_this();
62 m_digest = digest;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080063
64 updateStaleTime();
65
66 m_nameWithDigest = data.getName();
67 m_nameWithDigest.append(ndn::name::Component(getDigest()));
68}
69
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080070void
71Entry::updateStaleTime()
72{
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070073 m_staleAt = time::steady_clock::now() + m_dataPacket->getFreshnessPeriod();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080074}
75
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080076const ndn::ConstBufferPtr&
77Entry::getDigest() const
78{
79 if (!static_cast<bool>(m_digest))
80 {
81 const Block& block = m_dataPacket->wireEncode();
82 m_digest = ndn::crypto::sha256(block.wire(), block.size());
83 }
84
85 return m_digest;
86}
87
88void
89Entry::setIterator(int layer, const Entry::LayerIterators::mapped_type& layerIterator)
90{
91 m_layerIterators[layer] = layerIterator;
92}
93
94void
95Entry::removeIterator(int layer)
96{
97 m_layerIterators.erase(layer);
98}
99
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800100void
101Entry::printIterators() const
102{
103 for (LayerIterators::const_iterator it = m_layerIterators.begin();
104 it != m_layerIterators.end();
105 ++it)
106 {
Alexander Afanasyevbf9edee2014-03-31 23:05:27 -0700107 NFD_LOG_TRACE("[" << it->first << "]" << " " << &(*it->second));
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -0800108 }
109}
110
111} // namespace cs
112} // namespace nfd