Avoid deprecated Boost.Asio interfaces

Change-Id: I7041c89ea9147e08c8b6226b84a6d17dddeed0e1
diff --git a/.waf-tools/default-compiler-flags.py b/.waf-tools/default-compiler-flags.py
index 7746db9..4e09a82 100644
--- a/.waf-tools/default-compiler-flags.py
+++ b/.waf-tools/default-compiler-flags.py
@@ -128,7 +128,11 @@
 
     def getGeneralFlags(self, conf):
         """Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are always needed"""
-        return {'CXXFLAGS': [], 'LINKFLAGS': [], 'DEFINES': []}
+        return {
+            'CXXFLAGS': [],
+            'LINKFLAGS': [],
+            'DEFINES': ['BOOST_ASIO_NO_DEPRECATED', 'BOOST_FILESYSTEM_NO_DEPRECATED'],
+        }
 
     def getDebugFlags(self, conf):
         """Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are needed only in debug mode"""
diff --git a/examples/data-producer.cpp b/examples/data-producer.cpp
index 2a23e9c..c564671 100644
--- a/examples/data-producer.cpp
+++ b/examples/data-producer.cpp
@@ -87,7 +87,7 @@
 
 private:
   ndn::Face m_face;
-  ndn::Scheduler m_scheduler{m_face.getIoService()};
+  ndn::Scheduler m_scheduler{m_face.getIoContext()};
   std::uniform_int_distribution<> m_randomDist{200, 1000};
 };
 
@@ -118,7 +118,7 @@
 Publisher::generateFromFile()
 {
   if (insertStream.eof()) {
-    m_face.getIoService().stop();
+    m_face.getIoContext().stop();
     return;
   }
 
diff --git a/src/handles/tcp-bulk-insert-handle.cpp b/src/handles/tcp-bulk-insert-handle.cpp
index 2713d03..cd26334 100644
--- a/src/handles/tcp-bulk-insert-handle.cpp
+++ b/src/handles/tcp-bulk-insert-handle.cpp
@@ -28,40 +28,39 @@
 namespace ip = boost::asio::ip;
 
 namespace repo {
-namespace detail {
+namespace {
 
 class TcpBulkInsertClient : noncopyable
 {
 public:
-  TcpBulkInsertClient(TcpBulkInsertHandle& writer, std::shared_ptr<ip::tcp::socket> socket)
+  TcpBulkInsertClient(TcpBulkInsertHandle& writer, ip::tcp::socket socket)
     : m_writer(writer)
     , m_socket(std::move(socket))
   {
   }
 
   static void
-  startReceive(TcpBulkInsertHandle& writer, std::shared_ptr<ip::tcp::socket> socket)
+  startReceive(TcpBulkInsertHandle& writer, ip::tcp::socket socket)
   {
     auto client = std::make_shared<TcpBulkInsertClient>(writer, std::move(socket));
-    client->m_socket->async_receive(
+    client->m_socket.async_receive(
       boost::asio::buffer(client->m_inputBuffer, ndn::MAX_NDN_PACKET_SIZE), 0,
       std::bind(&TcpBulkInsertClient::handleReceive, client, _1, _2, client));
   }
 
 private:
   void
-  handleReceive(const boost::system::error_code& error,
-                std::size_t nBytesReceived,
+  handleReceive(const boost::system::error_code& error, std::size_t nBytesReceived,
                 const std::shared_ptr<TcpBulkInsertClient>& client);
 
 private:
   TcpBulkInsertHandle& m_writer;
-  std::shared_ptr<ip::tcp::socket> m_socket;
+  ip::tcp::socket m_socket;
   uint8_t m_inputBuffer[ndn::MAX_NDN_PACKET_SIZE];
   std::size_t m_inputBufferSize = 0;
 };
 
-} // namespace detail
+} // namespace
 
 TcpBulkInsertHandle::TcpBulkInsertHandle(boost::asio::io_context& io,
                                          RepoStorage& storageHandle)
@@ -74,14 +73,12 @@
 TcpBulkInsertHandle::listen(const std::string& host, const std::string& port)
 {
   ip::tcp::resolver resolver(m_acceptor.get_executor());
-  ip::tcp::resolver::query query(host, port);
+  boost::system::error_code ec;
+  auto results = resolver.resolve(host, port, ec);
+  if (ec)
+    NDN_THROW(Error("Cannot resolve " + host + ":" + port + " (" + ec.message() + ")"));
 
-  ip::tcp::resolver::iterator endpoint = resolver.resolve(query);
-  ip::tcp::resolver::iterator end;
-  if (endpoint == end)
-    NDN_THROW(Error("Cannot listen on " + host + " port " + port));
-
-  m_localEndpoint = *endpoint;
+  m_localEndpoint = *results.begin();
   NDN_LOG_DEBUG("Start listening on " << m_localEndpoint);
 
   m_acceptor.open(m_localEndpoint.protocol());
@@ -105,39 +102,31 @@
 void
 TcpBulkInsertHandle::asyncAccept()
 {
-  auto clientSocket = std::make_shared<ip::tcp::socket>(m_acceptor.get_executor());
-  m_acceptor.async_accept(*clientSocket,
-                          std::bind(&TcpBulkInsertHandle::handleAccept, this, _1, clientSocket));
+  m_acceptor.async_accept([this] (const auto& error, ip::tcp::socket socket) {
+    if (error) {
+      return;
+    }
+
+    NDN_LOG_DEBUG("New connection from " << socket.remote_endpoint());
+    TcpBulkInsertClient::startReceive(*this, std::move(socket));
+
+    // prepare accepting the next connection
+    asyncAccept();
+  });
 }
 
 void
-TcpBulkInsertHandle::handleAccept(const boost::system::error_code& error,
-                                  const std::shared_ptr<ip::tcp::socket>& socket)
+TcpBulkInsertClient::handleReceive(const boost::system::error_code& error,
+                                   std::size_t nBytesReceived,
+                                   const std::shared_ptr<TcpBulkInsertClient>& client)
 {
   if (error) {
-    return;
-  }
-
-  NDN_LOG_DEBUG("New connection from " << socket->remote_endpoint());
-
-  detail::TcpBulkInsertClient::startReceive(*this, socket);
-
-  // prepare accepting the next connection
-  asyncAccept();
-}
-
-void
-detail::TcpBulkInsertClient::handleReceive(const boost::system::error_code& error,
-                                           std::size_t nBytesReceived,
-                                           const std::shared_ptr<detail::TcpBulkInsertClient>& client)
-{
-  if (error) {
-    if (error == boost::system::errc::operation_canceled) // when socket is closed by someone
+    if (error == boost::asio::error::operation_aborted) // when socket is closed by someone
       return;
 
     boost::system::error_code ec;
-    m_socket->shutdown(ip::tcp::socket::shutdown_both, ec);
-    m_socket->close(ec);
+    m_socket.shutdown(ip::tcp::socket::shutdown_both, ec);
+    m_socket.close(ec);
     return;
   }
 
@@ -175,8 +164,8 @@
 
   if (!isOk && m_inputBufferSize == ndn::MAX_NDN_PACKET_SIZE && offset == 0) {
     boost::system::error_code ec;
-    m_socket->shutdown(ip::tcp::socket::shutdown_both, ec);
-    m_socket->close(ec);
+    m_socket.shutdown(ip::tcp::socket::shutdown_both, ec);
+    m_socket.close(ec);
     return;
   }
 
@@ -190,9 +179,9 @@
     }
   }
 
-  m_socket->async_receive(boost::asio::buffer(m_inputBuffer + m_inputBufferSize,
-                                              ndn::MAX_NDN_PACKET_SIZE - m_inputBufferSize), 0,
-                          std::bind(&TcpBulkInsertClient::handleReceive, this, _1, _2, client));
+  m_socket.async_receive(boost::asio::buffer(m_inputBuffer + m_inputBufferSize,
+                                             ndn::MAX_NDN_PACKET_SIZE - m_inputBufferSize), 0,
+                         std::bind(&TcpBulkInsertClient::handleReceive, this, _1, _2, client));
 }
 
 } // namespace repo
diff --git a/src/handles/tcp-bulk-insert-handle.hpp b/src/handles/tcp-bulk-insert-handle.hpp
index a0a8e7a..ab1ade7 100644
--- a/src/handles/tcp-bulk-insert-handle.hpp
+++ b/src/handles/tcp-bulk-insert-handle.hpp
@@ -55,10 +55,6 @@
   void
   asyncAccept();
 
-  void
-  handleAccept(const boost::system::error_code& error,
-               const std::shared_ptr<boost::asio::ip::tcp::socket>& socket);
-
 private:
   boost::asio::ip::tcp::acceptor m_acceptor;
   boost::asio::ip::tcp::endpoint m_localEndpoint;
diff --git a/tests/integrated/command-fixture.cpp b/tests/integrated/command-fixture.cpp
deleted file mode 100644
index 28990e3..0000000
--- a/tests/integrated/command-fixture.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2022, Regents of the University of California.
- *
- * This file is part of NDN repo-ng (Next generation of NDN repository).
- * See AUTHORS.md for complete list of repo-ng authors and contributors.
- *
- * repo-ng is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE.  See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * repo-ng, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "command-fixture.hpp"
-
-namespace repo::tests {
-
-CommandFixture::CommandFixture()
-  : scheduler(repoFace.getIoService())
-  , keyChain(m_keyChain)
-  , dispatcher(repoFace, keyChain)
-  , validator(repoFace)
-{
-  this->addIdentity("/ndn/test/repo");
-  this->saveIdentityCertificate("/ndn/test/repo", "tests/integrated/insert-delete-test.cert");
-  validator.load("tests/integrated/insert-delete-validator-config.conf");
-}
-
-} // namespace repo::tests
diff --git a/tests/integrated/command-fixture.hpp b/tests/integrated/command-fixture.hpp
index 6d4aa44..507a9f1 100644
--- a/tests/integrated/command-fixture.hpp
+++ b/tests/integrated/command-fixture.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2022, Regents of the University of California.
+ * Copyright (c) 2014-2023, Regents of the University of California.
  *
  * This file is part of NDN repo-ng (Next generation of NDN repository).
  * See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -30,15 +30,19 @@
 class CommandFixture : public virtual IdentityManagementFixture
 {
 protected:
-  CommandFixture();
+  CommandFixture()
+  {
+    addIdentity("/ndn/test/repo");
+    saveIdentityCertificate("/ndn/test/repo", "tests/integrated/insert-delete-test.cert");
+    validator.load("tests/integrated/insert-delete-validator-config.conf");
+  }
 
 protected:
   Face repoFace;
-  Scheduler scheduler;
-  ndn::KeyChain& keyChain;
-  ndn::mgmt::Dispatcher dispatcher;
+  Scheduler scheduler{repoFace.getIoContext()};
+  ndn::mgmt::Dispatcher dispatcher{repoFace, m_keyChain};
   /// \todo #4091 switch to ValidatorPolicyConf and load insert-delete-validator-config.conf
-  ndn::security::ValidatorConfig validator;
+  ndn::security::ValidatorConfig validator{repoFace};
 };
 
 } // namespace repo::tests
diff --git a/tests/integrated/test-basic-command-insert-delete.cpp b/tests/integrated/test-basic-command-insert-delete.cpp
index 0f868eb..f1a9110 100644
--- a/tests/integrated/test-basic-command-insert-delete.cpp
+++ b/tests/integrated/test-basic-command-insert-delete.cpp
@@ -50,9 +50,9 @@
   Fixture()
     : writeHandle(repoFace, *handle, dispatcher, scheduler, validator)
     , deleteHandle(repoFace, *handle, dispatcher, scheduler, validator)
-    , insertFace(repoFace.getIoService())
-    , deleteFace(repoFace.getIoService())
-    , signer(keyChain)
+    , insertFace(repoFace.getIoContext())
+    , deleteFace(repoFace.getIoContext())
+    , signer(m_keyChain)
   {
     Name cmdPrefix("/repo/command");
     repoFace.registerPrefix(cmdPrefix, nullptr,
@@ -114,11 +114,11 @@
 void
 Fixture<T>::onInsertInterest(const Interest& interest)
 {
-  Data data(Name(interest.getName()));
+  Data data(interest.getName());
   data.setContent(CONTENT);
-  data.setFreshnessPeriod(0_ms);
-  keyChain.sign(data);
+  m_keyChain.sign(data);
   insertFace.put(data);
+
   auto eventIt = insertEvents.find(interest.getName());
   if (eventIt != insertEvents.end()) {
     eventIt->second.cancel();
diff --git a/tests/integrated/test-basic-interest-read.cpp b/tests/integrated/test-basic-interest-read.cpp
index 81ceb98..c2b6a17 100644
--- a/tests/integrated/test-basic-interest-read.cpp
+++ b/tests/integrated/test-basic-interest-read.cpp
@@ -38,15 +38,15 @@
 {
 public:
   BasicInterestReadFixture()
-    : scheduler(repoFace.getIoService())
+    : scheduler(repoFace.getIoContext())
     , readHandle(repoFace, *handle, 0)
-    , readFace(repoFace.getIoService())
+    , readFace(repoFace.getIoContext())
   {
   }
 
   ~BasicInterestReadFixture()
   {
-    repoFace.getIoService().stop();
+    repoFace.getIoContext().stop();
   }
 
   void
diff --git a/tests/unit/read-handle.t.cpp b/tests/unit/read-handle.t.cpp
index 9d36b18..553f651 100644
--- a/tests/unit/read-handle.t.cpp
+++ b/tests/unit/read-handle.t.cpp
@@ -44,7 +44,7 @@
 public:
   Fixture()
     : face({true, true})
-    , scheduler(face.getIoService())
+    , scheduler(face.getIoContext())
     , subsetLength(1)
     , dataPrefix("/ndn/test/prefix")
     , identity("/ndn/test/identity")
diff --git a/tests/unit/tcp-bulk-insert-handle.cpp b/tests/unit/tcp-bulk-insert-handle.cpp
index 9c0398b..e227167 100644
--- a/tests/unit/tcp-bulk-insert-handle.cpp
+++ b/tests/unit/tcp-bulk-insert-handle.cpp
@@ -18,10 +18,11 @@
  */
 
 #include "handles/tcp-bulk-insert-handle.hpp"
-#include "storage/sqlite-storage.hpp"
+
 #include "../repo-storage-fixture.hpp"
 #include "../dataset-fixtures.hpp"
 
+#include <boost/asio/ip/tcp.hpp>
 #include <boost/test/unit_test.hpp>
 
 namespace repo::tests {
@@ -34,28 +35,21 @@
   void
   start(const std::string& host, const std::string& port)
   {
-    using namespace boost::asio;
-
-    ip::tcp::resolver resolver(ioCtx);
-    ip::tcp::resolver::query query(host, port);
-
-    ip::tcp::resolver::iterator endpoint = resolver.resolve(query);
-    ip::tcp::resolver::iterator end;
-
-    if (endpoint == end)
+    boost::asio::ip::tcp::resolver resolver(ioCtx);
+    boost::system::error_code ec;
+    auto results = resolver.resolve(host, port, ec);
+    if (ec) {
       BOOST_FAIL("Cannot resolve [" + host + ":" + port + "]");
+    }
 
-    ip::tcp::endpoint serverEndpoint = *endpoint;
-
-    socket.async_connect(serverEndpoint,
-                         std::bind(&TcpClient::onSuccessfullConnect, this, _1));
+    socket.async_connect(*results.begin(), std::bind(&TcpClient::handleConnect, this, _1));
   }
 
   virtual void
-  onSuccessfullConnect(const boost::system::error_code& error)
+  handleConnect(const boost::system::error_code& error)
   {
     if (error) {
-      BOOST_FAIL("TCP connection aborted");
+      BOOST_FAIL("TCP connection failed");
     }
   }
 
@@ -78,9 +72,9 @@
   }
 
   void
-  onSuccessfullConnect(const boost::system::error_code& error) override
+  handleConnect(const boost::system::error_code& error) override
   {
-    TcpClient::onSuccessfullConnect(error);
+    TcpClient::handleConnect(error);
 
     // This value may need to be adjusted if some dataset exceeds 100k
     socket.set_option(boost::asio::socket_base::send_buffer_size(100000));
diff --git a/tools/ndnputfile.cpp b/tools/ndnputfile.cpp
index 04e85ee..b011c71 100644
--- a/tools/ndnputfile.cpp
+++ b/tools/ndnputfile.cpp
@@ -72,7 +72,7 @@
     , timeout(0)
     , insertStream(nullptr)
     , isVerbose(false)
-    , m_scheduler(m_face.getIoService())
+    , m_scheduler(m_face.getIoContext())
     , m_timestampVersion(toUnixTimestamp(system_clock::now()).count())
     , m_processId(0)
     , m_checkPeriod(DEFAULT_CHECK_PERIOD)
@@ -111,9 +111,6 @@
   onRegisterFailed(const ndn::Name& prefix, const std::string& reason);
 
   void
-  stopProcess();
-
-  void
   signData(ndn::Data& data);
 
   void
@@ -222,7 +219,7 @@
                            bind(&NdnPutFile::onRegisterFailed, this, _1, _2));
 
   if (hasTimeout)
-    m_scheduler.schedule(timeout, [this] { stopProcess(); });
+    m_scheduler.schedule(timeout, [this] { m_face.getIoContext().stop(); });
 
   m_face.processEvents();
 }
@@ -349,12 +346,6 @@
 }
 
 void
-NdnPutFile::stopProcess()
-{
-  m_face.getIoService().stop();
-}
-
-void
 NdnPutFile::signData(ndn::Data& data)
 {
   if (useDigestSha256) {
@@ -393,7 +384,7 @@
 
     if (isSingle) {
       if (insertCount == 1) {
-        m_face.getIoService().stop();
+        m_face.getIoContext().stop();
         return;
       }
     }
@@ -401,7 +392,7 @@
     // write operation has been finished
 
     if (insertCount == m_currentSegmentNo) {
-      m_face.getIoService().stop();
+      m_face.getIoContext().stop();
       return;
     }
   }