pit: add EndpointId field in in-record and out-record

refs: #4842

Change-Id: Id4bca4ad9c2d7c8a2fd975c0b052fb9271b6e47d
diff --git a/daemon/table/cleanup.cpp b/daemon/table/cleanup.cpp
index 5a45bf7..d45b363 100644
--- a/daemon/table/cleanup.cpp
+++ b/daemon/table/cleanup.cpp
@@ -40,7 +40,7 @@
     }
 
     for (const auto& pitEntry : nte.getPitEntries()) {
-      pit.deleteInOutRecords(pitEntry.get(), face);
+      pit.deleteInOutRecordsByFace(pitEntry.get(), face);
     }
 
     if (!nte.hasTableEntries()) {
diff --git a/daemon/table/pit-entry.cpp b/daemon/table/pit-entry.cpp
index ee4b726..2edbc9f 100644
--- a/daemon/table/pit-entry.cpp
+++ b/daemon/table/pit-entry.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018,  Regents of the University of California,
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -50,21 +50,25 @@
 }
 
 InRecordCollection::iterator
-Entry::getInRecord(const Face& face)
+Entry::getInRecord(const Face& face, uint64_t endpointId)
 {
   return std::find_if(m_inRecords.begin(), m_inRecords.end(),
-    [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
+    [&face, endpointId] (const InRecord& inRecord) {
+      return &inRecord.getFace() == &face && inRecord.getEndpointId() == endpointId;
+    });
 }
 
 InRecordCollection::iterator
-Entry::insertOrUpdateInRecord(Face& face, const Interest& interest)
+Entry::insertOrUpdateInRecord(Face& face, uint64_t endpointId, const Interest& interest)
 {
   BOOST_ASSERT(this->canMatch(interest));
 
   auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
-    [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
+    [&face, endpointId] (const InRecord& inRecord) {
+      return &inRecord.getFace() == &face && inRecord.getEndpointId() == endpointId;
+    });
   if (it == m_inRecords.end()) {
-    m_inRecords.emplace_front(face);
+    m_inRecords.emplace_front(face, endpointId);
     it = m_inRecords.begin();
   }
 
@@ -73,10 +77,12 @@
 }
 
 void
-Entry::deleteInRecord(const Face& face)
+Entry::deleteInRecord(const Face& face, uint64_t endpointId)
 {
   auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
-    [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
+    [&face, endpointId] (const InRecord& inRecord) {
+      return &inRecord.getFace() == &face && inRecord.getEndpointId() == endpointId;
+    });
   if (it != m_inRecords.end()) {
     m_inRecords.erase(it);
   }
@@ -89,21 +95,25 @@
 }
 
 OutRecordCollection::iterator
-Entry::getOutRecord(const Face& face)
+Entry::getOutRecord(const Face& face, uint64_t endpointId)
 {
   return std::find_if(m_outRecords.begin(), m_outRecords.end(),
-    [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
+    [&face, endpointId] (const OutRecord& outRecord) {
+      return &outRecord.getFace() == &face && outRecord.getEndpointId() == endpointId;
+    });
 }
 
 OutRecordCollection::iterator
-Entry::insertOrUpdateOutRecord(Face& face, const Interest& interest)
+Entry::insertOrUpdateOutRecord(Face& face, uint64_t endpointId, const Interest& interest)
 {
   BOOST_ASSERT(this->canMatch(interest));
 
   auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
-    [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
+    [&face, endpointId] (const OutRecord& outRecord) {
+      return &outRecord.getFace() == &face && outRecord.getEndpointId() == endpointId;
+    });
   if (it == m_outRecords.end()) {
-    m_outRecords.emplace_front(face);
+    m_outRecords.emplace_front(face, endpointId);
     it = m_outRecords.begin();
   }
 
@@ -112,14 +122,27 @@
 }
 
 void
-Entry::deleteOutRecord(const Face& face)
+Entry::deleteOutRecord(const Face& face, uint64_t endpointId)
 {
   auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
-    [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
+    [&face, endpointId] (const OutRecord& outRecord) {
+      return &outRecord.getFace() == &face && outRecord.getEndpointId() == endpointId;
+    });
   if (it != m_outRecords.end()) {
     m_outRecords.erase(it);
   }
 }
 
+void
+Entry::deleteInOutRecordsByFace(const Face& face)
+{
+  m_inRecords.remove_if([&face] (const InRecord& inRecord) {
+    return &inRecord.getFace() == &face;
+  });
+  m_outRecords.remove_if([&face] (const OutRecord& outRecord) {
+    return &outRecord.getFace() == &face;
+  });
+}
+
 } // namespace pit
 } // namespace nfd
diff --git a/daemon/table/pit-entry.hpp b/daemon/table/pit-entry.hpp
index 2e49824..b1dc9ee 100644
--- a/daemon/table/pit-entry.hpp
+++ b/daemon/table/pit-entry.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018,  Regents of the University of California,
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -132,22 +132,22 @@
     return m_inRecords.end();
   }
 
-  /** \brief get the in-record for \p face
+  /** \brief get the in-record for \p face and \p endpointId
    *  \return an iterator to the in-record, or .in_end() if it does not exist
    */
   InRecordCollection::iterator
-  getInRecord(const Face& face);
+  getInRecord(const Face& face, uint64_t endpointId);
 
   /** \brief insert or update an in-record
    *  \return an iterator to the new or updated in-record
    */
   InRecordCollection::iterator
-  insertOrUpdateInRecord(Face& face, const Interest& interest);
+  insertOrUpdateInRecord(Face& face, uint64_t endpointId, const Interest& interest);
 
-  /** \brief delete the in-record for \p face if it exists
+  /** \brief delete the in-record for \p face and \p endpointId if it exists
    */
   void
-  deleteInRecord(const Face& face);
+  deleteInRecord(const Face& face, uint64_t endpointId);
 
   /** \brief delete all in-records
    */
@@ -199,22 +199,28 @@
     return m_outRecords.end();
   }
 
-  /** \brief get the out-record for \p face
+  /** \brief get the out-record for \p face and \p endpointId
    *  \return an iterator to the out-record, or .out_end() if it does not exist
    */
   OutRecordCollection::iterator
-  getOutRecord(const Face& face);
+  getOutRecord(const Face& face, uint64_t endpointId);
 
   /** \brief insert or update an out-record
    *  \return an iterator to the new or updated out-record
    */
   OutRecordCollection::iterator
-  insertOrUpdateOutRecord(Face& face, const Interest& interest);
+  insertOrUpdateOutRecord(Face& face, uint64_t endpointId, const Interest& interest);
 
-  /** \brief delete the out-record for \p face if it exists
+  /** \brief delete the out-record for \p face and \p endpointId if it exists
    */
   void
-  deleteOutRecord(const Face& face);
+  deleteOutRecord(const Face& face, uint64_t endpointId);
+
+public: // cleanup
+  /** \brief delete all in-records and out-records for \p face if it exists
+   */
+  void
+  deleteInOutRecordsByFace(const Face& face);
 
 public:
   /** \brief expiry timer
diff --git a/daemon/table/pit-face-record.cpp b/daemon/table/pit-face-record.cpp
index d594cb9..61fef7e 100644
--- a/daemon/table/pit-face-record.cpp
+++ b/daemon/table/pit-face-record.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016,  Regents of the University of California,
+/*
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -28,8 +28,9 @@
 namespace nfd {
 namespace pit {
 
-FaceRecord::FaceRecord(Face& face)
+FaceRecord::FaceRecord(Face& face, uint64_t endpointId)
   : m_face(face)
+  , m_endpointId(endpointId)
   , m_lastNonce(0)
   , m_lastRenewed(time::steady_clock::TimePoint::min())
   , m_expiry(time::steady_clock::TimePoint::min())
diff --git a/daemon/table/pit-face-record.hpp b/daemon/table/pit-face-record.hpp
index 90c3cdb..3e3f020 100644
--- a/daemon/table/pit-face-record.hpp
+++ b/daemon/table/pit-face-record.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016,  Regents of the University of California,
+/*
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -40,12 +40,14 @@
 class FaceRecord : public StrategyInfoHost
 {
 public:
-  explicit
-  FaceRecord(Face& face);
+  FaceRecord(Face& face, uint64_t endpointId);
 
   Face&
   getFace() const;
 
+  uint64_t
+  getEndpointId() const;
+
   uint32_t
   getLastNonce() const;
 
@@ -65,6 +67,7 @@
 
 private:
   Face& m_face;
+  uint64_t m_endpointId;
   uint32_t m_lastNonce;
   time::steady_clock::TimePoint m_lastRenewed;
   time::steady_clock::TimePoint m_expiry;
@@ -76,6 +79,12 @@
   return m_face;
 }
 
+inline uint64_t
+FaceRecord::getEndpointId() const
+{
+  return m_endpointId;
+}
+
 inline uint32_t
 FaceRecord::getLastNonce() const
 {
diff --git a/daemon/table/pit-in-record.cpp b/daemon/table/pit-in-record.cpp
index 8167190..7bb10b9 100644
--- a/daemon/table/pit-in-record.cpp
+++ b/daemon/table/pit-in-record.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016,  Regents of the University of California,
+/*
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -28,8 +28,8 @@
 namespace nfd {
 namespace pit {
 
-InRecord::InRecord(Face& face)
-  : FaceRecord(face)
+InRecord::InRecord(Face& face, uint64_t endpointId)
+  : FaceRecord(face, endpointId)
 {
 }
 
diff --git a/daemon/table/pit-in-record.hpp b/daemon/table/pit-in-record.hpp
index 45167c3..d758097 100644
--- a/daemon/table/pit-in-record.hpp
+++ b/daemon/table/pit-in-record.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016,  Regents of the University of California,
+/*
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -36,8 +36,7 @@
 class InRecord : public FaceRecord
 {
 public:
-  explicit
-  InRecord(Face& face);
+  InRecord(Face& face, uint64_t endpointId);
 
   void
   update(const Interest& interest);
diff --git a/daemon/table/pit-out-record.cpp b/daemon/table/pit-out-record.cpp
index 8b4f609..75d7e7f 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-2016,  Regents of the University of California,
+/*
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -28,8 +28,8 @@
 namespace nfd {
 namespace pit {
 
-OutRecord::OutRecord(Face& face)
-  : FaceRecord(face)
+OutRecord::OutRecord(Face& face, uint64_t endpointId)
+  : FaceRecord(face, endpointId)
 {
 }
 
diff --git a/daemon/table/pit-out-record.hpp b/daemon/table/pit-out-record.hpp
index 4400fd4..c0537fd 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-2016,  Regents of the University of California,
+/*
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -36,8 +36,7 @@
 class OutRecord : public FaceRecord
 {
 public:
-  explicit
-  OutRecord(Face& face);
+  OutRecord(Face& face, uint64_t endpointId);
 
   /** \return last NACK returned by \p getFace()
    *
@@ -79,4 +78,4 @@
 } // namespace pit
 } // namespace nfd
 
-#endif // NFD_DAEMON_TABLE_PIT_IN_RECORD_HPP
+#endif // NFD_DAEMON_TABLE_PIT_OUT_RECORD_HPP
diff --git a/daemon/table/pit.cpp b/daemon/table/pit.cpp
index 7a708da..5e26fc0 100644
--- a/daemon/table/pit.cpp
+++ b/daemon/table/pit.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018,  Regents of the University of California,
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -113,12 +113,11 @@
 }
 
 void
-Pit::deleteInOutRecords(Entry* entry, const Face& face)
+Pit::deleteInOutRecordsByFace(Entry* entry, const Face& face)
 {
   BOOST_ASSERT(entry != nullptr);
 
-  entry->deleteInRecord(face);
-  entry->deleteOutRecord(face);
+  entry->deleteInOutRecordsByFace(face);
 
   /// \todo decide whether to delete PIT entry if there's no more in/out-record left
 }
diff --git a/daemon/table/pit.hpp b/daemon/table/pit.hpp
index 6e8af8a..eb2438b 100644
--- a/daemon/table/pit.hpp
+++ b/daemon/table/pit.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018,  Regents of the University of California,
+ * Copyright (c) 2014-2019,  Regents of the University of California,
  *                           Arizona Board of Regents,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University,
@@ -93,10 +93,10 @@
     this->erase(entry, true);
   }
 
-  /** \brief deletes in-record and out-record for face
+  /** \brief deletes all in-records and out-records for \p face
    */
   void
-  deleteInOutRecords(Entry* entry, const Face& face);
+  deleteInOutRecordsByFace(Entry* entry, const Face& face);
 
 public: // enumeration
   typedef Iterator const_iterator;