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 | 319f2c8 | 2015-01-07 14:56:53 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2015, 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, |
| 9 | * The University of Memphis. |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 10 | * |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | * |
Alexander Afanasyev | 4b3fc86 | 2014-06-19 14:57:57 -0700 | [diff] [blame] | 25 | * \author Ilya Moiseenko <http://ilyamoiseenko.com/> |
| 26 | * \author Junxiao Shi <http://www.cs.arizona.edu/people/shijunxiao/> |
| 27 | * \author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html> |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 28 | */ |
| 29 | |
| 30 | #include "cs-entry.hpp" |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 31 | #include "core/logger.hpp" |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 32 | |
| 33 | namespace nfd { |
| 34 | namespace cs { |
| 35 | |
| 36 | NFD_LOG_INIT("CsEntry"); |
| 37 | |
Alexander Afanasyev | c91ebfa | 2015-01-03 18:09:57 -0800 | [diff] [blame] | 38 | Entry::Entry() |
| 39 | : m_isUnsolicited(false) |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 40 | { |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | void |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 44 | Entry::setData(const Data& data, bool isUnsolicited) |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 45 | { |
Ilya Moiseenko | 96b80bb | 2014-04-05 20:53:27 -0400 | [diff] [blame] | 46 | m_isUnsolicited = isUnsolicited; |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 47 | m_dataPacket = data.shared_from_this(); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 48 | |
| 49 | updateStaleTime(); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 50 | } |
| 51 | |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 52 | void |
| 53 | Entry::updateStaleTime() |
| 54 | { |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 55 | m_staleAt = time::steady_clock::now() + m_dataPacket->getFreshnessPeriod(); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 56 | } |
| 57 | |
Alexander Afanasyev | c91ebfa | 2015-01-03 18:09:57 -0800 | [diff] [blame] | 58 | bool |
| 59 | Entry::isStale() const |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 60 | { |
Alexander Afanasyev | c91ebfa | 2015-01-03 18:09:57 -0800 | [diff] [blame] | 61 | return m_staleAt < time::steady_clock::now(); |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | void |
Alexander Afanasyev | c91ebfa | 2015-01-03 18:09:57 -0800 | [diff] [blame] | 65 | Entry::reset() |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 66 | { |
Alexander Afanasyev | c91ebfa | 2015-01-03 18:09:57 -0800 | [diff] [blame] | 67 | m_staleAt = time::steady_clock::TimePoint(); |
| 68 | m_dataPacket.reset(); |
| 69 | m_isUnsolicited = false; |
Ilya Moiseenko | 76cf77a | 2014-03-05 14:35:51 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | } // namespace cs |
| 73 | } // namespace nfd |