[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/src/net/asio-fwd.hpp b/src/net/asio-fwd.hpp
index fb80ee5..788b19d 100644
--- a/src/net/asio-fwd.hpp
+++ b/src/net/asio-fwd.hpp
@@ -22,19 +22,13 @@
#ifndef NDN_NET_ASIO_FWD_HPP
#define NDN_NET_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_NET_ASIO_FWD_HPP
diff --git a/src/net/dns.cpp b/src/net/dns.cpp
deleted file mode 100644
index 0043ec9..0000000
--- a/src/net/dns.cpp
+++ /dev/null
@@ -1,160 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2017 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 "dns.hpp"
-#include "../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, bind(&Resolver::onResolveTimeout, this, 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(bind([] (const shared_ptr<Resolver>&) {}, 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(bind([] (const shared_ptr<Resolver>&) {}, 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/src/net/dns.hpp b/src/net/dns.hpp
deleted file mode 100644
index 961e5bd..0000000
--- a/src/net/dns.hpp
+++ /dev/null
@@ -1,118 +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 "asio-fwd.hpp"
-#include "../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();
- }
-};
-
-struct Error : public std::runtime_error
-{
- explicit
- Error(const std::string& what)
- : std::runtime_error(what)
- {
- }
-};
-
-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/src/net/face-uri.cpp b/src/net/face-uri.cpp
index 97fe0f7..c91add4 100644
--- a/src/net/face-uri.cpp
+++ b/src/net/face-uri.cpp
@@ -28,7 +28,7 @@
#include "face-uri.hpp"
#include "address-converter.hpp"
-#include "dns.hpp"
+// #include "dns.hpp"
#include "util/string-helper.hpp"
#include <boost/algorithm/string.hpp>
@@ -245,7 +245,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>
@@ -261,95 +261,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 = ip::addressFromString(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 = 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");
- }
+ // // 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:
@@ -366,54 +368,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)
@@ -451,14 +453,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
@@ -488,7 +490,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()) {
@@ -520,7 +522,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");
@@ -566,7 +568,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);
@@ -645,7 +647,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) {
@@ -660,7 +662,7 @@
cp->canonize(*this,
onSuccess ? onSuccess : successNop,
onFailure ? onFailure : failureNop,
- io, timeout);
+ timeout);
}
} // namespace ndn
diff --git a/src/net/face-uri.hpp b/src/net/face-uri.hpp
index 7461576..5f40e30 100644
--- a/src/net/face-uri.hpp
+++ b/src/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: