[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/detail/face-impl.hpp b/src/detail/face-impl.hpp
index 51aff16..44e6593 100644
--- a/src/detail/face-impl.hpp
+++ b/src/detail/face-impl.hpp
@@ -31,8 +31,9 @@
#include "../lp/tags.hpp"
#include "../mgmt/nfd/command-options.hpp"
#include "../mgmt/nfd/controller.hpp"
-#include "../transport/tcp-transport.hpp"
-#include "../transport/unix-transport.hpp"
+#include "../transport/transport.hpp"
+// #include "../transport/tcp-transport.hpp"
+// #include "../transport/unix-transport.hpp"
#include "../util/config-file.hpp"
#include "../util/logger.hpp"
#include "../util/scheduler.hpp"
@@ -371,8 +372,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/src/face.cpp b/src/face.cpp
index aaf8b63..555024f 100644
--- a/src/face.cpp
+++ b/src/face.cpp
@@ -62,36 +62,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/src/face.hpp b/src/face.hpp
index 99f6b5c..1909460 100644
--- a/src/face.hpp
+++ b/src/face.hpp
@@ -122,20 +122,6 @@
public: // constructors
/**
- * @brief Create Face using given transport (or default transport if omitted)
- * @param transport the transport for lower layer communication. If nullptr,
- * a default transport will be used. The default transport is
- * determined from a FaceUri in NDN_CLIENT_TRANSPORT environ,
- * a FaceUri in configuration file 'transport' key, or UnixTransport.
- *
- * @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
- */
- explicit
- Face(shared_ptr<Transport> transport = nullptr);
-
- /**
* @brief Create Face using default transport and given io_service
*
* Usage examples:
@@ -164,7 +150,21 @@
* @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 (or default transport if omitted)
+ * @param transport the transport for lower layer communication. If nullptr,
+ * a default transport will be used. The default transport is
+ * determined from a FaceUri in NDN_CLIENT_TRANSPORT environ,
+ * a FaceUri in configuration file 'transport' key, or UnixTransport.
+ *
+ * @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
+ */
+ explicit
+ Face(shared_ptr<Transport> transport = nullptr);
/**
* @brief Create Face using given transport and KeyChain
@@ -180,37 +180,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();
@@ -459,10 +428,11 @@
/**
* @brief Return 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/src/ims/in-memory-storage-fifo.cpp b/src/ims/in-memory-storage-fifo.cpp
index df6e173..b151ed0 100644
--- a/src/ims/in-memory-storage-fifo.cpp
+++ b/src/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/src/ims/in-memory-storage-fifo.hpp b/src/ims/in-memory-storage-fifo.hpp
index 6991451..dd88b74 100644
--- a/src/ims/in-memory-storage-fifo.hpp
+++ b/src/ims/in-memory-storage-fifo.hpp
@@ -39,7 +39,7 @@
InMemoryStorageFifo(size_t limit = 10);
explicit
- InMemoryStorageFifo(boost::asio::io_service& ioService, size_t limit = 10);
+ InMemoryStorageFifo(DummyIoService& ioService, size_t limit = 10);
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED:
/** @brief Removes one Data packet from in-memory storage based on FIFO
diff --git a/src/ims/in-memory-storage-lfu.cpp b/src/ims/in-memory-storage-lfu.cpp
index a155f60..41345e1 100644
--- a/src/ims/in-memory-storage-lfu.cpp
+++ b/src/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/src/ims/in-memory-storage-lfu.hpp b/src/ims/in-memory-storage-lfu.hpp
index 7633cfd..ebc9711 100644
--- a/src/ims/in-memory-storage-lfu.hpp
+++ b/src/ims/in-memory-storage-lfu.hpp
@@ -43,7 +43,7 @@
InMemoryStorageLfu(size_t limit = 10);
explicit
- InMemoryStorageLfu(boost::asio::io_service& ioService, size_t limit = 10);
+ InMemoryStorageLfu(DummyIoService& ioService, size_t limit = 10);
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/src/ims/in-memory-storage-lru.cpp b/src/ims/in-memory-storage-lru.cpp
index 22c463d..61eff85 100644
--- a/src/ims/in-memory-storage-lru.cpp
+++ b/src/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/src/ims/in-memory-storage-lru.hpp b/src/ims/in-memory-storage-lru.hpp
index 3dd9dfe..67ce33a 100644
--- a/src/ims/in-memory-storage-lru.hpp
+++ b/src/ims/in-memory-storage-lru.hpp
@@ -40,7 +40,7 @@
explicit
InMemoryStorageLru(size_t limit = 10);
- InMemoryStorageLru(boost::asio::io_service& ioService, size_t limit = 10);
+ InMemoryStorageLru(DummyIoService& ioService, size_t limit = 10);
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/src/ims/in-memory-storage-persistent.cpp b/src/ims/in-memory-storage-persistent.cpp
index ff6a3a9..716addb 100644
--- a/src/ims/in-memory-storage-persistent.cpp
+++ b/src/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/src/ims/in-memory-storage-persistent.hpp b/src/ims/in-memory-storage-persistent.hpp
index 5920ef3..a458a40 100644
--- a/src/ims/in-memory-storage-persistent.hpp
+++ b/src/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/src/ims/in-memory-storage.cpp b/src/ims/in-memory-storage.cpp
index 0dc7df7..ec9876f 100644
--- a/src/ims/in-memory-storage.cpp
+++ b/src/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/src/ims/in-memory-storage.hpp b/src/ims/in-memory-storage.hpp
index 9e61e7a..9850187 100644
--- a/src/ims/in-memory-storage.hpp
+++ b/src/ims/in-memory-storage.hpp
@@ -115,7 +115,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/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:
diff --git a/src/transport/stream-transport-impl.hpp b/src/transport/stream-transport-impl.hpp
deleted file mode 100644
index c8f1527..0000000
--- a/src/transport/stream-transport-impl.hpp
+++ /dev/null
@@ -1,283 +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.
- */
-
-#ifndef NDN_TRANSPORT_STREAM_TRANSPORT_IMPL_HPP
-#define NDN_TRANSPORT_STREAM_TRANSPORT_IMPL_HPP
-
-#include "transport.hpp"
-
-#include <boost/asio/deadline_timer.hpp>
-#include <boost/asio/write.hpp>
-
-#include <list>
-
-namespace ndn {
-
-/** \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, including boost::asio::ip::tcp
- * and boost::asio::local::stream_protocol
- */
-template<typename BaseTransport, typename Protocol>
-class StreamTransportImpl : public 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 ndn
-
-#endif // NDN_TRANSPORT_STREAM_TRANSPORT_IMPL_HPP
diff --git a/src/transport/stream-transport-with-resolver-impl.hpp b/src/transport/stream-transport-with-resolver-impl.hpp
deleted file mode 100644
index b9150d8..0000000
--- a/src/transport/stream-transport-with-resolver-impl.hpp
+++ /dev/null
@@ -1,94 +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.
- */
-
-#ifndef NDN_TRANSPORT_STREAM_TRANSPORT_WITH_RESOLVER_IMPL_HPP
-#define NDN_TRANSPORT_STREAM_TRANSPORT_WITH_RESOLVER_IMPL_HPP
-
-#include "stream-transport-impl.hpp"
-
-namespace ndn {
-
-/** \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 ndn
-
-#endif // NDN_TRANSPORT_STREAM_TRANSPORT_WITH_RESOLVER_IMPL_HPP
diff --git a/src/transport/tcp-transport.cpp b/src/transport/tcp-transport.cpp
deleted file mode 100644
index 8b99f3e..0000000
--- a/src/transport/tcp-transport.cpp
+++ /dev/null
@@ -1,136 +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 "tcp-transport.hpp"
-#include "stream-transport-with-resolver-impl.hpp"
-#include "net/face-uri.hpp"
-#include "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/src/transport/tcp-transport.hpp b/src/transport/tcp-transport.hpp
deleted file mode 100644
index 6e8977f..0000000
--- a/src/transport/tcp-transport.hpp
+++ /dev/null
@@ -1,88 +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.
- */
-
-#ifndef NDN_TRANSPORT_TCP_TRANSPORT_HPP
-#define NDN_TRANSPORT_TCP_TRANSPORT_HPP
-
-#include "transport.hpp"
-#include "../util/config-file.hpp"
-
-#include <boost/asio/ip/tcp.hpp>
-
-namespace ndn {
-
-template<typename BaseTransport, typename Protocol>
-class StreamTransportImpl;
-
-template<typename BaseTransport, typename Protocol>
-class StreamTransportWithResolverImpl;
-
-/** \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 = StreamTransportWithResolverImpl<TcpTransport, boost::asio::ip::tcp>;
- friend class StreamTransportImpl<TcpTransport, boost::asio::ip::tcp>;
- friend Impl;
- shared_ptr<Impl> m_impl;
-};
-
-} // namespace ndn
-
-#endif // NDN_TRANSPORT_TCP_TRANSPORT_HPP
diff --git a/src/transport/transport.cpp b/src/transport/transport.cpp
index 0ea5bee..7cca3a2 100644
--- a/src/transport/transport.cpp
+++ b/src/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/src/transport/transport.hpp b/src/transport/transport.hpp
index b177fad..f5b76dd 100644
--- a/src/transport/transport.hpp
+++ b/src/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/src/transport/unix-transport.cpp b/src/transport/unix-transport.cpp
deleted file mode 100644
index 34ccf83..0000000
--- a/src/transport/unix-transport.cpp
+++ /dev/null
@@ -1,131 +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 "unix-transport.hpp"
-#include "stream-transport-impl.hpp"
-
-#include "../face.hpp"
-#include "net/face-uri.hpp"
-#include "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/src/transport/unix-transport.hpp b/src/transport/unix-transport.hpp
deleted file mode 100644
index d337252..0000000
--- a/src/transport/unix-transport.hpp
+++ /dev/null
@@ -1,84 +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.
- */
-
-#ifndef NDN_TRANSPORT_UNIX_TRANSPORT_HPP
-#define NDN_TRANSPORT_UNIX_TRANSPORT_HPP
-
-#include "transport.hpp"
-#include "../util/config-file.hpp"
-
-#include <boost/asio/local/stream_protocol.hpp>
-
-namespace ndn {
-
-template<typename BaseTransport, typename Protocol>
-class StreamTransportImpl;
-
-/** \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 = 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/src/util/scheduler.cpp b/src/util/scheduler.cpp
index 513348f..431375a 100644
--- a/src/util/scheduler.cpp
+++ b/src/util/scheduler.cpp
@@ -46,7 +46,7 @@
namespace util {
namespace scheduler {
-Scheduler::Scheduler(boost::asio::io_service& ioService)
+Scheduler::Scheduler(DummyIoService& ioService)
: m_scheduledEvent(m_events.end())
{
}
diff --git a/src/util/scheduler.hpp b/src/util/scheduler.hpp
index 2d669b1..6f74e9a 100644
--- a/src/util/scheduler.hpp
+++ b/src/util/scheduler.hpp
@@ -62,7 +62,7 @@
typedef EventCallback Event;
explicit
- Scheduler(boost::asio::io_service& ioService);
+ Scheduler(DummyIoService& ioService);
~Scheduler();