diff --git a/ndn-cxx/ims/in-memory-storage.cpp b/ndn-cxx/ims/in-memory-storage.cpp index 401e84c40..71156856d 100644 --- a/ndn-cxx/ims/in-memory-storage.cpp +++ b/ndn-cxx/ims/in-memory-storage.cpp @@ -185,7 +185,7 @@ InMemoryStorage::insert(const Data& data, const time::milliseconds& mustBeFreshP 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 2658e4ef9..22cd3b53f 100644 --- a/ndn-cxx/ims/in-memory-storage.hpp +++ b/ndn-cxx/ims/in-memory-storage.hpp @@ -134,8 +134,14 @@ class InMemoryStorage : noncopyable /** @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 3c2356225..fe65955d0 100644 --- a/ndn-cxx/interest.cpp +++ b/ndn-cxx/interest.cpp @@ -340,11 +340,6 @@ Interest::matchesData(const Data& data) const 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 ac1c7c219..31532ed9d 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(PrefixName_NoCanBePrefix) 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 bbf3af6bd..055be6863 100644 --- a/tests/unit/interest.t.cpp +++ b/tests/unit/interest.t.cpp @@ -659,7 +659,7 @@ BOOST_AUTO_TEST_CASE(MatchesData) 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);