table: improve logging in DeadNonceList

Refs: #5165
Change-Id: I97f9e28af90d857b33808d385eb077380cafe00a
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index 1938c94..171a541 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -566,13 +566,13 @@
 }
 
 void
-Forwarder::insertDeadNonceList(pit::Entry& pitEntry, Face* upstream)
+Forwarder::insertDeadNonceList(pit::Entry& pitEntry, const Face* upstream)
 {
   // need Dead Nonce List insert?
   bool needDnl = true;
   if (pitEntry.isSatisfied) {
     BOOST_ASSERT(pitEntry.dataFreshnessPeriod >= 0_ms);
-    needDnl = static_cast<bool>(pitEntry.getInterest().getMustBeFresh()) &&
+    needDnl = pitEntry.getInterest().getMustBeFresh() &&
               pitEntry.dataFreshnessPeriod < m_deadNonceList.getLifetime();
   }
 
diff --git a/daemon/fw/forwarder.hpp b/daemon/fw/forwarder.hpp
index 6d4a068..51e4dd0 100644
--- a/daemon/fw/forwarder.hpp
+++ b/daemon/fw/forwarder.hpp
@@ -224,7 +224,7 @@
   NFD_VIRTUAL_WITH_TESTS void
   onNewNextHop(const Name& prefix, const fib::NextHop& nextHop);
 
-NFD_PROTECTED_WITH_TESTS_ELSE_PRIVATE:
+private:
   /** \brief set a new expiry timer (now + \p duration) on a PIT entry
    */
   void
@@ -234,8 +234,8 @@
    *  \param upstream if null, insert Nonces from all out-records;
    *                  if not null, insert Nonce only on the out-records of this face
    */
-  NFD_VIRTUAL_WITH_TESTS void
-  insertDeadNonceList(pit::Entry& pitEntry, Face* upstream);
+  void
+  insertDeadNonceList(pit::Entry& pitEntry, const Face* upstream);
 
 private:
   ForwarderCounters m_counters;
diff --git a/daemon/table/dead-nonce-list.cpp b/daemon/table/dead-nonce-list.cpp
index 5226140..5805842 100644
--- a/daemon/table/dead-nonce-list.cpp
+++ b/daemon/table/dead-nonce-list.cpp
@@ -45,8 +45,6 @@
 
 DeadNonceList::DeadNonceList(time::nanoseconds lifetime)
   : m_lifetime(lifetime)
-  , m_queue(m_index.get<0>())
-  , m_ht(m_index.get<1>())
   , m_capacity(INITIAL_CAPACITY)
   , m_markInterval(m_lifetime / EXPECTED_MARK_COUNT)
   , m_adjustCapacityInterval(m_lifetime)
@@ -91,10 +89,13 @@
 DeadNonceList::add(const Name& name, Interest::Nonce nonce)
 {
   Entry entry = DeadNonceList::makeEntry(name, nonce);
-
   const auto iter = m_ht.find(entry);
-  if (iter != m_ht.end()) {
-    m_queue.relocate(m_queue.end(), m_index.project<0>(iter));
+  bool isDuplicate = iter != m_ht.end();
+
+  NFD_LOG_TRACE("adding " << (isDuplicate ? "duplicate " : "") << name << " nonce=" << nonce);
+
+  if (isDuplicate) {
+    m_queue.relocate(m_queue.end(), m_index.project<Queue>(iter));
   }
   else {
     m_queue.push_back(entry);
@@ -132,16 +133,19 @@
 void
 DeadNonceList::adjustCapacity()
 {
+  auto oldCapacity = m_capacity;
   auto equalRange = m_actualMarkCounts.equal_range(EXPECTED_MARK_COUNT);
   if (equalRange.second == m_actualMarkCounts.begin()) {
     // all counts are above expected count, adjust down
     m_capacity = std::max(MIN_CAPACITY, static_cast<size_t>(m_capacity * CAPACITY_DOWN));
-    NFD_LOG_TRACE("adjustCapacity DOWN capacity=" << m_capacity);
   }
   else if (equalRange.first == m_actualMarkCounts.end()) {
     // all counts are below expected count, adjust up
     m_capacity = std::min(MAX_CAPACITY, static_cast<size_t>(m_capacity * CAPACITY_UP));
-    NFD_LOG_TRACE("adjustCapacity UP capacity=" << m_capacity);
+  }
+
+  if (m_capacity != oldCapacity) {
+    NFD_LOG_TRACE("adjusting capacity " << oldCapacity << " -> " << m_capacity);
   }
 
   m_actualMarkCounts.clear();
@@ -157,10 +161,12 @@
     return;
 
   auto nEvict = std::min(m_queue.size() - m_capacity, EVICT_LIMIT);
-  for (; nEvict > 0; --nEvict) {
-    m_queue.erase(m_queue.begin());
+  for (size_t i = 0; i < nEvict; i++) {
+    m_queue.pop_front();
   }
   BOOST_ASSERT(m_queue.size() >= m_capacity);
+
+  NFD_LOG_TRACE("evicted=" << nEvict << " size=" << size() << " capacity=" << m_capacity);
 }
 
 } // namespace nfd
diff --git a/daemon/table/dead-nonce-list.hpp b/daemon/table/dead-nonce-list.hpp
index ff9dfcd..84043be 100644
--- a/daemon/table/dead-nonce-list.hpp
+++ b/daemon/table/dead-nonce-list.hpp
@@ -131,19 +131,20 @@
 private:
   const time::nanoseconds m_lifetime;
 
-  using Index = boost::multi_index_container<
+  struct Queue {};
+  struct Hashtable {};
+  using Container = boost::multi_index_container<
     Entry,
     boost::multi_index::indexed_by<
-      boost::multi_index::sequenced<>,
-      boost::multi_index::hashed_non_unique<boost::multi_index::identity<Entry>>
+      boost::multi_index::sequenced<boost::multi_index::tag<Queue>>,
+      boost::multi_index::hashed_non_unique<boost::multi_index::tag<Hashtable>,
+                                            boost::multi_index::identity<Entry>>
     >
   >;
-  using Queue = Index::nth_index<0>::type;
-  using Hashtable = Index::nth_index<1>::type;
 
-  Index m_index;
-  Queue& m_queue;
-  Hashtable& m_ht;
+  Container m_index;
+  Container::index<Queue>::type& m_queue = m_index.get<Queue>();
+  Container::index<Hashtable>::type& m_ht = m_index.get<Hashtable>();
 
 NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE: