table: pit::FaceRecord stores Face& instead of shared_ptr

refs #3164

Change-Id: Ib23ab2341a37213fee791f2070f13b76da851d53
diff --git a/daemon/fw/best-route-strategy2.cpp b/daemon/fw/best-route-strategy2.cpp
index df6ca4d..5080d9c 100644
--- a/daemon/fw/best-route-strategy2.cpp
+++ b/daemon/fw/best-route-strategy2.cpp
@@ -195,7 +195,7 @@
     const lp::NackHeader* inNack = outR.getIncomingNack();
     if (inNack == nullptr) {
       ++nOutRecordsNotNacked;
-      lastFaceNotNacked = outR.getFace().get();
+      lastFaceNotNacked = &outR.getFace();
       continue;
     }
 
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index 2fbc93c..ff8e451 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -196,9 +196,8 @@
 {
   NFD_LOG_DEBUG("onContentStoreMiss interest=" << interest.getName());
 
-  shared_ptr<Face> face = const_pointer_cast<Face>(inFace.shared_from_this());
   // insert in-record
-  pitEntry->insertOrUpdateInRecord(face, interest);
+  pitEntry->insertOrUpdateInRecord(const_cast<Face&>(inFace), interest);
 
   // set PIT unsatisfy timer
   this->setUnsatisfyTimer(pitEntry);
@@ -252,8 +251,8 @@
   pit::InRecordCollection::iterator pickedInRecord = std::max_element(
     pitEntry->in_begin(), pitEntry->in_end(),
     [&outFace] (const pit::InRecord& a, const pit::InRecord& b) {
-      bool isOutFaceA = a.getFace().get() == &outFace;
-      bool isOutFaceB = b.getFace().get() == &outFace;
+      bool isOutFaceA = &a.getFace() == &outFace;
+      bool isOutFaceB = &b.getFace() == &outFace;
       return (isOutFaceA > isOutFaceB) ||
              (isOutFaceA == isOutFaceB && a.getLastRenewed() < b.getLastRenewed());
     });
@@ -267,7 +266,7 @@
   }
 
   // insert out-record
-  pitEntry->insertOrUpdateOutRecord(outFace.shared_from_this(), *interest);
+  pitEntry->insertOrUpdateOutRecord(outFace, *interest);
 
   // send Interest
   outFace.sendInterest(*interest);
@@ -360,7 +359,7 @@
     // remember pending downstreams
     for (const pit::InRecord& inRecord : pitEntry->getInRecords()) {
       if (inRecord.getExpiry() > now) {
-        pendingDownstreams.insert(inRecord.getFace().get());
+        pendingDownstreams.insert(&inRecord.getFace());
       }
     }
 
diff --git a/daemon/fw/pit-algorithm.cpp b/daemon/fw/pit-algorithm.cpp
index a9ef7ea..3ff63b8 100644
--- a/daemon/fw/pit-algorithm.cpp
+++ b/daemon/fw/pit-algorithm.cpp
@@ -49,7 +49,7 @@
   if (scope_prefix::LOCALHOP.isPrefixOf(pitEntry.getName())) {
     // face is non-local, violates localhop scope unless PIT entry has local in-record
     return std::none_of(pitEntry.in_begin(), pitEntry.in_end(),
-      [] (const pit::InRecord& inRecord) { return inRecord.getFace()->getScope() == ndn::nfd::FACE_SCOPE_LOCAL; });
+      [] (const pit::InRecord& inRecord) { return inRecord.getFace().getScope() == ndn::nfd::FACE_SCOPE_LOCAL; });
   }
 
   // Name is not subject to scope control
@@ -63,7 +63,7 @@
 
   bool hasUnexpiredOutRecord = std::any_of(pitEntry.out_begin(), pitEntry.out_end(),
     [&face, &now] (const pit::OutRecord& outRecord) {
-      return outRecord.getFace().get() == &face && outRecord.getExpiry() >= now;
+      return &outRecord.getFace() == &face && outRecord.getExpiry() >= now;
     });
   if (hasUnexpiredOutRecord) {
     return false;
@@ -71,7 +71,7 @@
 
   bool hasUnexpiredOtherInRecord = std::any_of(pitEntry.in_begin(), pitEntry.in_end(),
     [&face, &now] (const pit::InRecord& inRecord) {
-      return inRecord.getFace().get() != &face && inRecord.getExpiry() >= now;
+      return &inRecord.getFace() != &face && inRecord.getExpiry() >= now;
     });
   if (!hasUnexpiredOtherInRecord) {
     return false;
@@ -87,7 +87,7 @@
 
   for (const pit::InRecord& inRecord : pitEntry.getInRecords()) {
     if (inRecord.getLastNonce() == nonce) {
-      if (inRecord.getFace().get() == &face) {
+      if (&inRecord.getFace() == &face) {
         dnw |= DUPLICATE_NONCE_IN_SAME;
       }
       else {
@@ -98,7 +98,7 @@
 
   for (const pit::OutRecord& outRecord : pitEntry.getOutRecords()) {
     if (outRecord.getLastNonce() == nonce) {
-      if (outRecord.getFace().get() == &face) {
+      if (&outRecord.getFace() == &face) {
         dnw |= DUPLICATE_NONCE_OUT_SAME;
       }
       else {
diff --git a/daemon/fw/strategy.cpp b/daemon/fw/strategy.cpp
index 2a40517..f645369 100644
--- a/daemon/fw/strategy.cpp
+++ b/daemon/fw/strategy.cpp
@@ -75,10 +75,10 @@
   // populate downstreams with all downstreams faces
   std::unordered_set<const Face*> downstreams;
   std::transform(pitEntry->in_begin(), pitEntry->in_end(), std::inserter(downstreams, downstreams.end()),
-                 [] (const pit::InRecord& inR) { return inR.getFace().get(); });
+                 [] (const pit::InRecord& inR) { return &inR.getFace(); });
 
   // delete excluded faces
-  // .erase in a loop is more efficient than std::set_difference between that requires sorted range
+  // .erase in a loop is more efficient than std::set_difference because that requires sorted range
   for (const Face* exceptFace : exceptFaces) {
     downstreams.erase(exceptFace);
   }
diff --git a/daemon/table/pit-entry.cpp b/daemon/table/pit-entry.cpp
index d19369a..395fc90 100644
--- a/daemon/table/pit-entry.cpp
+++ b/daemon/table/pit-entry.cpp
@@ -38,14 +38,14 @@
 Entry::getInRecord(const Face& face)
 {
   return std::find_if(m_inRecords.begin(), m_inRecords.end(),
-    [&face] (const InRecord& inRecord) { return inRecord.getFace().get() == &face; });
+    [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
 }
 
 InRecordCollection::iterator
-Entry::insertOrUpdateInRecord(shared_ptr<Face> face, const Interest& interest)
+Entry::insertOrUpdateInRecord(Face& face, const Interest& interest)
 {
   auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
-    [&face] (const InRecord& inRecord) { return inRecord.getFace() == face; });
+    [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
   if (it == m_inRecords.end()) {
     m_inRecords.emplace_front(face);
     it = m_inRecords.begin();
@@ -59,7 +59,7 @@
 Entry::deleteInRecord(const Face& face)
 {
   auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
-    [&face] (const InRecord& inRecord) { return inRecord.getFace().get() == &face; });
+    [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
   if (it != m_inRecords.end()) {
     m_inRecords.erase(it);
   }
@@ -75,14 +75,14 @@
 Entry::getOutRecord(const Face& face)
 {
   return std::find_if(m_outRecords.begin(), m_outRecords.end(),
-    [&face] (const OutRecord& outRecord) { return outRecord.getFace().get() == &face; });
+    [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
 }
 
 OutRecordCollection::iterator
-Entry::insertOrUpdateOutRecord(shared_ptr<Face> face, const Interest& interest)
+Entry::insertOrUpdateOutRecord(Face& face, const Interest& interest)
 {
   auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
-    [&face] (const OutRecord& outRecord) { return outRecord.getFace() == face; });
+    [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
   if (it == m_outRecords.end()) {
     m_outRecords.emplace_front(face);
     it = m_outRecords.begin();
@@ -96,7 +96,7 @@
 Entry::deleteOutRecord(const Face& face)
 {
   auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
-    [&face] (const OutRecord& outRecord) { return outRecord.getFace().get() == &face; });
+    [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
   if (it != m_outRecords.end()) {
     m_outRecords.erase(it);
   }
diff --git a/daemon/table/pit-entry.hpp b/daemon/table/pit-entry.hpp
index 5f77a4d..99832ad 100644
--- a/daemon/table/pit-entry.hpp
+++ b/daemon/table/pit-entry.hpp
@@ -111,7 +111,7 @@
    *  \return an iterator to the new or updated in-record
    */
   InRecordCollection::iterator
-  insertOrUpdateInRecord(shared_ptr<Face> face, const Interest& interest);
+  insertOrUpdateInRecord(Face& face, const Interest& interest);
 
   /** \brief delete the in-record for \p face if it exists
    */
@@ -160,7 +160,7 @@
    *  \return an iterator to the new or updated out-record
    */
   OutRecordCollection::iterator
-  insertOrUpdateOutRecord(shared_ptr<Face> face, const Interest& interest);
+  insertOrUpdateOutRecord(Face& face, const Interest& interest);
 
   /** \brief delete the out-record for \p face if it exists
    */
diff --git a/daemon/table/pit-face-record.cpp b/daemon/table/pit-face-record.cpp
index c62a1b5..d594cb9 100644
--- a/daemon/table/pit-face-record.cpp
+++ b/daemon/table/pit-face-record.cpp
@@ -1,12 +1,12 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014,  Regents of the University of California,
- *                      Arizona Board of Regents,
- *                      Colorado State University,
- *                      University Pierre & Marie Curie, Sorbonne University,
- *                      Washington University in St. Louis,
- *                      Beijing Institute of Technology,
- *                      The University of Memphis
+ * Copyright (c) 2014-2016,  Regents of the University of California,
+ *                           Arizona Board of Regents,
+ *                           Colorado State University,
+ *                           University Pierre & Marie Curie, Sorbonne University,
+ *                           Washington University in St. Louis,
+ *                           Beijing Institute of Technology,
+ *                           The University of Memphis.
  *
  * This file is part of NFD (Named Data Networking Forwarding Daemon).
  * See AUTHORS.md for complete list of NFD authors and contributors.
@@ -28,7 +28,7 @@
 namespace nfd {
 namespace pit {
 
-FaceRecord::FaceRecord(shared_ptr<Face> face)
+FaceRecord::FaceRecord(Face& face)
   : m_face(face)
   , m_lastNonce(0)
   , m_lastRenewed(time::steady_clock::TimePoint::min())
diff --git a/daemon/table/pit-face-record.hpp b/daemon/table/pit-face-record.hpp
index c1d6c77..90c3cdb 100644
--- a/daemon/table/pit-face-record.hpp
+++ b/daemon/table/pit-face-record.hpp
@@ -1,12 +1,12 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014,  Regents of the University of California,
- *                      Arizona Board of Regents,
- *                      Colorado State University,
- *                      University Pierre & Marie Curie, Sorbonne University,
- *                      Washington University in St. Louis,
- *                      Beijing Institute of Technology,
- *                      The University of Memphis
+ * Copyright (c) 2014-2016,  Regents of the University of California,
+ *                           Arizona Board of Regents,
+ *                           Colorado State University,
+ *                           University Pierre & Marie Curie, Sorbonne University,
+ *                           Washington University in St. Louis,
+ *                           Beijing Institute of Technology,
+ *                           The University of Memphis.
  *
  * This file is part of NFD (Named Data Networking Forwarding Daemon).
  * See AUTHORS.md for complete list of NFD authors and contributors.
@@ -41,9 +41,9 @@
 {
 public:
   explicit
-  FaceRecord(shared_ptr<Face> face);
+  FaceRecord(Face& face);
 
-  shared_ptr<Face>
+  Face&
   getFace() const;
 
   uint32_t
@@ -64,13 +64,13 @@
   update(const Interest& interest);
 
 private:
-  shared_ptr<Face> m_face;
+  Face& m_face;
   uint32_t m_lastNonce;
   time::steady_clock::TimePoint m_lastRenewed;
   time::steady_clock::TimePoint m_expiry;
 };
 
-inline shared_ptr<Face>
+inline Face&
 FaceRecord::getFace() const
 {
   return m_face;
diff --git a/daemon/table/pit-in-record.cpp b/daemon/table/pit-in-record.cpp
index b7f0edf..8167190 100644
--- a/daemon/table/pit-in-record.cpp
+++ b/daemon/table/pit-in-record.cpp
@@ -1,11 +1,12 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014  Regents of the University of California,
- *                     Arizona Board of Regents,
- *                     Colorado State University,
- *                     University Pierre & Marie Curie, Sorbonne University,
- *                     Washington University in St. Louis,
- *                     Beijing Institute of Technology
+ * Copyright (c) 2014-2016,  Regents of the University of California,
+ *                           Arizona Board of Regents,
+ *                           Colorado State University,
+ *                           University Pierre & Marie Curie, Sorbonne University,
+ *                           Washington University in St. Louis,
+ *                           Beijing Institute of Technology,
+ *                           The University of Memphis.
  *
  * This file is part of NFD (Named Data Networking Forwarding Daemon).
  * See AUTHORS.md for complete list of NFD authors and contributors.
@@ -20,14 +21,14 @@
  *
  * You should have received a copy of the GNU General Public License along with
  * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- **/
+ */
 
 #include "pit-in-record.hpp"
 
 namespace nfd {
 namespace pit {
 
-InRecord::InRecord(shared_ptr<Face> face)
+InRecord::InRecord(Face& face)
   : FaceRecord(face)
 {
 }
diff --git a/daemon/table/pit-in-record.hpp b/daemon/table/pit-in-record.hpp
index dd6ad06..45167c3 100644
--- a/daemon/table/pit-in-record.hpp
+++ b/daemon/table/pit-in-record.hpp
@@ -37,7 +37,7 @@
 {
 public:
   explicit
-  InRecord(shared_ptr<Face> face);
+  InRecord(Face& face);
 
   void
   update(const Interest& interest);
diff --git a/daemon/table/pit-out-record.cpp b/daemon/table/pit-out-record.cpp
index 1cf303d..8b4f609 100644
--- a/daemon/table/pit-out-record.cpp
+++ b/daemon/table/pit-out-record.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2015,  Regents of the University of California,
+ * Copyright (c) 2014-2016,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -28,7 +28,7 @@
 namespace nfd {
 namespace pit {
 
-OutRecord::OutRecord(shared_ptr<Face> face)
+OutRecord::OutRecord(Face& face)
   : FaceRecord(face)
 {
 }
diff --git a/daemon/table/pit-out-record.hpp b/daemon/table/pit-out-record.hpp
index 4717779..4400fd4 100644
--- a/daemon/table/pit-out-record.hpp
+++ b/daemon/table/pit-out-record.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2015,  Regents of the University of California,
+ * Copyright (c) 2014-2016,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -37,7 +37,7 @@
 {
 public:
   explicit
-  OutRecord(shared_ptr<Face> face);
+  OutRecord(Face& face);
 
   /** \return last NACK returned by \p getFace()
    *