mgmt: InternalFace processes Interest asynchronously

This avoids forwarding's incoming Data pipeline to be called
within incoming Interest pipeline - this property holds for
other faces, and is expected by forwarding.

refs #1419

Change-Id: I3eb1ca84830d5d8aefe0ae67a562acdd835ca5ca
diff --git a/daemon/mgmt/internal-face.cpp b/daemon/mgmt/internal-face.cpp
index 5552d02..81bd2de 100644
--- a/daemon/mgmt/internal-face.cpp
+++ b/daemon/mgmt/internal-face.cpp
@@ -5,6 +5,7 @@
  */
 
 #include "internal-face.hpp"
+#include "core/global-io.hpp"
 
 namespace nfd {
 
@@ -20,6 +21,15 @@
 {
   onSendInterest(interest);
 
+  // Invoke .processInterest a bit later,
+  // to avoid potential problems in forwarding pipelines.
+  getGlobalIoService().post(bind(&InternalFace::processInterest,
+                                 this, boost::cref(interest)));
+}
+
+void
+InternalFace::processInterest(const Interest& interest)
+{
   if (m_interestFilters.size() == 0)
     {
       NFD_LOG_DEBUG("no Interest filters to match against");
diff --git a/daemon/mgmt/internal-face.hpp b/daemon/mgmt/internal-face.hpp
index 3ce32e3..3f061fb 100644
--- a/daemon/mgmt/internal-face.hpp
+++ b/daemon/mgmt/internal-face.hpp
@@ -20,9 +20,14 @@
   /**
    * \brief InternalFace-related error
    */
-  struct Error : public Face::Error
+  class Error : public Face::Error
   {
-    Error(const std::string& what) : Face::Error(what) {}
+  public:
+    explicit
+    Error(const std::string& what)
+      : Face::Error(what)
+    {
+    }
   };
 
   InternalFace();
@@ -54,7 +59,10 @@
   put(const Data& data);
 
 private:
+  void
+  processInterest(const Interest& interest);
 
+private:
   std::map<Name, OnInterest> m_interestFilters;
   CommandValidator m_validator;
 };
diff --git a/tests/mgmt/face-manager.cpp b/tests/mgmt/face-manager.cpp
index 9cfca66..d439ea4 100644
--- a/tests/mgmt/face-manager.cpp
+++ b/tests/mgmt/face-manager.cpp
@@ -653,6 +653,7 @@
          command->getName(), 400, "Malformed command");
 
   getFace()->sendInterest(*command);
+  g_io.run_one();
 
   BOOST_REQUIRE(didCallbackFire());
 }
diff --git a/tests/mgmt/fib-manager.cpp b/tests/mgmt/fib-manager.cpp
index 5076e0d..d672ab7 100644
--- a/tests/mgmt/fib-manager.cpp
+++ b/tests/mgmt/fib-manager.cpp
@@ -228,6 +228,7 @@
          command.getName(), 400, "Malformed command");
 
   face->sendInterest(command);
+  g_io.run_one();
 
   BOOST_REQUIRE(didCallbackFire());
 }
diff --git a/tests/mgmt/internal-face.cpp b/tests/mgmt/internal-face.cpp
index f4d51ca..8f70402 100644
--- a/tests/mgmt/internal-face.cpp
+++ b/tests/mgmt/internal-face.cpp
@@ -118,6 +118,7 @@
   Name commandName("/localhost/nfd/fib/end");
   Interest command(commandName);
   face->sendInterest(command);
+  g_io.run_one();
 
   BOOST_REQUIRE(didOnInterestFire());
   BOOST_REQUIRE(didNoOnInterestFire() == false);
@@ -140,6 +141,7 @@
   Name commandName("/localhost/nfd");
   Interest command(commandName);
   face->sendInterest(command);
+  g_io.run_one();
 
   BOOST_REQUIRE(didNoOnInterestFire() == false);
 }
@@ -168,6 +170,7 @@
   Name commandName("/localhost/nfd/fib");
   Interest command(commandName);
   face->sendInterest(command);
+  g_io.run_one();
 
   BOOST_REQUIRE(didOnInterestFire());
   BOOST_REQUIRE(didNoOnInterestFire() == false);
@@ -193,6 +196,7 @@
   Name commandName("/localhost/nfd/fib/previous");
   Interest command(commandName);
   face->sendInterest(command);
+  g_io.run_one();
 
   BOOST_REQUIRE(didOnInterestFire());
   BOOST_REQUIRE(didNoOnInterestFire() == false);
diff --git a/tests/mgmt/status-server.cpp b/tests/mgmt/status-server.cpp
index 99aa9f8..59a283e 100644
--- a/tests/mgmt/status-server.cpp
+++ b/tests/mgmt/status-server.cpp
@@ -34,7 +34,7 @@
   internalFace->onReceiveData += &interceptResponse;
   StatusServer statusServer(internalFace, boost::ref(forwarder));
   time::system_clock::TimePoint t2 = time::system_clock::now();
-  
+
   // populate tables
   forwarder.getFib().insert("ndn:/fib1");
   forwarder.getPit().insert(*makeInterest("ndn:/pit1"));
@@ -47,28 +47,29 @@
   BOOST_CHECK_GE(forwarder.getFib().size(), 1);
   BOOST_CHECK_GE(forwarder.getPit().size(), 4);
   BOOST_CHECK_GE(forwarder.getMeasurements().size(), 3);
-  
+
   // request
   shared_ptr<Interest> request = makeInterest("ndn:/localhost/nfd/status");
   request->setMustBeFresh(true);
   request->setChildSelector(1);
-  
+
   g_response.reset();
   time::system_clock::TimePoint t3 = time::system_clock::now();
   internalFace->sendInterest(*request);
+  g_io.run_one();
   time::system_clock::TimePoint t4 = time::system_clock::now();
   BOOST_REQUIRE(static_cast<bool>(g_response));
-  
+
   // verify
   ndn::nfd::Status status;
   BOOST_REQUIRE_NO_THROW(status.wireDecode(g_response->getContent()));
-  
+
   BOOST_CHECK_EQUAL(status.getNfdVersion(), NFD_VERSION);
   BOOST_CHECK_GE(time::toUnixTimestamp(status.getStartTimestamp()), time::toUnixTimestamp(t1));
   BOOST_CHECK_LE(time::toUnixTimestamp(status.getStartTimestamp()), time::toUnixTimestamp(t2));
   BOOST_CHECK_GE(time::toUnixTimestamp(status.getCurrentTimestamp()), time::toUnixTimestamp(t3));
   BOOST_CHECK_LE(time::toUnixTimestamp(status.getCurrentTimestamp()), time::toUnixTimestamp(t4));
-  
+
   // StatusServer under test isn't added to Forwarder,
   // so request and response won't affect table size
   BOOST_CHECK_EQUAL(status.getNNameTreeEntries(), forwarder.getNameTree().size());
diff --git a/tests/mgmt/strategy-choice-manager.cpp b/tests/mgmt/strategy-choice-manager.cpp
index f24d58a..9f9c3ce 100644
--- a/tests/mgmt/strategy-choice-manager.cpp
+++ b/tests/mgmt/strategy-choice-manager.cpp
@@ -189,6 +189,7 @@
          command->getName(), 400, "Malformed command");
 
   getFace()->sendInterest(*command);
+  g_io.run_one();
 
   BOOST_REQUIRE(didCallbackFire());
 }