Skip to content

Commit

Permalink
core: slim down common.hpp
Browse files Browse the repository at this point in the history
Change-Id: I875c35147edd2261fbaa24e809c170d5cd9b94d3
  • Loading branch information
Pesa committed Jan 28, 2024
1 parent 91c15c8 commit 2c9d2ca
Show file tree
Hide file tree
Showing 109 changed files with 381 additions and 246 deletions.
16 changes: 1 addition & 15 deletions core/common.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-2023, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -46,12 +46,8 @@

#include <cstddef>
#include <cstdint>
#include <functional>
#include <limits>
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <stdexcept>
#include <string>
#include <string_view>
Expand All @@ -63,10 +59,8 @@
#include <ndn-cxx/name.hpp>
#include <ndn-cxx/encoding/block.hpp>
#include <ndn-cxx/lp/nack.hpp>
#include <ndn-cxx/net/face-uri.hpp>
#include <ndn-cxx/util/backports.hpp>
#include <ndn-cxx/util/exception.hpp>
#include <ndn-cxx/util/scheduler.hpp>
#include <ndn-cxx/util/signal.hpp>
#include <ndn-cxx/util/span.hpp>
#include <ndn-cxx/util/time.hpp>
Expand All @@ -84,11 +78,6 @@ using std::weak_ptr;
using std::make_shared;
using std::make_unique;

using std::static_pointer_cast;
using std::dynamic_pointer_cast;
using std::const_pointer_cast;

using std::to_string;
using namespace std::string_literals;
using namespace std::string_view_literals;

Expand All @@ -97,11 +86,9 @@ using boost::noncopyable;
using ndn::span;
using ndn::Block;
using ndn::Data;
using ndn::FaceUri;
using ndn::Interest;
using ndn::Name;
using ndn::PartialName;
using ndn::Scheduler;

// Not using a namespace alias (namespace tlv = ndn::tlv), because
// it doesn't allow NFD to add other members to the namespace
Expand All @@ -111,7 +98,6 @@ using namespace ndn::tlv;

namespace lp = ndn::lp;
namespace name = ndn::name;
namespace scheduler = ndn::scheduler;
namespace signal = ndn::signal;
namespace time = ndn::time;

Expand Down
4 changes: 2 additions & 2 deletions daemon/common/config-file.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-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -106,7 +106,7 @@ ConfigFile::parse(std::istream& input, bool isDryRun, const std::string& filenam
}
catch (const boost::property_tree::info_parser_error& error) {
NDN_THROW(Error("Failed to parse configuration file " + filename +
": " + error.message() + " on line " + to_string(error.line())));
": " + error.message() + " on line " + std::to_string(error.line())));
}

process(isDryRun, filename);
Expand Down
9 changes: 6 additions & 3 deletions daemon/common/config-file.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-2023, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -30,6 +30,9 @@

#include <boost/property_tree/ptree.hpp>

#include <functional>
#include <map>

namespace nfd {

/**
Expand Down Expand Up @@ -140,9 +143,9 @@ class ConfigFile : noncopyable
static_assert(std::is_integral_v<T>);

if (value < min || value > max) {
NDN_THROW(Error("Invalid value '" + to_string(value) + "' for option '" + key +
NDN_THROW(Error("Invalid value '" + std::to_string(value) + "' for option '" + key +
"' in section '" + sectionName + "': out of acceptable range [" +
to_string(min) + ", " + to_string(max) + "]"));
std::to_string(min) + ", " + std::to_string(max) + "]"));
}
}

Expand Down
12 changes: 6 additions & 6 deletions daemon/common/global.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-2023, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand All @@ -27,25 +27,25 @@

namespace nfd {

static thread_local unique_ptr<boost::asio::io_context> g_ioCtx;
static thread_local unique_ptr<Scheduler> g_scheduler;
static thread_local std::unique_ptr<boost::asio::io_context> g_ioCtx;
static thread_local std::unique_ptr<ndn::Scheduler> g_scheduler;
static boost::asio::io_context* g_mainIoCtx = nullptr;
static boost::asio::io_context* g_ribIoCtx = nullptr;

boost::asio::io_context&
getGlobalIoService()
{
if (g_ioCtx == nullptr) {
g_ioCtx = make_unique<boost::asio::io_context>();
g_ioCtx = std::make_unique<boost::asio::io_context>();
}
return *g_ioCtx;
}

Scheduler&
ndn::Scheduler&
getScheduler()
{
if (g_scheduler == nullptr) {
g_scheduler = make_unique<Scheduler>(getGlobalIoService());
g_scheduler = std::make_unique<ndn::Scheduler>(getGlobalIoService());
}
return *g_scheduler;
}
Expand Down
7 changes: 4 additions & 3 deletions daemon/common/global.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-2023 Regents of the University of California,
* Copyright (c) 2014-2024 Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand All @@ -25,9 +25,10 @@
#ifndef NFD_DAEMON_COMMON_GLOBAL_HPP
#define NFD_DAEMON_COMMON_GLOBAL_HPP

#include "core/common.hpp"
#include "core/config.hpp"

#include <boost/asio/io_context.hpp>
#include <ndn-cxx/util/scheduler.hpp>

namespace nfd {

Expand All @@ -40,7 +41,7 @@ getGlobalIoService();
/**
* \brief Returns the global Scheduler instance for the calling thread.
*/
Scheduler&
ndn::Scheduler&
getScheduler();

boost::asio::io_context&
Expand Down
10 changes: 5 additions & 5 deletions daemon/common/privilege-helper.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-2021, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -123,11 +123,11 @@ PrivilegeHelper::drop()

NFD_LOG_TRACE("dropping to effective gid=" << s_normalGid);
if (::setegid(s_normalGid) != 0)
throw Error("Failed to drop to effective gid=" + to_string(s_normalGid));
throw Error("Failed to drop to effective gid=" + std::to_string(s_normalGid));

NFD_LOG_TRACE("dropping to effective uid=" << s_normalUid);
if (::seteuid(s_normalUid) != 0)
throw Error("Failed to drop to effective uid=" + to_string(s_normalUid));
throw Error("Failed to drop to effective uid=" + std::to_string(s_normalUid));

NFD_LOG_INFO("dropped to effective uid=" << ::geteuid() << " gid=" << ::getegid());
#else
Expand All @@ -144,11 +144,11 @@ PrivilegeHelper::raise()

NFD_LOG_TRACE("elevating to effective uid=" << s_privilegedUid);
if (::seteuid(s_privilegedUid) != 0)
throw Error("Failed to elevate to effective uid=" + to_string(s_privilegedUid));
throw Error("Failed to elevate to effective uid=" + std::to_string(s_privilegedUid));

NFD_LOG_TRACE("elevating to effective gid=" << s_privilegedGid);
if (::setegid(s_privilegedGid) != 0)
throw Error("Failed to elevate to effective gid=" + to_string(s_privilegedGid));
throw Error("Failed to elevate to effective gid=" + std::to_string(s_privilegedGid));

NFD_LOG_INFO("elevated to effective uid=" << ::geteuid() << " gid=" << ::getegid());
#else
Expand Down
4 changes: 3 additions & 1 deletion daemon/face/channel.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-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -29,6 +29,8 @@
#include "channel-log.hpp"
#include "face-common.hpp"

#include <functional>

namespace nfd::face {

/** \brief Represents a channel that listens on a local endpoint.
Expand Down
2 changes: 1 addition & 1 deletion daemon/face/ethernet-channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ EthernetChannel::updateFilter()
if (!isListening())
return;

std::string filter = "(ether proto " + to_string(ethernet::ETHERTYPE_NDN) +
std::string filter = "(ether proto " + std::to_string(ethernet::ETHERTYPE_NDN) +
") && (ether dst " + m_localEndpoint->getEthernetAddress().toString() + ")";
for (const auto& addr : m_channelFaces | boost::adaptors::map_keys) {
filter += " && (not ether src " + addr.toString() + ")";
Expand Down
2 changes: 2 additions & 0 deletions daemon/face/ethernet-channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <boost/asio/posix/stream_descriptor.hpp>
#include <ndn-cxx/net/network-interface.hpp>

#include <map>

namespace nfd::face {

/**
Expand Down
4 changes: 2 additions & 2 deletions daemon/face/ethernet-factory.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-2023, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -199,7 +199,7 @@ EthernetFactory::doCreateFace(const CreateFaceRequest& req,
if (req.params.mtu && *req.params.mtu < MIN_MTU) {
// The specified MTU must be greater than the minimum possible
NFD_LOG_TRACE("createFace: override MTU cannot be less than " << MIN_MTU);
onFailure(406, "Override MTU cannot be less than " + to_string(MIN_MTU));
onFailure(406, "Override MTU cannot be less than " + std::to_string(MIN_MTU));
return;
}

Expand Down
4 changes: 2 additions & 2 deletions daemon/face/ethernet-protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ std::tuple<const ether_header*, std::string>
checkFrameHeader(span<const uint8_t> packet, const Address& localAddr, const Address& destAddr)
{
if (packet.size() < HDR_LEN + MIN_DATA_LEN)
return {nullptr, "Received frame too short: " + to_string(packet.size()) + " bytes"};
return {nullptr, "Received frame too short: " + std::to_string(packet.size()) + " bytes"};

const ether_header* eh = reinterpret_cast<const ether_header*>(packet.data());

// in some cases VLAN-tagged frames may survive the BPF filter,
// make sure we do not process those frames (see #3348)
uint16_t ethertype = boost::endian::big_to_native(eh->ether_type);
if (ethertype != ETHERTYPE_NDN)
return {nullptr, "Received frame with wrong ethertype: " + to_string(ethertype)};
return {nullptr, "Received frame with wrong ethertype: " + std::to_string(ethertype)};

#ifndef NDEBUG
Address shost(eh->ether_shost);
Expand Down
4 changes: 2 additions & 2 deletions daemon/face/ethernet-transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ EthernetTransport::sendPacket(const ndn::Block& block)
if (sent < 0)
handleError("Send operation failed: " + m_pcap.getLastError());
else if (static_cast<size_t>(sent) < buffer.size())
handleError("Failed to send the full frame: size=" + to_string(buffer.size()) +
" sent=" + to_string(sent));
handleError("Failed to send the full frame: size=" + std::to_string(buffer.size()) +
" sent=" + std::to_string(sent));
else
// print block size because we don't want to count the padding in buffer
NFD_LOG_FACE_TRACE("Successfully sent: " << block.size() << " bytes");
Expand Down
25 changes: 15 additions & 10 deletions daemon/face/face-common.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-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -31,6 +31,7 @@
#include "common/logger.hpp"

#include <ndn-cxx/encoding/nfd-constants.hpp>
#include <ndn-cxx/net/face-uri.hpp>

#include <boost/logic/tribool.hpp>
#include <variant>
Expand Down Expand Up @@ -76,10 +77,11 @@ inline constexpr ssize_t MIN_MTU = 64;
*/
using EndpointId = std::variant<std::monostate, ethernet::Address, udp::Endpoint>;

/** \brief Parameters used to set Transport properties or LinkService options on a newly created face.
/**
* \brief Parameters used to set Transport properties or LinkService options on a newly created face.
*
* Parameters are passed as a struct rather than individually, so that a future change in the list
* of parameters does not require an update to the method signature in all subclasses.
* Parameters are passed as a struct rather than individually, so that a future change in the list
* of parameters does not require an update to the method signature in all subclasses.
*/
struct FaceParams
{
Expand All @@ -92,13 +94,14 @@ struct FaceParams
boost::logic::tribool wantCongestionMarking = boost::logic::indeterminate;
};

/** \brief For internal use by FaceLogging macros.
/**
* \brief For internal use by FaceLogging macros.
*
* FaceLogHelper wraps a reference to Face, LinkService, or Transport object.
* FaceLogHelper wraps a reference to Face, LinkService, or Transport object.
*
* `std::ostream& operator<<(std::ostream& os, const FaceLogHelper<T>& flh)`
* should be specialized to print "[id=888,local=scheme://local/uri,remote=scheme://remote/uri] "
* which will appear as part of the log message.
* `std::ostream& operator<<(std::ostream& os, const FaceLogHelper<T>& flh)`
* should be specialized to print "[id=888,local=scheme://local/uri,remote=scheme://remote/uri] "
* which will appear as part of the log message.
*/
template<typename T>
class FaceLogHelper
Expand All @@ -118,10 +121,12 @@ class FaceLogHelper

using face::EndpointId;
using face::FaceId;
using ::ndn::FaceUri;

} // namespace nfd

/** \defgroup FaceLogging Face logging macros
/**
* \defgroup FaceLogging Face logging macros.
*
* These macros augment the log message with some face-specific information,
* such as the face ID, that are useful to distinguish which face produced the
Expand Down
5 changes: 4 additions & 1 deletion daemon/face/face-system.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-2023, Regents of the University of California,
* Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
Expand Down Expand Up @@ -32,6 +32,9 @@
#include <ndn-cxx/net/network-interface.hpp>
#include <ndn-cxx/net/network-monitor.hpp>

#include <map>
#include <set>

namespace nfd {

class FaceTable;
Expand Down
2 changes: 2 additions & 0 deletions daemon/face/generic-link-service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "lp-reassembler.hpp"
#include "lp-reliability.hpp"

#include <limits>

namespace nfd::face {

/** \brief Counters provided by GenericLinkService.
Expand Down
Loading

0 comments on commit 2c9d2ca

Please sign in to comment.