cs+fw: omitted FreshnessPeriod implies always stale

refs #3944

Change-Id: I018242b3ba5850e8a126f956af4150b512406efd
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index 41ab2e2..3263b43 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -300,7 +300,7 @@
 
 void
 Forwarder::onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
-                              time::milliseconds dataFreshnessPeriod)
+                              ndn::optional<time::milliseconds> dataFreshnessPeriod)
 {
   NFD_LOG_DEBUG("onInterestFinalize interest=" << pitEntry->getName() <<
                 (isSatisfied ? " satisfied" : " unsatisfied"));
@@ -552,7 +552,7 @@
 
 void
 Forwarder::setStragglerTimer(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
-                             time::milliseconds dataFreshnessPeriod)
+                             ndn::optional<time::milliseconds> dataFreshnessPeriod)
 {
   time::nanoseconds stragglerTime = time::milliseconds(100);
 
@@ -577,18 +577,15 @@
 
 void
 Forwarder::insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
-                               time::milliseconds dataFreshnessPeriod, Face* upstream)
+                               ndn::optional<time::milliseconds> dataFreshnessPeriod, Face* upstream)
 {
   // need Dead Nonce List insert?
-  bool needDnl = false;
+  bool needDnl = true;
   if (isSatisfied) {
-    bool hasFreshnessPeriod = dataFreshnessPeriod >= time::milliseconds::zero();
-    // Data never becomes stale if it doesn't have FreshnessPeriod field
+    BOOST_ASSERT(dataFreshnessPeriod);
+    BOOST_ASSERT(*dataFreshnessPeriod >= time::milliseconds::zero());
     needDnl = static_cast<bool>(pitEntry.getInterest().getMustBeFresh()) &&
-              (hasFreshnessPeriod && dataFreshnessPeriod < m_deadNonceList.getLifetime());
-  }
-  else {
-    needDnl = true;
+              *dataFreshnessPeriod < m_deadNonceList.getLifetime();
   }
 
   if (!needDnl) {
diff --git a/daemon/fw/forwarder.hpp b/daemon/fw/forwarder.hpp
index fca81eb..b0cc156 100644
--- a/daemon/fw/forwarder.hpp
+++ b/daemon/fw/forwarder.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2016,  Regents of the University of California,
+ * Copyright (c) 2014-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -216,7 +216,7 @@
    */
   VIRTUAL_WITH_TESTS void
   onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
-                     time::milliseconds dataFreshnessPeriod = time::milliseconds(-1));
+                     ndn::optional<time::milliseconds> dataFreshnessPeriod = ndn::nullopt);
 
   /** \brief incoming Data pipeline
    */
@@ -249,7 +249,7 @@
 
   VIRTUAL_WITH_TESTS void
   setStragglerTimer(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
-                    time::milliseconds dataFreshnessPeriod = time::milliseconds(-1));
+                    ndn::optional<time::milliseconds> dataFreshnessPeriod = ndn::nullopt);
 
   VIRTUAL_WITH_TESTS void
   cancelUnsatisfyAndStragglerTimer(pit::Entry& pitEntry);
@@ -260,7 +260,7 @@
    */
   VIRTUAL_WITH_TESTS void
   insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
-                      time::milliseconds dataFreshnessPeriod, Face* upstream);
+                      ndn::optional<time::milliseconds> dataFreshnessPeriod, Face* upstream);
 
   /** \brief call trigger (method) on the effective strategy of pitEntry
    */
diff --git a/daemon/table/cs-entry-impl.cpp b/daemon/table/cs-entry-impl.cpp
index c8bd357..255cfff 100644
--- a/daemon/table/cs-entry-impl.cpp
+++ b/daemon/table/cs-entry-impl.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2015,  Regents of the University of California,
+ * Copyright (c) 2014-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -46,13 +46,6 @@
   return !this->hasData();
 }
 
-bool
-EntryImpl::canStale() const
-{
-  BOOST_ASSERT(!this->isQuery());
-  return this->getStaleTime() < time::steady_clock::TimePoint::max();
-}
-
 void
 EntryImpl::unsetUnsolicited()
 {
diff --git a/daemon/table/cs-entry-impl.hpp b/daemon/table/cs-entry-impl.hpp
index d061f88..262fcd1 100644
--- a/daemon/table/cs-entry-impl.hpp
+++ b/daemon/table/cs-entry-impl.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2015,  Regents of the University of California,
+ * Copyright (c) 2014-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -52,11 +52,6 @@
    */
   EntryImpl(shared_ptr<const Data> data, bool isUnsolicited);
 
-  /** \return true if entry can become stale, false if entry is never stale
-   */
-  bool
-  canStale() const;
-
   void
   unsetUnsolicited();
 
diff --git a/daemon/table/cs-entry.cpp b/daemon/table/cs-entry.cpp
index d4f3921..4bf84d5 100644
--- a/daemon/table/cs-entry.cpp
+++ b/daemon/table/cs-entry.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2015,  Regents of the University of California,
+ * Copyright (c) 2014-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -48,12 +48,7 @@
 Entry::updateStaleTime()
 {
   BOOST_ASSERT(this->hasData());
-  if (m_data->getFreshnessPeriod() >= time::milliseconds::zero()) {
-    m_staleTime = time::steady_clock::now() + time::milliseconds(m_data->getFreshnessPeriod());
-  }
-  else {
-    m_staleTime = time::steady_clock::TimePoint::max();
-  }
+  m_staleTime = time::steady_clock::now() + time::milliseconds(m_data->getFreshnessPeriod());
 }
 
 bool
diff --git a/daemon/table/cs-entry.hpp b/daemon/table/cs-entry.hpp
index 68289cf..48895b1 100644
--- a/daemon/table/cs-entry.hpp
+++ b/daemon/table/cs-entry.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2016,  Regents of the University of California,
+ * Copyright (c) 2014-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -76,8 +76,8 @@
     return m_isUnsolicited;
   }
 
-  /** \return the absolute time when the stored Data becomes expired
-   *  \retval time::steady_clock::TimePoint::max() if the stored Data never expires
+  /** \return the absolute time when the stored Data becomes stale
+   *  \note if the returned TimePoint is in the past, the Data is stale
    *  \pre hasData()
    */
   const time::steady_clock::TimePoint&
diff --git a/daemon/table/cs-policy-priority-fifo.cpp b/daemon/table/cs-policy-priority-fifo.cpp
index a61f334..934d759 100644
--- a/daemon/table/cs-policy-priority-fifo.cpp
+++ b/daemon/table/cs-policy-priority-fifo.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2016,  Regents of the University of California,
+ * Copyright (c) 2014-2017,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -117,11 +117,8 @@
   }
   else {
     entryInfo->queueType = QUEUE_FIFO;
-
-    if (i->canStale()) {
-      entryInfo->moveStaleEventId = scheduler::schedule(i->getData().getFreshnessPeriod(),
-                                              bind(&PriorityFifoPolicy::moveToStaleQueue, this, i));
-    }
+    entryInfo->moveStaleEventId = scheduler::schedule(i->getData().getFreshnessPeriod(),
+                                                      bind(&PriorityFifoPolicy::moveToStaleQueue, this, i));
   }
 
   Queue& queue = m_queues[entryInfo->queueType];