Slim down `common.hpp`

Change-Id: Ic9843a1b9ffc5b5b1fa6062c8250ba28c6aaa898
diff --git a/tools/chunks/catchunks/consumer.cpp b/tools/chunks/catchunks/consumer.cpp
index a1c2edf..6d30d70 100644
--- a/tools/chunks/catchunks/consumer.cpp
+++ b/tools/chunks/catchunks/consumer.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2016-2022, Regents of the University of California,
+ * Copyright (c) 2016-2024, Regents of the University of California,
  *                          Colorado State University,
  *                          University Pierre & Marie Curie, Sorbonne University.
  *
@@ -27,6 +27,8 @@
 
 #include "consumer.hpp"
 
+#include <ndn-cxx/util/exception.hpp>
+
 namespace ndn::chunks {
 
 Consumer::Consumer(security::Validator& validator, std::ostream& os)
@@ -36,7 +38,7 @@
 }
 
 void
-Consumer::run(unique_ptr<DiscoverVersion> discover, unique_ptr<PipelineInterests> pipeline)
+Consumer::run(std::unique_ptr<DiscoverVersion> discover, std::unique_ptr<PipelineInterests> pipeline)
 {
   m_discover = std::move(discover);
   m_pipeline = std::move(pipeline);
diff --git a/tools/chunks/catchunks/consumer.hpp b/tools/chunks/catchunks/consumer.hpp
index 8423ace..980df60 100644
--- a/tools/chunks/catchunks/consumer.hpp
+++ b/tools/chunks/catchunks/consumer.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2016-2022, Regents of the University of California,
+ * Copyright (c) 2016-2024, Regents of the University of California,
  *                          Colorado State University,
  *                          University Pierre & Marie Curie, Sorbonne University.
  *
@@ -34,12 +34,14 @@
 #include <ndn-cxx/security/validation-error.hpp>
 #include <ndn-cxx/security/validator.hpp>
 
+#include <boost/lexical_cast.hpp>
+#include <iostream>
 #include <map>
 
 namespace ndn::chunks {
 
 /**
- * @brief Segmented version consumer
+ * @brief Segmented version consumer.
  *
  * Discover the latest version of the data published under a specified prefix, and retrieve all the
  * segments associated to that version. The segments are fetched in order and written to a
@@ -78,7 +80,7 @@
    * @brief Run the consumer
    */
   void
-  run(unique_ptr<DiscoverVersion> discover, unique_ptr<PipelineInterests> pipeline);
+  run(std::unique_ptr<DiscoverVersion> discover, std::unique_ptr<PipelineInterests> pipeline);
 
 private:
   void
@@ -91,12 +93,12 @@
 private:
   security::Validator& m_validator;
   std::ostream& m_outputStream;
-  unique_ptr<DiscoverVersion> m_discover;
-  unique_ptr<PipelineInterests> m_pipeline;
+  std::unique_ptr<DiscoverVersion> m_discover;
+  std::unique_ptr<PipelineInterests> m_pipeline;
   uint64_t m_nextToPrint = 0;
 
 PUBLIC_WITH_TESTS_ELSE_PRIVATE:
-  std::map<uint64_t, shared_ptr<const Data>> m_bufferedData;
+  std::map<uint64_t, std::shared_ptr<const Data>> m_bufferedData;
 };
 
 } // namespace ndn::chunks
diff --git a/tools/chunks/catchunks/data-fetcher.cpp b/tools/chunks/catchunks/data-fetcher.cpp
index ccc142a..e058ca0 100644
--- a/tools/chunks/catchunks/data-fetcher.cpp
+++ b/tools/chunks/catchunks/data-fetcher.cpp
@@ -26,22 +26,25 @@
 
 #include "data-fetcher.hpp"
 
+#include <boost/lexical_cast.hpp>
+
 #include <cmath>
+#include <iostream>
 
 namespace ndn::chunks {
 
-shared_ptr<DataFetcher>
+std::shared_ptr<DataFetcher>
 DataFetcher::fetch(Face& face, const Interest& interest, int maxNackRetries, int maxTimeoutRetries,
                    DataCallback onData, FailureCallback onNack, FailureCallback onTimeout,
                    bool isVerbose)
 {
-  auto dataFetcher = shared_ptr<DataFetcher>(new DataFetcher(face,
-                                                             maxNackRetries,
-                                                             maxTimeoutRetries,
-                                                             std::move(onData),
-                                                             std::move(onNack),
-                                                             std::move(onTimeout),
-                                                             isVerbose));
+  auto dataFetcher = std::shared_ptr<DataFetcher>(new DataFetcher(face,
+                                                                  maxNackRetries,
+                                                                  maxTimeoutRetries,
+                                                                  std::move(onData),
+                                                                  std::move(onNack),
+                                                                  std::move(onTimeout),
+                                                                  isVerbose));
   dataFetcher->expressInterest(interest, dataFetcher);
   return dataFetcher;
 }
@@ -72,18 +75,18 @@
 }
 
 void
-DataFetcher::expressInterest(const Interest& interest, const shared_ptr<DataFetcher>& self)
+DataFetcher::expressInterest(const Interest& interest, const std::shared_ptr<DataFetcher>& self)
 {
   m_nCongestionRetries = 0;
   m_pendingInterest = m_face.expressInterest(interest,
-    [=] (auto&&... args) { handleData(std::forward<decltype(args)>(args)..., self); },
-    [=] (auto&&... args) { handleNack(std::forward<decltype(args)>(args)..., self); },
-    [=] (auto&&... args) { handleTimeout(std::forward<decltype(args)>(args)..., self); });
+    [this, self] (auto&&... args) { handleData(std::forward<decltype(args)>(args)..., self); },
+    [this, self] (auto&&... args) { handleNack(std::forward<decltype(args)>(args)..., self); },
+    [this, self] (auto&&... args) { handleTimeout(std::forward<decltype(args)>(args)..., self); });
 }
 
 void
 DataFetcher::handleData(const Interest& interest, const Data& data,
-                        const shared_ptr<DataFetcher>& self)
+                        const std::shared_ptr<DataFetcher>& self)
 {
   if (!isRunning())
     return;
@@ -94,7 +97,7 @@
 
 void
 DataFetcher::handleNack(const Interest& interest, const lp::Nack& nack,
-                        const shared_ptr<DataFetcher>& self)
+                        const std::shared_ptr<DataFetcher>& self)
 {
   if (!isRunning())
     return;
@@ -123,7 +126,9 @@
         else {
           m_nCongestionRetries++;
         }
-        m_scheduler.schedule(backoffTime, [=] { expressInterest(newInterest, self); });
+        m_scheduler.schedule(backoffTime, [this, newInterest, self] {
+          expressInterest(newInterest, self);
+        });
         break;
       }
       default: {
@@ -144,7 +149,7 @@
 }
 
 void
-DataFetcher::handleTimeout(const Interest& interest, const shared_ptr<DataFetcher>& self)
+DataFetcher::handleTimeout(const Interest& interest, const std::shared_ptr<DataFetcher>& self)
 {
   if (!isRunning())
     return;
diff --git a/tools/chunks/catchunks/data-fetcher.hpp b/tools/chunks/catchunks/data-fetcher.hpp
index c51d577..765963d 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-2022, Regents of the University of California,
+ * Copyright (c) 2016-2024, Regents of the University of California,
  *                          Colorado State University,
  *                          University Pierre & Marie Curie, Sorbonne University.
  *
@@ -29,6 +29,11 @@
 
 #include "core/common.hpp"
 
+#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/util/scheduler.hpp>
+
+#include <functional>
+
 namespace ndn::chunks {
 
 /**
@@ -66,7 +71,7 @@
    *
    * @param onData callback for segment correctly received, must not be empty
    */
-  static shared_ptr<DataFetcher>
+  static std::shared_ptr<DataFetcher>
   fetch(Face& face, const Interest& interest, int maxNackRetries, int maxTimeoutRetries,
         DataCallback onData, FailureCallback onTimeout, FailureCallback onNack,
         bool isVerbose);
@@ -95,16 +100,16 @@
               bool isVerbose);
 
   void
-  expressInterest(const Interest& interest, const shared_ptr<DataFetcher>& self);
+  expressInterest(const Interest& interest, const std::shared_ptr<DataFetcher>& self);
 
   void
-  handleData(const Interest& interest, const Data& data, const shared_ptr<DataFetcher>& self);
+  handleData(const Interest& interest, const Data& data, const std::shared_ptr<DataFetcher>& self);
 
   void
-  handleNack(const Interest& interest, const lp::Nack& nack, const shared_ptr<DataFetcher>& self);
+  handleNack(const Interest& interest, const lp::Nack& nack, const std::shared_ptr<DataFetcher>& self);
 
   void
-  handleTimeout(const Interest& interest, const shared_ptr<DataFetcher>& self);
+  handleTimeout(const Interest& interest, const std::shared_ptr<DataFetcher>& self);
 
 private:
   Face& m_face;
diff --git a/tools/chunks/catchunks/discover-version.cpp b/tools/chunks/catchunks/discover-version.cpp
index 5eae250..3e75850 100644
--- a/tools/chunks/catchunks/discover-version.cpp
+++ b/tools/chunks/catchunks/discover-version.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2016-2022, Regents of the University of California,
+ * Copyright (c) 2016-2024, Regents of the University of California,
  *                          Colorado State University,
  *                          University Pierre & Marie Curie, Sorbonne University.
  *
@@ -31,6 +31,8 @@
 
 #include <ndn-cxx/metadata-object.hpp>
 
+#include <iostream>
+
 namespace ndn::chunks {
 
 DiscoverVersion::DiscoverVersion(Face& face, const Name& prefix, const Options& options)
diff --git a/tools/chunks/catchunks/discover-version.hpp b/tools/chunks/catchunks/discover-version.hpp
index 3f6620e..1098d85 100644
--- a/tools/chunks/catchunks/discover-version.hpp
+++ b/tools/chunks/catchunks/discover-version.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2016-2023, Regents of the University of California,
+ * Copyright (c) 2016-2024, Regents of the University of California,
  *                          Colorado State University,
  *                          University Pierre & Marie Curie, Sorbonne University.
  *
@@ -31,6 +31,7 @@
 
 #include "options.hpp"
 
+#include <ndn-cxx/face.hpp>
 #include <ndn-cxx/util/signal.hpp>
 
 namespace ndn::chunks {
@@ -69,7 +70,7 @@
   Face& m_face;
   const Name m_prefix;
   const Options& m_options;
-  shared_ptr<DataFetcher> m_fetcher;
+  std::shared_ptr<DataFetcher> m_fetcher;
 };
 
 } // namespace ndn::chunks
diff --git a/tools/chunks/catchunks/main.cpp b/tools/chunks/catchunks/main.cpp
index e89d904..6c763a9 100644
--- a/tools/chunks/catchunks/main.cpp
+++ b/tools/chunks/catchunks/main.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2016-2022, Regents of the University of California,
+ * Copyright (c) 2016-2024, Regents of the University of California,
  *                          Colorado State University,
  *                          University Pierre & Marie Curie, Sorbonne University.
  *
@@ -37,7 +37,6 @@
 #include "statistics-collector.hpp"
 #include "core/version.hpp"
 
-#include <fstream>
 #include <ndn-cxx/security/validator-null.hpp>
 #include <ndn-cxx/util/rtt-estimator.hpp>
 
@@ -45,6 +44,9 @@
 #include <boost/program_options/parsers.hpp>
 #include <boost/program_options/variables_map.hpp>
 
+#include <fstream>
+#include <iostream>
+
 namespace ndn::chunks {
 
 namespace po = boost::program_options;
@@ -57,7 +59,7 @@
   Options options;
   std::string prefix, nameConv, pipelineType("cubic");
   std::string cwndPath, rttPath;
-  auto rttEstOptions = make_shared<util::RttEstimator::Options>();
+  auto rttEstOptions = std::make_shared<util::RttEstimator::Options>();
   rttEstOptions->k = 8; // increased from the ndn-cxx default of 4
 
   po::options_description basicDesc("Basic Options");
@@ -229,15 +231,15 @@
 
   try {
     Face face;
-    auto discover = make_unique<DiscoverVersion>(face, Name(prefix), options);
-    unique_ptr<PipelineInterests> pipeline;
-    unique_ptr<StatisticsCollector> statsCollector;
-    unique_ptr<RttEstimatorWithStats> rttEstimator;
+    auto discover = std::make_unique<DiscoverVersion>(face, Name(prefix), options);
+    std::unique_ptr<PipelineInterests> pipeline;
+    std::unique_ptr<StatisticsCollector> statsCollector;
+    std::unique_ptr<RttEstimatorWithStats> rttEstimator;
     std::ofstream statsFileCwnd;
     std::ofstream statsFileRtt;
 
     if (pipelineType == "fixed") {
-      pipeline = make_unique<PipelineInterestsFixed>(face, options);
+      pipeline = std::make_unique<PipelineInterestsFixed>(face, options);
     }
     else if (pipelineType == "aimd" || pipelineType == "cubic") {
       if (options.isVerbose) {
@@ -251,14 +253,14 @@
                   << "\tMax RTO = " << duration_cast<milliseconds>(rttEstOptions->maxRto) << "\n"
                   << "\tBackoff multiplier = " << rttEstOptions->rtoBackoffMultiplier << "\n";
       }
-      rttEstimator = make_unique<RttEstimatorWithStats>(std::move(rttEstOptions));
+      rttEstimator = std::make_unique<RttEstimatorWithStats>(std::move(rttEstOptions));
 
-      unique_ptr<PipelineInterestsAdaptive> adaptivePipeline;
+      std::unique_ptr<PipelineInterestsAdaptive> adaptivePipeline;
       if (pipelineType == "aimd") {
-        adaptivePipeline = make_unique<PipelineInterestsAimd>(face, *rttEstimator, options);
+        adaptivePipeline = std::make_unique<PipelineInterestsAimd>(face, *rttEstimator, options);
       }
       else {
-        adaptivePipeline = make_unique<PipelineInterestsCubic>(face, *rttEstimator, options);
+        adaptivePipeline = std::make_unique<PipelineInterestsCubic>(face, *rttEstimator, options);
       }
 
       if (!cwndPath.empty() || !rttPath.empty()) {
@@ -276,7 +278,7 @@
             return 4;
           }
         }
-        statsCollector = make_unique<StatisticsCollector>(*adaptivePipeline, statsFileCwnd, statsFileRtt);
+        statsCollector = std::make_unique<StatisticsCollector>(*adaptivePipeline, statsFileCwnd, statsFileRtt);
       }
 
       pipeline = std::move(adaptivePipeline);
diff --git a/tools/chunks/catchunks/options.hpp b/tools/chunks/catchunks/options.hpp
index c93e9c2..d21481a 100644
--- a/tools/chunks/catchunks/options.hpp
+++ b/tools/chunks/catchunks/options.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2016-2022, Regents of the University of California,
+ * Copyright (c) 2016-2024, Regents of the University of California,
  *                          Colorado State University,
  *                          University Pierre & Marie Curie, Sorbonne University.
  *
@@ -27,11 +27,14 @@
 #ifndef NDN_TOOLS_CHUNKS_CATCHUNKS_OPTIONS_HPP
 #define NDN_TOOLS_CHUNKS_CATCHUNKS_OPTIONS_HPP
 
-#include "core/common.hpp"
+#include <ndn-cxx/interest.hpp>
+#include <ndn-cxx/util/time.hpp>
+
+#include <limits>
 
 namespace ndn::chunks {
 
-struct Options : noncopyable
+struct Options
 {
   // Common options
   time::milliseconds interestLifetime = DEFAULT_INTEREST_LIFETIME;
diff --git a/tools/chunks/catchunks/pipeline-interests-adaptive.cpp b/tools/chunks/catchunks/pipeline-interests-adaptive.cpp
index 78c4c6e..492229f 100644
--- a/tools/chunks/catchunks/pipeline-interests-adaptive.cpp
+++ b/tools/chunks/catchunks/pipeline-interests-adaptive.cpp
@@ -29,7 +29,9 @@
 #include "pipeline-interests-adaptive.hpp"
 #include "data-fetcher.hpp"
 
+#include <boost/lexical_cast.hpp>
 #include <iomanip>
+#include <iostream>
 
 namespace ndn::chunks {
 
diff --git a/tools/chunks/catchunks/pipeline-interests-adaptive.hpp b/tools/chunks/catchunks/pipeline-interests-adaptive.hpp
index 28e6207..572418f 100644
--- a/tools/chunks/catchunks/pipeline-interests-adaptive.hpp
+++ b/tools/chunks/catchunks/pipeline-interests-adaptive.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2016-2023, Regents of the University of California,
+ * Copyright (c) 2016-2024, Regents of the University of California,
  *                          Colorado State University,
  *                          University Pierre & Marie Curie, Sorbonne University.
  *
@@ -32,6 +32,7 @@
 #include "pipeline-interests.hpp"
 
 #include <ndn-cxx/util/rtt-estimator.hpp>
+#include <ndn-cxx/util/scheduler.hpp>
 #include <ndn-cxx/util/signal.hpp>
 
 #include <queue>
diff --git a/tools/chunks/catchunks/pipeline-interests-cubic.cpp b/tools/chunks/catchunks/pipeline-interests-cubic.cpp
index 5eaf411..7fa57a5 100644
--- a/tools/chunks/catchunks/pipeline-interests-cubic.cpp
+++ b/tools/chunks/catchunks/pipeline-interests-cubic.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2016-2022, Regents of the University of California,
+ * Copyright (c) 2016-2024, Regents of the University of California,
  *                          Colorado State University,
  *                          University Pierre & Marie Curie, Sorbonne University.
  *
@@ -26,6 +26,7 @@
 #include "pipeline-interests-cubic.hpp"
 
 #include <cmath>
+#include <iostream>
 
 namespace ndn::chunks {
 
diff --git a/tools/chunks/catchunks/pipeline-interests-fixed.cpp b/tools/chunks/catchunks/pipeline-interests-fixed.cpp
index bd2559f..9e8ffa1 100644
--- a/tools/chunks/catchunks/pipeline-interests-fixed.cpp
+++ b/tools/chunks/catchunks/pipeline-interests-fixed.cpp
@@ -30,6 +30,8 @@
 #include "pipeline-interests-fixed.hpp"
 #include "data-fetcher.hpp"
 
+#include <iostream>
+
 namespace ndn::chunks {
 
 PipelineInterestsFixed::PipelineInterestsFixed(Face& face, const Options& opts)
@@ -88,13 +90,13 @@
   auto fetcher = DataFetcher::fetch(m_face, interest,
                                     m_options.maxRetriesOnTimeoutOrNack,
                                     m_options.maxRetriesOnTimeoutOrNack,
-                                    [=] (const auto& interest, const auto& data) {
+                                    [this, pipeNo] (const auto& interest, const auto& data) {
                                       handleData(interest, data, pipeNo);
                                     },
-                                    [=] (const auto&, const auto& reason) {
+                                    [this, pipeNo] (const auto&, const auto& reason) {
                                       handleFail(reason, pipeNo);
                                     },
-                                    [=] (const auto&, const auto& reason) {
+                                    [this, pipeNo] (const auto&, const auto& reason) {
                                       handleFail(reason, pipeNo);
                                     },
                                     m_options.isVerbose);
diff --git a/tools/chunks/catchunks/pipeline-interests-fixed.hpp b/tools/chunks/catchunks/pipeline-interests-fixed.hpp
index a317ad2..8e9e3ce 100644
--- a/tools/chunks/catchunks/pipeline-interests-fixed.hpp
+++ b/tools/chunks/catchunks/pipeline-interests-fixed.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2016-2022,  Regents of the University of California,
+ * Copyright (c) 2016-2024,  Regents of the University of California,
  *                           Colorado State University,
  *                           University Pierre & Marie Curie, Sorbonne University.
  *
@@ -32,6 +32,8 @@
 
 #include "pipeline-interests.hpp"
 
+#include <vector>
+
 namespace ndn::chunks {
 
 class DataFetcher;
@@ -81,7 +83,7 @@
   handleFail(const std::string& reason, size_t pipeNo);
 
 private:
-  std::vector<std::pair<shared_ptr<DataFetcher>, uint64_t>> m_segmentFetchers;
+  std::vector<std::pair<std::shared_ptr<DataFetcher>, uint64_t>> m_segmentFetchers;
 
   /**
    * true if one or more segment fetchers encountered an error; if m_hasFinalBlockId
diff --git a/tools/chunks/catchunks/pipeline-interests.cpp b/tools/chunks/catchunks/pipeline-interests.cpp
index 04d7fba..2e29487 100644
--- a/tools/chunks/catchunks/pipeline-interests.cpp
+++ b/tools/chunks/catchunks/pipeline-interests.cpp
@@ -34,6 +34,8 @@
 #include <boost/asio/io_context.hpp>
 #include <boost/asio/post.hpp>
 
+#include <iostream>
+
 namespace ndn::chunks {
 
 PipelineInterests::PipelineInterests(Face& face, const Options& opts)
diff --git a/tools/chunks/catchunks/pipeline-interests.hpp b/tools/chunks/catchunks/pipeline-interests.hpp
index ea52d2f..2757b21 100644
--- a/tools/chunks/catchunks/pipeline-interests.hpp
+++ b/tools/chunks/catchunks/pipeline-interests.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2016-2022, Regents of the University of California,
+ * Copyright (c) 2016-2024, Regents of the University of California,
  *                          Colorado State University,
  *                          University Pierre & Marie Curie, Sorbonne University.
  *
@@ -31,8 +31,13 @@
 #ifndef NDN_TOOLS_CHUNKS_CATCHUNKS_PIPELINE_INTERESTS_HPP
 #define NDN_TOOLS_CHUNKS_CATCHUNKS_PIPELINE_INTERESTS_HPP
 
+#include "core/common.hpp"
 #include "options.hpp"
 
+#include <ndn-cxx/face.hpp>
+
+#include <functional>
+
 namespace ndn::chunks {
 
 /**