[ndnSIM] More intrusive changes removing use of boost::asio::io_service
Use of either removed or replaced with defunct DummyIoService for API
compatibility.
Change-Id: I9f99a944bf5cd082180e3f0ebccf977d5bf73f26
diff --git a/ndn-cxx/detail/asio-fwd.hpp b/ndn-cxx/detail/asio-fwd.hpp
index b90d23b..0234952 100644
--- a/ndn-cxx/detail/asio-fwd.hpp
+++ b/ndn-cxx/detail/asio-fwd.hpp
@@ -22,19 +22,13 @@
#ifndef NDN_CXX_DETAIL_ASIO_FWD_HPP
#define NDN_CXX_DETAIL_ASIO_FWD_HPP
-#include <boost/version.hpp>
+namespace ndn {
-namespace boost {
-namespace asio {
+class DummyIoService
+{
+public:
+};
-#if BOOST_VERSION >= 106600
-class io_context;
-using io_service = io_context;
-#else
-class io_service;
-#endif // BOOST_VERSION >= 106600
-
-} // namespace asio
-} // namespace boost
+} // namespace ndn
#endif // NDN_CXX_DETAIL_ASIO_FWD_HPP
diff --git a/ndn-cxx/face.cpp b/ndn-cxx/face.cpp
index da37615..379cac9 100644
--- a/ndn-cxx/face.cpp
+++ b/ndn-cxx/face.cpp
@@ -41,7 +41,7 @@
#define IO_CAPTURE_WEAK_IMPL(OP) \
{ \
weak_ptr<Impl> implWeak(m_impl); \
- m_impl->m_scheduler.scheduleEvent(time::seconds(0), [=] { \
+ m_impl->m_scheduler.schedule(time::seconds(0), [=] { \
auto impl = implWeak.lock(); \
if (impl != nullptr) {
#define IO_CAPTURE_WEAK_IMPL_END \
@@ -61,27 +61,17 @@
{
}
-Face::Face(shared_ptr<Transport> transport)
-{
- construct(std::move(transport), ns3::ndn::StackHelper::getKeyChain());
-}
-
-Face::Face(boost::asio::io_service& ioService)
+Face::Face(DummyIoService& ioService)
{
construct(nullptr, ns3::ndn::StackHelper::getKeyChain());
}
-Face::Face(shared_ptr<Transport> transport, KeyChain& keyChain)
-{
- construct(std::move(transport), keyChain);
-}
-
-Face::Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService)
+Face::Face(shared_ptr<Transport> transport)
{
construct(transport, ns3::ndn::StackHelper::getKeyChain());
}
-Face::Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService, KeyChain& keyChain)
+Face::Face(shared_ptr<Transport> transport, KeyChain& keyChain)
{
construct(std::move(transport), keyChain);
}
diff --git a/ndn-cxx/face.hpp b/ndn-cxx/face.hpp
index 3fa5209..b52a287 100644
--- a/ndn-cxx/face.hpp
+++ b/ndn-cxx/face.hpp
@@ -160,7 +160,7 @@
* @throw ConfigFile::Error the configuration file cannot be parsed or specifies an unsupported protocol
*/
explicit
- Face(boost::asio::io_service& ioService);
+ Face(DummyIoService& ioService);
/**
* @brief Create Face using given transport and KeyChain
@@ -176,37 +176,6 @@
*/
Face(shared_ptr<Transport> transport, KeyChain& keyChain);
- /**
- * @brief Create Face using given transport and io_service
- * @param transport the transport for lower layer communication. If nullptr,
- * a default transport will be used.
- * @param ioService the io_service that controls all IO operations
- *
- * @sa Face(boost::asio::io_service&)
- * @sa Face(shared_ptr<Transport>)
- *
- * @throw ConfigFile::Error @p transport is nullptr, and the configuration file cannot be
- * parsed or specifies an unsupported protocol
- * @note shared_ptr is passed by value because ownership is shared with this class
- */
- Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService);
-
- /**
- * @brief Create a new Face using given Transport and io_service
- * @param transport the transport for lower layer communication. If nullptr,
- * a default transport will be used.
- * @param ioService the io_service that controls all IO operations
- * @param keyChain the KeyChain to sign commands
- *
- * @sa Face(boost::asio::io_service&)
- * @sa Face(shared_ptr<Transport>, KeyChain&)
- *
- * @throw ConfigFile::Error @p transport is nullptr, and the configuration file cannot be
- * parsed or specifies an unsupported protocol
- * @note shared_ptr is passed by value because ownership is shared with this class
- */
- Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService, KeyChain& keyChain);
-
virtual
~Face();
@@ -410,10 +379,11 @@
/**
* @return Dereferenced nullptr (cannot use IoService in simulations), preserved for API compatibility
*/
- boost::asio::io_service&
+ DummyIoService&
getIoService()
{
- return *static_cast<boost::asio::io_service*>(nullptr);
+ static DummyIoService io;
+ return io;
}
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED:
diff --git a/ndn-cxx/impl/face-impl.hpp b/ndn-cxx/impl/face-impl.hpp
index 60f88a8..c463eee 100644
--- a/ndn-cxx/impl/face-impl.hpp
+++ b/ndn-cxx/impl/face-impl.hpp
@@ -65,18 +65,15 @@
, m_scheduler(m_face.getIoService())
, m_nfdController(m_face, keyChain)
{
- auto postOnEmptyPitOrNoRegisteredPrefixes = [this] {
- m_scheduler.scheduleEvent(time::seconds(0), bind(&Impl::onEmptyPitOrNoRegisteredPrefixes, this));
- // without this extra "post", transport can get paused (-async_read) and then resumed
+ auto onEmptyPitOrNoRegisteredPrefixes = [this] {
+ // Without this extra "post", transport can get paused (-async_read) and then resumed
// (+async_read) from within onInterest/onData callback. After onInterest/onData
// finishes, there is another +async_read with the same memory block. A few of such
// async_read duplications can cause various effects and result in segfault.
- m_face.getIoService().post([this] {
+ m_scheduler.schedule(time::seconds(0), [this] {
if (m_pendingInterestTable.empty() && m_registeredPrefixTable.empty()) {
m_face.m_transport->pause();
- if (!m_ioServiceWork) {
- m_processEventsTimeoutEvent.cancel();
- }
+ m_processEventsTimeoutEvent.cancel();
}
});
};
@@ -112,7 +109,7 @@
void
asyncRemovePendingInterest(detail::RecordId id)
{
- m_face.getIoService().post([id, w = weak_ptr<Impl>{shared_from_this()}] { // use weak_from_this() in C++17
+ m_scheduler.schedule(time::seconds(0), [id, w = weak_ptr<Impl>{shared_from_this()}] { // use weak_from_this() in C++17
auto impl = w.lock();
if (impl != nullptr) {
impl->m_pendingInterestTable.erase(id);
@@ -196,7 +193,7 @@
void
asyncUnsetInterestFilter(detail::RecordId id)
{
- m_face.getIoService().post([id, w = weak_ptr<Impl>{shared_from_this()}] { // use weak_from_this() in C++17
+ m_scheduler.schedule(time::seconds(0), [id, w = weak_ptr<Impl>{shared_from_this()}] { // use weak_from_this() in C++17
auto impl = w.lock();
if (impl != nullptr) {
impl->unsetInterestFilter(id);
@@ -293,7 +290,7 @@
const UnregisterPrefixSuccessCallback& onSuccess,
const UnregisterPrefixFailureCallback& onFailure)
{
- m_face.getIoService().post([=, w = weak_ptr<Impl>{shared_from_this()}] { // use weak_from_this() in C++17
+ m_scheduler.schedule(time::seconds(0), [=, w = weak_ptr<Impl>{shared_from_this()}] { // use weak_from_this() in C++17
auto impl = w.lock();
if (impl != nullptr) {
impl->unregisterPrefix(id, onSuccess, onFailure);
@@ -306,8 +303,7 @@
ensureConnected(bool wantResume)
{
if (!m_face.m_transport->isConnected()) {
- m_face.m_transport->connect(m_face.getIoService(),
- [this] (const Block& wire) { m_face.onReceiveElement(wire); });
+ m_face.m_transport->connect([this] (const Block& wire) { m_face.onReceiveElement(wire); });
}
if (wantResume && !m_face.m_transport->isReceiving()) {
@@ -316,14 +312,6 @@
}
void
- onEmptyPitOrNoRegisteredPrefixes()
- {
- if (m_pendingInterestTable.empty() && m_registeredPrefixTable.empty()) {
- m_face.m_transport->pause();
- }
- }
-
- void
shutdown()
{
m_pendingInterestTable.clear();
diff --git a/ndn-cxx/ims/in-memory-storage-fifo.cpp b/ndn-cxx/ims/in-memory-storage-fifo.cpp
index 976170b..fcbd35d 100644
--- a/ndn-cxx/ims/in-memory-storage-fifo.cpp
+++ b/ndn-cxx/ims/in-memory-storage-fifo.cpp
@@ -28,7 +28,7 @@
{
}
-InMemoryStorageFifo::InMemoryStorageFifo(boost::asio::io_service& ioService, size_t limit)
+InMemoryStorageFifo::InMemoryStorageFifo(DummyIoService& ioService, size_t limit)
: InMemoryStorage(ioService, limit)
{
}
diff --git a/ndn-cxx/ims/in-memory-storage-fifo.hpp b/ndn-cxx/ims/in-memory-storage-fifo.hpp
index 50e5cf9..1607ff0 100644
--- a/ndn-cxx/ims/in-memory-storage-fifo.hpp
+++ b/ndn-cxx/ims/in-memory-storage-fifo.hpp
@@ -39,7 +39,7 @@
InMemoryStorageFifo(size_t limit = 16);
explicit
- InMemoryStorageFifo(boost::asio::io_service& ioService, size_t limit = 16);
+ InMemoryStorageFifo(DummyIoService& ioService, size_t limit = 16);
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED:
/** @brief Removes one Data packet from in-memory storage based on FIFO
diff --git a/ndn-cxx/ims/in-memory-storage-lfu.cpp b/ndn-cxx/ims/in-memory-storage-lfu.cpp
index 2e5e333..b2de51e 100644
--- a/ndn-cxx/ims/in-memory-storage-lfu.cpp
+++ b/ndn-cxx/ims/in-memory-storage-lfu.cpp
@@ -28,7 +28,7 @@
{
}
-InMemoryStorageLfu::InMemoryStorageLfu(boost::asio::io_service& ioService, size_t limit)
+InMemoryStorageLfu::InMemoryStorageLfu(DummyIoService& ioService, size_t limit)
: InMemoryStorage(ioService, limit)
{
}
diff --git a/ndn-cxx/ims/in-memory-storage-lfu.hpp b/ndn-cxx/ims/in-memory-storage-lfu.hpp
index 6c6ebfb..7032be8 100644
--- a/ndn-cxx/ims/in-memory-storage-lfu.hpp
+++ b/ndn-cxx/ims/in-memory-storage-lfu.hpp
@@ -43,7 +43,7 @@
InMemoryStorageLfu(size_t limit = 16);
explicit
- InMemoryStorageLfu(boost::asio::io_service& ioService, size_t limit = 16);
+ InMemoryStorageLfu(DummyIoService& ioService, size_t limit = 16);
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED:
/** @brief Removes one Data packet from in-memory storage based on LFU, i.e. evict the least
diff --git a/ndn-cxx/ims/in-memory-storage-lru.cpp b/ndn-cxx/ims/in-memory-storage-lru.cpp
index f80f854..33a986f 100644
--- a/ndn-cxx/ims/in-memory-storage-lru.cpp
+++ b/ndn-cxx/ims/in-memory-storage-lru.cpp
@@ -28,7 +28,7 @@
{
}
-InMemoryStorageLru::InMemoryStorageLru(boost::asio::io_service& ioService,
+InMemoryStorageLru::InMemoryStorageLru(DummyIoService& ioService,
size_t limit)
: InMemoryStorage(ioService, limit)
{
diff --git a/ndn-cxx/ims/in-memory-storage-lru.hpp b/ndn-cxx/ims/in-memory-storage-lru.hpp
index b5524e5..f5eb4e1 100644
--- a/ndn-cxx/ims/in-memory-storage-lru.hpp
+++ b/ndn-cxx/ims/in-memory-storage-lru.hpp
@@ -40,8 +40,7 @@
explicit
InMemoryStorageLru(size_t limit = 16);
- explicit
- InMemoryStorageLru(boost::asio::io_service& ioService, size_t limit = 16);
+ InMemoryStorageLru(DummyIoService& ioService, size_t limit = 16);
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED:
/** @brief Removes one Data packet from in-memory storage based on LRU, i.e. evict the least
diff --git a/ndn-cxx/ims/in-memory-storage-persistent.cpp b/ndn-cxx/ims/in-memory-storage-persistent.cpp
index bd3c195..1c345ea 100644
--- a/ndn-cxx/ims/in-memory-storage-persistent.cpp
+++ b/ndn-cxx/ims/in-memory-storage-persistent.cpp
@@ -28,7 +28,7 @@
{
}
-InMemoryStoragePersistent::InMemoryStoragePersistent(boost::asio::io_service& ioService)
+InMemoryStoragePersistent::InMemoryStoragePersistent(DummyIoService& ioService)
: InMemoryStorage(ioService)
{
}
diff --git a/ndn-cxx/ims/in-memory-storage-persistent.hpp b/ndn-cxx/ims/in-memory-storage-persistent.hpp
index 6710434..4119aa7 100644
--- a/ndn-cxx/ims/in-memory-storage-persistent.hpp
+++ b/ndn-cxx/ims/in-memory-storage-persistent.hpp
@@ -35,7 +35,7 @@
InMemoryStoragePersistent();
explicit
- InMemoryStoragePersistent(boost::asio::io_service& ioService);
+ InMemoryStoragePersistent(DummyIoService& ioService);
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED:
/** @brief Do nothing.
diff --git a/ndn-cxx/ims/in-memory-storage.cpp b/ndn-cxx/ims/in-memory-storage.cpp
index 64624a7..b1a2793 100644
--- a/ndn-cxx/ims/in-memory-storage.cpp
+++ b/ndn-cxx/ims/in-memory-storage.cpp
@@ -88,7 +88,7 @@
init();
}
-InMemoryStorage::InMemoryStorage(boost::asio::io_service& ioService, size_t limit)
+InMemoryStorage::InMemoryStorage(DummyIoService& ioService, size_t limit)
: m_limit(limit)
, m_nPackets(0)
{
diff --git a/ndn-cxx/ims/in-memory-storage.hpp b/ndn-cxx/ims/in-memory-storage.hpp
index 8fa603e..129d85c 100644
--- a/ndn-cxx/ims/in-memory-storage.hpp
+++ b/ndn-cxx/ims/in-memory-storage.hpp
@@ -23,6 +23,7 @@
#define NDN_CXX_IMS_IN_MEMORY_STORAGE_HPP
#include "ndn-cxx/ims/in-memory-storage-entry.hpp"
+#include "ndn-cxx/util/scheduler.hpp"
#include <iterator>
#include <stack>
@@ -121,7 +122,7 @@
* The InMemoryStorage created through this method will handle MustBeFresh in interest processing
*/
explicit
- InMemoryStorage(boost::asio::io_service& ioService,
+ InMemoryStorage(DummyIoService& ioService,
size_t limit = std::numeric_limits<size_t>::max());
/** @note Please make sure to implement it to free m_freeEntries and evict
@@ -341,7 +342,7 @@
/// memory pool
std::stack<InMemoryStorageEntry*> m_freeEntries;
/// scheduler
- unique_ptr<Scheduler> m_scheduler;
+ unique_ptr<scheduler::Scheduler> m_scheduler;
};
} // namespace ndn
diff --git a/ndn-cxx/net/dns.cpp b/ndn-cxx/net/dns.cpp
deleted file mode 100644
index 9b0a9f1..0000000
--- a/ndn-cxx/net/dns.cpp
+++ /dev/null
@@ -1,173 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2013-2021 Regents of the University of California.
- *
- * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
- *
- * ndn-cxx library is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * ndn-cxx library 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 Lesser General Public License for more details.
- *
- * You should have received copies of the GNU General Public License and GNU Lesser
- * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- */
-
-#include "ndn-cxx/net/dns.hpp"
-#include "ndn-cxx/util/scheduler.hpp"
-
-#include <boost/asio/io_service.hpp>
-#include <boost/asio/ip/udp.hpp>
-#if BOOST_VERSION >= 106600
-#include <boost/asio/post.hpp>
-#endif
-
-namespace ndn {
-namespace dns {
-
-class Resolver : noncopyable
-{
-public:
- using protocol = boost::asio::ip::udp;
- using iterator = protocol::resolver::iterator;
- using query = protocol::resolver::query;
-
-public:
- Resolver(boost::asio::io_service& ioService,
- const AddressSelector& addressSelector)
- : m_resolver(ioService)
- , m_addressSelector(addressSelector)
- , m_scheduler(ioService)
- {
- BOOST_ASSERT(m_addressSelector != nullptr);
- }
-
- void
- asyncResolve(const query& q,
- const SuccessCallback& onSuccess,
- const ErrorCallback& onError,
- time::nanoseconds timeout,
- const shared_ptr<Resolver>& self)
- {
- m_onSuccess = onSuccess;
- m_onError = onError;
-
- m_resolver.async_resolve(q, [=] (auto&&... args) {
- onResolveResult(std::forward<decltype(args)>(args)..., self);
- });
-
- m_resolveTimeout = m_scheduler.schedule(timeout, [=] { onResolveTimeout(self); });
- }
-
- iterator
- syncResolve(const query& q)
- {
- return selectAddress(m_resolver.resolve(q));
- }
-
-private:
- void
- onResolveResult(const boost::system::error_code& error,
- iterator it, const shared_ptr<Resolver>& self)
- {
- m_resolveTimeout.cancel();
-
- // ensure the Resolver isn't destructed while callbacks are still pending, see #2653
-#if BOOST_VERSION >= 106600
- boost::asio::post(m_resolver.get_executor(), [self] {});
-#else
- m_resolver.get_io_service().post([self] {});
-#endif
-
- if (error) {
- if (error == boost::asio::error::operation_aborted)
- return;
-
- if (m_onError)
- m_onError("Hostname cannot be resolved: " + error.message());
-
- return;
- }
-
- it = selectAddress(it);
-
- if (it != iterator() && m_onSuccess) {
- m_onSuccess(it->endpoint().address());
- }
- else if (m_onError) {
- m_onError("No endpoints match the specified address selector");
- }
- }
-
- void
- onResolveTimeout(const shared_ptr<Resolver>& self)
- {
- m_resolver.cancel();
-
- // ensure the Resolver isn't destructed while callbacks are still pending, see #2653
-#if BOOST_VERSION >= 106600
- boost::asio::post(m_resolver.get_executor(), [self] {});
-#else
- m_resolver.get_io_service().post([self] {});
-#endif
-
- if (m_onError)
- m_onError("Hostname resolution timed out");
- }
-
- iterator
- selectAddress(iterator it) const
- {
- while (it != iterator() && !m_addressSelector(it->endpoint().address())) {
- ++it;
- }
- return it;
- }
-
-private:
- protocol::resolver m_resolver;
-
- AddressSelector m_addressSelector;
- SuccessCallback m_onSuccess;
- ErrorCallback m_onError;
-
- Scheduler m_scheduler;
- scheduler::EventId m_resolveTimeout;
-};
-
-void
-asyncResolve(const std::string& host,
- const SuccessCallback& onSuccess,
- const ErrorCallback& onError,
- boost::asio::io_service& ioService,
- const AddressSelector& addressSelector,
- time::nanoseconds timeout)
-{
- auto resolver = make_shared<Resolver>(ioService, addressSelector);
- resolver->asyncResolve(Resolver::query(host, ""), onSuccess, onError, timeout, resolver);
- // resolver will be destroyed when async operation finishes or ioService stops
-}
-
-IpAddress
-syncResolve(const std::string& host,
- boost::asio::io_service& ioService,
- const AddressSelector& addressSelector)
-{
- Resolver resolver(ioService, addressSelector);
- auto it = resolver.syncResolve(Resolver::query(host, ""));
-
- if (it == Resolver::iterator()) {
- NDN_THROW(Error("No endpoints match the specified address selector"));
- }
-
- return it->endpoint().address();
-}
-
-} // namespace dns
-} // namespace ndn
diff --git a/ndn-cxx/net/dns.hpp b/ndn-cxx/net/dns.hpp
deleted file mode 100644
index e3f8b7c..0000000
--- a/ndn-cxx/net/dns.hpp
+++ /dev/null
@@ -1,115 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2013-2021 Regents of the University of California.
- *
- * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
- *
- * ndn-cxx library is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * ndn-cxx library 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 Lesser General Public License for more details.
- *
- * You should have received copies of the GNU General Public License and GNU Lesser
- * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- */
-
-#ifndef NDN_CXX_NET_DNS_HPP
-#define NDN_CXX_NET_DNS_HPP
-
-#include "ndn-cxx/detail/asio-fwd.hpp"
-#include "ndn-cxx/util/time.hpp"
-
-#include <boost/asio/ip/address.hpp>
-
-namespace ndn {
-namespace dns {
-
-typedef boost::asio::ip::address IpAddress;
-typedef function<bool (const IpAddress& address)> AddressSelector;
-
-struct AnyAddress
-{
- bool
- operator()(const IpAddress& address) const
- {
- return true;
- }
-};
-
-struct Ipv4Only
-{
- bool
- operator()(const IpAddress& address) const
- {
- return address.is_v4();
- }
-};
-
-struct Ipv6Only
-{
- bool
- operator()(const IpAddress& address) const
- {
- return address.is_v6();
- }
-};
-
-class Error : public std::runtime_error
-{
-public:
- using std::runtime_error::runtime_error;
-};
-
-typedef function<void (const IpAddress& address)> SuccessCallback;
-typedef function<void (const std::string& reason)> ErrorCallback;
-
-/** \brief Asynchronously resolve host
- *
- * If an address selector predicate is specified, then each resolved IP address
- * is checked against the predicate.
- *
- * Available address selector predicates:
- *
- * - dns::AnyAddress()
- * - dns::Ipv4Address()
- * - dns::Ipv6Address()
- *
- * \warning Even after the DNS resolution has timed out, it's possible that
- * \p ioService keeps running and \p onSuccess is invoked at a later time.
- * This could cause segmentation fault if \p onSuccess is deallocated.
- * To stop the io_service, explicitly invoke \p ioService.stop().
- */
-void
-asyncResolve(const std::string& host,
- const SuccessCallback& onSuccess,
- const ErrorCallback& onError,
- boost::asio::io_service& ioService,
- const AddressSelector& addressSelector = AnyAddress(),
- time::nanoseconds timeout = 4_s);
-
-/** \brief Synchronously resolve host
- *
- * If an address selector predicate is specified, then each resolved IP address
- * is checked against the predicate.
- *
- * Available address selector predicates:
- *
- * - dns::AnyAddress()
- * - dns::Ipv4Address()
- * - dns::Ipv6Address()
- */
-IpAddress
-syncResolve(const std::string& host,
- boost::asio::io_service& ioService,
- const AddressSelector& addressSelector = AnyAddress());
-
-} // namespace dns
-} // namespace ndn
-
-#endif // NDN_CXX_NET_DNS_HPP
diff --git a/ndn-cxx/net/face-uri.cpp b/ndn-cxx/net/face-uri.cpp
index 00e1060..abe24d4 100644
--- a/ndn-cxx/net/face-uri.cpp
+++ b/ndn-cxx/net/face-uri.cpp
@@ -26,7 +26,7 @@
*/
#include "ndn-cxx/net/face-uri.hpp"
-#include "ndn-cxx/net/dns.hpp"
+// #include "ndn-cxx/net/dns.hpp"
#include "ndn-cxx/util/string-helper.hpp"
#include <boost/algorithm/string/classification.hpp>
@@ -229,7 +229,7 @@
canonize(const FaceUri& faceUri,
const FaceUri::CanonizeSuccessCallback& onSuccess,
const FaceUri::CanonizeFailureCallback& onFailure,
- boost::asio::io_service& io, time::nanoseconds timeout) const = 0;
+ time::nanoseconds timeout) const = 0;
};
template<typename Protocol>
@@ -245,95 +245,97 @@
bool
isCanonical(const FaceUri& faceUri) const override
{
- if (faceUri.getPort().empty()) {
- return false;
- }
- if (!faceUri.getPath().empty()) {
- return false;
- }
+ BOOST_THROW_EXCEPTION(std::runtime_error("IP host canonization not supported"));
+ // if (faceUri.getPort().empty()) {
+ // return false;
+ // }
+ // if (!faceUri.getPath().empty()) {
+ // return false;
+ // }
- boost::system::error_code ec;
- auto addr = boost::asio::ip::address::from_string(unescapeHost(faceUri.getHost()), ec);
- if (ec) {
- return false;
- }
+ // boost::system::error_code ec;
+ // auto addr = ip::addressFromString(unescapeHost(faceUri.getHost()), ec);
+ // if (ec) {
+ // return false;
+ // }
- bool hasCorrectScheme = (faceUri.getScheme() == m_v4Scheme && addr.is_v4()) ||
- (faceUri.getScheme() == m_v6Scheme && addr.is_v6());
- if (!hasCorrectScheme) {
- return false;
- }
+ // bool hasCorrectScheme = (faceUri.getScheme() == m_v4Scheme && addr.is_v4()) ||
+ // (faceUri.getScheme() == m_v6Scheme && addr.is_v6());
+ // if (!hasCorrectScheme) {
+ // return false;
+ // }
- auto checkAddressWithUri = [] (const boost::asio::ip::address& addr,
- const FaceUri& faceUri) -> bool {
- if (addr.is_v4() || !addr.to_v6().is_link_local()) {
- return addr.to_string() == faceUri.getHost();
- }
+ // auto checkAddressWithUri = [] (const boost::asio::ip::address& addr,
+ // const FaceUri& faceUri) -> bool {
+ // if (addr.is_v4() || !addr.to_v6().is_link_local()) {
+ // return addr.to_string() == faceUri.getHost();
+ // }
- std::vector<std::string> addrFields, faceUriFields;
- std::string addrString = addr.to_string();
- std::string faceUriString = faceUri.getHost();
+ // std::vector<std::string> addrFields, faceUriFields;
+ // std::string addrString = addr.to_string();
+ // std::string faceUriString = faceUri.getHost();
- boost::algorithm::split(addrFields, addrString, boost::is_any_of("%"));
- boost::algorithm::split(faceUriFields, faceUriString, boost::is_any_of("%"));
- if (addrFields.size() != 2 || faceUriFields.size() != 2) {
- return false;
- }
+ // boost::algorithm::split(addrFields, addrString, boost::is_any_of("%"));
+ // boost::algorithm::split(faceUriFields, faceUriString, boost::is_any_of("%"));
+ // if (addrFields.size() != 2 || faceUriFields.size() != 2) {
+ // return false;
+ // }
- if (faceUriFields[1].size() > 2 && faceUriFields[1].compare(0, 2, "25") == 0) {
- // %25... is accepted, but not a canonical form
- return false;
- }
+ // if (faceUriFields[1].size() > 2 && faceUriFields[1].compare(0, 2, "25") == 0) {
+ // // %25... is accepted, but not a canonical form
+ // return false;
+ // }
- return addrFields[0] == faceUriFields[0] &&
- addrFields[1] == faceUriFields[1];
- };
+ // return addrFields[0] == faceUriFields[0] &&
+ // addrFields[1] == faceUriFields[1];
+ // };
- return checkAddressWithUri(addr, faceUri) && checkAddress(addr).first;
+ // return checkAddressWithUri(addr, faceUri) && checkAddress(addr).first;
}
void
canonize(const FaceUri& faceUri,
const FaceUri::CanonizeSuccessCallback& onSuccess,
const FaceUri::CanonizeFailureCallback& onFailure,
- boost::asio::io_service& io, time::nanoseconds timeout) const override
+ time::nanoseconds timeout) const override
{
- if (this->isCanonical(faceUri)) {
- onSuccess(faceUri);
- return;
- }
+ BOOST_THROW_EXCEPTION(std::runtime_error("IP host canonization not supported"));
+ // if (this->isCanonical(faceUri)) {
+ // onSuccess(faceUri);
+ // return;
+ // }
- // make a copy because caller may modify faceUri
- auto uri = make_shared<FaceUri>(faceUri);
- boost::system::error_code ec;
- auto ipAddress = boost::asio::ip::address::from_string(unescapeHost(faceUri.getHost()), ec);
- if (!ec) {
- // No need to resolve IP address if host is already an IP
- if ((faceUri.getScheme() == m_v4Scheme && !ipAddress.is_v4()) ||
- (faceUri.getScheme() == m_v6Scheme && !ipAddress.is_v6())) {
- return onFailure("IPv4/v6 mismatch");
- }
+ // // make a copy because caller may modify faceUri
+ // auto uri = make_shared<FaceUri>(faceUri);
+ // boost::system::error_code ec;
+ // auto ipAddress = ip::addressFromString(unescapeHost(faceUri.getHost()), ec);
+ // if (!ec) {
+ // // No need to resolve IP address if host is already an IP
+ // if ((faceUri.getScheme() == m_v4Scheme && !ipAddress.is_v4()) ||
+ // (faceUri.getScheme() == m_v6Scheme && !ipAddress.is_v6())) {
+ // return onFailure("IPv4/v6 mismatch");
+ // }
- onDnsSuccess(uri, onSuccess, onFailure, ipAddress);
- }
- else {
- dns::AddressSelector addressSelector;
- if (faceUri.getScheme() == m_v4Scheme) {
- addressSelector = dns::Ipv4Only();
- }
- else if (faceUri.getScheme() == m_v6Scheme) {
- addressSelector = dns::Ipv6Only();
- }
- else {
- BOOST_ASSERT(faceUri.getScheme() == m_baseScheme);
- addressSelector = dns::AnyAddress();
- }
+ // onDnsSuccess(uri, onSuccess, onFailure, ipAddress);
+ // }
+ // else {
+ // dns::AddressSelector addressSelector;
+ // if (faceUri.getScheme() == m_v4Scheme) {
+ // addressSelector = dns::Ipv4Only();
+ // }
+ // else if (faceUri.getScheme() == m_v6Scheme) {
+ // addressSelector = dns::Ipv6Only();
+ // }
+ // else {
+ // BOOST_ASSERT(faceUri.getScheme() == m_baseScheme);
+ // addressSelector = dns::AnyAddress();
+ // }
- dns::asyncResolve(unescapeHost(faceUri.getHost()),
- [=] (const auto& ipAddr) { onDnsSuccess(uri, onSuccess, onFailure, ipAddr); },
- [=] (const auto& reason) { onDnsFailure(uri, onFailure, reason); },
- io, addressSelector, timeout);
- }
+ // dns::asyncResolve(unescapeHost(faceUri.getHost()),
+ // bind(&IpHostCanonizeProvider<Protocol>::onDnsSuccess, this, uri, onSuccess, onFailure, _1),
+ // bind(&IpHostCanonizeProvider<Protocol>::onDnsFailure, this, uri, onFailure, _1),
+ // io, addressSelector, timeout);
+ // }
}
protected:
@@ -350,54 +352,54 @@
}
private:
- void
- onDnsSuccess(const shared_ptr<FaceUri>& faceUri,
- const FaceUri::CanonizeSuccessCallback& onSuccess,
- const FaceUri::CanonizeFailureCallback& onFailure,
- const dns::IpAddress& ipAddress) const
- {
- bool isOk = false;
- std::string reason;
- std::tie(isOk, reason) = this->checkAddress(ipAddress);
- if (!isOk) {
- return onFailure(reason);
- }
+ // void
+ // onDnsSuccess(const shared_ptr<FaceUri>& faceUri,
+ // const FaceUri::CanonizeSuccessCallback& onSuccess,
+ // const FaceUri::CanonizeFailureCallback& onFailure,
+ // const dns::IpAddress& ipAddress) const
+ // {
+ // bool isOk = false;
+ // std::string reason;
+ // std::tie(isOk, reason) = this->checkAddress(ipAddress);
+ // if (!isOk) {
+ // return onFailure(reason);
+ // }
- uint16_t port = 0;
- if (faceUri->getPort().empty()) {
- port = ipAddress.is_multicast() ? m_defaultMulticastPort : m_defaultUnicastPort;
- }
- else {
- try {
- port = boost::lexical_cast<uint16_t>(faceUri->getPort());
- }
- catch (const boost::bad_lexical_cast&) {
- return onFailure("invalid port number '" + faceUri->getPort() + "'");
- }
- }
+ // uint16_t port = 0;
+ // if (faceUri->getPort().empty()) {
+ // port = ipAddress.is_multicast() ? m_defaultMulticastPort : m_defaultUnicastPort;
+ // }
+ // else {
+ // try {
+ // port = boost::lexical_cast<uint16_t>(faceUri->getPort());
+ // }
+ // catch (const boost::bad_lexical_cast&) {
+ // return onFailure("invalid port number '" + faceUri->getPort() + "'");
+ // }
+ // }
- FaceUri canonicalUri(typename Protocol::endpoint(ipAddress, port));
- BOOST_ASSERT(canonicalUri.isCanonical());
- onSuccess(canonicalUri);
- }
+ // FaceUri canonicalUri(typename Protocol::endpoint(ipAddress, port));
+ // BOOST_ASSERT(canonicalUri.isCanonical());
+ // onSuccess(canonicalUri);
+ // }
- void
- onDnsFailure(const shared_ptr<FaceUri>&,
- const FaceUri::CanonizeFailureCallback& onFailure,
- const std::string& reason) const
- {
- onFailure(reason);
- }
+ // void
+ // onDnsFailure(const shared_ptr<FaceUri>& faceUri,
+ // const FaceUri::CanonizeFailureCallback& onFailure,
+ // const std::string& reason) const
+ // {
+ // onFailure(reason);
+ // }
/** \brief when overriden in a subclass, check the IP address is allowable
* \return (true,ignored) if the address is allowable;
* (false,reason) if the address is not allowable.
*/
- virtual std::pair<bool, std::string>
- checkAddress(const dns::IpAddress&) const
- {
- return {true, ""};
- }
+ // virtual std::pair<bool, std::string>
+ // checkAddress(const dns::IpAddress& ipAddress) const
+ // {
+ // return {true, ""};
+ // }
static std::string
unescapeHost(std::string host)
@@ -435,14 +437,14 @@
}
protected:
- std::pair<bool, std::string>
- checkAddress(const dns::IpAddress& ipAddress) const override
- {
- if (ipAddress.is_multicast()) {
- return {false, "cannot use multicast address"};
- }
- return {true, ""};
- }
+ // std::pair<bool, std::string>
+ // checkAddress(const dns::IpAddress& ipAddress) const override
+ // {
+ // if (ipAddress.is_multicast()) {
+ // return {false, "cannot use multicast address"};
+ // }
+ // return {true, ""};
+ // }
};
class EtherCanonizeProvider : public CanonizeProvider
@@ -472,7 +474,7 @@
canonize(const FaceUri& faceUri,
const FaceUri::CanonizeSuccessCallback& onSuccess,
const FaceUri::CanonizeFailureCallback& onFailure,
- boost::asio::io_service&, time::nanoseconds timeout) const override
+ time::nanoseconds timeout) const override
{
auto addr = ethernet::Address::fromString(faceUri.getHost());
if (addr.isNull()) {
@@ -504,7 +506,7 @@
canonize(const FaceUri& faceUri,
const FaceUri::CanonizeSuccessCallback& onSuccess,
const FaceUri::CanonizeFailureCallback& onFailure,
- boost::asio::io_service&, time::nanoseconds timeout) const override
+ time::nanoseconds timeout) const override
{
if (faceUri.getHost().empty()) {
onFailure("network interface name is missing");
@@ -550,7 +552,7 @@
canonize(const FaceUri& faceUri,
const FaceUri::CanonizeSuccessCallback& onSuccess,
const FaceUri::CanonizeFailureCallback& onFailure,
- boost::asio::io_service&, time::nanoseconds timeout) const override
+ time::nanoseconds timeout) const override
{
if (this->isCanonical(faceUri)) {
onSuccess(faceUri);
@@ -629,7 +631,7 @@
void
FaceUri::canonize(const CanonizeSuccessCallback& onSuccess,
const CanonizeFailureCallback& onFailure,
- boost::asio::io_service& io, time::nanoseconds timeout) const
+ time::nanoseconds timeout) const
{
const CanonizeProvider* cp = getCanonizeProvider(this->getScheme());
if (cp == nullptr) {
@@ -642,7 +644,7 @@
cp->canonize(*this,
onSuccess ? onSuccess : [] (auto&&) {},
onFailure ? onFailure : [] (auto&&) {},
- io, timeout);
+ timeout);
}
} // namespace ndn
diff --git a/ndn-cxx/net/face-uri.hpp b/ndn-cxx/net/face-uri.hpp
index 8194dad..53dfcfb 100644
--- a/ndn-cxx/net/face-uri.hpp
+++ b/ndn-cxx/net/face-uri.hpp
@@ -157,7 +157,6 @@
* \param onSuccess function to call after this FaceUri is converted to canonical form
* \note A new FaceUri in canonical form will be created; this FaceUri is unchanged.
* \param onFailure function to call if this FaceUri cannot be converted to canonical form
- * \param io reference to `boost::asio::io_service` instance
* \param timeout maximum allowable duration of the operations.
* It's intentional not to provide a default value: the caller should set
* a reasonable value in balance between network delay and user experience.
@@ -165,7 +164,6 @@
void
canonize(const CanonizeSuccessCallback& onSuccess,
const CanonizeFailureCallback& onFailure,
- boost::asio::io_service& io,
time::nanoseconds timeout) const;
private: // non-member operators
diff --git a/ndn-cxx/transport/detail/stream-transport-impl.hpp b/ndn-cxx/transport/detail/stream-transport-impl.hpp
deleted file mode 100644
index f11a622..0000000
--- a/ndn-cxx/transport/detail/stream-transport-impl.hpp
+++ /dev/null
@@ -1,258 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2013-2022 Regents of the University of California.
- *
- * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
- *
- * ndn-cxx library is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * ndn-cxx library 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 Lesser General Public License for more details.
- *
- * You should have received copies of the GNU General Public License and GNU Lesser
- * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- */
-
-#ifndef NDN_CXX_TRANSPORT_DETAIL_STREAM_TRANSPORT_IMPL_HPP
-#define NDN_CXX_TRANSPORT_DETAIL_STREAM_TRANSPORT_IMPL_HPP
-
-#include "ndn-cxx/transport/transport.hpp"
-
-#include <boost/asio/steady_timer.hpp>
-#include <boost/asio/write.hpp>
-
-#include <list>
-#include <queue>
-
-namespace ndn {
-namespace detail {
-
-/** \brief Implementation detail of a Boost.Asio-based stream-oriented transport.
- * \tparam BaseTransport a subclass of Transport
- * \tparam Protocol a Boost.Asio stream-oriented protocol, e.g. boost::asio::ip::tcp
- * or boost::asio::local::stream_protocol
- */
-template<typename BaseTransport, typename Protocol>
-class StreamTransportImpl : public std::enable_shared_from_this<StreamTransportImpl<BaseTransport, Protocol>>
-{
-public:
- using Impl = StreamTransportImpl<BaseTransport, Protocol>;
- using TransmissionQueue = std::queue<Block, std::list<Block>>;
-
- StreamTransportImpl(BaseTransport& transport, boost::asio::io_service& ioService)
- : m_transport(transport)
- , m_socket(ioService)
- , m_connectTimer(ioService)
- {
- }
-
- void
- connect(const typename Protocol::endpoint& endpoint)
- {
- if (m_isConnecting) {
- return;
- }
- m_isConnecting = true;
-
- // Wait at most 4 seconds to connect
- /// @todo Decide whether this number should be configurable
- m_connectTimer.expires_from_now(std::chrono::seconds(4));
- m_connectTimer.async_wait([self = this->shared_from_this()] (const auto& error) {
- self->connectTimeoutHandler(error);
- });
-
- m_socket.open();
- m_socket.async_connect(endpoint, [self = this->shared_from_this()] (const auto& error) {
- self->connectHandler(error);
- });
- }
-
- void
- close()
- {
- m_isConnecting = false;
-
- boost::system::error_code error; // to silently ignore all errors
- m_connectTimer.cancel(error);
- m_socket.cancel(error);
- m_socket.close(error);
-
- m_transport.m_isConnected = false;
- m_transport.m_isReceiving = false;
- TransmissionQueue{}.swap(m_transmissionQueue); // clear the queue
- }
-
- void
- pause()
- {
- if (m_isConnecting)
- return;
-
- if (m_transport.m_isReceiving) {
- m_transport.m_isReceiving = false;
- m_socket.cancel();
- }
- }
-
- void
- resume()
- {
- if (m_isConnecting)
- return;
-
- if (!m_transport.m_isReceiving) {
- m_transport.m_isReceiving = true;
- m_inputBufferSize = 0;
- asyncReceive();
- }
- }
-
- void
- send(const Block& block)
- {
- m_transmissionQueue.push(block);
-
- if (m_transport.m_isConnected && m_transmissionQueue.size() == 1) {
- asyncWrite();
- }
- // if not connected or there's another transmission in progress (m_transmissionQueue.size() > 1),
- // the next write will be scheduled either in connectHandler or in asyncWriteHandler
- }
-
-protected:
- void
- connectHandler(const boost::system::error_code& error)
- {
- m_isConnecting = false;
- m_connectTimer.cancel();
-
- if (error) {
- m_transport.m_isConnected = false;
- m_transport.close();
- NDN_THROW(Transport::Error(error, "error while connecting to the forwarder"));
- }
-
- m_transport.m_isConnected = true;
-
- if (!m_transmissionQueue.empty()) {
- resume();
- asyncWrite();
- }
- }
-
- void
- connectTimeoutHandler(const boost::system::error_code& error)
- {
- if (error) // e.g., cancelled timer
- return;
-
- m_transport.close();
- NDN_THROW(Transport::Error(error, "error while connecting to the forwarder"));
- }
-
- void
- asyncWrite()
- {
- BOOST_ASSERT(!m_transmissionQueue.empty());
- boost::asio::async_write(m_socket, boost::asio::buffer(m_transmissionQueue.front()),
- // capture a copy of the shared_ptr to "this" to prevent deallocation
- [this, self = this->shared_from_this()] (const auto& error, size_t) {
- if (error) {
- if (error == boost::system::errc::operation_canceled) {
- // async receive has been explicitly cancelled (e.g., socket close)
- return;
- }
- m_transport.close();
- NDN_THROW(Transport::Error(error, "error while writing data to socket"));
- }
-
- if (!m_transport.m_isConnected) {
- return; // queue has been already cleared
- }
-
- BOOST_ASSERT(!m_transmissionQueue.empty());
- m_transmissionQueue.pop();
-
- if (!m_transmissionQueue.empty()) {
- asyncWrite();
- }
- });
- }
-
- void
- asyncReceive()
- {
- m_socket.async_receive(boost::asio::buffer(m_inputBuffer + m_inputBufferSize,
- MAX_NDN_PACKET_SIZE - m_inputBufferSize), 0,
- // capture a copy of the shared_ptr to "this" to prevent deallocation
- [this, self = this->shared_from_this()] (const auto& error, size_t nBytesRecvd) {
- if (error) {
- if (error == boost::system::errc::operation_canceled) {
- // async receive has been explicitly cancelled (e.g., socket close)
- return;
- }
- m_transport.close();
- NDN_THROW(Transport::Error(error, "error while receiving data from socket"));
- }
-
- m_inputBufferSize += nBytesRecvd;
- // do magic
-
- std::size_t offset = 0;
- bool hasProcessedSome = processAllReceived(m_inputBuffer, offset, m_inputBufferSize);
- if (!hasProcessedSome && m_inputBufferSize == MAX_NDN_PACKET_SIZE && offset == 0) {
- m_transport.close();
- NDN_THROW(Transport::Error("input buffer full, but a valid TLV cannot be decoded"));
- }
-
- if (offset > 0) {
- if (offset != m_inputBufferSize) {
- std::copy(m_inputBuffer + offset, m_inputBuffer + m_inputBufferSize, m_inputBuffer);
- m_inputBufferSize -= offset;
- }
- else {
- m_inputBufferSize = 0;
- }
- }
-
- asyncReceive();
- });
- }
-
- bool
- processAllReceived(uint8_t* buffer, size_t& offset, size_t nBytesAvailable)
- {
- while (offset < nBytesAvailable) {
- bool isOk = false;
- Block element;
- std::tie(isOk, element) = Block::fromBuffer({buffer + offset, nBytesAvailable - offset});
- if (!isOk)
- return false;
-
- m_transport.m_receiveCallback(element);
- offset += element.size();
- }
- return true;
- }
-
-protected:
- BaseTransport& m_transport;
-
- typename Protocol::socket m_socket;
- uint8_t m_inputBuffer[MAX_NDN_PACKET_SIZE];
- size_t m_inputBufferSize = 0;
- TransmissionQueue m_transmissionQueue;
- boost::asio::steady_timer m_connectTimer;
- bool m_isConnecting = false;
-};
-
-} // namespace detail
-} // namespace ndn
-
-#endif // NDN_CXX_TRANSPORT_DETAIL_STREAM_TRANSPORT_IMPL_HPP
diff --git a/ndn-cxx/transport/detail/stream-transport-with-resolver-impl.hpp b/ndn-cxx/transport/detail/stream-transport-with-resolver-impl.hpp
deleted file mode 100644
index f8ebe31..0000000
--- a/ndn-cxx/transport/detail/stream-transport-with-resolver-impl.hpp
+++ /dev/null
@@ -1,106 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2013-2021 Regents of the University of California.
- *
- * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
- *
- * ndn-cxx library is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * ndn-cxx library 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 Lesser General Public License for more details.
- *
- * You should have received copies of the GNU General Public License and GNU Lesser
- * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- */
-
-#ifndef NDN_CXX_TRANSPORT_DETAIL_STREAM_TRANSPORT_WITH_RESOLVER_IMPL_HPP
-#define NDN_CXX_TRANSPORT_DETAIL_STREAM_TRANSPORT_WITH_RESOLVER_IMPL_HPP
-
-#include "ndn-cxx/transport/detail/stream-transport-impl.hpp"
-
-namespace ndn {
-namespace detail {
-
-/** \brief implementation detail of a Boost.Asio-based stream-oriented transport
- * with resolver support
- */
-template<typename BaseTransport, typename Protocol>
-class StreamTransportWithResolverImpl : public StreamTransportImpl<BaseTransport, Protocol>
-{
-public:
- StreamTransportWithResolverImpl(BaseTransport& transport, boost::asio::io_service& ioService)
- : StreamTransportImpl<BaseTransport, Protocol>(transport, ioService)
- {
- }
-
- void
- connect(const typename Protocol::resolver::query& query)
- {
- if (this->m_isConnecting) {
- return;
- }
- this->m_isConnecting = true;
-
- // Wait at most 4 seconds to connect
- /// @todo Decide whether this number should be configurable
- this->m_connectTimer.expires_from_now(std::chrono::seconds(4));
- this->m_connectTimer.async_wait([self = this->shared_from_base()] (const auto& ec) {
- self->connectTimeoutHandler(ec);
- });
-
- auto resolver = make_shared<typename Protocol::resolver>(this->m_socket
-#if BOOST_VERSION >= 107000
- .get_executor()
-#else
- .get_io_service()
-#endif
- );
- resolver->async_resolve(query, [self = this->shared_from_base(), resolver] (auto&&... args) {
- self->resolveHandler(std::forward<decltype(args)>(args)..., resolver);
- });
- }
-
-protected:
- void
- resolveHandler(const boost::system::error_code& error,
- typename Protocol::resolver::iterator endpoint,
- const shared_ptr<typename Protocol::resolver>&)
- {
- if (error) {
- if (error == boost::system::errc::operation_canceled)
- return;
-
- NDN_THROW(Transport::Error(error, "Error during resolution of host or port"));
- }
-
- typename Protocol::resolver::iterator end;
- if (endpoint == end) {
- this->m_transport.close();
- NDN_THROW(Transport::Error(error, "Unable to resolve host or port"));
- }
-
- this->m_socket.async_connect(*endpoint, [self = this->shared_from_base()] (const auto& ec) {
- self->connectHandler(ec);
- });
- }
-
-private:
- using Impl = StreamTransportWithResolverImpl<BaseTransport, Protocol>;
-
- shared_ptr<Impl>
- shared_from_base()
- {
- return static_pointer_cast<Impl>(this->shared_from_this());
- }
-};
-
-} // namespace detail
-} // namespace ndn
-
-#endif // NDN_CXX_TRANSPORT_DETAIL_STREAM_TRANSPORT_WITH_RESOLVER_IMPL_HPP
diff --git a/ndn-cxx/transport/tcp-transport.cpp b/ndn-cxx/transport/tcp-transport.cpp
deleted file mode 100644
index 0c5e516..0000000
--- a/ndn-cxx/transport/tcp-transport.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2013-2022 Regents of the University of California.
- *
- * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
- *
- * ndn-cxx library is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * ndn-cxx library 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 Lesser General Public License for more details.
- *
- * You should have received copies of the GNU General Public License and GNU Lesser
- * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- */
-
-#include "ndn-cxx/transport/tcp-transport.hpp"
-#include "ndn-cxx/transport/detail/stream-transport-with-resolver-impl.hpp"
-#include "ndn-cxx/net/face-uri.hpp"
-#include "ndn-cxx/util/logger.hpp"
-
-NDN_LOG_INIT(ndn.TcpTransport);
-// DEBUG level: connect, close, pause, resume.
-
-namespace ndn {
-
-TcpTransport::TcpTransport(const std::string& host, const std::string& port/* = "6363"*/)
- : m_host(host)
- , m_port(port)
-{
-}
-
-TcpTransport::~TcpTransport() = default;
-
-shared_ptr<TcpTransport>
-TcpTransport::create(const std::string& uri)
-{
- const auto hostAndPort(getSocketHostAndPortFromUri(uri));
- return make_shared<TcpTransport>(hostAndPort.first, hostAndPort.second);
-}
-
-std::pair<std::string, std::string>
-TcpTransport::getSocketHostAndPortFromUri(const std::string& uriString)
-{
- std::string host = "localhost";
- std::string port = "6363";
-
- if (uriString.empty()) {
- return {host, port};
- }
-
- try {
- const FaceUri uri(uriString);
-
- const std::string scheme = uri.getScheme();
- if (scheme != "tcp" && scheme != "tcp4" && scheme != "tcp6") {
- NDN_THROW(Error("Cannot create TcpTransport from \"" + scheme + "\" URI"));
- }
-
- if (!uri.getHost().empty()) {
- host = uri.getHost();
- }
-
- if (!uri.getPort().empty()) {
- port = uri.getPort();
- }
- }
- catch (const FaceUri::Error& error) {
- NDN_THROW_NESTED(Error(error.what()));
- }
-
- return {host, port};
-}
-
-void
-TcpTransport::connect(boost::asio::io_service& ioService, ReceiveCallback receiveCallback)
-{
- NDN_LOG_DEBUG("connect host=" << m_host << " port=" << m_port);
-
- if (m_impl == nullptr) {
- Transport::connect(ioService, std::move(receiveCallback));
- m_impl = make_shared<Impl>(*this, ioService);
- }
-
- boost::asio::ip::tcp::resolver::query query(m_host, m_port);
- m_impl->connect(query);
-}
-
-void
-TcpTransport::send(const Block& wire)
-{
- BOOST_ASSERT(m_impl != nullptr);
- m_impl->send(wire);
-}
-
-void
-TcpTransport::close()
-{
- BOOST_ASSERT(m_impl != nullptr);
- NDN_LOG_DEBUG("close");
- m_impl->close();
- m_impl.reset();
-}
-
-void
-TcpTransport::pause()
-{
- if (m_impl != nullptr) {
- NDN_LOG_DEBUG("pause");
- m_impl->pause();
- }
-}
-
-void
-TcpTransport::resume()
-{
- BOOST_ASSERT(m_impl != nullptr);
- NDN_LOG_DEBUG("resume");
- m_impl->resume();
-}
-
-} // namespace ndn
diff --git a/ndn-cxx/transport/tcp-transport.hpp b/ndn-cxx/transport/tcp-transport.hpp
deleted file mode 100644
index 95c28ea..0000000
--- a/ndn-cxx/transport/tcp-transport.hpp
+++ /dev/null
@@ -1,88 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2013-2022 Regents of the University of California.
- *
- * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
- *
- * ndn-cxx library is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * ndn-cxx library 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 Lesser General Public License for more details.
- *
- * You should have received copies of the GNU General Public License and GNU Lesser
- * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- */
-
-#ifndef NDN_CXX_TRANSPORT_TCP_TRANSPORT_HPP
-#define NDN_CXX_TRANSPORT_TCP_TRANSPORT_HPP
-
-#include "ndn-cxx/transport/transport.hpp"
-
-#include <boost/asio/ip/tcp.hpp>
-
-namespace ndn {
-
-namespace detail {
-
-template<typename BaseTransport, typename Protocol>
-class StreamTransportImpl;
-
-template<typename BaseTransport, typename Protocol>
-class StreamTransportWithResolverImpl;
-
-} // namespace detail
-
-/** \brief a transport using TCP socket
- */
-class TcpTransport : public Transport
-{
-public:
- explicit
- TcpTransport(const std::string& host, const std::string& port = "6363");
-
- ~TcpTransport() override;
-
- void
- connect(boost::asio::io_service& ioService, ReceiveCallback receiveCallback) override;
-
- void
- close() override;
-
- void
- pause() override;
-
- void
- resume() override;
-
- void
- send(const Block& wire) override;
-
- /** \brief Create transport with parameters defined in URI
- * \throw Transport::Error incorrect URI or unsupported protocol is specified
- */
- static shared_ptr<TcpTransport>
- create(const std::string& uri);
-
-NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
- static std::pair<std::string, std::string>
- getSocketHostAndPortFromUri(const std::string& uri);
-
-private:
- std::string m_host;
- std::string m_port;
-
- using Impl = detail::StreamTransportWithResolverImpl<TcpTransport, boost::asio::ip::tcp>;
- friend class detail::StreamTransportImpl<TcpTransport, boost::asio::ip::tcp>;
- friend Impl;
- shared_ptr<Impl> m_impl;
-};
-
-} // namespace ndn
-
-#endif // NDN_CXX_TRANSPORT_TCP_TRANSPORT_HPP
diff --git a/ndn-cxx/transport/transport.cpp b/ndn-cxx/transport/transport.cpp
index a78e36f..05fa481 100644
--- a/ndn-cxx/transport/transport.cpp
+++ b/ndn-cxx/transport/transport.cpp
@@ -29,11 +29,10 @@
}
void
-Transport::connect(boost::asio::io_service& ioService, ReceiveCallback receiveCallback)
+Transport::connect(ReceiveCallback receiveCallback)
{
BOOST_ASSERT(receiveCallback != nullptr);
- m_ioService = &ioService;
m_receiveCallback = std::move(receiveCallback);
}
diff --git a/ndn-cxx/transport/transport.hpp b/ndn-cxx/transport/transport.hpp
index 6fd4374..1f38c3f 100644
--- a/ndn-cxx/transport/transport.hpp
+++ b/ndn-cxx/transport/transport.hpp
@@ -49,14 +49,12 @@
virtual
~Transport() = default;
- /**
- * \brief Asynchronously open the connection.
- * \param ioService io_service to create socket on
- * \param receiveCallback callback function when a TLV block is received; must not be empty
- * \throw boost::system::system_error connection cannot be established
+ /** \brief Asynchronously open the connection.
+ * \param receiveCallback callback function when a TLV block is received; must not be empty
+ * \throw boost::system::system_error connection cannot be established
*/
virtual void
- connect(boost::asio::io_service& ioService, ReceiveCallback receiveCallback);
+ connect(ReceiveCallback receiveCallback);
/**
* \brief Close the connection.
@@ -108,7 +106,6 @@
}
protected:
- boost::asio::io_service* m_ioService = nullptr;
ReceiveCallback m_receiveCallback;
bool m_isConnected = false;
bool m_isReceiving = false;
diff --git a/ndn-cxx/transport/unix-transport.cpp b/ndn-cxx/transport/unix-transport.cpp
deleted file mode 100644
index b8404eb..0000000
--- a/ndn-cxx/transport/unix-transport.cpp
+++ /dev/null
@@ -1,125 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2013-2022 Regents of the University of California.
- *
- * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
- *
- * ndn-cxx library is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * ndn-cxx library 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 Lesser General Public License for more details.
- *
- * You should have received copies of the GNU General Public License and GNU Lesser
- * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- */
-
-#include "ndn-cxx/transport/unix-transport.hpp"
-#include "ndn-cxx/transport/detail/stream-transport-impl.hpp"
-
-#include "ndn-cxx/face.hpp"
-#include "ndn-cxx/net/face-uri.hpp"
-#include "ndn-cxx/util/logger.hpp"
-
-NDN_LOG_INIT(ndn.UnixTransport);
-// DEBUG level: connect, close, pause, resume.
-
-namespace ndn {
-
-UnixTransport::UnixTransport(const std::string& unixSocket)
- : m_unixSocket(unixSocket)
-{
-}
-
-UnixTransport::~UnixTransport() = default;
-
-std::string
-UnixTransport::getSocketNameFromUri(const std::string& uriString)
-{
- // Assume the default nfd.sock location.
-#ifdef __linux__
- std::string path = "/run/nfd.sock";
-#else
- std::string path = "/var/run/nfd.sock";
-#endif // __linux__
-
- if (uriString.empty()) {
- return path;
- }
-
- try {
- const FaceUri uri(uriString);
-
- if (uri.getScheme() != "unix") {
- NDN_THROW(Error("Cannot create UnixTransport from \"" + uri.getScheme() + "\" URI"));
- }
-
- if (!uri.getPath().empty()) {
- path = uri.getPath();
- }
- }
- catch (const FaceUri::Error& error) {
- NDN_THROW_NESTED(Error(error.what()));
- }
-
- return path;
-}
-
-shared_ptr<UnixTransport>
-UnixTransport::create(const std::string& uri)
-{
- return make_shared<UnixTransport>(getSocketNameFromUri(uri));
-}
-
-void
-UnixTransport::connect(boost::asio::io_service& ioService, ReceiveCallback receiveCallback)
-{
- NDN_LOG_DEBUG("connect path=" << m_unixSocket);
-
- if (m_impl == nullptr) {
- Transport::connect(ioService, std::move(receiveCallback));
- m_impl = make_shared<Impl>(*this, ioService);
- }
-
- m_impl->connect(boost::asio::local::stream_protocol::endpoint(m_unixSocket));
-}
-
-void
-UnixTransport::send(const Block& wire)
-{
- BOOST_ASSERT(m_impl != nullptr);
- m_impl->send(wire);
-}
-
-void
-UnixTransport::close()
-{
- BOOST_ASSERT(m_impl != nullptr);
- NDN_LOG_DEBUG("close");
- m_impl->close();
- m_impl.reset();
-}
-
-void
-UnixTransport::pause()
-{
- if (m_impl != nullptr) {
- NDN_LOG_DEBUG("pause");
- m_impl->pause();
- }
-}
-
-void
-UnixTransport::resume()
-{
- BOOST_ASSERT(m_impl != nullptr);
- NDN_LOG_DEBUG("resume");
- m_impl->resume();
-}
-
-} // namespace ndn
diff --git a/ndn-cxx/transport/unix-transport.hpp b/ndn-cxx/transport/unix-transport.hpp
deleted file mode 100644
index 2d1ef05..0000000
--- a/ndn-cxx/transport/unix-transport.hpp
+++ /dev/null
@@ -1,83 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2013-2022 Regents of the University of California.
- *
- * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
- *
- * ndn-cxx library is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * ndn-cxx library 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 Lesser General Public License for more details.
- *
- * You should have received copies of the GNU General Public License and GNU Lesser
- * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- */
-
-#ifndef NDN_CXX_TRANSPORT_UNIX_TRANSPORT_HPP
-#define NDN_CXX_TRANSPORT_UNIX_TRANSPORT_HPP
-
-#include "ndn-cxx/transport/transport.hpp"
-
-#include <boost/asio/local/stream_protocol.hpp>
-
-namespace ndn {
-
-namespace detail {
-
-template<typename BaseTransport, typename Protocol>
-class StreamTransportImpl;
-
-} // namespace detail
-
-/** \brief a transport using Unix stream socket
- */
-class UnixTransport : public Transport
-{
-public:
- explicit
- UnixTransport(const std::string& unixSocket);
-
- ~UnixTransport() override;
-
- void
- connect(boost::asio::io_service& ioService, ReceiveCallback receiveCallback) override;
-
- void
- close() override;
-
- void
- pause() override;
-
- void
- resume() override;
-
- void
- send(const Block& wire) override;
-
- /** \brief Create transport with parameters defined in URI
- * \throw Transport::Error incorrect URI or unsupported protocol is specified
- */
- static shared_ptr<UnixTransport>
- create(const std::string& uri);
-
-NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
- static std::string
- getSocketNameFromUri(const std::string& uri);
-
-private:
- std::string m_unixSocket;
-
- using Impl = detail::StreamTransportImpl<UnixTransport, boost::asio::local::stream_protocol>;
- friend Impl;
- shared_ptr<Impl> m_impl;
-};
-
-} // namespace ndn
-
-#endif // NDN_CXX_TRANSPORT_UNIX_TRANSPORT_HPP
diff --git a/ndn-cxx/util/scheduler.cpp b/ndn-cxx/util/scheduler.cpp
index 838a563..dd25771 100644
--- a/ndn-cxx/util/scheduler.cpp
+++ b/ndn-cxx/util/scheduler.cpp
@@ -83,7 +83,7 @@
return a->expireTime < b->expireTime;
}
-Scheduler::Scheduler(boost::asio::io_service& ioService)
+Scheduler::Scheduler(DummyIoService& ioService)
{
}
diff --git a/ndn-cxx/util/scheduler.hpp b/ndn-cxx/util/scheduler.hpp
index 07d3231..f710264 100644
--- a/ndn-cxx/util/scheduler.hpp
+++ b/ndn-cxx/util/scheduler.hpp
@@ -133,7 +133,7 @@
{
public:
explicit
- Scheduler(boost::asio::io_service& ioService);
+ Scheduler(DummyIoService& ioService);
~Scheduler();
diff --git a/ndn-cxx/util/segment-fetcher.cpp b/ndn-cxx/util/segment-fetcher.cpp
index 60fdc2a..5d9a845 100644
--- a/ndn-cxx/util/segment-fetcher.cpp
+++ b/ndn-cxx/util/segment-fetcher.cpp
@@ -93,7 +93,7 @@
}
m_pendingSegments.clear(); // cancels pending Interests and timeout events
- m_face.getIoService().post([self = std::move(m_this)] {});
+ m_scheduler.schedule(0_s, [self = std::move(m_this)] {});
}
bool