chunks+poke+ping: use PendingInterestHandle and RegisteredPrefixHandle

refs #4316, #3919

Change-Id: Ia95362067a9024964cf67543c76375144b8a2782
diff --git a/tools/chunks/catchunks/data-fetcher.cpp b/tools/chunks/catchunks/data-fetcher.cpp
index 313334f..7600016 100644
--- a/tools/chunks/catchunks/data-fetcher.cpp
+++ b/tools/chunks/catchunks/data-fetcher.cpp
@@ -1,8 +1,8 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2016,  Regents of the University of California,
- *                      Colorado State University,
- *                      University Pierre & Marie Curie, Sorbonne University.
+/*
+ * Copyright (c) 2016-2019, Regents of the University of California,
+ *                          Colorado State University,
+ *                          University Pierre & Marie Curie, Sorbonne University.
  *
  * This file is part of ndn-tools (Named Data Networking Essential Tools).
  * See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -75,7 +75,7 @@
 {
   if (isRunning()) {
     m_isStopped = true;
-    m_face.removePendingInterest(m_interestId);
+    m_pendingInterest.cancel();
     m_scheduler.cancelAllEvents();
   }
 }
@@ -84,10 +84,10 @@
 DataFetcher::expressInterest(const Interest& interest, const shared_ptr<DataFetcher>& self)
 {
   m_nCongestionRetries = 0;
-  m_interestId = m_face.expressInterest(interest,
-                                        bind(&DataFetcher::handleData, this, _1, _2, self),
-                                        bind(&DataFetcher::handleNack, this, _1, _2, self),
-                                        bind(&DataFetcher::handleTimeout, this, _1, self));
+  m_pendingInterest = m_face.expressInterest(interest,
+                                             bind(&DataFetcher::handleData, this, _1, _2, self),
+                                             bind(&DataFetcher::handleNack, this, _1, _2, self),
+                                             bind(&DataFetcher::handleTimeout, this, _1, self));
 }
 
 void
diff --git a/tools/chunks/catchunks/data-fetcher.hpp b/tools/chunks/catchunks/data-fetcher.hpp
index 5b66450..53e32c0 100644
--- a/tools/chunks/catchunks/data-fetcher.hpp
+++ b/tools/chunks/catchunks/data-fetcher.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2016-2018, Regents of the University of California,
+ * Copyright (c) 2016-2019, Regents of the University of California,
  *                          Colorado State University,
  *                          University Pierre & Marie Curie, Sorbonne University.
  *
@@ -110,7 +110,7 @@
 private:
   Face& m_face;
   Scheduler m_scheduler;
-  const PendingInterestId* m_interestId;
+  PendingInterestHandle m_pendingInterest;
   DataCallback m_onData;
   FailureCallback m_onNack;
   FailureCallback m_onTimeout;
diff --git a/tools/chunks/catchunks/pipeline-interests-aimd.cpp b/tools/chunks/catchunks/pipeline-interests-aimd.cpp
index 73e22c5..eea122e 100644
--- a/tools/chunks/catchunks/pipeline-interests-aimd.cpp
+++ b/tools/chunks/catchunks/pipeline-interests-aimd.cpp
@@ -86,9 +86,6 @@
 void
 PipelineInterestsAimd::doCancel()
 {
-  for (const auto& entry : m_segmentInfo) {
-    m_face.removePendingInterest(entry.second.interestId);
-  }
   m_checkRtoEvent.cancel();
   m_segmentInfo.clear();
 }
@@ -155,8 +152,6 @@
                   << " is " << m_retxCount[segNo] << std::endl;
       }
     }
-
-    m_face.removePendingInterest(m_segmentInfo[segNo].interestId);
   }
 
   Interest interest(Name(m_prefix).appendSegment(segNo));
@@ -164,26 +159,24 @@
   interest.setMustBeFresh(m_options.mustBeFresh);
   interest.setMaxSuffixComponents(1);
 
-  auto interestId = m_face.expressInterest(interest,
-                                           bind(&PipelineInterestsAimd::handleData, this, _1, _2),
-                                           bind(&PipelineInterestsAimd::handleNack, this, _1, _2),
-                                           bind(&PipelineInterestsAimd::handleLifetimeExpiration, this, _1));
+  SegmentInfo& segInfo = m_segmentInfo[segNo];
+  segInfo.interestHdl = m_face.expressInterest(interest,
+                                               bind(&PipelineInterestsAimd::handleData, this, _1, _2),
+                                               bind(&PipelineInterestsAimd::handleNack, this, _1, _2),
+                                               bind(&PipelineInterestsAimd::handleLifetimeExpiration, this, _1));
+  segInfo.timeSent = time::steady_clock::now();
+  segInfo.rto = m_rttEstimator.getEstimatedRto();
+
   m_nInFlight++;
   m_nSent++;
 
   if (isRetransmission) {
-    SegmentInfo& segInfo = m_segmentInfo[segNo];
-    segInfo.timeSent = time::steady_clock::now();
-    segInfo.rto = m_rttEstimator.getEstimatedRto();
     segInfo.state = SegmentState::Retransmitted;
     m_nRetransmitted++;
   }
   else {
     m_highInterest = segNo;
-    m_segmentInfo[segNo] = {interestId,
-                            time::steady_clock::now(),
-                            m_rttEstimator.getEstimatedRto(),
-                            SegmentState::FirstTimeSent};
+    segInfo.state = SegmentState::FirstTimeSent;
   }
 }
 
@@ -427,7 +420,6 @@
   for (auto it = m_segmentInfo.begin(); it != m_segmentInfo.end();) {
     // cancel fetching all segments that follow
     if (it->first > segNo) {
-      m_face.removePendingInterest(it->second.interestId);
       it = m_segmentInfo.erase(it);
       m_nInFlight--;
     }
diff --git a/tools/chunks/catchunks/pipeline-interests-aimd.hpp b/tools/chunks/catchunks/pipeline-interests-aimd.hpp
index aea2d19..12edb95 100644
--- a/tools/chunks/catchunks/pipeline-interests-aimd.hpp
+++ b/tools/chunks/catchunks/pipeline-interests-aimd.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2016-2018, Regents of the University of California,
+ * Copyright (c) 2016-2019, Regents of the University of California,
  *                          Colorado State University,
  *                          University Pierre & Marie Curie, Sorbonne University.
  *
@@ -76,7 +76,7 @@
  */
 struct SegmentInfo
 {
-  const PendingInterestId* interestId; ///< pending interest ID returned by ndn::Face::expressInterest
+  ScopedPendingInterestHandle interestHdl;
   time::steady_clock::TimePoint timeSent;
   Milliseconds rto;
   SegmentState state;