handles: consolidate command prefix registrations
Previously, each command handle performs prefix registrations
separately, creating an excessive number of FIB entries in NFD.
This commit consolidates those registrations into one place,
and uses ndn::Face to dispatch Interests to command handlers.
refs #2023
Change-Id: Ia74ff970797eceac4df260e84dec727952d96489
diff --git a/src/handles/delete-handle.cpp b/src/handles/delete-handle.cpp
index f39856f..d062399 100644
--- a/src/handles/delete-handle.cpp
+++ b/src/handles/delete-handle.cpp
@@ -36,28 +36,6 @@
bind(&DeleteHandle::onValidationFailed, this, _1, _2));
}
-
-void
-DeleteHandle::onRegisterFailed(const Name& prefix, const std::string& reason)
-{
- BOOST_THROW_EXCEPTION(Error("Delete prefix registration failed"));
-}
-
-
-void
-DeleteHandle::onCheckInterest(const Name& prefix, const Interest& interest)
-{
- BOOST_ASSERT(false); // Deletion progress check, not implemented
-}
-
-
-void
-DeleteHandle::onCheckRegisterFailed(const Name& prefix, const std::string& reason)
-{
- BOOST_THROW_EXCEPTION(Error("Delete check prefix registration failed"));
-}
-
-
void
DeleteHandle::onValidated(const shared_ptr<const Interest>& interest, const Name& prefix)
{
@@ -102,11 +80,8 @@
void
DeleteHandle::listen(const Name& prefix)
{
- ndn::Name deleteprefix = Name(prefix).append("delete");
- ndn::InterestFilter filter(deleteprefix);
- getFace().setInterestFilter(filter,
- bind(&DeleteHandle::onInterest, this, _1, _2),
- bind(&DeleteHandle::onRegisterFailed, this, _1, _2));
+ getFace().setInterestFilter(Name(prefix).append("delete"),
+ bind(&DeleteHandle::onInterest, this, _1, _2));
}
void
diff --git a/src/handles/delete-handle.hpp b/src/handles/delete-handle.hpp
index 0bb0e06..265d5ef 100644
--- a/src/handles/delete-handle.hpp
+++ b/src/handles/delete-handle.hpp
@@ -50,9 +50,6 @@
onInterest(const Name& prefix, const Interest& interest);
void
- onRegisterFailed(const Name& prefix, const std::string& reason);
-
- void
onValidated(const std::shared_ptr<const Interest>& interest, const Name& prefix);
void
@@ -65,9 +62,6 @@
onCheckInterest(const Name& prefix, const Interest& interest);
void
- onCheckRegisterFailed(const Name& prefix, const std::string& reason);
-
- void
positiveReply(const Interest& interest, const RepoCommandParameter& parameter,
uint64_t statusCode, uint64_t nDeletedDatas);
diff --git a/src/handles/watch-handle.cpp b/src/handles/watch-handle.cpp
index 97aea8f..91eaac4 100644
--- a/src/handles/watch-handle.cpp
+++ b/src/handles/watch-handle.cpp
@@ -53,25 +53,6 @@
}
void
-WatchHandle::onRegistered(const Name& prefix)
-{
- getFace().setInterestFilter(Name().append(prefix).append("start"),
- bind(&WatchHandle::onInterest, this, _1, _2));
- getFace().setInterestFilter(Name().append(prefix).append("check"),
- bind(&WatchHandle::onCheckInterest, this, _1, _2));
- getFace().setInterestFilter(Name().append(prefix).append("stop"),
- bind(&WatchHandle::onStopInterest, this, _1, _2));
-}
-
-// onRegisterFailed for watch start.
-void
-WatchHandle::onRegisterFailed(const Name& prefix, const std::string& reason)
-{
- std::cerr << reason << std::endl;
- BOOST_THROW_EXCEPTION(Error("watch prefix registration failed"));
-}
-
-void
WatchHandle::onValidated(const shared_ptr<const Interest>& interest, const Name& prefix)
{
RepoCommandParameter parameter;
@@ -221,11 +202,12 @@
void
WatchHandle::listen(const Name& prefix)
{
- Name baseWatchPrefix(prefix);
- baseWatchPrefix.append("watch");
- getFace().registerPrefix(baseWatchPrefix,
- bind(&WatchHandle::onRegistered, this, _1),
- bind(&WatchHandle::onRegisterFailed, this, _1, _2));
+ getFace().setInterestFilter(Name(prefix).append("watch").append("start"),
+ bind(&WatchHandle::onInterest, this, _1, _2));
+ getFace().setInterestFilter(Name(prefix).append("watch").append("check"),
+ bind(&WatchHandle::onCheckInterest, this, _1, _2));
+ getFace().setInterestFilter(Name(prefix).append("watch").append("stop"),
+ bind(&WatchHandle::onStopInterest, this, _1, _2));
}
void
diff --git a/src/handles/watch-handle.hpp b/src/handles/watch-handle.hpp
index a3e9e5f..5768e06 100644
--- a/src/handles/watch-handle.hpp
+++ b/src/handles/watch-handle.hpp
@@ -73,12 +73,6 @@
void
onValidationFailed(const std::shared_ptr<const Interest>& interest, const std::string& reason);
- void
- onRegistered(const Name& prefix);
-
- void
- onRegisterFailed(const Name& prefix, const std::string& reason);
-
private: // data fetching
/**
* @brief fetch data and send next interest
diff --git a/src/handles/write-handle.cpp b/src/handles/write-handle.cpp
index 862616a..a398f0b 100644
--- a/src/handles/write-handle.cpp
+++ b/src/handles/write-handle.cpp
@@ -54,22 +54,6 @@
bind(&WriteHandle::onValidationFailed, this, _1, _2));
}
-// onRegisterFailed.
-void
-WriteHandle::onRegisterFailed(const Name& prefix, const std::string& reason)
-{
- std::cerr << reason << std::endl;
- BOOST_THROW_EXCEPTION(Error("Insert prefix registration failed"));
-}
-
-// onRegisterFailed for insert.
-void
-WriteHandle::onCheckRegisterFailed(const Name& prefix, const std::string& reason)
-{
- std::cerr << reason << std::endl;
- BOOST_THROW_EXCEPTION(Error("Insert check prefix registration failed"));
-}
-
void
WriteHandle::onValidated(const std::shared_ptr<const Interest>& interest, const Name& prefix)
{
@@ -201,18 +185,10 @@
void
WriteHandle::listen(const Name& prefix)
{
- Name insertPrefix;
- insertPrefix.append(prefix).append("insert");
- ndn::InterestFilter filter_insert(insertPrefix);
- getFace().setInterestFilter(filter_insert,
- bind(&WriteHandle::onInterest, this, _1, _2),
- bind(&WriteHandle::onRegisterFailed, this, _1, _2));
- Name insertCheckPrefix;
- insertCheckPrefix.append(prefix).append("insert check");
- ndn::InterestFilter filter_insertCheck(insertCheckPrefix);
- getFace().setInterestFilter(filter_insertCheck,
- bind(&WriteHandle::onCheckInterest, this, _1, _2),
- bind(&WriteHandle::onRegisterFailed, this, _1, _2));
+ getFace().setInterestFilter(Name(prefix).append("insert"),
+ bind(&WriteHandle::onInterest, this, _1, _2));
+ getFace().setInterestFilter(Name(prefix).append("insert check"),
+ bind(&WriteHandle::onCheckInterest, this, _1, _2));
}
void
diff --git a/src/handles/write-handle.hpp b/src/handles/write-handle.hpp
index 1347470..1e7a007 100644
--- a/src/handles/write-handle.hpp
+++ b/src/handles/write-handle.hpp
@@ -112,12 +112,6 @@
void
onValidationFailed(const std::shared_ptr<const Interest>& interest, const std::string& reason);
- /**
- * @brief insert command prefix register failed
- */
- void
- onRegisterFailed(const Name& prefix, const std::string& reason);
-
private: // single data fetching
/**
* @brief fetch one data
@@ -199,12 +193,6 @@
void
onCheckInterest(const Name& prefix, const Interest& interest);
- /**
- * @brief insert check command prefix register failed
- */
- void
- onCheckRegisterFailed(const Name& prefix, const std::string& reason);
-
void
onCheckValidated(const std::shared_ptr<const Interest>& interest, const Name& prefix);
diff --git a/src/repo.cpp b/src/repo.cpp
index ff2422d..e12698f 100644
--- a/src/repo.cpp
+++ b/src/repo.cpp
@@ -142,31 +142,26 @@
void
Repo::enableListening()
{
- // Enable "listening" on Data prefixes
- for (auto it = m_config.dataPrefixes.begin();
- it != m_config.dataPrefixes.end();
- ++it)
- {
- m_readHandle.listen(*it);
- }
+ for (const ndn::Name& dataPrefix : m_config.dataPrefixes) {
+ // ReadHandle performs prefix registration internally.
+ m_readHandle.listen(dataPrefix);
+ }
- // Enable "listening" on control prefixes
- for (auto it = m_config.repoPrefixes.begin();
- it != m_config.repoPrefixes.end();
- ++it)
- {
- m_writeHandle.listen(*it);
- m_watchHandle.listen(*it);
- m_deleteHandle.listen(*it);
- }
+ for (const ndn::Name& cmdPrefix : m_config.repoPrefixes) {
+ m_face.registerPrefix(cmdPrefix, nullptr,
+ [] (const Name& cmdPrefix, const std::string& reason) {
+ std::cerr << "Command prefix " << cmdPrefix << " registration error: " << reason << std::endl;
+ BOOST_THROW_EXCEPTION(Error("Command prefix registration failed"));
+ });
- // Enable listening on TCP bulk insert addresses
- for (auto it = m_config.tcpBulkInsertEndpoints.begin();
- it != m_config.tcpBulkInsertEndpoints.end();
- ++it)
- {
- m_tcpBulkInsertHandle.listen(it->first, it->second);
- }
+ m_writeHandle.listen(cmdPrefix);
+ m_watchHandle.listen(cmdPrefix);
+ m_deleteHandle.listen(cmdPrefix);
+ }
+
+ for (const auto& ep : m_config.tcpBulkInsertEndpoints) {
+ m_tcpBulkInsertHandle.listen(ep.first, ep.second);
+ }
}
void
diff --git a/tests/integrated/test-basic-command-insert-delete.cpp b/tests/integrated/test-basic-command-insert-delete.cpp
index 775a16d..28fea81 100644
--- a/tests/integrated/test-basic-command-insert-delete.cpp
+++ b/tests/integrated/test-basic-command-insert-delete.cpp
@@ -54,8 +54,13 @@
, insertFace(repoFace.getIoService())
, deleteFace(repoFace.getIoService())
{
- writeHandle.listen(Name("/repo/command"));
- deleteHandle.listen(Name("/repo/command"));
+ Name cmdPrefix("/repo/command");
+ repoFace.registerPrefix(cmdPrefix, nullptr,
+ [] (const Name& cmdPrefix, const std::string& reason) {
+ BOOST_FAIL("Command prefix registration error: " << reason);
+ });
+ writeHandle.listen(cmdPrefix);
+ deleteHandle.listen(cmdPrefix);
}
void
@@ -163,13 +168,13 @@
template<class T> void
Fixture<T>::onInsertTimeout(const Interest& interest)
{
- BOOST_ERROR("Inserert command timeout");
+ BOOST_ERROR("Insert command timeout");
}
template<class T> void
Fixture<T>::onDeleteTimeout(const Interest& interest)
{
- BOOST_ERROR("delete command timeout");
+ BOOST_ERROR("Delete command timeout");
}
template<class T> void
diff --git a/tests/integrated/test-basic-command-watch.cpp b/tests/integrated/test-basic-command-watch.cpp
index 8b8f327..a29deed 100644
--- a/tests/integrated/test-basic-command-watch.cpp
+++ b/tests/integrated/test-basic-command-watch.cpp
@@ -50,7 +50,12 @@
: watchHandle(repoFace, *handle, keyChain, scheduler, validator)
, watchFace(repoFace.getIoService())
{
- watchHandle.listen(Name("/repo/command"));
+ Name cmdPrefix("/repo/command");
+ repoFace.registerPrefix(cmdPrefix, nullptr,
+ [] (const Name& cmdPrefix, const std::string& reason) {
+ BOOST_FAIL("Command prefix registration error: " << reason);
+ });
+ watchHandle.listen(cmdPrefix);
}
void