blob: 0bcdefc33c0f5f943183386f89e1926cc654fad5 [file] [log] [blame]
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev4b3fc862014-06-19 14:57:57 -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,
9 * The University of Memphis
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080010 *
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070011 * 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 Afanasyev4b3fc862014-06-19 14:57:57 -070025 * \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 Moiseenko76cf77a2014-03-05 14:35:51 -080028 */
29
30#include "cs-entry.hpp"
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060031#include "core/logger.hpp"
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080032
33namespace nfd {
34namespace cs {
35
36NFD_LOG_INIT("CsEntry");
37
Alexander Afanasyevc91ebfa2015-01-03 18:09:57 -080038Entry::Entry()
39 : m_isUnsolicited(false)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080040{
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080041}
42
43void
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040044Entry::setData(const Data& data, bool isUnsolicited)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080045{
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040046 m_isUnsolicited = isUnsolicited;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080047 m_dataPacket = data.shared_from_this();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080048
49 updateStaleTime();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080050}
51
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080052void
53Entry::updateStaleTime()
54{
Alexander Afanasyeveb3197f2014-03-17 19:28:18 -070055 m_staleAt = time::steady_clock::now() + m_dataPacket->getFreshnessPeriod();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080056}
57
Alexander Afanasyevc91ebfa2015-01-03 18:09:57 -080058bool
59Entry::isStale() const
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080060{
Alexander Afanasyevc91ebfa2015-01-03 18:09:57 -080061 return m_staleAt < time::steady_clock::now();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080062}
63
64void
Alexander Afanasyevc91ebfa2015-01-03 18:09:57 -080065Entry::reset()
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080066{
Alexander Afanasyevc91ebfa2015-01-03 18:09:57 -080067 m_staleAt = time::steady_clock::TimePoint();
68 m_dataPacket.reset();
69 m_isUnsolicited = false;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080070}
71
72} // namespace cs
73} // namespace nfd