face: Remove Tcp|UdpChannel::connect overloads that perform DNS resolution
Change-Id: Ib5da2a43d1e33654940aa42f568b6a604c171e3e
Refs: #2422
diff --git a/daemon/face/tcp-channel.cpp b/daemon/face/tcp-channel.cpp
index 69a5241..0a6ce78 100644
--- a/daemon/face/tcp-channel.cpp
+++ b/daemon/face/tcp-channel.cpp
@@ -92,29 +92,6 @@
onFaceCreated, onConnectFailed));
}
-void
-TcpChannel::connect(const std::string& remoteHost, const std::string& remotePort,
- const TcpChannel::FaceCreatedCallback& onFaceCreated,
- const TcpChannel::ConnectFailedCallback& onConnectFailed,
- const time::seconds& timeout/* = time::seconds(4)*/)
-{
- shared_ptr<ip::tcp::socket> clientSocket =
- make_shared<ip::tcp::socket>(ref(getGlobalIoService()));
-
- ip::tcp::resolver::query query(remoteHost, remotePort);
- shared_ptr<ip::tcp::resolver> resolver =
- make_shared<ip::tcp::resolver>(ref(getGlobalIoService()));
-
- scheduler::EventId connectTimeoutEvent = scheduler::schedule(timeout,
- bind(&TcpChannel::handleFailedConnect, this, clientSocket, onConnectFailed));
-
- resolver->async_resolve(query,
- bind(&TcpChannel::handleEndpointResolution, this, _1, _2,
- clientSocket, connectTimeoutEvent,
- onFaceCreated, onConnectFailed,
- resolver));
-}
-
size_t
TcpChannel::size() const
{
@@ -243,37 +220,4 @@
socket->close(); // abort the connection
}
-void
-TcpChannel::handleEndpointResolution(const boost::system::error_code& error,
- ip::tcp::resolver::iterator remoteEndpoint,
- const shared_ptr<boost::asio::ip::tcp::socket>& socket,
- const scheduler::EventId& connectTimeoutEvent,
- const FaceCreatedCallback& onFaceCreated,
- const ConnectFailedCallback& onConnectFailed,
- const shared_ptr<ip::tcp::resolver>& resolver)
-{
- if (error ||
- remoteEndpoint == ip::tcp::resolver::iterator())
- {
- if (error == boost::system::errc::operation_canceled) // when socket is closed by someone
- return;
-
- socket->close();
- scheduler::cancel(connectTimeoutEvent);
-
- NFD_LOG_DEBUG("Remote endpoint hostname or port cannot be resolved: "
- << error.category().message(error.value()));
-
- onConnectFailed("Remote endpoint hostname or port cannot be resolved: " +
- error.category().message(error.value()));
- return;
- }
-
- // got endpoint, now trying to connect (only try the first resolution option)
- socket->async_connect(*remoteEndpoint,
- bind(&TcpChannel::handleSuccessfulConnect, this, _1,
- socket, connectTimeoutEvent,
- onFaceCreated, onConnectFailed));
-}
-
} // namespace nfd
diff --git a/daemon/face/tcp-channel.hpp b/daemon/face/tcp-channel.hpp
index f83ca55..25c5fb0 100644
--- a/daemon/face/tcp-channel.hpp
+++ b/daemon/face/tcp-channel.hpp
@@ -82,23 +82,6 @@
const time::seconds& timeout = time::seconds(4));
/**
- * \brief Create a face by establishing connection to the specified
- * remote host and remote port
- *
- * This method will never block and will return immediately. All
- * necessary hostname and port resolution and connection will happen
- * in asynchronous mode.
- *
- * If connection cannot be established within specified timeout, it
- * will be aborted.
- */
- void
- connect(const std::string& remoteHost, const std::string& remotePort,
- const FaceCreatedCallback& onFaceCreated,
- const ConnectFailedCallback& onConnectFailed,
- const time::seconds& timeout = time::seconds(4));
-
- /**
* \brief Get number of faces in the channel
*/
size_t
@@ -133,15 +116,6 @@
handleFailedConnect(const shared_ptr<boost::asio::ip::tcp::socket>& socket,
const ConnectFailedCallback& onConnectFailed);
- void
- handleEndpointResolution(const boost::system::error_code& error,
- boost::asio::ip::tcp::resolver::iterator remoteEndpoint,
- const shared_ptr<boost::asio::ip::tcp::socket>& socket,
- const scheduler::EventId& connectTimeoutEvent,
- const FaceCreatedCallback& onFaceCreated,
- const ConnectFailedCallback& onConnectFailed,
- const shared_ptr<boost::asio::ip::tcp::resolver>& resolver);
-
private:
tcp::Endpoint m_localEndpoint;
diff --git a/daemon/face/udp-channel.cpp b/daemon/face/udp-channel.cpp
index 8e151b3..ffe6137 100644
--- a/daemon/face/udp-channel.cpp
+++ b/daemon/face/udp-channel.cpp
@@ -117,46 +117,6 @@
createFace(clientSocket, onFaceCreated, false);
}
-void
-UdpChannel::connect(const std::string& remoteHost,
- const std::string& remotePort,
- const FaceCreatedCallback& onFaceCreated,
- const ConnectFailedCallback& onConnectFailed)
-{
- ip::udp::resolver::query query(remoteHost, remotePort);
- shared_ptr<ip::udp::resolver> resolver =
- make_shared<ip::udp::resolver>(ref(getGlobalIoService()));
-
- resolver->async_resolve(query,
- bind(&UdpChannel::handleEndpointResolution, this, _1, _2,
- onFaceCreated, onConnectFailed,
- resolver));
-}
-
-void
-UdpChannel::handleEndpointResolution(const boost::system::error_code& error,
- ip::udp::resolver::iterator remoteEndpoint,
- const FaceCreatedCallback& onFaceCreated,
- const ConnectFailedCallback& onConnectFailed,
- const shared_ptr<ip::udp::resolver>& resolver)
-{
- if (error != 0 ||
- remoteEndpoint == ip::udp::resolver::iterator())
- {
- if (error == boost::system::errc::operation_canceled) // when socket is closed by someone
- return;
-
- NFD_LOG_DEBUG("Remote endpoint hostname or port cannot be resolved: "
- << error.category().message(error.value()));
-
- onConnectFailed("Remote endpoint hostname or port cannot be resolved: " +
- error.category().message(error.value()));
- return;
- }
-
- connect(*remoteEndpoint, onFaceCreated, onConnectFailed);
-}
-
size_t
UdpChannel::size() const
{
diff --git a/daemon/face/udp-channel.hpp b/daemon/face/udp-channel.hpp
index bcefd8b..b51d50d 100644
--- a/daemon/face/udp-channel.hpp
+++ b/daemon/face/udp-channel.hpp
@@ -90,21 +90,6 @@
connect(const udp::Endpoint& remoteEndpoint,
const FaceCreatedCallback& onFaceCreated,
const ConnectFailedCallback& onConnectFailed);
- /**
- * \brief Create a face by establishing connection to the specified
- * remote host and remote port
- *
- * This method will never block and will return immediately. All
- * necessary hostname and port resolution and connection will happen
- * in asynchronous mode.
- *
- * If connection cannot be established within specified timeout, it
- * will be aborted.
- */
- void
- connect(const std::string& remoteHost, const std::string& remotePort,
- const FaceCreatedCallback& onFaceCreated,
- const ConnectFailedCallback& onConnectFailed);
/**
* \brief Get number of faces in the channel
@@ -127,13 +112,6 @@
void
newPeer(const boost::system::error_code& error, size_t nBytesReceived);
- void
- handleEndpointResolution(const boost::system::error_code& error,
- boost::asio::ip::udp::resolver::iterator remoteEndpoint,
- const FaceCreatedCallback& onFaceCreated,
- const ConnectFailedCallback& onConnectFailed,
- const shared_ptr<boost::asio::ip::udp::resolver>& resolver);
-
private:
udp::Endpoint m_localEndpoint;
diff --git a/tests/daemon/face/tcp.cpp b/tests/daemon/face/tcp.cpp
index 23899e6..70da6d1 100644
--- a/tests/daemon/face/tcp.cpp
+++ b/tests/daemon/face/tcp.cpp
@@ -225,7 +225,8 @@
const std::string& remoteHost,
const std::string& remotePort)
{
- channel->connect(remoteHost, remotePort,
+ channel->connect(tcp::Endpoint(boost::asio::ip::address::from_string(remoteHost),
+ boost::lexical_cast<uint16_t>(remotePort)),
bind(&EndToEndFixture::channel_onFaceCreated, this, _1),
bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
}
@@ -404,7 +405,8 @@
channel1->listen(bind(&EndToEndFixture::channel_onFaceCreated, this, _1),
bind(&EndToEndFixture::channel_onConnectFailed, this, _1));
- channel2->connect("127.0.0.1", "20070",
+ using namespace boost::asio;
+ channel2->connect(tcp::Endpoint(ip::address::from_string("127.0.0.1"), 20070),
bind(&EndToEndFixture::channel_onFaceCreated, this, _1),
bind(&EndToEndFixture::channel_onConnectFailed, this, _1),
time::seconds(4)); // very short timeout
@@ -416,7 +418,7 @@
BOOST_CHECK_EQUAL(faces.size(), 2);
shared_ptr<TcpChannel> channel3 = factory.createChannel("127.0.0.1", "20072");
- channel3->connect("127.0.0.1", "20070",
+ channel3->connect(tcp::Endpoint(ip::address::from_string("127.0.0.1"), 20070),
bind(&EndToEndFixture::channel_onFaceCreated, this, _1),
bind(&EndToEndFixture::channel_onConnectFailed, this, _1),
time::seconds(4)); // very short timeout
@@ -450,7 +452,8 @@
channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1),
bind(&EndToEndFixture::channel1_onConnectFailed, this, _1));
- channel2->connect("127.0.0.1", "20070",
+ using namespace boost::asio;
+ channel2->connect(tcp::Endpoint(ip::address::from_string("127.0.0.1"), 20070),
bind(&EndToEndFixture::channel2_onFaceCreated, this, _1),
bind(&EndToEndFixture::channel2_onConnectFailed, this, _1),
time::seconds(4)); // very short timeout