[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 5789abd..4d632c2 100644
--- a/ndn-cxx/detail/asio-fwd.hpp
+++ b/ndn-cxx/detail/asio-fwd.hpp
@@ -22,19 +22,13 @@
#ifndef NDN_DETAIL_ASIO_FWD_HPP
#define NDN_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_DETAIL_ASIO_FWD_HPP
diff --git a/ndn-cxx/face.cpp b/ndn-cxx/face.cpp
index 0b20bb4..bc29949 100644
--- a/ndn-cxx/face.cpp
+++ b/ndn-cxx/face.cpp
@@ -61,36 +61,24 @@
{
}
+Face::Face(DummyIoService& ioService)
+ : m_impl(new Impl(*this))
+{
+ construct(nullptr, ns3::ndn::StackHelper::getKeyChain());
+}
+
Face::Face(shared_ptr<Transport> transport)
: m_impl(new Impl(*this))
{
construct(transport, ns3::ndn::StackHelper::getKeyChain());
}
-Face::Face(boost::asio::io_service& ioService)
- : m_impl(new Impl(*this))
-{
- construct(nullptr, ns3::ndn::StackHelper::getKeyChain());
-}
-
Face::Face(shared_ptr<Transport> transport, KeyChain& keyChain)
: m_impl(new Impl(*this))
{
construct(std::move(transport), keyChain);
}
-Face::Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService)
- : m_impl(new Impl(*this))
-{
- construct(transport, ns3::ndn::StackHelper::getKeyChain());
-}
-
-Face::Face(shared_ptr<Transport> transport, boost::asio::io_service& ioService, KeyChain& keyChain)
- : m_impl(new Impl(*this))
-{
- construct(std::move(transport), keyChain);
-}
-
shared_ptr<Transport>
Face::makeDefaultTransport()
{
diff --git a/ndn-cxx/face.hpp b/ndn-cxx/face.hpp
index 9e151f2..d62a58e 100644
--- a/ndn-cxx/face.hpp
+++ b/ndn-cxx/face.hpp
@@ -163,7 +163,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
@@ -179,37 +179,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();
@@ -466,10 +435,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 47fa7ba..7a5c281 100644
--- a/ndn-cxx/impl/face-impl.hpp
+++ b/ndn-cxx/impl/face-impl.hpp
@@ -371,8 +371,7 @@
ensureConnected(bool wantResume)
{
if (!m_face.m_transport->isConnected())
- m_face.m_transport->connect(m_face.getIoService(),
- [=] (const Block& wire) { m_face.onReceiveElement(wire); });
+ m_face.m_transport->connect([=] (const Block& wire) { m_face.onReceiveElement(wire); });
if (wantResume && !m_face.m_transport->isReceiving()) {
m_face.m_transport->resume();
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 e66e0d9..e196829 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 6582f57..2b579ff 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 c425ede..9326b6f 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 a7dda69..331bdcf 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 31ec616..3d07fda 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 25adfa8..6514afb 100644
--- a/ndn-cxx/ims/in-memory-storage.hpp
+++ b/ndn-cxx/ims/in-memory-storage.hpp
@@ -121,7 +121,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
diff --git a/ndn-cxx/net/dns.cpp b/ndn-cxx/net/dns.cpp
deleted file mode 100644
index d398117..0000000
--- a/ndn-cxx/net/dns.cpp
+++ /dev/null
@@ -1,160 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2013-2018 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>
-
-namespace ndn {
-namespace dns {
-
-class Resolver : noncopyable
-{
-public:
- typedef boost::asio::ip::udp protocol;
- typedef protocol::resolver::iterator iterator;
- typedef protocol::resolver::query 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, bind(&Resolver::onResolveResult, this, _1, _2, self));
-
- m_resolveTimeout = m_scheduler.scheduleEvent(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_scheduler.cancelEvent(m_resolveTimeout);
- // ensure the Resolver isn't destructed while callbacks are still pending, see #2653
- m_resolver.get_io_service().post([self] {});
-
- 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
- m_resolver.get_io_service().post([self] {});
-
- 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;
-
- util::scheduler::Scheduler m_scheduler;
- util::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>(ref(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()) {
- BOOST_THROW_EXCEPTION(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 660efcd..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-2018 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_NET_DNS_HPP
-#define NDN_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_NET_DNS_HPP
diff --git a/ndn-cxx/net/face-uri.cpp b/ndn-cxx/net/face-uri.cpp
index c1bbe8b..567d60c 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.hpp>
@@ -244,7 +244,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>
@@ -260,95 +260,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()),
- bind(&IpHostCanonizeProvider<Protocol>::onDnsSuccess, this, uri, onSuccess, onFailure, _1),
- bind(&IpHostCanonizeProvider<Protocol>::onDnsFailure, this, uri, onFailure, _1),
- 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:
@@ -365,54 +367,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>& 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& 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)
@@ -450,14 +452,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
@@ -487,7 +489,7 @@
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
{
auto addr = ethernet::Address::fromString(faceUri.getHost());
if (addr.isNull()) {
@@ -519,7 +521,7 @@
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 (faceUri.getHost().empty()) {
onFailure("network interface name is missing");
@@ -565,7 +567,7 @@
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);
@@ -644,7 +646,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) {
@@ -657,7 +659,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 650e7c7..6828320 100644
--- a/ndn-cxx/net/face-uri.hpp
+++ b/ndn-cxx/net/face-uri.hpp
@@ -168,7 +168,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.
@@ -176,7 +175,6 @@
void
canonize(const CanonizeSuccessCallback& onSuccess,
const CanonizeFailureCallback& onFailure,
- boost::asio::io_service& io,
time::nanoseconds timeout) const;
private:
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 dda33e9..0000000
--- a/ndn-cxx/transport/detail/stream-transport-impl.hpp
+++ /dev/null
@@ -1,285 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2013-2018 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_TRANSPORT_DETAIL_STREAM_TRANSPORT_IMPL_HPP
-#define NDN_TRANSPORT_DETAIL_STREAM_TRANSPORT_IMPL_HPP
-
-#include "ndn-cxx/transport/transport.hpp"
-
-#include <boost/asio/deadline_timer.hpp>
-#include <boost/asio/write.hpp>
-
-#include <list>
-
-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:
- typedef StreamTransportImpl<BaseTransport, Protocol> Impl;
- typedef std::list<Block> BlockSequence;
- typedef std::list<BlockSequence> TransmissionQueue;
-
- StreamTransportImpl(BaseTransport& transport, boost::asio::io_service& ioService)
- : m_transport(transport)
- , m_socket(ioService)
- , m_inputBufferSize(0)
- , m_isConnecting(false)
- , m_connectTimer(ioService)
- {
- }
-
- void
- connect(const typename Protocol::endpoint& endpoint)
- {
- if (!m_isConnecting) {
- m_isConnecting = true;
-
- // Wait at most 4 seconds to connect
- /// @todo Decide whether this number should be configurable
- m_connectTimer.expires_from_now(boost::posix_time::seconds(4));
- m_connectTimer.async_wait(bind(&Impl::connectTimeoutHandler, this->shared_from_this(), _1));
-
- m_socket.open();
- m_socket.async_connect(endpoint, bind(&Impl::connectHandler, this->shared_from_this(), _1));
- }
- }
-
- 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;
- m_transmissionQueue.clear();
- }
-
- 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& wire)
- {
- BlockSequence sequence;
- sequence.push_back(wire);
- send(std::move(sequence));
- }
-
- void
- send(const Block& header, const Block& payload)
- {
- BlockSequence sequence;
- sequence.push_back(header);
- sequence.push_back(payload);
- send(std::move(sequence));
- }
-
-protected:
- void
- connectHandler(const boost::system::error_code& error)
- {
- m_isConnecting = false;
- m_connectTimer.cancel();
-
- if (!error) {
- m_transport.m_isConnected = true;
-
- if (!m_transmissionQueue.empty()) {
- resume();
- asyncWrite();
- }
- }
- else {
- m_transport.m_isConnected = false;
- m_transport.close();
- BOOST_THROW_EXCEPTION(Transport::Error(error, "error while connecting to the forwarder"));
- }
- }
-
- void
- connectTimeoutHandler(const boost::system::error_code& error)
- {
- if (error) // e.g., cancelled timer
- return;
-
- m_transport.close();
- BOOST_THROW_EXCEPTION(Transport::Error(error, "error while connecting to the forwarder"));
- }
-
- void
- send(BlockSequence&& sequence)
- {
- m_transmissionQueue.emplace_back(sequence);
-
- if (m_transport.m_isConnected && m_transmissionQueue.size() == 1) {
- asyncWrite();
- }
-
- // if not connected or there is transmission in progress (m_transmissionQueue.size() > 1),
- // next write will be scheduled either in connectHandler or in asyncWriteHandler
- }
-
- void
- asyncWrite()
- {
- BOOST_ASSERT(!m_transmissionQueue.empty());
- boost::asio::async_write(m_socket, m_transmissionQueue.front(),
- bind(&Impl::handleAsyncWrite, this->shared_from_this(), _1, m_transmissionQueue.begin()));
- }
-
- void
- handleAsyncWrite(const boost::system::error_code& error, TransmissionQueue::iterator queueItem)
- {
- if (error) {
- if (error == boost::system::errc::operation_canceled) {
- // async receive has been explicitly cancelled (e.g., socket close)
- return;
- }
-
- m_transport.close();
- BOOST_THROW_EXCEPTION(Transport::Error(error, "error while sending data to socket"));
- }
-
- if (!m_transport.m_isConnected) {
- return; // queue has been already cleared
- }
-
- m_transmissionQueue.erase(queueItem);
-
- 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,
- bind(&Impl::handleAsyncReceive, this->shared_from_this(), _1, _2));
- }
-
- void
- handleAsyncReceive(const boost::system::error_code& error, std::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();
- BOOST_THROW_EXCEPTION(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();
- BOOST_THROW_EXCEPTION(Transport::Error(boost::system::error_code(),
- "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.receive(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;
-
- TransmissionQueue m_transmissionQueue;
- bool m_isConnecting;
-
- boost::asio::deadline_timer m_connectTimer;
-};
-
-} // namespace detail
-} // namespace ndn
-
-#endif // NDN_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 6ca3b1e..0000000
--- a/ndn-cxx/transport/detail/stream-transport-with-resolver-impl.hpp
+++ /dev/null
@@ -1,95 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2013-2018 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_TRANSPORT_DETAIL_STREAM_TRANSPORT_WITH_RESOLVER_IMPL_HPP
-#define NDN_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:
- using Impl = StreamTransportWithResolverImpl<BaseTransport,Protocol>;
-
- 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(boost::posix_time::seconds(4));
- this->m_connectTimer.async_wait(bind(&Impl::connectTimeoutHandler, this->shared_from_this(), _1));
-
- auto resolver = make_shared<typename Protocol::resolver>(ref(this->m_socket.get_io_service()));
- resolver->async_resolve(query, bind(&Impl::resolveHandler, this->shared_from_base(), _1, _2, 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;
-
- BOOST_THROW_EXCEPTION(Transport::Error(error, "Error during resolution of host or port"));
- }
-
- typename Protocol::resolver::iterator end;
- if (endpoint == end) {
- this->m_transport.close();
- BOOST_THROW_EXCEPTION(Transport::Error(error, "Unable to resolve host or port"));
- }
-
- this->m_socket.async_connect(*endpoint, bind(&Impl::connectHandler, this->shared_from_this(), _1));
- }
-
-private:
- shared_ptr<Impl>
- shared_from_base()
- {
- return static_pointer_cast<Impl>(this->shared_from_this());
- }
-};
-
-} // namespace detail
-} // namespace ndn
-
-#endif // NDN_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 30a5087..0000000
--- a/ndn-cxx/transport/tcp-transport.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2013-2018 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") {
- BOOST_THROW_EXCEPTION(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) {
- BOOST_THROW_EXCEPTION(Error(error.what()));
- }
-
- return {host, port};
-}
-
-void
-TcpTransport::connect(boost::asio::io_service& ioService,
- const ReceiveCallback& receiveCallback)
-{
- NDN_LOG_DEBUG("connect host=" << m_host << " port=" << m_port);
-
- if (m_impl == nullptr) {
- Transport::connect(ioService, receiveCallback);
-
- m_impl = make_shared<Impl>(ref(*this), ref(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::send(const Block& header, const Block& payload)
-{
- BOOST_ASSERT(m_impl != nullptr);
- m_impl->send(header, payload);
-}
-
-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 e3bb5a3..0000000
--- a/ndn-cxx/transport/tcp-transport.hpp
+++ /dev/null
@@ -1,92 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2013-2018 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_TRANSPORT_TCP_TRANSPORT_HPP
-#define NDN_TRANSPORT_TCP_TRANSPORT_HPP
-
-#include "ndn-cxx/transport/transport.hpp"
-#include "ndn-cxx/util/config-file.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, const ReceiveCallback& receiveCallback) override;
-
- void
- close() override;
-
- void
- pause() override;
-
- void
- resume() override;
-
- void
- send(const Block& wire) override;
-
- void
- send(const Block& header, const Block& payload) 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_TRANSPORT_TCP_TRANSPORT_HPP
diff --git a/ndn-cxx/transport/transport.cpp b/ndn-cxx/transport/transport.cpp
index b6dac08..f796fd7 100644
--- a/ndn-cxx/transport/transport.cpp
+++ b/ndn-cxx/transport/transport.cpp
@@ -34,19 +34,16 @@
}
Transport::Transport()
- : m_ioService(nullptr)
- , m_isConnected(false)
+ : m_isConnected(false)
, m_isReceiving(false)
{
}
void
-Transport::connect(boost::asio::io_service& ioService,
- const ReceiveCallback& receiveCallback)
+Transport::connect(const ReceiveCallback& receiveCallback)
{
BOOST_ASSERT(receiveCallback != nullptr);
- m_ioService = &ioService;
m_receiveCallback = receiveCallback;
}
diff --git a/ndn-cxx/transport/transport.hpp b/ndn-cxx/transport/transport.hpp
index daede21..c313092 100644
--- a/ndn-cxx/transport/transport.hpp
+++ b/ndn-cxx/transport/transport.hpp
@@ -53,12 +53,11 @@
~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
*/
virtual void
- connect(boost::asio::io_service& ioService, const ReceiveCallback& receiveCallback);
+ connect(const ReceiveCallback& receiveCallback);
/** \brief Close the connection.
*/
@@ -113,7 +112,6 @@
receive(const Block& wire);
protected:
- boost::asio::io_service* m_ioService;
bool m_isConnected;
bool m_isReceiving;
ReceiveCallback m_receiveCallback;
diff --git a/ndn-cxx/transport/unix-transport.cpp b/ndn-cxx/transport/unix-transport.cpp
deleted file mode 100644
index d444e35..0000000
--- a/ndn-cxx/transport/unix-transport.cpp
+++ /dev/null
@@ -1,131 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2013-2018 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.
- std::string path = "/var/run/nfd.sock";
-
- if (uriString.empty()) {
- return path;
- }
-
- try {
- const FaceUri uri(uriString);
-
- if (uri.getScheme() != "unix") {
- BOOST_THROW_EXCEPTION(Error("Cannot create UnixTransport from \"" +
- uri.getScheme() + "\" URI"));
- }
-
- if (!uri.getPath().empty()) {
- path = uri.getPath();
- }
- }
- catch (const FaceUri::Error& error) {
- BOOST_THROW_EXCEPTION(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,
- const ReceiveCallback& receiveCallback)
-{
- NDN_LOG_DEBUG("connect path=" << m_unixSocket);
-
- if (m_impl == nullptr) {
- Transport::connect(ioService, receiveCallback);
-
- m_impl = make_shared<Impl>(ref(*this), ref(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::send(const Block& header, const Block& payload)
-{
- BOOST_ASSERT(m_impl != nullptr);
- m_impl->send(header, payload);
-}
-
-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 424ed53..0000000
--- a/ndn-cxx/transport/unix-transport.hpp
+++ /dev/null
@@ -1,88 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2013-2018 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_TRANSPORT_UNIX_TRANSPORT_HPP
-#define NDN_TRANSPORT_UNIX_TRANSPORT_HPP
-
-#include "ndn-cxx/transport/transport.hpp"
-#include "ndn-cxx/util/config-file.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,
- const ReceiveCallback& receiveCallback) override;
-
- void
- close() override;
-
- void
- pause() override;
-
- void
- resume() override;
-
- void
- send(const Block& wire) override;
-
- void
- send(const Block& header, const Block& payload) 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_TRANSPORT_UNIX_TRANSPORT_HPP
diff --git a/ndn-cxx/util/scheduler.cpp b/ndn-cxx/util/scheduler.cpp
index f2a8123..6d9b766 100644
--- a/ndn-cxx/util/scheduler.cpp
+++ b/ndn-cxx/util/scheduler.cpp
@@ -89,7 +89,7 @@
return a->expireTime < b->expireTime;
}
-Scheduler::Scheduler(boost::asio::io_service& ioService)
+Scheduler::Scheduler(DummyIoService& ioService)
: m_isEventExecuting(false)
{
}
diff --git a/ndn-cxx/util/scheduler.hpp b/ndn-cxx/util/scheduler.hpp
index 6163495..755d3a1 100644
--- a/ndn-cxx/util/scheduler.hpp
+++ b/ndn-cxx/util/scheduler.hpp
@@ -151,7 +151,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 bc537a5..18c4eaf 100644
--- a/ndn-cxx/util/segment-fetcher.cpp
+++ b/ndn-cxx/util/segment-fetcher.cpp
@@ -110,7 +110,7 @@
m_scheduler.cancelEvent(pendingSegment.timeoutEvent);
}
}
- m_face.getIoService().post([self = std::move(m_this)] {});
+ m_scheduler.scheduleEvent(0_s, [self = std::move(m_this)] {});
}
bool