table: advisory limit of NameTree depth

refs #4262

Change-Id: I691f9615e2b8a3b146a683919c6d5833f53f6122
diff --git a/daemon/table/name-tree.cpp b/daemon/table/name-tree.cpp
index db0e3ff..65cafd7 100644
--- a/daemon/table/name-tree.cpp
+++ b/daemon/table/name-tree.cpp
@@ -41,15 +41,16 @@
 }
 
 Entry&
-NameTree::lookup(const Name& name)
+NameTree::lookup(const Name& name, bool enforceMaxDepth)
 {
   NFD_LOG_TRACE("lookup " << name);
+  size_t depth = enforceMaxDepth ? getMaxDepth() : name.size();
 
-  HashSequence hashes = computeHashes(name);
+  HashSequence hashes = computeHashes(name, depth);
   const Node* node = nullptr;
   Entry* parent = nullptr;
 
-  for (size_t prefixLen = 0; prefixLen <= name.size(); ++prefixLen) {
+  for (size_t prefixLen = 0; prefixLen <= depth; ++prefixLen) {
     bool isNew = false;
     std::tie(node, isNew) = m_ht.insert(name, prefixLen, hashes);