Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 3 | * 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 Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 9 | * |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * 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 Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 25 | */ |
| 26 | |
| 27 | #include "cs-entry.hpp" |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 28 | #include "core/logger.hpp" |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 29 | |
| 30 | namespace nfd { |
| 31 | namespace cs { |
| 32 | |
| 33 | NFD_LOG_INIT("CsEntry"); |
| 34 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame^] | 35 | void |
| 36 | Entry::release() |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 37 | { |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame^] | 38 | BOOST_ASSERT(m_layerIterators.empty()); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 39 | |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame^] | 40 | m_dataPacket.reset(); |
| 41 | m_digest.reset(); |
| 42 | m_nameWithDigest.clear(); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | void |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame^] | 46 | Entry::setData(const Data& data, bool isUnsolicited) |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 47 | { |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame^] | 48 | m_isUnsolicited = isUnsolicited; |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 49 | m_dataPacket = data.shared_from_this(); |
| 50 | m_digest.reset(); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 51 | |
| 52 | updateStaleTime(); |
| 53 | |
| 54 | m_nameWithDigest = data.getName(); |
| 55 | m_nameWithDigest.append(ndn::name::Component(getDigest())); |
| 56 | } |
| 57 | |
| 58 | void |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame^] | 59 | Entry::setData(const Data& data, bool isUnsolicited, const ndn::ConstBufferPtr& digest) |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 60 | { |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 61 | m_dataPacket = data.shared_from_this(); |
| 62 | m_digest = digest; |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 63 | |
| 64 | updateStaleTime(); |
| 65 | |
| 66 | m_nameWithDigest = data.getName(); |
| 67 | m_nameWithDigest.append(ndn::name::Component(getDigest())); |
| 68 | } |
| 69 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 70 | void |
| 71 | Entry::updateStaleTime() |
| 72 | { |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 73 | m_staleAt = time::steady_clock::now() + m_dataPacket->getFreshnessPeriod(); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 74 | } |
| 75 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 76 | const ndn::ConstBufferPtr& |
| 77 | Entry::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 | |
| 88 | void |
| 89 | Entry::setIterator(int layer, const Entry::LayerIterators::mapped_type& layerIterator) |
| 90 | { |
| 91 | m_layerIterators[layer] = layerIterator; |
| 92 | } |
| 93 | |
| 94 | void |
| 95 | Entry::removeIterator(int layer) |
| 96 | { |
| 97 | m_layerIterators.erase(layer); |
| 98 | } |
| 99 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 100 | void |
| 101 | Entry::printIterators() const |
| 102 | { |
| 103 | for (LayerIterators::const_iterator it = m_layerIterators.begin(); |
| 104 | it != m_layerIterators.end(); |
| 105 | ++it) |
| 106 | { |
Alexander Afanasyev | bf9edee | 2014-03-31 23:05:27 -0700 | [diff] [blame] | 107 | NFD_LOG_TRACE("[" << it->first << "]" << " " << &(*it->second)); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 108 | } |
| 109 | } |
| 110 | |
| 111 | } // namespace cs |
| 112 | } // namespace nfd |