nrd: Added interest filter for /localhop/nrd
refs #1323
Change-Id: Ib97e772a3111b75216ed3b666bad23230f1ed41f
diff --git a/src/nrd.cpp b/src/nrd.cpp
index 0928a63..239f940 100644
--- a/src/nrd.cpp
+++ b/src/nrd.cpp
@@ -10,6 +10,7 @@
namespace nrd {
const Name Nrd::COMMAND_PREFIX = "/localhost/nrd";
+const Name Nrd::REMOTE_COMMAND_PREFIX = "/localhop/nrd";
const size_t Nrd::COMMAND_UNSIGNED_NCOMPS =
Nrd::COMMAND_PREFIX.size() +
@@ -34,9 +35,10 @@
};
void
-setInterestFilterFailed(const Name& name, const std::string& msg)
+Nrd::setInterestFilterFailed(const Name& name, const std::string& msg)
{
std::cerr << "Error in setting interest filter (" << name << "): " << msg << std::endl;
+ m_face.shutdown();
}
Nrd::Nrd()
@@ -44,10 +46,19 @@
m_verbDispatch(COMMAND_VERBS,
COMMAND_VERBS + (sizeof(COMMAND_VERBS) / sizeof(VerbAndProcessor)))
{
+ //check whether the components of localhop and localhost prefixes are same
+ BOOST_ASSERT(COMMAND_PREFIX.size() == REMOTE_COMMAND_PREFIX.size ());
+
+ std::cerr << "Setting interest filter on: " << COMMAND_PREFIX.toUri() << std::endl;
m_face.setController(m_nfdController);
- m_face.setInterestFilter("/localhost/nrd",
+ m_face.setInterestFilter(COMMAND_PREFIX.toUri(),
bind(&Nrd::onRibRequest, this, _2),
- bind(&setInterestFilterFailed, _1, _2));
+ bind(&Nrd::setInterestFilterFailed, this, _1, _2));
+
+ std::cerr << "Setting interest filter on: " << REMOTE_COMMAND_PREFIX.toUri() << std::endl;
+ m_face.setInterestFilter(REMOTE_COMMAND_PREFIX.toUri(),
+ bind(&Nrd::onRibRequest, this, _2),
+ bind(&Nrd::setInterestFilterFailed, this, _1, _2));
}
void
@@ -86,13 +97,16 @@
return;
}
else if (commandNComps < COMMAND_SIGNED_NCOMPS ||
- !COMMAND_PREFIX.isPrefixOf(command))
- {
+ !(COMMAND_PREFIX.isPrefixOf(command) ||
+ REMOTE_COMMAND_PREFIX.isPrefixOf(command)))
+ {
std::cerr << "Error: Malformed Command" << std::endl;
sendResponse(command, 400, "Malformed command");
return;
}
+ //REMOTE_COMMAND_PREFIX number of componenets are same as
+ // NRD_COMMAND_PREFIX's so no extra checks are required.
const Name::Component& verb = command.get(COMMAND_PREFIX.size());
VerbDispatchTable::const_iterator verbProcessor = m_verbDispatch.find(verb);
@@ -130,6 +144,8 @@
PrefixRegOptions& extractedOptions)
{
const Name& command = request.getName();
+ //REMOTE_COMMAND_PREFIX is same in size of NRD_COMMAND_PREFIX
+ //so no extra processing is required.
const size_t optionCompIndex = COMMAND_PREFIX.size() + 1;
try
diff --git a/src/nrd.hpp b/src/nrd.hpp
index 210af74..7e7ce08 100644
--- a/src/nrd.hpp
+++ b/src/nrd.hpp
@@ -53,6 +53,9 @@
onControlHeaderError();
void
+ setInterestFilterFailed(const Name& name, const std::string& msg);
+
+ void
insertEntry(const Interest& request, const PrefixRegOptions& options);
void
@@ -79,6 +82,7 @@
const VerbDispatchTable m_verbDispatch;
static const Name COMMAND_PREFIX; // /localhost/nrd
+ static const Name REMOTE_COMMAND_PREFIX; // /localhop/nrd
// number of components in an invalid, but not malformed, unsigned command.
// (/localhost/nrd + verb + options) = 4