Skip to content

Commit

Permalink
face: minor code cleanups
Browse files Browse the repository at this point in the history
Change-Id: I154d2ad4dfd9e12e1fa9756f74884286b31298e4
  • Loading branch information
Pesa committed Oct 8, 2023
1 parent 9c36a65 commit c0df94e
Show file tree
Hide file tree
Showing 21 changed files with 106 additions and 103 deletions.
7 changes: 4 additions & 3 deletions daemon/face/datagram-transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct Unicast {};
struct Multicast {};

/**
* \brief Implements Transport for datagram-based protocols.
* \brief Implements a Transport for datagram-based protocols.
*
* \tparam Protocol A datagram-based protocol in Boost.Asio
* \tparam Addressing The addressing mode, either Unicast or Multicast
Expand All @@ -52,9 +52,10 @@ class DatagramTransport : public Transport
using protocol = Protocol;
using addressing = Addressing;

/** \brief Construct datagram transport.
/**
* \brief Construct datagram transport.
*
* \param socket Protocol-specific socket for the created transport
* \param socket Protocol-specific socket for the created transport
*/
explicit
DatagramTransport(typename protocol::socket&& socket);
Expand Down
8 changes: 4 additions & 4 deletions daemon/face/ethernet-transport.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -36,7 +36,7 @@
namespace nfd::face {

/**
* @brief Base class for Ethernet-based Transports
* @brief Base class for Ethernet-based Transports.
*/
class EthernetTransport : public Transport
{
Expand All @@ -48,7 +48,7 @@ class EthernetTransport : public Transport
};

/**
* @brief Processes the payload of an incoming frame
* @brief Processes the payload of an incoming frame.
* @param payload Payload bytes, starting from the first byte after the Ethernet header
* @param sender Sender address
*/
Expand Down Expand Up @@ -82,7 +82,7 @@ class EthernetTransport : public Transport
doSend(const Block& packet) final;

/**
* @brief Sends the specified TLV block on the network wrapped in an Ethernet frame
* @brief Sends the specified TLV block on the network wrapped in an Ethernet frame.
*/
void
sendPacket(const ndn::Block& block);
Expand Down
5 changes: 2 additions & 3 deletions daemon/face/multicast-ethernet-transport.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -103,8 +103,7 @@ MulticastEthernetTransport::joinMulticastGroup()

#if defined(__APPLE__) || defined(__FreeBSD__)
// see bug #2327
using boost::asio::ip::udp;
udp::socket sock(getGlobalIoService(), udp::v4());
boost::asio::ip::udp::socket sock(getGlobalIoService(), boost::asio::ip::udp::v4());
int fd = sock.native_handle();

// Differences between Linux and the BSDs (including macOS):
Expand Down
8 changes: 4 additions & 4 deletions daemon/face/multicast-ethernet-transport.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -31,21 +31,21 @@
namespace nfd::face {

/**
* @brief A multicast Transport that uses raw Ethernet II frames
* @brief A multicast Transport that uses raw Ethernet II frames.
*/
class MulticastEthernetTransport final : public EthernetTransport
{
public:
/**
* @brief Creates an Ethernet-based transport for multicast communication
* @brief Creates an Ethernet-based transport for multicast communication.
*/
MulticastEthernetTransport(const ndn::net::NetworkInterface& localEndpoint,
const ethernet::Address& mcastAddress,
ndn::nfd::LinkType linkType);

private:
/**
* @brief Enables receiving frames addressed to our MAC multicast group
* @brief Enables receiving frames addressed to our MAC multicast group.
*/
void
joinMulticastGroup();
Expand Down
43 changes: 22 additions & 21 deletions daemon/face/multicast-udp-transport.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -40,11 +40,13 @@

namespace nfd::face {

NFD_LOG_MEMBER_INIT_SPECIALIZED((DatagramTransport<boost::asio::ip::udp, Multicast>), MulticastUdpTransport);
namespace ip = boost::asio::ip;

MulticastUdpTransport::MulticastUdpTransport(const protocol::endpoint& multicastGroup,
protocol::socket&& recvSocket,
protocol::socket&& sendSocket,
NFD_LOG_MEMBER_INIT_SPECIALIZED((DatagramTransport<ip::udp, Multicast>), MulticastUdpTransport);

MulticastUdpTransport::MulticastUdpTransport(const ip::udp::endpoint& multicastGroup,
ip::udp::socket&& recvSocket,
ip::udp::socket&& sendSocket,
ndn::nfd::LinkType linkType)
: DatagramTransport(std::move(recvSocket))
, m_multicastGroup(multicastGroup)
Expand All @@ -57,7 +59,7 @@ MulticastUdpTransport::MulticastUdpTransport(const protocol::endpoint& multicast
this->setLinkType(linkType);
this->setMtu(udp::computeMtu(m_sendSocket.local_endpoint()));

protocol::socket::send_buffer_size sendBufferSizeOption;
boost::asio::socket_base::send_buffer_size sendBufferSizeOption;
boost::system::error_code error;
m_sendSocket.get_option(sendBufferSizeOption);
if (error) {
Expand Down Expand Up @@ -131,55 +133,54 @@ bindToDevice(int fd, const std::string& ifname)
}

void
MulticastUdpTransport::openRxSocket(protocol::socket& sock,
const protocol::endpoint& multicastGroup,
const boost::asio::ip::address& localAddress,
MulticastUdpTransport::openRxSocket(ip::udp::socket& sock,
const ip::udp::endpoint& multicastGroup,
const ip::address& localAddress,
const ndn::net::NetworkInterface* netif)
{
BOOST_ASSERT(!sock.is_open());

sock.open(multicastGroup.protocol());
sock.set_option(protocol::socket::reuse_address(true));
sock.set_option(boost::asio::socket_base::reuse_address(true));

if (multicastGroup.address().is_v4()) {
BOOST_ASSERT(localAddress.is_v4());
sock.bind(multicastGroup);
sock.set_option(boost::asio::ip::multicast::join_group(multicastGroup.address().to_v4(),
localAddress.to_v4()));
sock.set_option(ip::multicast::join_group(multicastGroup.address().to_v4(), localAddress.to_v4()));
}
else {
BOOST_ASSERT(multicastGroup.address().to_v6().scope_id() != 0);
sock.set_option(boost::asio::ip::v6_only(true));
sock.set_option(ip::v6_only(true));
sock.bind(multicastGroup);
sock.set_option(boost::asio::ip::multicast::join_group(multicastGroup.address().to_v6()));
sock.set_option(ip::multicast::join_group(multicastGroup.address().to_v6()));
}

if (netif)
bindToDevice(sock.native_handle(), netif->getName());
}

void
MulticastUdpTransport::openTxSocket(protocol::socket& sock,
const protocol::endpoint& localEndpoint,
MulticastUdpTransport::openTxSocket(ip::udp::socket& sock,
const ip::udp::endpoint& localEndpoint,
const ndn::net::NetworkInterface* netif,
bool enableLoopback)
{
BOOST_ASSERT(!sock.is_open());

sock.open(localEndpoint.protocol());
sock.set_option(protocol::socket::reuse_address(true));
sock.set_option(boost::asio::ip::multicast::enable_loopback(enableLoopback));
sock.set_option(boost::asio::socket_base::reuse_address(true));
sock.set_option(ip::multicast::enable_loopback(enableLoopback));

if (localEndpoint.address().is_v4()) {
sock.bind(localEndpoint);
if (!localEndpoint.address().is_unspecified())
sock.set_option(boost::asio::ip::multicast::outbound_interface(localEndpoint.address().to_v4()));
sock.set_option(ip::multicast::outbound_interface(localEndpoint.address().to_v4()));
}
else {
sock.set_option(boost::asio::ip::v6_only(true));
sock.set_option(ip::v6_only(true));
sock.bind(localEndpoint);
if (netif)
sock.set_option(boost::asio::ip::multicast::outbound_interface(netif->getIndex()));
sock.set_option(ip::multicast::outbound_interface(netif->getIndex()));
}
}

Expand Down
28 changes: 14 additions & 14 deletions daemon/face/multicast-udp-transport.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2022, Regents of the University of California,
* Copyright (c) 2014-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -36,7 +36,7 @@ namespace nfd::face {
NFD_LOG_MEMBER_DECL_SPECIALIZED((DatagramTransport<boost::asio::ip::udp, Multicast>));

/**
* \brief A Transport that communicates on a UDP multicast group
* \brief A Transport that communicates on a UDP multicast group.
*/
class MulticastUdpTransport final : public DatagramTransport<boost::asio::ip::udp, Multicast>
{
Expand All @@ -48,35 +48,35 @@ class MulticastUdpTransport final : public DatagramTransport<boost::asio::ip::ud
};

/**
* \brief Creates a UDP-based transport for multicast communication
* \brief Creates a UDP-based transport for multicast communication.
* \param multicastGroup multicast group
* \param recvSocket socket used to receive multicast packets
* \param sendSocket socket used to send to the multicast group
* \param linkType either `ndn::nfd::LINK_TYPE_MULTI_ACCESS` or `ndn::nfd::LINK_TYPE_AD_HOC`
*/
MulticastUdpTransport(const protocol::endpoint& multicastGroup,
protocol::socket&& recvSocket,
protocol::socket&& sendSocket,
MulticastUdpTransport(const boost::asio::ip::udp::endpoint& multicastGroup,
boost::asio::ip::udp::socket&& recvSocket,
boost::asio::ip::udp::socket&& sendSocket,
ndn::nfd::LinkType linkType);

ssize_t
getSendQueueLength() final;

/**
* \brief Opens and configures the receive-side socket
* \brief Opens and configures the receive-side socket.
*/
static void
openRxSocket(protocol::socket& sock,
const protocol::endpoint& multicastGroup,
openRxSocket(boost::asio::ip::udp::socket& sock,
const boost::asio::ip::udp::endpoint& multicastGroup,
const boost::asio::ip::address& localAddress = {},
const ndn::net::NetworkInterface* netif = nullptr);

/**
* \brief Opens and configures the transmit-side socket
* \brief Opens and configures the transmit-side socket.
*/
static void
openTxSocket(protocol::socket& sock,
const protocol::endpoint& localEndpoint,
openTxSocket(boost::asio::ip::udp::socket& sock,
const boost::asio::ip::udp::endpoint& localEndpoint,
const ndn::net::NetworkInterface* netif = nullptr,
bool enableLoopback = false);

Expand All @@ -88,8 +88,8 @@ class MulticastUdpTransport final : public DatagramTransport<boost::asio::ip::ud
doClose() final;

private:
protocol::endpoint m_multicastGroup;
protocol::socket m_sendSocket;
boost::asio::ip::udp::endpoint m_multicastGroup;
boost::asio::ip::udp::socket m_sendSocket;
};

} // namespace nfd::face
Expand Down
2 changes: 1 addition & 1 deletion daemon/face/network-predicate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class NetworkPredicateBase : private boost::equality_comparable<NetworkPredicate
~NetworkPredicateBase();

/**
* \brief Set the whitelist to "*" and clear the blacklist
* \brief Set the whitelist to "*" and clear the blacklist.
*/
void
clear();
Expand Down
10 changes: 6 additions & 4 deletions daemon/face/stream-transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,21 @@

namespace nfd::face {

/** \brief Implements Transport for stream-based protocols.
/**
* \brief Implements a Transport for stream-based protocols.
*
* \tparam Protocol a stream-based protocol in Boost.Asio
* \tparam Protocol a stream-based protocol in Boost.Asio
*/
template<class Protocol>
class StreamTransport : public Transport
{
public:
using protocol = Protocol;

/** \brief Construct stream transport.
/**
* \brief Construct stream transport.
*
* \param socket Protocol-specific socket for the created transport
* \param socket Protocol-specific socket for the created transport
*/
explicit
StreamTransport(typename protocol::socket&& socket);
Expand Down
6 changes: 3 additions & 3 deletions daemon/face/tcp-channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@

namespace nfd::face {

NFD_LOG_INIT(TcpChannel);

namespace ip = boost::asio::ip;

NFD_LOG_INIT(TcpChannel);

TcpChannel::TcpChannel(const tcp::Endpoint& localEndpoint, bool wantCongestionMarking,
DetermineFaceScopeFromAddress determineFaceScope)
: m_localEndpoint(localEndpoint)
Expand All @@ -59,7 +59,7 @@ TcpChannel::listen(const FaceCreatedCallback& onFaceCreated,
}

m_acceptor.open(m_localEndpoint.protocol());
m_acceptor.set_option(ip::tcp::acceptor::reuse_address(true));
m_acceptor.set_option(boost::asio::socket_base::reuse_address(true));
if (m_localEndpoint.address().is_v6()) {
m_acceptor.set_option(ip::v6_only(true));
}
Expand Down
4 changes: 2 additions & 2 deletions daemon/face/tcp-factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ TcpFactory::doGetChannels() const
}

ndn::nfd::FaceScope
TcpFactory::determineFaceScopeFromAddresses(const boost::asio::ip::address& localAddress,
const boost::asio::ip::address& remoteAddress) const
TcpFactory::determineFaceScopeFromAddresses(const ip::address& localAddress,
const ip::address& remoteAddress) const
{
if (m_local(localAddress) && m_local(remoteAddress)) {
return ndn::nfd::FACE_SCOPE_LOCAL;
Expand Down
8 changes: 5 additions & 3 deletions daemon/face/tcp-transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@

namespace nfd::face {

NFD_LOG_MEMBER_INIT_SPECIALIZED(StreamTransport<boost::asio::ip::tcp>, TcpTransport);
namespace ip = boost::asio::ip;

TcpTransport::TcpTransport(protocol::socket&& socket,
NFD_LOG_MEMBER_INIT_SPECIALIZED(StreamTransport<ip::tcp>, TcpTransport);

TcpTransport::TcpTransport(ip::tcp::socket&& socket,
ndn::nfd::FacePersistency persistency,
ndn::nfd::FaceScope faceScope)
: StreamTransport(std::move(socket))
Expand Down Expand Up @@ -130,7 +132,7 @@ TcpTransport::reconnect()
BOOST_ASSERT(getState() == TransportState::DOWN);

// recreate the socket
m_socket = protocol::socket(m_socket.get_executor());
m_socket = ip::tcp::socket(m_socket.get_executor());
this->resetReceiveBuffer();
this->resetSendQueue();

Expand Down
Loading

0 comments on commit c0df94e

Please sign in to comment.