fw: Add default HopLimit to Interest when missing

Refs: #5171
Change-Id: I5973811b5ca7c7cf5ff344872afa51b253b9cae8
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index fea18f6..3683734 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -40,6 +40,8 @@
 
 NFD_LOG_INIT(Forwarder);
 
+const std::string CFGSEC_FORWARDER = "forwarder";
+
 static Name
 getDefaultStrategyName()
 {
@@ -186,6 +188,11 @@
   NFD_LOG_DEBUG("onContentStoreMiss interest=" << interest.getName());
   ++m_counters.nCsMisses;
 
+  // attach HopLimit if configured and not present in Interest
+  if (m_config.defaultHopLimit > 0 && !interest.getHopLimit()) {
+    const_cast<Interest&>(interest).setHopLimit(m_config.defaultHopLimit);
+  }
+
   // insert in-record
   pitEntry->insertOrUpdateInRecord(ingress.face, interest);
 
@@ -597,4 +604,30 @@
   }
 }
 
+void
+Forwarder::setConfigFile(ConfigFile& configFile)
+{
+  configFile.addSectionHandler(CFGSEC_FORWARDER, bind(&Forwarder::processConfig, this, _1, _2, _3));
+}
+
+void
+Forwarder::processConfig(const ConfigSection& configSection, bool isDryRun, const std::string&)
+{
+  Config config;
+
+  for (const auto& pair : configSection) {
+    const std::string& key = pair.first;
+    if (key == "default_hop_limit") {
+      config.defaultHopLimit = ConfigFile::parseNumber<uint8_t>(pair, CFGSEC_FORWARDER);
+    }
+    else {
+      NDN_THROW(ConfigFile::Error("Unrecognized option " + CFGSEC_FORWARDER + "." + key));
+    }
+  }
+
+  if (!isDryRun) {
+    m_config = config;
+  }
+}
+
 } // namespace nfd