face: move Channel and subclasses into nfd::face namespace

Change-Id: I163ef20e11b65d19d68585ec075fd3cd224a573b
This commit is contained in:
Davide Pesavento
2017-04-06 19:58:54 -04:00
parent b283f52c78
commit 8fd15e628a
21 changed files with 85 additions and 50 deletions
+4 -6
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, Regents of the University of California,
* Copyright (c) 2014-2017, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -26,10 +26,9 @@
#include "channel.hpp"
namespace nfd {
namespace face {
Channel::~Channel()
{
}
Channel::~Channel() = default;
void
Channel::setUri(const FaceUri& uri)
@@ -40,8 +39,6 @@ Channel::setUri(const FaceUri& uri)
void
connectFaceClosedSignal(Face& face, const std::function<void()>& f)
{
using face::FaceState;
face.afterStateChange.connect(
[f] (FaceState oldState, FaceState newState) {
if (newState == FaceState::CLOSED) {
@@ -50,4 +47,5 @@ connectFaceClosedSignal(Face& face, const std::function<void()>& f)
});
}
} // namespace face
} // namespace nfd
+2
View File
@@ -29,6 +29,7 @@
#include "face.hpp"
namespace nfd {
namespace face {
/**
* \brief Prototype for the callback that is invoked when the face
@@ -82,6 +83,7 @@ Channel::getUri() const
void
connectFaceClosedSignal(Face& face, const std::function<void()>& f);
} // namespace face
} // namespace nfd
#endif // NFD_DAEMON_FACE_CHANNEL_HPP
+3 -3
View File
@@ -161,12 +161,12 @@ EthernetFactory::createMulticastFace(const NetworkInterfaceInfo& netif,
return found->second;
}
face::GenericLinkService::Options opts;
GenericLinkService::Options opts;
opts.allowFragmentation = true;
opts.allowReassembly = true;
auto linkService = make_unique<face::GenericLinkService>(opts);
auto transport = make_unique<face::MulticastEthernetTransport>(netif, address, m_mcastConfig.linkType);
auto linkService = make_unique<GenericLinkService>(opts);
auto transport = make_unique<MulticastEthernetTransport>(netif, address, m_mcastConfig.linkType);
auto face = make_shared<Face>(std::move(linkService), std::move(transport));
m_mcastFaces[key] = face;
+1 -1
View File
@@ -50,7 +50,7 @@ protected:
/** \brief implements a forwarder-side transport that can be paired with another
*/
class InternalForwarderTransport : public face::Transport, public InternalTransportBase
class InternalForwarderTransport : public Transport, public InternalTransportBase
{
public:
InternalForwarderTransport(const FaceUri& localUri = FaceUri("internal://"),
+5 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2016, Regents of the University of California,
* Copyright (c) 2014-2017, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -29,6 +29,7 @@
#include "core/global-io.hpp"
namespace nfd {
namespace face {
NFD_LOG_INIT("TcpChannel");
@@ -108,12 +109,12 @@ TcpChannel::createFace(ip::tcp::socket&& socket,
if (it == m_channelFaces.end()) {
auto persistency = isOnDemand ? ndn::nfd::FACE_PERSISTENCY_ON_DEMAND
: ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
auto linkService = make_unique<face::GenericLinkService>();
auto linkService = make_unique<GenericLinkService>();
auto options = linkService->getOptions();
options.allowLocalFields = wantLocalFieldsEnabled;
linkService->setOptions(options);
auto transport = make_unique<face::TcpTransport>(std::move(socket), persistency);
auto transport = make_unique<TcpTransport>(std::move(socket), persistency);
face = make_shared<Face>(std::move(linkService), std::move(transport));
@@ -220,4 +221,5 @@ TcpChannel::handleConnectTimeout(const shared_ptr<ip::tcp::socket>& socket,
onConnectFailed(504, "Connect to remote endpoint timed out");
}
} // namespace face
} // namespace nfd
+4 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2016, Regents of the University of California,
* Copyright (c) 2014-2017, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -35,6 +35,8 @@ namespace tcp {
typedef boost::asio::ip::tcp::endpoint Endpoint;
} // namespace tcp
namespace face {
/**
* \brief Class implementing TCP-based channel to create faces
*
@@ -129,6 +131,7 @@ TcpChannel::isListening() const
return m_acceptor.is_open();
}
} // namespace face
} // namespace nfd
#endif // NFD_DAEMON_FACE_TCP_CHANNEL_HPP
+6 -4
View File
@@ -29,10 +29,11 @@
#include "core/global-io.hpp"
namespace nfd {
namespace face {
NFD_LOG_INIT("UdpChannel");
using namespace boost::asio;
namespace ip = boost::asio::ip;
UdpChannel::UdpChannel(const udp::Endpoint& localEndpoint,
const time::seconds& timeout)
@@ -136,7 +137,7 @@ UdpChannel::handleNewPeer(const boost::system::error_code& error,
onFaceCreated(face);
// dispatch the datagram to the face for processing
static_cast<face::UnicastUdpTransport*>(face->getTransport())->receiveDatagram(m_inputBuffer, nBytesReceived, error);
static_cast<UnicastUdpTransport*>(face->getTransport())->receiveDatagram(m_inputBuffer, nBytesReceived, error);
this->waitForNewPeer(onFaceCreated, onReceiveFailed);
}
@@ -156,8 +157,8 @@ UdpChannel::createFace(const udp::Endpoint& remoteEndpoint, ndn::nfd::FacePersis
socket.bind(m_localEndpoint);
socket.connect(remoteEndpoint);
auto linkService = make_unique<face::GenericLinkService>();
auto transport = make_unique<face::UnicastUdpTransport>(std::move(socket), persistency, m_idleFaceTimeout);
auto linkService = make_unique<GenericLinkService>();
auto transport = make_unique<UnicastUdpTransport>(std::move(socket), persistency, m_idleFaceTimeout);
auto face = make_shared<Face>(std::move(linkService), std::move(transport));
m_channelFaces[remoteEndpoint] = face;
@@ -170,4 +171,5 @@ UdpChannel::createFace(const udp::Endpoint& remoteEndpoint, ndn::nfd::FacePersis
return {true, face};
}
} // namespace face
} // namespace nfd
+2
View File
@@ -30,6 +30,7 @@
#include "udp-protocol.hpp"
namespace nfd {
namespace face {
/**
* \brief Class implementing UDP-based channel to create faces
@@ -133,6 +134,7 @@ UdpChannel::isListening() const
return m_socket.is_open();
}
} // namespace face
} // namespace nfd
#endif // NFD_DAEMON_FACE_UDP_CHANNEL_HPP
+5 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2016, Regents of the University of California,
* Copyright (c) 2014-2017, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -32,6 +32,7 @@
#include <sys/stat.h> // for chmod()
namespace nfd {
namespace face {
NFD_LOG_INIT("UnixStreamChannel");
@@ -132,8 +133,8 @@ UnixStreamChannel::handleAccept(const boost::system::error_code& error,
NFD_LOG_DEBUG("[" << m_endpoint << "] Incoming connection");
auto linkService = make_unique<face::GenericLinkService>();
auto transport = make_unique<face::UnixStreamTransport>(std::move(m_socket));
auto linkService = make_unique<GenericLinkService>();
auto transport = make_unique<UnixStreamTransport>(std::move(m_socket));
auto face = make_shared<Face>(std::move(linkService), std::move(transport));
onFaceCreated(face);
@@ -141,4 +142,5 @@ UnixStreamChannel::handleAccept(const boost::system::error_code& error,
accept(onFaceCreated, onAcceptFailed);
}
} // namespace face
} // namespace nfd
+4 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2016, Regents of the University of California,
* Copyright (c) 2014-2017, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -34,6 +34,8 @@ namespace unix_stream {
typedef boost::asio::local::stream_protocol::endpoint Endpoint;
} // namespace unix_stream
namespace face {
/**
* \brief Class implementing a local channel to create faces
*
@@ -101,6 +103,7 @@ UnixStreamChannel::isListening() const
return m_acceptor.is_open();
}
} // namespace face
} // namespace nfd
#endif // NFD_DAEMON_FACE_UNIX_STREAM_CHANNEL_HPP
+8 -6
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, Regents of the University of California,
* Copyright (c) 2014-2017, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -29,6 +29,7 @@
#include "core/global-io.hpp"
namespace nfd {
namespace face {
NFD_LOG_INIT("WebSocketChannel");
@@ -77,7 +78,7 @@ WebSocketChannel::handlePongTimeout(websocketpp::connection_hdl hdl)
{
auto it = m_channelFaces.find(hdl);
if (it != m_channelFaces.end()) {
static_cast<face::WebSocketTransport*>(it->second->getTransport())->handlePongTimeout();
static_cast<WebSocketTransport*>(it->second->getTransport())->handlePongTimeout();
}
else {
NFD_LOG_WARN("Pong timeout on unknown transport");
@@ -89,7 +90,7 @@ WebSocketChannel::handlePong(websocketpp::connection_hdl hdl)
{
auto it = m_channelFaces.find(hdl);
if (it != m_channelFaces.end()) {
static_cast<face::WebSocketTransport*>(it->second->getTransport())->handlePong();
static_cast<WebSocketTransport*>(it->second->getTransport())->handlePong();
}
else {
NFD_LOG_WARN("Pong received on unknown transport");
@@ -102,7 +103,7 @@ WebSocketChannel::handleMessage(websocketpp::connection_hdl hdl,
{
auto it = m_channelFaces.find(hdl);
if (it != m_channelFaces.end()) {
static_cast<face::WebSocketTransport*>(it->second->getTransport())->receiveMessage(msg->get_payload());
static_cast<WebSocketTransport*>(it->second->getTransport())->receiveMessage(msg->get_payload());
}
else {
NFD_LOG_WARN("Message received on unknown transport");
@@ -112,8 +113,8 @@ WebSocketChannel::handleMessage(websocketpp::connection_hdl hdl,
void
WebSocketChannel::handleOpen(websocketpp::connection_hdl hdl)
{
auto linkService = make_unique<face::GenericLinkService>();
auto transport = make_unique<face::WebSocketTransport>(hdl, ref(m_server), m_pingInterval);
auto linkService = make_unique<GenericLinkService>();
auto transport = make_unique<WebSocketTransport>(hdl, ref(m_server), m_pingInterval);
auto face = make_shared<Face>(std::move(linkService), std::move(transport));
m_channelFaces[hdl] = face;
@@ -153,4 +154,5 @@ WebSocketChannel::size() const
return m_channelFaces.size();
}
} // namespace face
} // namespace nfd
+4 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2015, Regents of the University of California,
* Copyright (c) 2014-2017, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -35,6 +35,8 @@ namespace websocket {
typedef boost::asio::ip::tcp::endpoint Endpoint;
} // namespace websocket
namespace face {
/**
* \brief Class implementing WebSocket-based channel to create faces
*/
@@ -114,6 +116,7 @@ WebSocketChannel::isListening() const
return m_server.is_listening();
}
} // namespace face
} // namespace nfd
#endif // NFD_DAEMON_FACE_WEBSOCKET_CHANNEL_HPP
+5 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2016, Regents of the University of California,
* Copyright (c) 2014-2017, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -32,8 +32,11 @@
#include <type_traits>
namespace nfd {
namespace face {
namespace tests {
using namespace nfd::tests;
template<class ChannelT, class EndpointT>
class ChannelFixture : public BaseFixture
{
@@ -104,6 +107,7 @@ private:
};
} // namespace tests
} // namespace face
} // namespace nfd
#endif // NFD_TESTS_DAEMON_FACE_CHANNEL_FIXTURE_HPP
+5 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2016, Regents of the University of California,
* Copyright (c) 2014-2017, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -31,12 +31,13 @@
#include "channel-fixture.hpp"
namespace nfd {
namespace face {
namespace tests {
class TcpChannelFixture : public ChannelFixture<TcpChannel, tcp::Endpoint>
{
protected:
virtual unique_ptr<TcpChannel>
unique_ptr<TcpChannel>
makeChannel(const boost::asio::ip::address& addr, uint16_t port = 0) final
{
if (port == 0)
@@ -45,7 +46,7 @@ protected:
return make_unique<TcpChannel>(tcp::Endpoint(addr, port));
}
virtual void
void
connect(TcpChannel& channel) final
{
g_io.post([&] {
@@ -65,6 +66,7 @@ protected:
};
} // namespace tests
} // namespace face
} // namespace nfd
#endif // NFD_TESTS_DAEMON_FACE_TCP_CHANNEL_FIXTURE_HPP
+3 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2016, Regents of the University of California,
* Copyright (c) 2014-2017, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -30,6 +30,7 @@
#include <boost/mpl/vector.hpp>
namespace nfd {
namespace face {
namespace tests {
BOOST_AUTO_TEST_SUITE(Face)
@@ -64,4 +65,5 @@ BOOST_AUTO_TEST_SUITE_END() // TestTcpChannel
BOOST_AUTO_TEST_SUITE_END() // Face
} // namespace tests
} // namespace face
} // namespace nfd
+3 -1
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2016, Regents of the University of California,
* Copyright (c) 2014-2017, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -31,6 +31,7 @@
#include <boost/mpl/vector.hpp>
namespace nfd {
namespace face {
namespace tests {
BOOST_AUTO_TEST_SUITE(Face)
@@ -148,4 +149,5 @@ BOOST_AUTO_TEST_SUITE_END() // TestTcpUdpChannel
BOOST_AUTO_TEST_SUITE_END() // Face
} // namespace tests
} // namespace face
} // namespace nfd
+5 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2016, Regents of the University of California,
* Copyright (c) 2014-2017, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -32,12 +32,13 @@
#include "channel-fixture.hpp"
namespace nfd {
namespace face {
namespace tests {
class UdpChannelFixture : public ChannelFixture<UdpChannel, udp::Endpoint>
{
protected:
virtual unique_ptr<UdpChannel>
unique_ptr<UdpChannel>
makeChannel(const boost::asio::ip::address& addr, uint16_t port = 0) final
{
if (port == 0)
@@ -46,7 +47,7 @@ protected:
return make_unique<UdpChannel>(udp::Endpoint(addr, port), time::seconds(2));
}
virtual void
void
connect(UdpChannel& channel) final
{
g_io.post([&] {
@@ -68,6 +69,7 @@ protected:
};
} // namespace tests
} // namespace face
} // namespace nfd
#endif // NFD_TESTS_DAEMON_FACE_UDP_CHANNEL_FIXTURE_HPP
+4 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2016, Regents of the University of California,
* Copyright (c) 2014-2017, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -31,6 +31,7 @@
#include <fstream>
namespace nfd {
namespace face {
namespace tests {
namespace fs = boost::filesystem;
@@ -44,7 +45,7 @@ protected:
listenerEp = unix_stream::Endpoint("nfd-test-unix-stream-channel.sock");
}
virtual unique_ptr<UnixStreamChannel>
unique_ptr<UnixStreamChannel>
makeChannel() final
{
return make_unique<UnixStreamChannel>(listenerEp);
@@ -174,4 +175,5 @@ BOOST_AUTO_TEST_SUITE_END() // TestUnixStreamChannel
BOOST_AUTO_TEST_SUITE_END() // Face
} // namespace tests
} // namespace face
} // namespace nfd
+4 -2
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2016, Regents of the University of California,
* Copyright (c) 2014-2017, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -30,6 +30,7 @@
#include "test-ip.hpp"
namespace nfd {
namespace face {
namespace tests {
namespace ip = boost::asio::ip;
@@ -37,7 +38,7 @@ namespace ip = boost::asio::ip;
class WebSocketChannelFixture : public ChannelFixture<WebSocketChannel, websocket::Endpoint>
{
protected:
virtual unique_ptr<WebSocketChannel>
unique_ptr<WebSocketChannel>
makeChannel(const ip::address& addr, uint16_t port = 0) final
{
if (port == 0)
@@ -319,4 +320,5 @@ BOOST_AUTO_TEST_SUITE_END() // TestWebSocketChannel
BOOST_AUTO_TEST_SUITE_END() // Face
} // namespace tests
} // namespace face
} // namespace nfd
+5 -5
View File
@@ -239,7 +239,7 @@ BOOST_AUTO_TEST_CASE(FaceQuery)
CheckResponseResult::OK);
}
class TestChannel : public Channel
class TestChannel : public face::Channel
{
public:
explicit
@@ -263,12 +263,12 @@ public:
const ndn::optional<FaceUri>& localUri,
ndn::nfd::FacePersistency persistency,
bool wantLocalFieldsEnabled,
const FaceCreatedCallback& onCreated,
const FaceCreationFailedCallback& onConnectFailed) final
const face::FaceCreatedCallback& onCreated,
const face::FaceCreationFailedCallback& onConnectFailed) final
{
}
std::vector<shared_ptr<const Channel>>
std::vector<shared_ptr<const face::Channel>>
getChannels() const final
{
return m_channels;
@@ -284,7 +284,7 @@ public:
}
private:
std::vector<shared_ptr<const Channel>> m_channels;
std::vector<shared_ptr<const face::Channel>> m_channels;
};
BOOST_AUTO_TEST_CASE(ChannelDataset)
+3 -3
View File
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2014-2016, Regents of the University of California,
* Copyright (c) 2014-2017, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -166,8 +166,8 @@ private:
private:
boost::asio::signal_set m_terminationSignalSet;
TcpChannel m_tcpChannel;
UdpChannel m_udpChannel;
face::TcpChannel m_tcpChannel;
face::UdpChannel m_udpChannel;
std::vector<std::pair<FaceUri, FaceUri>> m_faceUris;
};