interest: Match data to Interest regardless of FreshnessPeriod/MustBeFresh
When Data is received from the wire it should match Interest with
MustBeFresh even if the Data packet doesn't specify FreshnessPeriod.
Refs: #5270
Change-Id: I2ce4d23062f6346ebcd54e2e3e6e5de5a927e516
diff --git a/ndn-cxx/ims/in-memory-storage.cpp b/ndn-cxx/ims/in-memory-storage.cpp
index 401e84c..7115685 100644
--- a/ndn-cxx/ims/in-memory-storage.cpp
+++ b/ndn-cxx/ims/in-memory-storage.cpp
@@ -185,7 +185,7 @@
m_freeEntries.pop();
m_nPackets++;
entry->setData(data);
- if (m_scheduler != nullptr && mustBeFreshProcessingWindow > ZERO_WINDOW) {
+ if (m_scheduler != nullptr && mustBeFreshProcessingWindow >= ZERO_WINDOW) {
entry->scheduleMarkStale(*m_scheduler, mustBeFreshProcessingWindow);
}
m_cache.insert(entry);
diff --git a/ndn-cxx/ims/in-memory-storage.hpp b/ndn-cxx/ims/in-memory-storage.hpp
index 2658e4e..22cd3b5 100644
--- a/ndn-cxx/ims/in-memory-storage.hpp
+++ b/ndn-cxx/ims/in-memory-storage.hpp
@@ -134,8 +134,14 @@
/** @brief Inserts a Data packet.
*
* @param data the packet to insert, must be signed and have wire encoding
- * @param mustBeFreshProcessingWindow Beyond this time period after the data is inserted, the
- * data can only be used to answer interest without MustBeFresh selector.
+ * @param mustBeFreshProcessingWindow Beyond this time period, the inserted data can
+ * only be used to answer interest without MustBeFresh. The value of
+ * mustBeFreshProcessingWindow is an application decision and it may or may not
+ * correspond to FreshnessPeriod.
+ *
+ * @note InMemoryStorage does not use the inserted data packet's FreshnessPeriod value.
+ * If the packet needs to be marked "stale" after application-defined period of time,
+ * the application must supply proper @p mustBeFreshProcessingWindow value.
*
* @note Packets are considered duplicate if the name with implicit digest matches.
* The new Data packet with the identical name, but a different payload
diff --git a/ndn-cxx/interest.cpp b/ndn-cxx/interest.cpp
index 3c23562..fe65955 100644
--- a/ndn-cxx/interest.cpp
+++ b/ndn-cxx/interest.cpp
@@ -340,11 +340,6 @@
return false;
}
- // check MustBeFresh
- if (getMustBeFresh() && data.getFreshnessPeriod() <= 0_ms) {
- return false;
- }
-
return true;
}
diff --git a/tests/unit/ims/in-memory-storage.t.cpp b/tests/unit/ims/in-memory-storage.t.cpp
index ac1c7c2..31532ed 100644
--- a/tests/unit/ims/in-memory-storage.t.cpp
+++ b/tests/unit/ims/in-memory-storage.t.cpp
@@ -562,8 +562,8 @@
BOOST_AUTO_TEST_CASE(MustBeFresh)
{
- insert(1, "/A/1"); // omitted FreshnessPeriod means FreshnessPeriod = 0 ms
- insert(2, "/A/2", [] (Data& data) { data.setFreshnessPeriod(0_s); });
+ insert(1, "/A/1", nullptr, 0_ms); // omitted FreshnessPeriod means FreshnessPeriod = 0 ms
+ insert(2, "/A/2", [] (Data& data) { data.setFreshnessPeriod(0_s); }, 0_ms);
insert(3, "/A/3", [] (Data& data) { data.setFreshnessPeriod(1_s); }, 1_s);
insert(4, "/A/4", [] (Data& data) { data.setFreshnessPeriod(1_h); }, 1_h);
diff --git a/tests/unit/interest.t.cpp b/tests/unit/interest.t.cpp
index bbf3af6..055be68 100644
--- a/tests/unit/interest.t.cpp
+++ b/tests/unit/interest.t.cpp
@@ -659,7 +659,7 @@
BOOST_CHECK_EQUAL(interest->matchesData(*data), true);
interest->setMustBeFresh(true);
- BOOST_CHECK_EQUAL(interest->matchesData(*data), false); // violates MustBeFresh
+ BOOST_CHECK_EQUAL(interest->matchesData(*data), true);
data->setFreshnessPeriod(1_s);
BOOST_CHECK_EQUAL(interest->matchesData(*data), true);