Skip to content

Commit

Permalink
interest: Match data to Interest regardless of FreshnessPeriod/MustBe…
Browse files Browse the repository at this point in the history
…Fresh

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
  • Loading branch information
cawka committed Aug 9, 2023
1 parent 12b8aaa commit 0af48fb
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ndn-cxx/ims/in-memory-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 8 additions & 2 deletions ndn-cxx/ims/in-memory-storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions ndn-cxx/interest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,6 @@ Interest::matchesData(const Data& data) const
return false;
}

// check MustBeFresh
if (getMustBeFresh() && data.getFreshnessPeriod() <= 0_ms) {
return false;
}

return true;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/ims/in-memory-storage.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/interest.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0af48fb

Please sign in to comment.