fw: /localhost scope control for incoming Interest

refs #1230

Change-Id: I86fd071ef144caa506b26a723f14232e2af5e2de
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index 67aeba7..6ab6fd4 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -12,6 +12,8 @@
 
 NFD_LOG_INIT("Forwarder");
 
+const Name Forwarder::s_localhostName("ndn:/localhost");
+
 Forwarder::Forwarder(boost::asio::io_service& ioService)
   : m_scheduler(ioService)
   , m_lastFaceId(0)
@@ -75,6 +77,15 @@
   NFD_LOG_DEBUG("onIncomingInterest face=" << inFace.getId() << " interest=" << interest.getName());
   const_cast<Interest&>(interest).setIncomingFaceId(inFace.getId());
   
+  // /localhost scope control
+  bool violatesLocalhost = !inFace.isLocal() &&
+                           s_localhostName.isPrefixOf(interest.getName());
+  if (violatesLocalhost) {
+    NFD_LOG_DEBUG("onIncomingInterest face=" << inFace.getId()
+      << " interest=" << interest.getName() << " violates /localhost");
+    return;
+  }
+  
   // PIT insert
   std::pair<shared_ptr<pit::Entry>, bool>
     pitInsertResult = m_pit.insert(interest);
@@ -123,8 +134,7 @@
   // TODO use Fib::findParent(pitEntry)
   
   // dispatch to strategy
-  m_strategy->afterReceiveInterest(inFace, interest, fibEntry, pitEntry);
-  // TODO dispatch according to fibEntry
+  this->dispatchToStrategy(inFace, interest, fibEntry, pitEntry);
 }
 
 void
@@ -184,6 +194,15 @@
   NFD_LOG_DEBUG("onIncomingData face=" << inFace.getId() << " data=" << data.getName());
   const_cast<Data&>(data).setIncomingFaceId(inFace.getId());
   
+  // /localhost scope control
+  bool violatesLocalhost = !inFace.isLocal() &&
+                           s_localhostName.isPrefixOf(data.getName());
+  if (violatesLocalhost) {
+    NFD_LOG_DEBUG("onIncomingData face=" << inFace.getId()
+      << " interest=" << data.getName() << " violates /localhost");
+    return;
+  }
+  
   // PIT match
   shared_ptr<pit::DataMatchResult> pitMatches = m_pit.findAllDataMatches(data);
   if (pitMatches->begin() == pitMatches->end()) {
@@ -298,6 +317,14 @@
   m_scheduler.cancelEvent(pitEntry->m_stragglerTimer);
 }
 
-
+void
+Forwarder::dispatchToStrategy(const Face& inFace,
+                              const Interest& interest,
+                              shared_ptr<fib::Entry> fibEntry,
+                              shared_ptr<pit::Entry> pitEntry)
+{
+  m_strategy->afterReceiveInterest(inFace, interest, fibEntry, pitEntry);
+  // TODO dispatch according to fibEntry
+}
 
 } // namespace nfd