blob: 4bf84d59fa357e26bc2c3bf19a9f49ea52296a28 [file] [log] [blame]
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Eric Newberryf4056d02017-05-26 17:31:53 +00003 * Copyright (c) 2014-2017, Regents of the University of California,
Junxiao Shi5640ec82015-01-07 21:51:19 -07004 * 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/>.
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080024 */
25
26#include "cs-entry.hpp"
27
28namespace nfd {
29namespace cs {
30
Junxiao Shifc206962015-01-16 11:12:22 -070031void
32Entry::setData(shared_ptr<const Data> data, bool isUnsolicited)
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080033{
Junxiao Shifc206962015-01-16 11:12:22 -070034 m_data = data;
35 m_isUnsolicited = isUnsolicited;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080036
Junxiao Shifc206962015-01-16 11:12:22 -070037 updateStaleTime();
Junxiao Shia9388182014-12-13 23:16:09 -070038}
39
40bool
41Entry::isStale() const
42{
Junxiao Shifc206962015-01-16 11:12:22 -070043 BOOST_ASSERT(this->hasData());
44 return m_staleTime < time::steady_clock::now();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080045}
46
47void
Junxiao Shifc206962015-01-16 11:12:22 -070048Entry::updateStaleTime()
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080049{
Junxiao Shifc206962015-01-16 11:12:22 -070050 BOOST_ASSERT(this->hasData());
Eric Newberryf4056d02017-05-26 17:31:53 +000051 m_staleTime = time::steady_clock::now() + time::milliseconds(m_data->getFreshnessPeriod());
Junxiao Shia9388182014-12-13 23:16:09 -070052}
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080053
Junxiao Shia9388182014-12-13 23:16:09 -070054bool
Junxiao Shia9388182014-12-13 23:16:09 -070055Entry::canSatisfy(const Interest& interest) const
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080056{
Junxiao Shifc206962015-01-16 11:12:22 -070057 BOOST_ASSERT(this->hasData());
Junxiao Shia9388182014-12-13 23:16:09 -070058 if (!interest.matchesData(*m_data)) {
59 return false;
60 }
61
62 if (interest.getMustBeFresh() == static_cast<int>(true) && this->isStale()) {
63 return false;
64 }
65
66 return true;
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080067}
68
Junxiao Shifc206962015-01-16 11:12:22 -070069void
70Entry::reset()
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080071{
Junxiao Shifc206962015-01-16 11:12:22 -070072 m_data.reset();
73 m_isUnsolicited = false;
74 m_staleTime = time::steady_clock::TimePoint();
Ilya Moiseenko76cf77a2014-03-05 14:35:51 -080075}
76
77} // namespace cs
78} // namespace nfd