face: Multiple matching for setInterestFilter and expressInterest callbacks
As of this commit, all callbacks registered by setInterestFilter will be
called for every interest that is matching the filter.
Similarly for expressed Interest, all pending Interest will be satisfied
by any incoming matching Data.
Change-Id: I2463bd4114a2a1cdbe92ff03805adc5c404266a9
diff --git a/src/face.cpp b/src/face.cpp
index 25ce3ab..7d40345 100644
--- a/src/face.cpp
+++ b/src/face.cpp
@@ -327,10 +327,7 @@
if (&block != &blockFromDaemon)
interest->getLocalControlHeader().wireDecode(blockFromDaemon);
- RegisteredPrefixTable::iterator entry = getEntryForRegisteredPrefix(interest->getName());
- if (entry != m_registeredPrefixTable.end()) {
- (*entry)->getOnInterest()((*entry)->getPrefix(), *interest);
- }
+ processInterestFilters(*interest);
}
else if (block.type() == Tlv::Data)
{
@@ -339,60 +336,54 @@
if (&block != &blockFromDaemon)
data->getLocalControlHeader().wireDecode(blockFromDaemon);
- PendingInterestTable::iterator entry = getEntryIndexForExpressedInterest(data->getName());
- if (entry != m_pendingInterestTable.end()) {
- // Copy pointers to the needed objects and remove the PIT entry before the calling the callback.
- const OnData onData = (*entry)->getOnData();
- const shared_ptr<const Interest> interest = (*entry)->getInterest();
- m_pendingInterestTable.erase(entry);
+ satisfyPendingInterests(*data);
- if (onData) {
- onData(*interest, *data);
- }
-
- if (m_pendingInterestTable.empty()) {
- m_pitTimeoutCheckTimer->cancel(); // this will cause checkPitExpire invocation
- }
+ if (m_pendingInterestTable.empty()) {
+ m_pitTimeoutCheckTimer->cancel(); // this will cause checkPitExpire invocation
}
}
// ignore any other type
}
-Face::PendingInterestTable::iterator
-Face::getEntryIndexForExpressedInterest(const Name& name)
+void
+Face::satisfyPendingInterests(Data& data)
{
for (PendingInterestTable::iterator i = m_pendingInterestTable.begin ();
- i != m_pendingInterestTable.end(); ++i)
+ i != m_pendingInterestTable.end();
+ )
{
- if ((*i)->getInterest()->matchesName(name))
+ if ((*i)->getInterest()->matchesName(data.getName()))
{
- return i;
- }
- }
+ // Copy pointers to the needed objects and remove the PIT entry before the calling the callback.
+ OnData onData = (*i)->getOnData();
+ shared_ptr<const Interest> interest = (*i)->getInterest();
- return m_pendingInterestTable.end();
+ PendingInterestTable::iterator next = i;
+ ++next;
+ m_pendingInterestTable.erase(i);
+ i = next;
+
+ if (static_cast<bool>(onData)) {
+ onData(*interest, data);
+ }
+ }
+ else
+ ++i;
+ }
}
-Face::RegisteredPrefixTable::iterator
-Face::getEntryForRegisteredPrefix(const Name& name)
+void
+Face::processInterestFilters(Interest& interest)
{
- RegisteredPrefixTable::iterator longestPrefix = m_registeredPrefixTable.end();
-
for (RegisteredPrefixTable::iterator i = m_registeredPrefixTable.begin();
i != m_registeredPrefixTable.end();
++i)
{
- if ((*i)->getPrefix().isPrefixOf(name))
+ if ((*i)->getPrefix().isPrefixOf(interest.getName()))
{
-
- if (longestPrefix == m_registeredPrefixTable.end() ||
- (*i)->getPrefix().size() > (*longestPrefix)->getPrefix().size())
- {
- longestPrefix = i;
- }
+ (*i)->getOnInterest()((*i)->getPrefix(), interest);
}
}
- return longestPrefix;
}
} // namespace ndn
diff --git a/src/face.hpp b/src/face.hpp
index 6a9a87c..7e14ffd 100644
--- a/src/face.hpp
+++ b/src/face.hpp
@@ -229,23 +229,12 @@
static void
fireProcessEventsTimeout(const boost::system::error_code& error);
- /**
- * Find the entry from the pit_ where the name conforms to the entry's interest selectors, and
- * the entry interest name is the longest that matches name.
- * @param name The name to find the interest for (from the incoming data packet).
- * @return The index in pit_ of the pit entry, or -1 if not found.
- */
- PendingInterestTable::iterator
- getEntryIndexForExpressedInterest(const Name& name);
-
- /**
- * Find the first entry from the m_registeredPrefixTable where the entry prefix is the longest that matches name.
- * @param name The name to find the PrefixEntry for (from the incoming interest packet).
- * @return A pointer to the entry, or 0 if not found.
- */
- RegisteredPrefixTable::iterator
- getEntryForRegisteredPrefix(const Name& name);
-
+ void
+ satisfyPendingInterests(Data& data);
+
+ void
+ processInterestFilters(Interest& interest);
+
void
checkPitExpire();