Use more C++17 features
Mainly structured bindings, inline variables, and class template
argument deduction, plus many more smaller things.
Change-Id: I810d17e0adb470426e4e30c898e03b3140ad052f
diff --git a/daemon/common/config-file.cpp b/daemon/common/config-file.cpp
index 8d70349..a71bade 100644
--- a/daemon/common/config-file.cpp
+++ b/daemon/common/config-file.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -32,8 +32,8 @@
namespace nfd {
-ConfigFile::ConfigFile(UnknownConfigSectionHandler unknownSectionCallback)
- : m_unknownSectionCallback(unknownSectionCallback)
+ConfigFile::ConfigFile(UnknownConfigSectionHandler callback)
+ : m_unknownSectionCallback(std::move(callback))
{
}
@@ -77,7 +77,7 @@
ConfigFile::addSectionHandler(const std::string& sectionName,
ConfigSectionHandler subscriber)
{
- m_subscriptions[sectionName] = subscriber;
+ m_subscriptions[sectionName] = std::move(subscriber);
}
void
diff --git a/daemon/common/privilege-helper.hpp b/daemon/common/privilege-helper.hpp
index f0eb3bd..b26dce6 100644
--- a/daemon/common/privilege-helper.hpp
+++ b/daemon/common/privilege-helper.hpp
@@ -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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -71,7 +71,7 @@
{
raise();
try {
- std::forward<F>(f)();
+ std::invoke(std::forward<F>(f));
}
catch (...) {
drop();
diff --git a/daemon/face/datagram-transport.hpp b/daemon/face/datagram-transport.hpp
index e0e2f58..950a49f 100644
--- a/daemon/face/datagram-transport.hpp
+++ b/daemon/face/datagram-transport.hpp
@@ -178,9 +178,7 @@
NFD_LOG_FACE_TRACE("Received: " << buffer.size() << " bytes from " << m_sender);
- bool isOk = false;
- Block element;
- std::tie(isOk, element) = Block::fromBuffer(buffer);
+ auto [isOk, element] = Block::fromBuffer(buffer);
if (!isOk) {
NFD_LOG_FACE_WARN("Failed to parse incoming packet from " << m_sender);
// This packet won't extend the face lifetime
diff --git a/daemon/face/ethernet-channel.cpp b/daemon/face/ethernet-channel.cpp
index fae9af2..2509140 100644
--- a/daemon/face/ethernet-channel.cpp
+++ b/daemon/face/ethernet-channel.cpp
@@ -120,19 +120,15 @@
return;
}
- span<const uint8_t> pkt;
- std::string err;
- std::tie(pkt, err) = m_pcap.readNextPacket();
-
+ auto [pkt, readErr] = m_pcap.readNextPacket();
if (pkt.empty()) {
- NFD_LOG_CHAN_WARN("Read error: " << err);
+ NFD_LOG_CHAN_WARN("Read error: " << readErr);
}
else {
- const ether_header* eh;
- std::tie(eh, err) = ethernet::checkFrameHeader(pkt, m_localEndpoint->getEthernetAddress(),
- m_localEndpoint->getEthernetAddress());
+ auto [eh, frameErr] = ethernet::checkFrameHeader(pkt, m_localEndpoint->getEthernetAddress(),
+ m_localEndpoint->getEthernetAddress());
if (eh == nullptr) {
- NFD_LOG_CHAN_DEBUG(err);
+ NFD_LOG_CHAN_DEBUG(frameErr);
}
else {
ethernet::Address sender(eh->ether_shost);
diff --git a/daemon/face/ethernet-factory.cpp b/daemon/face/ethernet-factory.cpp
index fec671f..4fea598 100644
--- a/daemon/face/ethernet-factory.cpp
+++ b/daemon/face/ethernet-factory.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2020, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -240,7 +240,7 @@
{
BOOST_ASSERT(address.isMulticast());
- auto key = std::make_pair(netif.getName(), address);
+ std::pair key(netif.getName(), address);
auto found = m_mcastFaces.find(key);
if (found != m_mcastFaces.end()) {
return found->second;
@@ -339,7 +339,7 @@
return nullptr;
}
- if (face->getId() == face::INVALID_FACEID) {
+ if (face->getId() == INVALID_FACEID) {
// new face: register with forwarding
this->addFace(face);
}
diff --git a/daemon/face/ethernet-transport.cpp b/daemon/face/ethernet-transport.cpp
index 7aac95a..568064b 100644
--- a/daemon/face/ethernet-transport.cpp
+++ b/daemon/face/ethernet-transport.cpp
@@ -168,19 +168,15 @@
return;
}
- span<const uint8_t> pkt;
- std::string err;
- std::tie(pkt, err) = m_pcap.readNextPacket();
-
+ auto [pkt, readErr] = m_pcap.readNextPacket();
if (pkt.empty()) {
- NFD_LOG_FACE_WARN("Read error: " << err);
+ NFD_LOG_FACE_WARN("Read error: " << readErr);
}
else {
- const ether_header* eh;
- std::tie(eh, err) = ethernet::checkFrameHeader(pkt, m_srcAddress,
- m_destAddress.isMulticast() ? m_destAddress : m_srcAddress);
+ auto [eh, frameErr] = ethernet::checkFrameHeader(pkt, m_srcAddress,
+ m_destAddress.isMulticast() ? m_destAddress : m_srcAddress);
if (eh == nullptr) {
- NFD_LOG_FACE_WARN(err);
+ NFD_LOG_FACE_WARN(frameErr);
}
else {
ethernet::Address sender(eh->ether_shost);
@@ -204,9 +200,7 @@
{
NFD_LOG_FACE_TRACE("Received: " << payload.size() << " bytes from " << sender);
- bool isOk = false;
- Block element;
- std::tie(isOk, element) = Block::fromBuffer(payload);
+ auto [isOk, element] = Block::fromBuffer(payload);
if (!isOk) {
NFD_LOG_FACE_WARN("Failed to parse incoming packet from " << sender);
// This packet won't extend the face lifetime
diff --git a/daemon/face/face-common.hpp b/daemon/face/face-common.hpp
index 0e6f0bb..039d2fe 100644
--- a/daemon/face/face-common.hpp
+++ b/daemon/face/face-common.hpp
@@ -39,26 +39,28 @@
class Face;
class LinkService;
-/** \brief Identifies a face.
+/**
+ * \brief Identifies a face.
*/
using FaceId = uint64_t;
-/// indicates an invalid FaceId
-const FaceId INVALID_FACEID = ndn::nfd::INVALID_FACE_ID;
-/// identifies the InternalFace used in management
-const FaceId FACEID_INTERNAL_FACE = 1;
-/// identifies a packet comes from the ContentStore
-const FaceId FACEID_CONTENT_STORE = 254;
-/// identifies the NullFace that drops every packet
-const FaceId FACEID_NULL = 255;
-/// upper bound of reserved FaceIds
-const FaceId FACEID_RESERVED_MAX = 255;
+/// Indicates an invalid FaceId
+constexpr FaceId INVALID_FACEID = ndn::nfd::INVALID_FACE_ID;
+/// Identifies the InternalFace used in management
+constexpr FaceId FACEID_INTERNAL_FACE = 1;
+/// Identifies a packet comes from the ContentStore
+constexpr FaceId FACEID_CONTENT_STORE = 254;
+/// Identifies the NullFace that drops every packet
+constexpr FaceId FACEID_NULL = 255;
+/// Upper bound of reserved FaceIds
+constexpr FaceId FACEID_RESERVED_MAX = 255;
-/** \brief Minimum MTU that may be set
+/**
+ * \brief Minimum MTU that may be set.
*
- * This is done to ensure the NDNLPv2 fragmentation feature functions properly.
+ * This is done to ensure the NDNLPv2 fragmentation feature functions properly.
*/
-const ssize_t MIN_MTU = 64;
+constexpr ssize_t MIN_MTU = 64;
/** \brief Identifies a remote endpoint on the link.
*
diff --git a/daemon/face/face-system.cpp b/daemon/face/face-system.cpp
index 79cb436..f86ea25 100644
--- a/daemon/face/face-system.cpp
+++ b/daemon/face/face-system.cpp
@@ -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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -120,22 +120,19 @@
}
// process in protocol factories
- for (const auto& pair : m_factories) {
- const std::string& sectionName = pair.first;
- ProtocolFactory* factory = pair.second.get();
-
+ for (const auto& [sectionName, factory] : m_factories) {
std::set<std::string> oldProvidedSchemes = factory->getProvidedSchemes();
factory->processConfig(configSection.get_child_optional(sectionName), context);
if (!isDryRun) {
- for (const std::string& scheme : factory->getProvidedSchemes()) {
- m_factoryByScheme[scheme] = factory;
+ for (const auto& scheme : factory->getProvidedSchemes()) {
+ m_factoryByScheme[scheme] = factory.get();
if (oldProvidedSchemes.erase(scheme) == 0) {
NFD_LOG_TRACE("factory " << sectionName <<
" provides " << scheme << " FaceUri scheme");
}
}
- for (const std::string& scheme : oldProvidedSchemes) {
+ for (const auto& scheme : oldProvidedSchemes) {
m_factoryByScheme.erase(scheme);
NFD_LOG_TRACE("factory " << sectionName <<
" no longer provides " << scheme << " FaceUri scheme");
diff --git a/daemon/face/face.cpp b/daemon/face/face.cpp
index 6422a39..cc606d0 100644
--- a/daemon/face/face.cpp
+++ b/daemon/face/face.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2017, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -34,7 +34,6 @@
, afterReceiveNack(service->afterReceiveNack)
, onDroppedInterest(service->onDroppedInterest)
, afterStateChange(transport->afterStateChange)
- , m_id(INVALID_FACEID)
, m_service(std::move(service))
, m_transport(std::move(transport))
, m_counters(m_service->getCounters(), m_transport->getCounters())
diff --git a/daemon/face/face.hpp b/daemon/face/face.hpp
index e9731ee..976a959 100644
--- a/daemon/face/face.hpp
+++ b/daemon/face/face.hpp
@@ -202,7 +202,7 @@
}
private:
- FaceId m_id;
+ FaceId m_id = INVALID_FACEID;
unique_ptr<LinkService> m_service;
unique_ptr<Transport> m_transport;
FaceCounters m_counters;
diff --git a/daemon/face/generic-link-service.cpp b/daemon/face/generic-link-service.cpp
index 5ed4ac2..a21aec2 100644
--- a/daemon/face/generic-link-service.cpp
+++ b/daemon/face/generic-link-service.cpp
@@ -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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -312,10 +312,7 @@
return;
}
- bool isReassembled = false;
- Block netPkt;
- lp::Packet firstPkt;
- std::tie(isReassembled, netPkt, firstPkt) = m_reassembler.receiveFragment(endpoint, pkt);
+ auto [isReassembled, netPkt, firstPkt] = m_reassembler.receiveFragment(endpoint, pkt);
if (isReassembled) {
this->decodeNetPacket(netPkt, firstPkt, endpoint);
}
diff --git a/daemon/face/generic-link-service.hpp b/daemon/face/generic-link-service.hpp
index 7a86b09..0f589a3 100644
--- a/daemon/face/generic-link-service.hpp
+++ b/daemon/face/generic-link-service.hpp
@@ -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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -310,7 +310,7 @@
/// number of marked packets in the current incident of congestion
size_t m_nMarkedSinceInMarkingState;
- friend class LpReliability;
+ friend LpReliability;
};
inline const GenericLinkService::Options&
diff --git a/daemon/face/internal-face.cpp b/daemon/face/internal-face.cpp
index 764dfd7..a7aa7fb 100644
--- a/daemon/face/internal-face.cpp
+++ b/daemon/face/internal-face.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -46,7 +46,7 @@
auto clientFace = make_shared<ndn::Face>(clientTransport, getGlobalIoService(), clientKeyChain);
- return std::make_tuple(face, clientFace);
+ return {face, clientFace};
}
} // namespace face
diff --git a/daemon/face/lp-fragmenter.cpp b/daemon/face/lp-fragmenter.cpp
index 7494ca7..6b1755a 100644
--- a/daemon/face/lp-fragmenter.cpp
+++ b/daemon/face/lp-fragmenter.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -39,18 +39,18 @@
static_assert(lp::tlv::FragCount < 253, "FragCount TLV-TYPE must fit in 1 octet");
static_assert(lp::tlv::Fragment < 253, "Fragment TLV-TYPE must fit in 1 octet");
-/** \brief maximum overhead on a single fragment,
- * not counting other NDNLPv2 headers
+/**
+ * \brief Maximum overhead on a single fragment, not counting other NDNLPv2 headers.
*/
-static const size_t MAX_SINGLE_FRAG_OVERHEAD =
+const size_t MAX_SINGLE_FRAG_OVERHEAD =
1 + 9 + // LpPacket TLV-TYPE and TLV-LENGTH
1 + 1 + 8 + // Sequence TLV
1 + 9; // Fragment TLV-TYPE and TLV-LENGTH
-/** \brief maximum overhead of adding fragmentation to payload,
- * not counting other NDNLPv2 headers
+/**
+ * \brief Maximum overhead of adding fragmentation to payload, not counting other NDNLPv2 headers.
*/
-static const size_t MAX_FRAG_OVERHEAD =
+const size_t MAX_FRAG_OVERHEAD =
1 + 9 + // LpPacket TLV-TYPE and TLV-LENGTH
1 + 1 + 8 + // Sequence TLV
1 + 1 + 8 + // FragIndex TLV
@@ -86,18 +86,17 @@
// fast path: fragmentation not needed
// To qualify for fast path, the packet must have space for adding a sequence number,
// because another NDNLPv2 feature may require the sequence number.
- return std::make_tuple(true, std::vector<lp::Packet>{packet});
+ return {true, {packet}};
}
- ndn::Buffer::const_iterator netPktBegin, netPktEnd;
- std::tie(netPktBegin, netPktEnd) = packet.get<lp::FragmentField>();
+ auto [netPktBegin, netPktEnd] = packet.get<lp::FragmentField>();
size_t netPktSize = std::distance(netPktBegin, netPktEnd);
// compute size of other NDNLPv2 headers to be placed on the first fragment
size_t firstHeaderSize = 0;
- const Block& packetWire = packet.wireEncode();
+ const auto& packetWire = packet.wireEncode();
if (packetWire.type() == lp::tlv::LpPacket) {
- for (const Block& element : packetWire.elements()) {
+ for (const auto& element : packetWire.elements()) {
if (element.type() != lp::tlv::Fragment) {
firstHeaderSize += element.size();
}
@@ -107,7 +106,7 @@
// compute payload size
if (MAX_FRAG_OVERHEAD + firstHeaderSize + 1 > mtu) { // 1-octet fragment
NFD_LOG_FACE_WARN("fragmentation error, MTU too small for first fragment: DROP");
- return std::make_tuple(false, std::vector<lp::Packet>{});
+ return {false, {}};
}
size_t firstPayloadSize = std::min(netPktSize, mtu - firstHeaderSize - MAX_FRAG_OVERHEAD);
size_t payloadSize = mtu - MAX_FRAG_OVERHEAD;
@@ -117,7 +116,7 @@
// compute FragCount
if (fragCount > m_options.nMaxFragments) {
NFD_LOG_FACE_WARN("fragmentation error, FragCount over limit: DROP");
- return std::make_tuple(false, std::vector<lp::Packet>{});
+ return {false, {}};
}
// populate fragments
@@ -139,7 +138,7 @@
}
BOOST_ASSERT(fragIndex == fragCount);
- return std::make_tuple(true, frags);
+ return {true, frags};
}
std::ostream&
diff --git a/daemon/face/lp-reassembler.cpp b/daemon/face/lp-reassembler.cpp
index 77a7120..a4b255b 100644
--- a/daemon/face/lp-reassembler.cpp
+++ b/daemon/face/lp-reassembler.cpp
@@ -45,8 +45,6 @@
{
BOOST_ASSERT(packet.has<lp::FragmentField>());
- static auto FALSE_RETURN = std::make_tuple(false, Block(), lp::Packet());
-
// read and check FragIndex and FragCount
uint64_t fragIndex = 0;
uint64_t fragCount = 1;
@@ -59,12 +57,12 @@
if (fragIndex >= fragCount) {
NFD_LOG_FACE_WARN("reassembly error, FragIndex>=FragCount: DROP");
- return FALSE_RETURN;
+ return {false, {}, {}};
}
if (fragCount > m_options.nMaxFragments) {
NFD_LOG_FACE_WARN("reassembly error, FragCount over limit: DROP");
- return FALSE_RETURN;
+ return {false, {}, {}};
}
// check for fast path
@@ -77,10 +75,11 @@
// check Sequence and compute message identifier
if (!packet.has<lp::SequenceField>()) {
NFD_LOG_FACE_WARN("reassembly error, Sequence missing: DROP");
- return FALSE_RETURN;
+ return {false, {}, {}};
}
+
lp::Sequence messageIdentifier = packet.get<lp::SequenceField>() - fragIndex;
- Key key = std::make_tuple(remoteEndpoint, messageIdentifier);
+ Key key(remoteEndpoint, messageIdentifier);
// add to PartialPacket
PartialPacket& pp = m_partialPackets[key];
@@ -92,13 +91,13 @@
else {
if (fragCount != pp.fragCount) {
NFD_LOG_FACE_WARN("reassembly error, FragCount changed: DROP");
- return FALSE_RETURN;
+ return {false, {}, {}};
}
}
if (pp.fragments[fragIndex].has<lp::SequenceField>()) {
NFD_LOG_FACE_TRACE("fragment already received: DROP");
- return FALSE_RETURN;
+ return {false, {}, {}};
}
pp.fragments[fragIndex] = packet;
@@ -109,13 +108,13 @@
Block reassembled = doReassembly(key);
lp::Packet firstFrag(std::move(pp.fragments[0]));
m_partialPackets.erase(key);
- return std::make_tuple(true, reassembled, firstFrag);
+ return {true, reassembled, firstFrag};
}
// set drop timer
pp.dropTimer = getScheduler().schedule(m_options.reassemblyTimeout, [=] { timeoutPartialPacket(key); });
- return FALSE_RETURN;
+ return {false, {}, {}};
}
Block
@@ -125,20 +124,16 @@
size_t payloadSize = std::accumulate(pp.fragments.begin(), pp.fragments.end(), 0U,
[&] (size_t sum, const lp::Packet& pkt) -> size_t {
- ndn::Buffer::const_iterator fragBegin, fragEnd;
- std::tie(fragBegin, fragEnd) = pkt.get<lp::FragmentField>();
+ auto [fragBegin, fragEnd] = pkt.get<lp::FragmentField>();
return sum + std::distance(fragBegin, fragEnd);
});
ndn::Buffer fragBuffer(payloadSize);
auto it = fragBuffer.begin();
-
for (const lp::Packet& frag : pp.fragments) {
- ndn::Buffer::const_iterator fragBegin, fragEnd;
- std::tie(fragBegin, fragEnd) = frag.get<lp::FragmentField>();
+ auto [fragBegin, fragEnd] = frag.get<lp::FragmentField>();
it = std::copy(fragBegin, fragEnd, it);
}
-
return Block(fragBuffer);
}
diff --git a/daemon/face/lp-reassembler.hpp b/daemon/face/lp-reassembler.hpp
index 95c66ff..59db89b 100644
--- a/daemon/face/lp-reassembler.hpp
+++ b/daemon/face/lp-reassembler.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -33,8 +33,9 @@
namespace nfd {
namespace face {
-/** \brief reassembles fragmented network-layer packets
- * \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
+/**
+ * \brief Reassembles fragmented network-layer packets
+ * \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
*/
class LpReassembler : noncopyable
{
@@ -96,7 +97,8 @@
signal::Signal<LpReassembler, EndpointId, size_t> beforeTimeout;
private:
- /** \brief holds all fragments of packet until reassembled
+ /**
+ * \brief Holds all fragments of packet until reassembled
*/
struct PartialPacket
{
@@ -106,12 +108,13 @@
scheduler::ScopedEventId dropTimer;
};
- /** \brief index key for PartialPackets
+ /**
+ * \brief Index key for PartialPackets
*/
- typedef std::tuple<
+ using Key = std::tuple<
EndpointId, // remoteEndpoint
lp::Sequence // message identifier (sequence of the first fragment)
- > Key;
+ >;
Block
doReassembly(const Key& key);
diff --git a/daemon/face/lp-reliability.cpp b/daemon/face/lp-reliability.cpp
index 95849b1..b287bc3 100644
--- a/daemon/face/lp-reliability.cpp
+++ b/daemon/face/lp-reliability.cpp
@@ -80,10 +80,7 @@
lp::Sequence txSeq = assignTxSequence(frag);
// Store LpPacket for future retransmissions
- unackedFragsIt = m_unackedFrags.emplace_hint(unackedFragsIt,
- std::piecewise_construct,
- std::forward_as_tuple(txSeq),
- std::forward_as_tuple(frag));
+ unackedFragsIt = m_unackedFrags.try_emplace(unackedFragsIt, txSeq, frag);
unackedFragsIt->second.sendTime = sendTime;
auto rto = m_rttEst.getEstimatedRto();
lp::Sequence seq = frag.get<lp::SequenceField>();
@@ -179,7 +176,7 @@
m_recentRecvSeqs.erase(m_recentRecvSeqsQueue.front());
m_recentRecvSeqsQueue.pop();
}
- m_recentRecvSeqs.emplace(pktSequence, now);
+ m_recentRecvSeqs.try_emplace(pktSequence, now);
m_recentRecvSeqsQueue.push(pktSequence);
}
@@ -324,13 +321,10 @@
netPkt->didRetx = true;
// Move fragment to new TxSequence mapping
- auto newTxFragIt = m_unackedFrags.emplace_hint(
- m_firstUnackedFrag != m_unackedFrags.end() && m_firstUnackedFrag->first > newTxSeq
- ? m_firstUnackedFrag
- : m_unackedFrags.end(),
- std::piecewise_construct,
- std::forward_as_tuple(newTxSeq),
- std::forward_as_tuple(txFrag.pkt));
+ auto hint = m_firstUnackedFrag != m_unackedFrags.end() && m_firstUnackedFrag->first > newTxSeq
+ ? m_firstUnackedFrag
+ : m_unackedFrags.end();
+ auto newTxFragIt = m_unackedFrags.try_emplace(hint, newTxSeq, txFrag.pkt);
auto& newTxFrag = newTxFragIt->second;
newTxFrag.retxCount = txFrag.retxCount + 1;
newTxFrag.netPkt = netPkt;
diff --git a/daemon/face/lp-reliability.hpp b/daemon/face/lp-reliability.hpp
index 4349fca..c83b0bc 100644
--- a/daemon/face/lp-reliability.hpp
+++ b/daemon/face/lp-reliability.hpp
@@ -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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -39,12 +39,18 @@
class GenericLinkService;
-/** \brief provides for reliable sending and receiving of link-layer packets
- * \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
+/**
+ * \brief Provides for reliable sending and receiving of link-layer packets
+ * \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
*/
class LpReliability : noncopyable
{
public:
+ /// TxSequence TLV-TYPE (3 octets) + TLV-LENGTH (1 octet) + lp::Sequence (8 octets)
+ static constexpr size_t RESERVED_HEADER_SPACE = tlv::sizeOfVarNumber(lp::tlv::TxSequence) +
+ tlv::sizeOfVarNumber(sizeof(lp::Sequence)) +
+ sizeof(lp::Sequence);
+
struct Options
{
/** \brief enables link-layer reliability
@@ -110,7 +116,6 @@
class NetPkt;
using UnackedFrags = std::map<lp::Sequence, UnackedFrag>;
-NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
/** \brief assign TxSequence number to a fragment
* \param frag fragment to assign TxSequence to
* \return assigned TxSequence number
@@ -163,7 +168,8 @@
deleteUnackedFrag(UnackedFrags::iterator fragIt);
NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
- /** \brief contains a sent fragment that has not been acknowledged and associated data
+ /**
+ * \brief Contains a sent fragment that has not been acknowledged and associated data
*/
class UnackedFrag
{
@@ -180,7 +186,8 @@
shared_ptr<NetPkt> netPkt;
};
- /** \brief contains a network-layer packet with unacknowledged fragments
+ /**
+ * \brief Contains a network-layer packet with unacknowledged fragments
*/
class NetPkt
{
@@ -194,13 +201,6 @@
bool didRetx;
};
-public:
- /// TxSequence TLV-TYPE (3 octets) + TLV-LENGTH (1 octet) + lp::Sequence (8 octets)
- static constexpr size_t RESERVED_HEADER_SPACE = tlv::sizeOfVarNumber(lp::tlv::TxSequence) +
- tlv::sizeOfVarNumber(sizeof(lp::Sequence)) +
- sizeof(lp::Sequence);
-
-NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Options m_options;
GenericLinkService* m_linkService;
UnackedFrags m_unackedFrags;
diff --git a/daemon/face/netdev-bound.cpp b/daemon/face/netdev-bound.cpp
index 124ea3a..b22bf62 100644
--- a/daemon/face/netdev-bound.cpp
+++ b/daemon/face/netdev-bound.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -46,9 +46,7 @@
std::vector<Rule> rules;
if (configSection) {
int ruleIndex = 0;
- for (const auto& pair : *configSection) {
- const std::string& key = pair.first;
- const ConfigSection& value = pair.second;
+ for (const auto& [key, value] : *configSection) {
if (key == "rule") {
rules.push_back(parseRule(ruleIndex++, value));
}
@@ -94,9 +92,7 @@
bool hasWhitelist = false;
bool hasBlacklist = false;
- for (const auto& pair : confRule) {
- const std::string& key = pair.first;
- const ConfigSection& value = pair.second;
+ for (const auto& [key, value] : confRule) {
if (key == "remote") {
try {
rule.remotes.emplace_back(value.get_value<std::string>());
diff --git a/daemon/face/protocol-factory.hpp b/daemon/face/protocol-factory.hpp
index 50023cc..fcc0418 100644
--- a/daemon/face/protocol-factory.hpp
+++ b/daemon/face/protocol-factory.hpp
@@ -69,9 +69,11 @@
static void
registerType(const std::string& id = PF::getId())
{
- Registry& registry = getRegistry();
- BOOST_ASSERT(registry.count(id) == 0);
- registry[id] = [] (const CtorParams& p) { return make_unique<PF>(p); };
+ BOOST_ASSERT(!id.empty());
+ auto r = getRegistry().insert_or_assign(id, [] (auto&&... p) {
+ return make_unique<PF>(std::forward<decltype(p)>(p)...);
+ });
+ BOOST_VERIFY(r.second);
}
/** \brief Create a protocol factory instance
diff --git a/daemon/face/tcp-transport.cpp b/daemon/face/tcp-transport.cpp
index 0da07af..466e2c6 100644
--- a/daemon/face/tcp-transport.cpp
+++ b/daemon/face/tcp-transport.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -36,16 +36,12 @@
NFD_LOG_MEMBER_INIT_SPECIALIZED(StreamTransport<boost::asio::ip::tcp>, TcpTransport);
-time::milliseconds TcpTransport::s_initialReconnectWait = 1_s;
-time::milliseconds TcpTransport::s_maxReconnectWait = 5_min;
-float TcpTransport::s_reconnectWaitMultiplier = 2.0f;
-
TcpTransport::TcpTransport(protocol::socket&& socket,
ndn::nfd::FacePersistency persistency,
ndn::nfd::FaceScope faceScope)
: StreamTransport(std::move(socket))
, m_remoteEndpoint(m_socket.remote_endpoint())
- , m_nextReconnectWait(s_initialReconnectWait)
+ , m_nextReconnectWait(INITIAL_RECONNECT_DELAY)
{
this->setLocalUri(FaceUri(m_socket.local_endpoint()));
this->setRemoteUri(FaceUri(m_socket.remote_endpoint()));
@@ -165,7 +161,7 @@
}
m_reconnectEvent.cancel();
- m_nextReconnectWait = s_initialReconnectWait;
+ m_nextReconnectWait = INITIAL_RECONNECT_DELAY;
this->setLocalUri(FaceUri(m_socket.local_endpoint()));
NFD_LOG_FACE_TRACE("TCP connection reestablished");
@@ -182,8 +178,8 @@
// exponentially back off the reconnection timer
m_nextReconnectWait =
- std::min(time::duration_cast<time::milliseconds>(m_nextReconnectWait * s_reconnectWaitMultiplier),
- s_maxReconnectWait);
+ std::min(time::duration_cast<time::milliseconds>(m_nextReconnectWait * RECONNECT_DELAY_MULTIPLIER),
+ MAX_RECONNECT_DELAY);
// do this asynchronously because there could be some callbacks still pending
getGlobalIoService().post([this] { reconnect(); });
diff --git a/daemon/face/tcp-transport.hpp b/daemon/face/tcp-transport.hpp
index c300eed..950d850 100644
--- a/daemon/face/tcp-transport.hpp
+++ b/daemon/face/tcp-transport.hpp
@@ -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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -72,17 +72,20 @@
handleReconnectTimeout();
NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
- /** \brief how long to wait before the first reconnection attempt after the TCP connection has been severed
+ /**
+ * \brief Delay before the first reconnection attempt after the TCP connection has been severed
*/
- static time::milliseconds s_initialReconnectWait;
+ static constexpr time::milliseconds INITIAL_RECONNECT_DELAY = 1_s;
- /** \brief maximum amount of time to wait before a reconnection attempt
+ /**
+ * \brief Maximum amount of time to wait before a reconnection attempt
*/
- static time::milliseconds s_maxReconnectWait;
+ static constexpr time::milliseconds MAX_RECONNECT_DELAY = 5_min;
- /** \brief multiplier for the exponential backoff of the reconnection timer
+ /**
+ * \brief Multiplier for the exponential backoff of the reconnection timer
*/
- static float s_reconnectWaitMultiplier;
+ static constexpr float RECONNECT_DELAY_MULTIPLIER = 2.0f;
private:
typename protocol::endpoint m_remoteEndpoint;
diff --git a/daemon/face/transport.hpp b/daemon/face/transport.hpp
index 9b84c99..2725596 100644
--- a/daemon/face/transport.hpp
+++ b/daemon/face/transport.hpp
@@ -86,24 +86,29 @@
ByteCounter nOutBytes;
};
-/** \brief indicates the transport has no limit on payload size
+/**
+ * \brief Indicates that the transport has no limit on payload size
*/
-const ssize_t MTU_UNLIMITED = -1;
+constexpr ssize_t MTU_UNLIMITED = -1;
-/** \brief (for internal use) indicates MTU field is unset
+/**
+ * \brief (for internal use) Indicates that the MTU field is unset
*/
-const ssize_t MTU_INVALID = -2;
+constexpr ssize_t MTU_INVALID = -2;
-/** \brief indicates that the transport does not support reading the queue capacity/length
+/**
+ * \brief Indicates that the transport does not support reading the queue capacity/length
*/
-const ssize_t QUEUE_UNSUPPORTED = -1;
+constexpr ssize_t QUEUE_UNSUPPORTED = -1;
-/** \brief indicates that the transport was unable to retrieve the queue capacity/length
+/**
+ * \brief Indicates that the transport was unable to retrieve the queue capacity/length
*/
-const ssize_t QUEUE_ERROR = -2;
+constexpr ssize_t QUEUE_ERROR = -2;
-/** \brief The lower half of a Face.
- * \sa Face
+/**
+ * \brief The lower half of a Face.
+ * \sa Face
*/
class Transport : protected virtual TransportCounters, noncopyable
{
diff --git a/daemon/fw/access-strategy.cpp b/daemon/fw/access-strategy.cpp
index e1443df..e80c581 100644
--- a/daemon/fw/access-strategy.cpp
+++ b/daemon/fw/access-strategy.cpp
@@ -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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -60,8 +60,7 @@
AccessStrategy::afterReceiveInterest(const Interest& interest, const FaceEndpoint& ingress,
const shared_ptr<pit::Entry>& pitEntry)
{
- auto suppressResult = m_retxSuppression.decidePerPitEntry(*pitEntry);
- switch (suppressResult) {
+ switch (auto res = m_retxSuppression.decidePerPitEntry(*pitEntry); res) {
case RetxSuppressionResult::NEW:
return afterReceiveNewInterest(interest, ingress, pitEntry);
case RetxSuppressionResult::FORWARD:
@@ -77,9 +76,7 @@
const shared_ptr<pit::Entry>& pitEntry)
{
const auto& fibEntry = this->lookupFib(*pitEntry);
- Name miName;
- MtInfo* mi = nullptr;
- std::tie(miName, mi) = this->findPrefixMeasurements(*pitEntry);
+ auto [miName, mi] = this->findPrefixMeasurements(*pitEntry);
// has measurements for Interest Name?
if (mi != nullptr) {
@@ -236,10 +233,7 @@
void
AccessStrategy::updateMeasurements(const Face& inFace, const Data& data, time::nanoseconds rtt)
{
- auto ret = m_fit.emplace(std::piecewise_construct,
- std::forward_as_tuple(inFace.getId()),
- std::forward_as_tuple(m_rttEstimatorOpts));
- FaceInfo& fi = ret.first->second;
+ FaceInfo& fi = m_fit.try_emplace(inFace.getId(), m_rttEstimatorOpts).first->second;
fi.rtt.addMeasurement(rtt);
MtInfo* mi = this->addPrefixMeasurements(data);
@@ -257,14 +251,14 @@
{
auto me = this->getMeasurements().findLongestPrefixMatch(pitEntry);
if (me == nullptr) {
- return std::make_tuple(Name(), nullptr);
+ return {Name{}, nullptr};
}
auto mi = me->getStrategyInfo<MtInfo>();
// TODO: after a runtime strategy change, it's possible that a measurements::Entry exists but
// the corresponding MtInfo doesn't exist (mi == nullptr); this case needs another longest
// prefix match until an MtInfo is found.
- return std::make_tuple(me->getName(), mi);
+ return {me->getName(), mi};
}
AccessStrategy::MtInfo*
diff --git a/daemon/fw/asf-measurements.cpp b/daemon/fw/asf-measurements.cpp
index 2eb81dd..c49f5d5 100644
--- a/daemon/fw/asf-measurements.cpp
+++ b/daemon/fw/asf-measurements.cpp
@@ -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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -30,9 +30,6 @@
namespace fw {
namespace asf {
-const time::nanoseconds FaceInfo::RTT_NO_MEASUREMENT{-1};
-const time::nanoseconds FaceInfo::RTT_TIMEOUT{-2};
-
time::nanoseconds
FaceInfo::scheduleTimeout(const Name& interestName, scheduler::EventCallback cb)
{
@@ -63,11 +60,9 @@
FaceInfo&
NamespaceInfo::getOrCreateFaceInfo(FaceId faceId)
{
- auto ret = m_fiMap.emplace(std::piecewise_construct,
- std::forward_as_tuple(faceId),
- std::forward_as_tuple(m_rttEstimatorOpts));
- auto& faceInfo = ret.first->second;
- if (ret.second) {
+ auto [it, isNew] = m_fiMap.try_emplace(faceId, m_rttEstimatorOpts);
+ auto& faceInfo = it->second;
+ if (isNew) {
extendFaceInfoLifetime(faceInfo, faceId);
}
return faceInfo;
@@ -83,8 +78,6 @@
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
-constexpr time::microseconds AsfMeasurements::MEASUREMENTS_LIFETIME;
-
AsfMeasurements::AsfMeasurements(MeasurementsAccessor& measurements)
: m_measurements(measurements)
, m_rttEstimatorOpts(make_shared<ndn::util::RttEstimator::Options>())
diff --git a/daemon/fw/asf-measurements.hpp b/daemon/fw/asf-measurements.hpp
index a3eafc9..1d2b90f 100644
--- a/daemon/fw/asf-measurements.hpp
+++ b/daemon/fw/asf-measurements.hpp
@@ -105,8 +105,8 @@
}
public:
- static const time::nanoseconds RTT_NO_MEASUREMENT;
- static const time::nanoseconds RTT_TIMEOUT;
+ static constexpr time::nanoseconds RTT_NO_MEASUREMENT = -1_ns;
+ static constexpr time::nanoseconds RTT_TIMEOUT = -2_ns;
private:
ndn::util::RttEstimator m_rttEstimator;
diff --git a/daemon/fw/asf-probing-module.cpp b/daemon/fw/asf-probing-module.cpp
index 425b39c..0df1712 100644
--- a/daemon/fw/asf-probing-module.cpp
+++ b/daemon/fw/asf-probing-module.cpp
@@ -33,11 +33,7 @@
namespace fw {
namespace asf {
-constexpr time::milliseconds ProbingModule::DEFAULT_PROBING_INTERVAL;
-constexpr time::milliseconds ProbingModule::MIN_PROBING_INTERVAL;
-
-static_assert(ProbingModule::DEFAULT_PROBING_INTERVAL < AsfMeasurements::MEASUREMENTS_LIFETIME,
- "ProbingModule::DEFAULT_PROBING_INTERVAL must be less than AsfMeasurements::MEASUREMENTS_LIFETIME");
+static_assert(ProbingModule::DEFAULT_PROBING_INTERVAL < AsfMeasurements::MEASUREMENTS_LIFETIME);
ProbingModule::ProbingModule(AsfMeasurements& measurements)
: m_probingInterval(DEFAULT_PROBING_INTERVAL)
diff --git a/daemon/fw/face-table.cpp b/daemon/fw/face-table.cpp
index 49d33b6..93567bf 100644
--- a/daemon/fw/face-table.cpp
+++ b/daemon/fw/face-table.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -76,19 +76,20 @@
}
void
-FaceTable::addImpl(shared_ptr<Face> face, FaceId faceId)
+FaceTable::addImpl(shared_ptr<Face> facePtr, FaceId faceId)
{
- face->setId(faceId);
- auto ret = m_faces.emplace(faceId, face);
- BOOST_VERIFY(ret.second);
+ facePtr->setId(faceId);
+ auto [it, isNew] = m_faces.try_emplace(faceId, std::move(facePtr));
+ BOOST_VERIFY(isNew);
+ auto& face = *it->second;
NFD_LOG_INFO("Added face id=" << faceId <<
- " remote=" << face->getRemoteUri() <<
- " local=" << face->getLocalUri());
+ " remote=" << face.getRemoteUri() <<
+ " local=" << face.getLocalUri());
- connectFaceClosedSignal(*face, [=] { remove(faceId); });
+ connectFaceClosedSignal(face, [this, faceId] { remove(faceId); });
- this->afterAdd(*face);
+ this->afterAdd(face);
}
void
diff --git a/daemon/fw/forwarder.hpp b/daemon/fw/forwarder.hpp
index 47c6e03..cad9396 100644
--- a/daemon/fw/forwarder.hpp
+++ b/daemon/fw/forwarder.hpp
@@ -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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -251,7 +251,7 @@
NetworkRegionTable m_networkRegionTable;
// allow Strategy (base class) to enter pipelines
- friend class fw::Strategy;
+ friend fw::Strategy;
};
} // namespace nfd
diff --git a/daemon/fw/retx-suppression-exponential.cpp b/daemon/fw/retx-suppression-exponential.cpp
index 114b491..6158120 100644
--- a/daemon/fw/retx-suppression-exponential.cpp
+++ b/daemon/fw/retx-suppression-exponential.cpp
@@ -24,14 +24,11 @@
*/
#include "retx-suppression-exponential.hpp"
+#include "algorithm.hpp"
namespace nfd {
namespace fw {
-const RetxSuppressionExponential::Duration RetxSuppressionExponential::DEFAULT_INITIAL_INTERVAL = 10_ms;
-const RetxSuppressionExponential::Duration RetxSuppressionExponential::DEFAULT_MAX_INTERVAL = 250_ms;
-const float RetxSuppressionExponential::DEFAULT_MULTIPLIER = 2.0f;
-
namespace {
class PitInfo final : public StrategyInfo
diff --git a/daemon/fw/retx-suppression-exponential.hpp b/daemon/fw/retx-suppression-exponential.hpp
index 3c3be60..41d5bdb 100644
--- a/daemon/fw/retx-suppression-exponential.hpp
+++ b/daemon/fw/retx-suppression-exponential.hpp
@@ -26,7 +26,6 @@
#ifndef NFD_DAEMON_FW_RETX_SUPPRESSION_EXPONENTIAL_HPP
#define NFD_DAEMON_FW_RETX_SUPPRESSION_EXPONENTIAL_HPP
-#include "algorithm.hpp"
#include "retx-suppression.hpp"
#include "strategy.hpp"
@@ -83,9 +82,9 @@
}
public:
- static const Duration DEFAULT_INITIAL_INTERVAL;
- static const Duration DEFAULT_MAX_INTERVAL;
- static const float DEFAULT_MULTIPLIER;
+ static constexpr Duration DEFAULT_INITIAL_INTERVAL = 10_ms;
+ static constexpr Duration DEFAULT_MAX_INTERVAL = 250_ms;
+ static constexpr float DEFAULT_MULTIPLIER = 2.0f;
NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
const Duration m_initialInterval;
diff --git a/daemon/fw/retx-suppression-fixed.cpp b/daemon/fw/retx-suppression-fixed.cpp
index 50ade91..790ce45 100644
--- a/daemon/fw/retx-suppression-fixed.cpp
+++ b/daemon/fw/retx-suppression-fixed.cpp
@@ -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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -24,12 +24,11 @@
*/
#include "retx-suppression-fixed.hpp"
+#include "algorithm.hpp"
namespace nfd {
namespace fw {
-const time::milliseconds RetxSuppressionFixed::DEFAULT_MIN_RETX_INTERVAL = 100_ms;
-
RetxSuppressionFixed::RetxSuppressionFixed(const time::milliseconds& minRetxInterval)
: m_minRetxInterval(minRetxInterval)
{
diff --git a/daemon/fw/retx-suppression-fixed.hpp b/daemon/fw/retx-suppression-fixed.hpp
index 33ee765..e8af73b 100644
--- a/daemon/fw/retx-suppression-fixed.hpp
+++ b/daemon/fw/retx-suppression-fixed.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2017, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -26,8 +26,8 @@
#ifndef NFD_DAEMON_FW_RETX_SUPPRESSION_FIXED_HPP
#define NFD_DAEMON_FW_RETX_SUPPRESSION_FIXED_HPP
-#include "algorithm.hpp"
#include "retx-suppression.hpp"
+#include "table/pit-entry.hpp"
namespace nfd {
namespace fw {
@@ -48,7 +48,7 @@
decidePerPitEntry(pit::Entry& pitEntry) const;
public:
- static const time::milliseconds DEFAULT_MIN_RETX_INTERVAL;
+ static constexpr time::milliseconds DEFAULT_MIN_RETX_INTERVAL = 100_ms;
private:
const time::milliseconds m_minRetxInterval;
diff --git a/daemon/fw/self-learning-strategy.cpp b/daemon/fw/self-learning-strategy.cpp
index 89ca397..db58050 100644
--- a/daemon/fw/self-learning-strategy.cpp
+++ b/daemon/fw/self-learning-strategy.cpp
@@ -42,7 +42,7 @@
NFD_LOG_INIT(SelfLearningStrategy);
NFD_REGISTER_STRATEGY(SelfLearningStrategy);
-const time::milliseconds SelfLearningStrategy::ROUTE_RENEW_LIFETIME(10_min);
+constexpr time::milliseconds ROUTE_RENEW_LIFETIME = 10_min;
SelfLearningStrategy::SelfLearningStrategy(Forwarder& forwarder, const Name& name)
: Strategy(forwarder)
@@ -191,11 +191,11 @@
// (the PIT entry's expiry timer was set to 0 before dispatching)
this->setExpiryTimer(pitEntry, 1_s);
- runOnRibIoService([pitEntryWeak = weak_ptr<pit::Entry>{pitEntry}, inFaceId = inFace.getId(), data, this] {
+ runOnRibIoService([this, pitEntryWeak = weak_ptr<pit::Entry>{pitEntry}, inFaceId = inFace.getId(), data] {
rib::Service::get().getRibManager().slFindAnn(data.getName(),
- [pitEntryWeak, inFaceId, data, this] (std::optional<ndn::PrefixAnnouncement> paOpt) {
+ [this, pitEntryWeak, inFaceId, data] (std::optional<ndn::PrefixAnnouncement> paOpt) {
if (paOpt) {
- runOnMainIoService([pitEntryWeak, inFaceId, data, pa = std::move(*paOpt), this] {
+ runOnMainIoService([this, pitEntryWeak, inFaceId, data, pa = std::move(*paOpt)] {
auto pitEntry = pitEntryWeak.lock();
auto inFace = this->getFace(inFaceId);
if (pitEntry && inFace) {
diff --git a/daemon/fw/self-learning-strategy.hpp b/daemon/fw/self-learning-strategy.hpp
index bb4f6f7..47e59af 100644
--- a/daemon/fw/self-learning-strategy.hpp
+++ b/daemon/fw/self-learning-strategy.hpp
@@ -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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -136,9 +136,6 @@
*/
void
renewRoute(const Name& name, FaceId inFaceId, time::milliseconds maxLifetime);
-
-private:
- static const time::milliseconds ROUTE_RENEW_LIFETIME;
};
} // namespace fw
diff --git a/daemon/fw/strategy.hpp b/daemon/fw/strategy.hpp
index 4e162bd..570f219 100644
--- a/daemon/fw/strategy.hpp
+++ b/daemon/fw/strategy.hpp
@@ -52,11 +52,10 @@
{
BOOST_ASSERT(strategyName.size() > 1);
BOOST_ASSERT(strategyName.at(-1).isVersion());
- Registry& registry = getRegistry();
- BOOST_ASSERT(registry.count(strategyName) == 0);
- registry[strategyName] = [] (auto&&... args) {
+ auto r = getRegistry().insert_or_assign(strategyName, [] (auto&&... args) {
return make_unique<S>(std::forward<decltype(args)>(args)...);
- };
+ });
+ BOOST_VERIFY(r.second);
}
/** \return Whether a strategy instance can be created from \p instanceName
diff --git a/daemon/fw/unsolicited-data-policy.cpp b/daemon/fw/unsolicited-data-policy.cpp
index 8cf59d9..b29b827 100644
--- a/daemon/fw/unsolicited-data-policy.cpp
+++ b/daemon/fw/unsolicited-data-policy.cpp
@@ -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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -24,6 +24,7 @@
*/
#include "unsolicited-data-policy.hpp"
+
#include <boost/range/adaptor/map.hpp>
#include <boost/range/algorithm/copy.hpp>
@@ -70,7 +71,7 @@
NFD_REGISTER_UNSOLICITED_DATA_POLICY(DropAllUnsolicitedDataPolicy);
UnsolicitedDataDecision
-DropAllUnsolicitedDataPolicy::decide(const Face& inFace, const Data& data) const
+DropAllUnsolicitedDataPolicy::decide(const Face&, const Data&) const
{
return UnsolicitedDataDecision::DROP;
}
@@ -79,7 +80,7 @@
NFD_REGISTER_UNSOLICITED_DATA_POLICY(AdmitLocalUnsolicitedDataPolicy);
UnsolicitedDataDecision
-AdmitLocalUnsolicitedDataPolicy::decide(const Face& inFace, const Data& data) const
+AdmitLocalUnsolicitedDataPolicy::decide(const Face& inFace, const Data&) const
{
if (inFace.getScope() == ndn::nfd::FACE_SCOPE_LOCAL) {
return UnsolicitedDataDecision::CACHE;
@@ -91,7 +92,7 @@
NFD_REGISTER_UNSOLICITED_DATA_POLICY(AdmitNetworkUnsolicitedDataPolicy);
UnsolicitedDataDecision
-AdmitNetworkUnsolicitedDataPolicy::decide(const Face& inFace, const Data& data) const
+AdmitNetworkUnsolicitedDataPolicy::decide(const Face& inFace, const Data&) const
{
if (inFace.getScope() == ndn::nfd::FACE_SCOPE_NON_LOCAL) {
return UnsolicitedDataDecision::CACHE;
@@ -103,7 +104,7 @@
NFD_REGISTER_UNSOLICITED_DATA_POLICY(AdmitAllUnsolicitedDataPolicy);
UnsolicitedDataDecision
-AdmitAllUnsolicitedDataPolicy::decide(const Face& inFace, const Data& data) const
+AdmitAllUnsolicitedDataPolicy::decide(const Face&, const Data&) const
{
return UnsolicitedDataDecision::CACHE;
}
diff --git a/daemon/fw/unsolicited-data-policy.hpp b/daemon/fw/unsolicited-data-policy.hpp
index 5d562a1..486903a 100644
--- a/daemon/fw/unsolicited-data-policy.hpp
+++ b/daemon/fw/unsolicited-data-policy.hpp
@@ -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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -31,7 +31,8 @@
namespace nfd {
namespace fw {
-/** \brief a decision made by UnsolicitedDataPolicy
+/**
+ * \brief Decision made by UnsolicitedDataPolicy
*/
enum class UnsolicitedDataDecision {
DROP, ///< the Data should be dropped
@@ -41,11 +42,12 @@
std::ostream&
operator<<(std::ostream& os, UnsolicitedDataDecision d);
-/** \brief determines how to process an unsolicited Data
+/**
+ * \brief Determines how to process an unsolicited Data packet
*
- * An incoming Data is unsolicited if it does not match any PIT entry.
- * This class assists forwarding pipelines to decide whether to drop an unsolicited Data
- * or admit it into the ContentStore.
+ * An incoming Data packet is *unsolicited* if it does not match any PIT entry.
+ * This class assists forwarding pipelines to decide whether to drop an unsolicited Data
+ * or admit it into the ContentStore.
*/
class UnsolicitedDataPolicy : noncopyable
{
@@ -61,9 +63,9 @@
static void
registerPolicy(const std::string& policyName = P::POLICY_NAME)
{
- Registry& registry = getRegistry();
- BOOST_ASSERT(registry.count(policyName) == 0);
- registry[policyName] = [] { return make_unique<P>(); };
+ BOOST_ASSERT(!policyName.empty());
+ auto r = getRegistry().insert_or_assign(policyName, [] { return make_unique<P>(); });
+ BOOST_VERIFY(r.second);
}
/** \return an UnsolicitedDataPolicy identified by \p policyName,
@@ -78,14 +80,15 @@
getPolicyNames();
private:
- typedef std::function<unique_ptr<UnsolicitedDataPolicy>()> CreateFunc;
- typedef std::map<std::string, CreateFunc> Registry; // indexed by policy name
+ using CreateFunc = std::function<unique_ptr<UnsolicitedDataPolicy>()>;
+ using Registry = std::map<std::string, CreateFunc>; // indexed by policy name
static Registry&
getRegistry();
};
-/** \brief drops all unsolicited Data
+/**
+ * \brief Drops all unsolicited Data
*/
class DropAllUnsolicitedDataPolicy final : public UnsolicitedDataPolicy
{
@@ -97,7 +100,8 @@
static const std::string POLICY_NAME;
};
-/** \brief admits unsolicited Data from local faces
+/**
+ * \brief Admits unsolicited Data from local faces
*/
class AdmitLocalUnsolicitedDataPolicy final : public UnsolicitedDataPolicy
{
@@ -109,7 +113,8 @@
static const std::string POLICY_NAME;
};
-/** \brief admits unsolicited Data from non-local faces
+/**
+ * \brief Admits unsolicited Data from non-local faces
*/
class AdmitNetworkUnsolicitedDataPolicy final : public UnsolicitedDataPolicy
{
@@ -121,7 +126,8 @@
static const std::string POLICY_NAME;
};
-/** \brief admits all unsolicited Data
+/**
+ * \brief Admits all unsolicited Data
*/
class AdmitAllUnsolicitedDataPolicy final : public UnsolicitedDataPolicy
{
@@ -133,16 +139,18 @@
static const std::string POLICY_NAME;
};
-/** \brief The default UnsolicitedDataPolicy
+/**
+ * \brief The default UnsolicitedDataPolicy
*/
using DefaultUnsolicitedDataPolicy = DropAllUnsolicitedDataPolicy;
} // namespace fw
} // namespace nfd
-/** \brief registers an unsolicited data policy
- * \param P a subclass of nfd::fw::UnsolicitedDataPolicy;
- * P::POLICY_NAME must be a string that contains policy name
+/**
+ * \brief Registers an unsolicited data policy
+ * \param P A subclass of nfd::fw::UnsolicitedDataPolicy. \p P must have a static data
+ * member `POLICY_NAME` convertible to std::string that contains the policy name.
*/
#define NFD_REGISTER_UNSOLICITED_DATA_POLICY(P) \
static class NfdAuto ## P ## UnsolicitedDataPolicyRegistrationClass \
diff --git a/daemon/mgmt/cs-manager.cpp b/daemon/mgmt/cs-manager.cpp
index eaf2cda..36d7014 100644
--- a/daemon/mgmt/cs-manager.cpp
+++ b/daemon/mgmt/cs-manager.cpp
@@ -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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -31,8 +31,6 @@
namespace nfd {
-constexpr size_t CsManager::ERASE_LIMIT;
-
CsManager::CsManager(Cs& cs, const ForwarderCounters& fwCounters,
Dispatcher& dispatcher, CommandAuthenticator& authenticator)
: ManagerBase("cs", dispatcher, authenticator)
@@ -101,8 +99,7 @@
}
void
-CsManager::serveInfo(const Name& topPrefix, const Interest& interest,
- ndn::mgmt::StatusDatasetContext& context) const
+CsManager::serveInfo(const Name&, const Interest&, ndn::mgmt::StatusDatasetContext& context) const
{
ndn::nfd::CsInfo info;
info.setCapacity(m_cs.getLimit());
diff --git a/daemon/mgmt/face-manager.cpp b/daemon/mgmt/face-manager.cpp
index 839a6fb..cc89061 100644
--- a/daemon/mgmt/face-manager.cpp
+++ b/daemon/mgmt/face-manager.cpp
@@ -260,7 +260,7 @@
const ndn::mgmt::CommandContinuation& done)
{
FaceId faceId = parameters.getFaceId();
- if (faceId == 0) { // Self-update
+ if (faceId == face::INVALID_FACEID) { // Self-update
auto incomingFaceIdTag = interest.getTag<lp::IncomingFaceIdTag>();
if (incomingFaceIdTag == nullptr) {
NFD_LOG_TRACE("unable to determine face for self-update");
diff --git a/daemon/mgmt/fib-manager.cpp b/daemon/mgmt/fib-manager.cpp
index f8a99d8..474d616 100644
--- a/daemon/mgmt/fib-manager.cpp
+++ b/daemon/mgmt/fib-manager.cpp
@@ -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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -53,7 +53,7 @@
}
void
-FibManager::addNextHop(const Name& topPrefix, const Interest& interest,
+FibManager::addNextHop(const Name&, const Interest& interest,
ControlParameters parameters,
const ndn::mgmt::CommandContinuation& done)
{
@@ -84,7 +84,7 @@
}
void
-FibManager::removeNextHop(const Name& topPrefix, const Interest& interest,
+FibManager::removeNextHop(const Name&, const Interest& interest,
ControlParameters parameters,
const ndn::mgmt::CommandContinuation& done)
{
@@ -121,7 +121,7 @@
}
void
-FibManager::listEntries(const Name& topPrefix, const Interest& interest,
+FibManager::listEntries(const Name&, const Interest&,
ndn::mgmt::StatusDatasetContext& context)
{
for (const auto& entry : m_fib) {
@@ -142,9 +142,9 @@
void
FibManager::setFaceForSelfRegistration(const Interest& request, ControlParameters& parameters)
{
- bool isSelfRegistration = (parameters.getFaceId() == 0);
+ bool isSelfRegistration = parameters.getFaceId() == face::INVALID_FACEID;
if (isSelfRegistration) {
- shared_ptr<lp::IncomingFaceIdTag> incomingFaceIdTag = request.getTag<lp::IncomingFaceIdTag>();
+ auto incomingFaceIdTag = request.getTag<lp::IncomingFaceIdTag>();
// NDNLPv2 says "application MUST be prepared to receive a packet without IncomingFaceId field",
// but it's fine to assert IncomingFaceId is available, because InternalFace lives inside NFD
// and is initialized synchronously with IncomingFaceId field enabled.
diff --git a/daemon/mgmt/rib-manager.cpp b/daemon/mgmt/rib-manager.cpp
index d66baea..24d52b7 100644
--- a/daemon/mgmt/rib-manager.cpp
+++ b/daemon/mgmt/rib-manager.cpp
@@ -42,11 +42,9 @@
NFD_LOG_INIT(RibManager);
-static const std::string MGMT_MODULE_NAME = "rib";
-static const Name LOCALHOST_TOP_PREFIX = "/localhost/nfd";
-static const time::seconds ACTIVE_FACE_FETCH_INTERVAL = 5_min;
-
-const Name RibManager::LOCALHOP_TOP_PREFIX = "/localhop/nfd";
+const std::string MGMT_MODULE_NAME = "rib";
+const Name LOCALHOST_TOP_PREFIX = "/localhost/nfd";
+const time::seconds ACTIVE_FACE_FETCH_INTERVAL = 5_min;
RibManager::RibManager(rib::Rib& rib, ndn::Face& face, ndn::KeyChain& keyChain,
ndn::nfd::Controller& nfdController, Dispatcher& dispatcher)
diff --git a/daemon/mgmt/rib-manager.hpp b/daemon/mgmt/rib-manager.hpp
index ac2a324..ec2394d 100644
--- a/daemon/mgmt/rib-manager.hpp
+++ b/daemon/mgmt/rib-manager.hpp
@@ -240,7 +240,7 @@
onNotification(const ndn::nfd::FaceEventNotification& notification);
public:
- static const Name LOCALHOP_TOP_PREFIX;
+ static inline const Name LOCALHOP_TOP_PREFIX{"/localhop/nfd"};
private:
rib::Rib& m_rib;
diff --git a/daemon/mgmt/strategy-choice-manager.cpp b/daemon/mgmt/strategy-choice-manager.cpp
index 9be09d2..ea0c056 100644
--- a/daemon/mgmt/strategy-choice-manager.cpp
+++ b/daemon/mgmt/strategy-choice-manager.cpp
@@ -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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -63,9 +63,7 @@
}
NFD_LOG_DEBUG("strategy-choice/set(" << prefix << "," << strategy << "): OK");
- bool hasEntry = false;
- Name instanceName;
- std::tie(hasEntry, instanceName) = m_table.get(prefix);
+ auto [hasEntry, instanceName] = m_table.get(prefix);
BOOST_ASSERT_MSG(hasEntry, "StrategyChoice entry must exist after StrategyChoice::insert");
parameters.setStrategy(instanceName);
return done(ControlResponse(200, "OK").setBody(parameters.wireEncode()));
diff --git a/daemon/mgmt/tables-config-section.cpp b/daemon/mgmt/tables-config-section.cpp
index f6adced..f693a73 100644
--- a/daemon/mgmt/tables-config-section.cpp
+++ b/daemon/mgmt/tables-config-section.cpp
@@ -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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -28,7 +28,7 @@
namespace nfd {
-const size_t DEFAULT_CS_MAX_PACKETS = 65536;
+constexpr size_t DEFAULT_CS_MAX_PACKETS = 65536;
TablesConfigSection::TablesConfigSection(Forwarder& forwarder)
: m_forwarder(forwarder)
@@ -118,22 +118,19 @@
void
TablesConfigSection::processStrategyChoiceSection(const ConfigSection& section, bool isDryRun)
{
- using fw::Strategy;
-
std::map<Name, Name> choices;
for (const auto& prefixAndStrategy : section) {
Name prefix(prefixAndStrategy.first);
Name strategy(prefixAndStrategy.second.get_value<std::string>());
- if (!Strategy::canCreate(strategy)) {
- NDN_THROW(ConfigFile::Error(
- "Unknown strategy '" + prefixAndStrategy.second.get_value<std::string>() +
- "' for prefix '" + prefix.toUri() + "' in section 'strategy_choice'"));
+ if (!fw::Strategy::canCreate(strategy)) {
+ NDN_THROW(ConfigFile::Error("Unknown strategy '" + prefixAndStrategy.second.get_value<std::string>() +
+ "' for prefix '" + prefix.toUri() + "' in section 'strategy_choice'"));
}
- if (!choices.emplace(prefix, strategy).second) {
- NDN_THROW(ConfigFile::Error(
- "Duplicate strategy choice for prefix '" + prefix.toUri() + "' in section 'strategy_choice'"));
+ if (!choices.try_emplace(prefix, std::move(strategy)).second) {
+ NDN_THROW(ConfigFile::Error("Duplicate strategy choice for prefix '" + prefix.toUri() +
+ "' in section 'strategy_choice'"));
}
}
diff --git a/daemon/rib/readvertise/host-to-gateway-readvertise-policy.cpp b/daemon/rib/readvertise/host-to-gateway-readvertise-policy.cpp
index 89f11fd..5aa6e3b 100644
--- a/daemon/rib/readvertise/host-to-gateway-readvertise-policy.cpp
+++ b/daemon/rib/readvertise/host-to-gateway-readvertise-policy.cpp
@@ -33,8 +33,8 @@
namespace nfd {
namespace rib {
-static const name::Component IGNORE_COMPONENT("nrd");
-static const time::seconds DEFAULT_REFRESH_INTERVAL = 25_s;
+const name::Component IGNORE_COMPONENT("nrd");
+const time::seconds DEFAULT_REFRESH_INTERVAL = 25_s;
HostToGatewayReadvertisePolicy::HostToGatewayReadvertisePolicy(const ndn::KeyChain& keyChain,
const ConfigSection& section)
diff --git a/daemon/rib/readvertise/readvertise.cpp b/daemon/rib/readvertise/readvertise.cpp
index addad72..ded568d 100644
--- a/daemon/rib/readvertise/readvertise.cpp
+++ b/daemon/rib/readvertise/readvertise.cpp
@@ -34,8 +34,8 @@
NFD_LOG_INIT(Readvertise);
-const time::milliseconds Readvertise::RETRY_DELAY_MIN = 50_s;
-const time::milliseconds Readvertise::RETRY_DELAY_MAX = 1_h;
+constexpr time::milliseconds RETRY_DELAY_MIN = 50_s;
+constexpr time::milliseconds RETRY_DELAY_MAX = 1_h;
static time::milliseconds
randomizeTimer(time::milliseconds baseTimer)
@@ -74,20 +74,16 @@
return;
}
- ReadvertisedRouteContainer::iterator rrIt;
- bool isNew = false;
- std::tie(rrIt, isNew) = m_rrs.emplace(action->prefix);
-
- if (!isNew && rrIt->signer != action->signer) {
+ auto [rrIt, isNewRr] = m_rrs.emplace(action->prefix);
+ if (!isNewRr && rrIt->signer != action->signer) {
NFD_LOG_WARN("add-route " << ribRoute.entry->getName() << '(' << ribRoute.route->faceId <<
- ',' << ribRoute.route->origin << ") readvertising-as " << action->prefix <<
+ ',' << ribRoute.route->origin << ") readvertising-as " << action->prefix <<
" old-signer " << rrIt->signer << " new-signer " << action->signer);
}
rrIt->signer = action->signer;
- RouteRrIndex::iterator indexIt;
- std::tie(indexIt, isNew) = m_routeToRr.emplace(ribRoute, rrIt);
- BOOST_ASSERT(isNew);
+ bool isNewInMap = m_routeToRr.try_emplace(ribRoute, rrIt).second;
+ BOOST_VERIFY(isNewInMap);
if (rrIt->nRibRoutes++ > 0) {
NFD_LOG_DEBUG("add-route " << ribRoute.entry->getName() << '(' << ribRoute.route->faceId <<
diff --git a/daemon/rib/readvertise/readvertise.hpp b/daemon/rib/readvertise/readvertise.hpp
index 871702f..aeaa823 100644
--- a/daemon/rib/readvertise/readvertise.hpp
+++ b/daemon/rib/readvertise/readvertise.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -68,18 +68,14 @@
withdraw(ReadvertisedRouteContainer::iterator rrIt);
private:
- /** \brief maps from RIB route to readvertised route derived from RIB route(s)
- */
- using RouteRrIndex = std::map<RibRouteRef, ReadvertisedRouteContainer::iterator>;
-
- static const time::milliseconds RETRY_DELAY_MIN;
- static const time::milliseconds RETRY_DELAY_MAX;
-
unique_ptr<ReadvertisePolicy> m_policy;
unique_ptr<ReadvertiseDestination> m_destination;
ReadvertisedRouteContainer m_rrs;
- RouteRrIndex m_routeToRr;
+ /**
+ * \brief maps from RIB route to readvertised route derived from RIB route(s)
+ */
+ std::map<RibRouteRef, ReadvertisedRouteContainer::iterator> m_routeToRr;
signal::ScopedConnection m_addRouteConn;
signal::ScopedConnection m_removeRouteConn;
diff --git a/daemon/rib/rib-entry.cpp b/daemon/rib/rib-entry.cpp
index 6acae09..1710aff 100644
--- a/daemon/rib/rib-entry.cpp
+++ b/daemon/rib/rib-entry.cpp
@@ -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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -271,7 +271,7 @@
ndn::PrefixAnnouncement ann;
ann.setAnnouncedName(m_name);
- ann.setExpiration(ndn::clamp(
+ ann.setExpiration(std::clamp(
time::duration_cast<time::milliseconds>(entryExpiry - time::steady_clock::now()),
minExpiration, maxExpiration));
return ann;
@@ -280,16 +280,12 @@
std::ostream&
operator<<(std::ostream& os, const RibEntry& entry)
{
- os << "RibEntry {\n";
- os << " Name: " << entry.getName() << "\n";
-
+ os << "RibEntry {\n"
+ << " Name: " << entry.getName() << "\n";
for (const Route& route : entry) {
os << " " << route << "\n";
}
-
- os << "}";
-
- return os;
+ return os << "}";
}
} // namespace rib
diff --git a/daemon/rib/rib-entry.hpp b/daemon/rib/rib-entry.hpp
index 03cfc8c..79f1627 100644
--- a/daemon/rib/rib-entry.hpp
+++ b/daemon/rib/rib-entry.hpp
@@ -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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -33,19 +33,15 @@
namespace nfd {
namespace rib {
-/** \brief Represents a RIB entry, which contains one or more Routes with the same prefix.
+/**
+ * \brief Represents a RIB entry, which contains one or more Routes with the same prefix.
*/
class RibEntry : public std::enable_shared_from_this<RibEntry>
{
public:
- typedef std::list<Route> RouteList;
- typedef RouteList::iterator iterator;
- typedef RouteList::const_iterator const_iterator;
-
- RibEntry()
- : m_nRoutesWithCaptureSet(0)
- {
- }
+ using RouteList = std::list<Route>;
+ using iterator = RouteList::iterator;
+ using const_iterator = RouteList::const_iterator;
void
setName(const Name& prefix);
@@ -210,7 +206,7 @@
* If the number is greater than zero, a route on the namespace has its capture
* flag set which means the namespace should not inherit any routes.
*/
- uint64_t m_nRoutesWithCaptureSet;
+ uint64_t m_nRoutesWithCaptureSet = 0;
};
inline void
@@ -228,7 +224,7 @@
inline void
RibEntry::setParent(shared_ptr<RibEntry> parent)
{
- m_parent = parent;
+ m_parent = std::move(parent);
}
inline shared_ptr<RibEntry>
diff --git a/daemon/rib/rib-update-batch.hpp b/daemon/rib/rib-update-batch.hpp
index f72a9e8..f3facb3 100644
--- a/daemon/rib/rib-update-batch.hpp
+++ b/daemon/rib/rib-update-batch.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -33,20 +33,24 @@
namespace nfd {
namespace rib {
-typedef std::list<RibUpdate> RibUpdateList;
+using RibUpdateList = std::list<RibUpdate>;
-/** \brief Represents a collection of RibUpdates to be applied to a single FaceId.
+/**
+ * \brief Represents a collection of RibUpdates to be applied to a single FaceId.
*/
class RibUpdateBatch
{
public:
- typedef RibUpdateList::const_iterator const_iterator;
+ using const_iterator = RibUpdateList::const_iterator;
explicit
RibUpdateBatch(uint64_t faceId);
uint64_t
- getFaceId() const;
+ getFaceId() const
+ {
+ return m_faceId;
+ }
void
add(const RibUpdate& update);
@@ -65,12 +69,6 @@
RibUpdateList m_updates;
};
-inline uint64_t
-RibUpdateBatch::getFaceId() const
-{
- return m_faceId;
-}
-
} // namespace rib
} // namespace nfd
diff --git a/daemon/rib/rib-update.cpp b/daemon/rib/rib-update.cpp
index 8efe327..be2636d 100644
--- a/daemon/rib/rib-update.cpp
+++ b/daemon/rib/rib-update.cpp
@@ -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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -28,13 +28,8 @@
namespace nfd {
namespace rib {
-RibUpdate::RibUpdate()
-{
-
-}
-
std::ostream&
-operator<<(std::ostream& os, const RibUpdate::Action action)
+operator<<(std::ostream& os, RibUpdate::Action action)
{
switch (action) {
case RibUpdate::REGISTER:
@@ -47,22 +42,18 @@
os << "REMOVE_FACE";
break;
}
-
return os;
}
std::ostream&
operator<<(std::ostream& os, const RibUpdate& update)
{
- os << "RibUpdate {\n";
- os << " Name: " << update.getName() << "\n";
- os << " Action: " << update.getAction() << "\n";
- os << " " << update.getRoute() << "\n";
- os << "}";
-
- return os;
+ return os << "RibUpdate {\n"
+ << " Name: " << update.getName() << "\n"
+ << " Action: " << update.getAction() << "\n"
+ << " " << update.getRoute() << "\n"
+ << "}";
}
-
} // namespace rib
} // namespace nfd
diff --git a/daemon/rib/rib-update.hpp b/daemon/rib/rib-update.hpp
index ad5a390..bcdb342 100644
--- a/daemon/rib/rib-update.hpp
+++ b/daemon/rib/rib-update.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -32,27 +32,23 @@
namespace nfd {
namespace rib {
-/** RibUpdate
- * \brief represents a route that will be added to or removed from a namespace
- *
- * \note This type is copyable so that it can be stored in STL containers.
+/**
+ * \brief Represents a route that will be added to or removed from a namespace
+ * \note This type is copyable so that it can be stored in STL containers.
*/
class RibUpdate
{
public:
enum Action {
- REGISTER = 0,
- UNREGISTER = 1,
-
- /** \brief An update triggered by a face destruction notification
- *
- * \note indicates a Route needs to be removed after a face is destroyed
+ REGISTER = 0,
+ UNREGISTER = 1,
+ /**
+ * \brief An update triggered by a face destruction notification
+ * \note indicates a Route needs to be removed after a face is destroyed
*/
- REMOVE_FACE = 2
+ REMOVE_FACE = 2,
};
- RibUpdate();
-
RibUpdate&
setAction(Action action);
@@ -117,7 +113,7 @@
}
std::ostream&
-operator<<(std::ostream& os, const RibUpdate::Action action);
+operator<<(std::ostream& os, RibUpdate::Action action);
std::ostream&
operator<<(std::ostream& os, const RibUpdate& update);
diff --git a/daemon/rib/rib.cpp b/daemon/rib/rib.cpp
index a81e77a..fe4db0b 100644
--- a/daemon/rib/rib.cpp
+++ b/daemon/rib/rib.cpp
@@ -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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -96,10 +96,7 @@
// Name prefix exists
if (ribIt != m_rib.end()) {
shared_ptr<RibEntry> entry(ribIt->second);
-
- RibEntry::iterator entryIt;
- bool didInsert = false;
- std::tie(entryIt, didInsert) = entry->insertRoute(route);
+ auto [entryIt, didInsert] = entry->insertRoute(route);
if (didInsert) {
// The route was new and we successfully inserted it.
@@ -139,15 +136,13 @@
parent->addChild(entry);
}
- RibEntryList children = findDescendants(prefix);
-
+ auto children = findDescendants(prefix);
for (const auto& child : children) {
if (child->getParent() == parent) {
// Remove child from parent and inherit parent's child
if (parent != nullptr) {
parent->removeChild(child);
}
-
entry->addChild(child);
}
}
@@ -229,12 +224,12 @@
{
std::list<shared_ptr<RibEntry>> children;
- RibTable::const_iterator it = m_rib.find(prefix);
+ auto it = m_rib.find(prefix);
if (it != m_rib.end()) {
++it;
for (; it != m_rib.end(); ++it) {
if (prefix.isPrefixOf(it->first)) {
- children.push_back((it->second));
+ children.push_back(it->second);
}
else {
break;
@@ -250,9 +245,9 @@
{
std::list<shared_ptr<RibEntry>> children;
- for (const auto& pair : m_rib) {
- if (prefix.isPrefixOf(pair.first)) {
- children.push_back(pair.second);
+ for (const auto& [name, ribEntry] : m_rib) {
+ if (prefix.isPrefixOf(name)) {
+ children.push_back(ribEntry);
}
}
@@ -268,7 +263,6 @@
}
shared_ptr<RibEntry> entry(it->second);
-
shared_ptr<RibEntry> parent = entry->getParent();
// Remove self from parent's children
@@ -293,7 +287,7 @@
auto nextIt = m_rib.erase(it);
- // do something after erasing an entry.
+ // do something after erasing an entry
afterEraseEntry(entry->getName());
return nextIt;
@@ -304,10 +298,9 @@
{
RouteSet ancestorRoutes(&sortRoutes);
- shared_ptr<RibEntry> parent = entry.getParent();
-
+ auto parent = entry.getParent();
while (parent != nullptr) {
- for (const Route& route : parent->getRoutes()) {
+ for (const auto& route : parent->getRoutes()) {
if (route.isChildInherit()) {
ancestorRoutes.insert(route);
}
@@ -328,10 +321,9 @@
{
RouteSet ancestorRoutes(&sortRoutes);
- shared_ptr<RibEntry> parent = findParent(name);
-
+ auto parent = findParent(name);
while (parent != nullptr) {
- for (const Route& route : parent->getRoutes()) {
+ for (const auto& route : parent->getRoutes()) {
if (route.isChildInherit()) {
ancestorRoutes.insert(route);
}
@@ -353,9 +345,7 @@
const Rib::UpdateFailureCallback& onFailure)
{
BOOST_ASSERT(m_fibUpdater != nullptr);
-
addUpdateToQueue(update, onSuccess, onFailure);
-
sendBatchFromQueue();
}
@@ -372,11 +362,11 @@
void
Rib::beginRemoveFailedFaces(const std::set<uint64_t>& activeFaceIds)
{
- for (auto it = m_faceEntries.begin(); it != m_faceEntries.end(); ++it) {
- if (activeFaceIds.count(it->first) > 0) {
+ for (const auto& [faceId, ribEntry] : m_faceEntries) {
+ if (activeFaceIds.count(faceId) > 0) {
continue;
}
- enqueueRemoveFace(*it->second, it->first);
+ enqueueRemoveFace(*ribEntry, faceId);
}
sendBatchFromQueue();
}
@@ -428,7 +418,6 @@
auto fibSuccessCb = std::bind(&Rib::onFibUpdateSuccess, this, batch, _1, item.managerSuccessCallback);
auto fibFailureCb = std::bind(&Rib::onFibUpdateFailure, this, item.managerFailureCallback, _1, _2);
-
m_fibUpdater->computeAndSendFibUpdates(batch, fibSuccessCb, fibFailureCb);
}
diff --git a/daemon/rib/rib.hpp b/daemon/rib/rib.hpp
index dbfdba8..f6912c3 100644
--- a/daemon/rib/rib.hpp
+++ b/daemon/rib/rib.hpp
@@ -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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -248,7 +248,7 @@
UpdateQueue m_updateBatches;
bool m_isUpdateInProgress = false;
- friend class FibUpdater;
+ friend FibUpdater;
};
std::ostream&
diff --git a/daemon/rib/service.cpp b/daemon/rib/service.cpp
index 0c674b3..d850ed2 100644
--- a/daemon/rib/service.cpp
+++ b/daemon/rib/service.cpp
@@ -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-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -43,8 +43,6 @@
NFD_LOG_INIT(RibService);
-Service* Service::s_instance = nullptr;
-
const std::string CFG_RIB = "rib";
const std::string CFG_LOCALHOST_SECURITY = "localhost_security";
const std::string CFG_LOCALHOP_SECURITY = "localhop_security";
@@ -52,8 +50,8 @@
const std::string CFG_PREFIX_PROPAGATE = "auto_prefix_propagate";
const std::string CFG_READVERTISE_NLSR = "readvertise_nlsr";
const Name READVERTISE_NLSR_PREFIX = "/localhost/nlsr";
-const uint64_t PROPAGATE_DEFAULT_COST = 15;
-const time::milliseconds PROPAGATE_DEFAULT_TIMEOUT = 10_s;
+constexpr uint64_t PROPAGATE_DEFAULT_COST = 15;
+constexpr time::milliseconds PROPAGATE_DEFAULT_TIMEOUT = 10_s;
static ConfigSection
loadConfigSectionFromFile(const std::string& filename)
@@ -64,10 +62,7 @@
return config;
}
-/**
- * \brief Look into the config file and construct appropriate transport to communicate with NFD
- * If NFD-RIB instance was initialized with config file, INFO format is assumed
- */
+// Look into NFD's config file and construct an appropriate transport to communicate with NFD.
static shared_ptr<ndn::Transport>
makeLocalNfdTransport(const ConfigSection& config)
{
diff --git a/daemon/rib/service.hpp b/daemon/rib/service.hpp
index ca5f57b..8928011 100644
--- a/daemon/rib/service.hpp
+++ b/daemon/rib/service.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -107,7 +107,7 @@
applyConfig(const ConfigSection& section, const std::string& filename);
private:
- static Service* s_instance;
+ static inline Service* s_instance = nullptr;
ndn::KeyChain& m_keyChain;
ndn::Face m_face;
diff --git a/daemon/table/cs-policy-lru.cpp b/daemon/table/cs-policy-lru.cpp
index 56b21ec..1b477aa 100644
--- a/daemon/table/cs-policy-lru.cpp
+++ b/daemon/table/cs-policy-lru.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -71,17 +71,15 @@
BOOST_ASSERT(!m_queue.empty());
EntryRef i = m_queue.front();
m_queue.pop_front();
- this->emitSignal(beforeEvict, i);
+ emitSignal(beforeEvict, i);
}
}
void
LruPolicy::insertToQueue(EntryRef i, bool isNewEntry)
{
- Queue::iterator it;
- bool isNew = false;
// push_back only if i does not exist
- std::tie(it, isNew) = m_queue.push_back(i);
+ auto [it, isNew] = m_queue.push_back(i);
BOOST_ASSERT(isNew == isNewEntry);
if (!isNewEntry) {
diff --git a/daemon/table/cs-policy.cpp b/daemon/table/cs-policy.cpp
index b51aac1..6b24eb3 100644
--- a/daemon/table/cs-policy.cpp
+++ b/daemon/table/cs-policy.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -59,7 +59,7 @@
return policyNames;
}
-Policy::Policy(const std::string& policyName)
+Policy::Policy(std::string_view policyName)
: m_policyName(policyName)
{
}
diff --git a/daemon/table/cs-policy.hpp b/daemon/table/cs-policy.hpp
index fb59990..9a4c6ed 100644
--- a/daemon/table/cs-policy.hpp
+++ b/daemon/table/cs-policy.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -33,7 +33,8 @@
class Cs;
-/** \brief represents a CS replacement policy
+/**
+ * \brief Represents a CS replacement policy
*/
class Policy : noncopyable
{
@@ -42,9 +43,9 @@
static void
registerPolicy(const std::string& policyName = P::POLICY_NAME)
{
- Registry& registry = getRegistry();
- BOOST_ASSERT(registry.count(policyName) == 0);
- registry[policyName] = [] { return make_unique<P>(); };
+ BOOST_ASSERT(!policyName.empty());
+ auto r = getRegistry().insert_or_assign(policyName, [] { return make_unique<P>(); });
+ BOOST_VERIFY(r.second);
}
/** \return a cs::Policy identified by \p policyName,
@@ -59,9 +60,6 @@
getPolicyNames();
public:
- explicit
- Policy(const std::string& policyName);
-
virtual
~Policy() = default;
@@ -190,6 +188,9 @@
evictEntries() = 0;
protected:
+ explicit
+ Policy(std::string_view policyName);
+
DECLARE_SIGNAL_EMIT(beforeEvict)
private: // registry
@@ -200,7 +201,7 @@
getRegistry();
private:
- std::string m_policyName;
+ const std::string m_policyName;
size_t m_limit;
Cs* m_cs;
};
diff --git a/daemon/table/cs.cpp b/daemon/table/cs.cpp
index b240e3d..5fc8301 100644
--- a/daemon/table/cs.cpp
+++ b/daemon/table/cs.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -56,7 +56,7 @@
NFD_LOG_DEBUG("insert " << data.getName());
// recognize CachePolicy
- shared_ptr<lp::CachePolicyTag> tag = data.getTag<lp::CachePolicyTag>();
+ auto tag = data.getTag<lp::CachePolicyTag>();
if (tag != nullptr) {
lp::CachePolicyType policy = tag->get().getPolicy();
if (policy == lp::CachePolicyType::NO_CACHE) {
@@ -64,10 +64,8 @@
}
}
- const_iterator it;
- bool isNewEntry = false;
- std::tie(it, isNewEntry) = m_table.emplace(data.shared_from_this(), isUnsolicited);
- Entry& entry = const_cast<Entry&>(*it);
+ auto [it, isNewEntry] = m_table.emplace(data.shared_from_this(), isUnsolicited);
+ auto& entry = const_cast<Entry&>(*it);
entry.updateFreshUntil();
@@ -76,7 +74,6 @@
if (entry.isUnsolicited() && !isUnsolicited) {
entry.clearUnsolicited();
}
-
m_policy->afterRefresh(it);
}
else {
@@ -89,7 +86,7 @@
{
auto first = m_table.lower_bound(prefix);
auto last = m_table.end();
- if (prefix.size() > 0) {
+ if (!prefix.empty()) {
last = m_table.lower_bound(prefix.getSuccessor());
}
return {first, last};
diff --git a/daemon/table/dead-nonce-list.cpp b/daemon/table/dead-nonce-list.cpp
index 55bf346..6149fd6 100644
--- a/daemon/table/dead-nonce-list.cpp
+++ b/daemon/table/dead-nonce-list.cpp
@@ -32,17 +32,6 @@
NFD_LOG_INIT(DeadNonceList);
-const time::nanoseconds DeadNonceList::DEFAULT_LIFETIME;
-const time::nanoseconds DeadNonceList::MIN_LIFETIME;
-const size_t DeadNonceList::INITIAL_CAPACITY;
-const size_t DeadNonceList::MIN_CAPACITY;
-const size_t DeadNonceList::MAX_CAPACITY;
-const DeadNonceList::Entry DeadNonceList::MARK;
-const size_t DeadNonceList::EXPECTED_MARK_COUNT;
-const double DeadNonceList::CAPACITY_UP;
-const double DeadNonceList::CAPACITY_DOWN;
-const size_t DeadNonceList::EVICT_LIMIT;
-
DeadNonceList::DeadNonceList(time::nanoseconds lifetime)
: m_lifetime(lifetime)
, m_capacity(INITIAL_CAPACITY)
@@ -61,15 +50,15 @@
m_adjustCapacityEvent = getScheduler().schedule(m_adjustCapacityInterval, [this] { adjustCapacity(); });
BOOST_ASSERT_MSG(DEFAULT_LIFETIME >= MIN_LIFETIME, "DEFAULT_LIFETIME is too small");
- static_assert(INITIAL_CAPACITY >= MIN_CAPACITY, "INITIAL_CAPACITY is too small");
- static_assert(INITIAL_CAPACITY <= MAX_CAPACITY, "INITIAL_CAPACITY is too large");
+ static_assert(INITIAL_CAPACITY >= MIN_CAPACITY);
+ static_assert(INITIAL_CAPACITY <= MAX_CAPACITY);
BOOST_ASSERT_MSG(static_cast<size_t>(MIN_CAPACITY * CAPACITY_UP) > MIN_CAPACITY,
"CAPACITY_UP must be able to increase from MIN_CAPACITY");
BOOST_ASSERT_MSG(static_cast<size_t>(MAX_CAPACITY * CAPACITY_DOWN) < MAX_CAPACITY,
"CAPACITY_DOWN must be able to decrease from MAX_CAPACITY");
BOOST_ASSERT_MSG(CAPACITY_UP > 1.0, "CAPACITY_UP must adjust up");
BOOST_ASSERT_MSG(CAPACITY_DOWN < 1.0, "CAPACITY_DOWN must adjust down");
- static_assert(EVICT_LIMIT >= 1, "EVICT_LIMIT must be at least 1");
+ static_assert(EVICT_LIMIT >= 1);
}
size_t
diff --git a/daemon/table/fib-entry.cpp b/daemon/table/fib-entry.cpp
index ade4c9f..71c2516 100644
--- a/daemon/table/fib-entry.cpp
+++ b/daemon/table/fib-entry.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -62,7 +62,7 @@
it->setCost(cost);
this->sortNextHops();
- return std::make_pair(it, isNew);
+ return {it, isNew};
}
bool
diff --git a/daemon/table/fib-entry.hpp b/daemon/table/fib-entry.hpp
index 7460eda..facf248 100644
--- a/daemon/table/fib-entry.hpp
+++ b/daemon/table/fib-entry.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -48,7 +48,9 @@
*/
using NextHopList = std::vector<NextHop>;
-/** \brief represents a FIB entry
+/**
+ * \brief Represents an entry in the FIB.
+ * \sa Fib
*/
class Entry : noncopyable
{
@@ -115,8 +117,8 @@
name_tree::Entry* m_nameTreeEntry = nullptr;
- friend class name_tree::Entry;
- friend class Fib;
+ friend name_tree::Entry;
+ friend Fib;
};
} // namespace fib
diff --git a/daemon/table/fib.cpp b/daemon/table/fib.cpp
index 99892e6..c6c8f2c 100644
--- a/daemon/table/fib.cpp
+++ b/daemon/table/fib.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -135,10 +135,7 @@
void
Fib::addOrUpdateNextHop(Entry& entry, Face& face, uint64_t cost)
{
- NextHopList::iterator it;
- bool isNew;
- std::tie(it, isNew) = entry.addOrUpdateNextHop(face, cost);
-
+ auto [it, isNew] = entry.addOrUpdateNextHop(face, cost);
if (isNew)
this->afterNewNextHop(entry.getPrefix(), *it);
}
diff --git a/daemon/table/fib.hpp b/daemon/table/fib.hpp
index a4b688f..6073533 100644
--- a/daemon/table/fib.hpp
+++ b/daemon/table/fib.hpp
@@ -36,6 +36,7 @@
namespace measurements {
class Entry;
} // namespace measurements
+
namespace pit {
class Entry;
} // namespace pit
diff --git a/daemon/table/measurements-entry.hpp b/daemon/table/measurements-entry.hpp
index fa80327..a70f6e0 100644
--- a/daemon/table/measurements-entry.hpp
+++ b/daemon/table/measurements-entry.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -36,7 +36,11 @@
namespace measurements {
-/** \brief Represents a Measurements entry
+class Measurements;
+
+/**
+ * \brief Represents an entry in the %Measurements table.
+ * \sa Measurements
*/
class Entry : public StrategyInfoHost, noncopyable
{
@@ -60,8 +64,8 @@
name_tree::Entry* m_nameTreeEntry = nullptr;
- friend class Measurements;
- friend class name_tree::Entry;
+ friend Measurements;
+ friend name_tree::Entry;
};
} // namespace measurements
diff --git a/daemon/table/pit-entry.hpp b/daemon/table/pit-entry.hpp
index 9e4a357..e088e70 100644
--- a/daemon/table/pit-entry.hpp
+++ b/daemon/table/pit-entry.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -39,21 +39,26 @@
namespace pit {
-/** \brief An unordered collection of in-records
+/**
+ * \brief An unordered collection of in-records
*/
-typedef std::list<InRecord> InRecordCollection;
+using InRecordCollection = std::list<InRecord>;
-/** \brief An unordered collection of out-records
+/**
+ * \brief An unordered collection of out-records
*/
-typedef std::list<OutRecord> OutRecordCollection;
+using OutRecordCollection = std::list<OutRecord>;
-/** \brief An Interest table entry
+/**
+ * \brief Represents an entry in the %Interest table (PIT).
*
- * An Interest table entry represents either a pending Interest or a recently satisfied Interest.
- * Each entry contains a collection of in-records, a collection of out-records,
- * and two timers used in forwarding pipelines.
- * In addition, the entry, in-records, and out-records are subclasses of StrategyInfoHost,
- * which allows forwarding strategy to store arbitrary information on them.
+ * An Interest table entry represents either a pending Interest or a recently satisfied Interest.
+ * Each entry contains a collection of in-records, a collection of out-records,
+ * and two timers used in forwarding pipelines.
+ * In addition, the entry, in-records, and out-records are subclasses of StrategyInfoHost,
+ * which allows forwarding strategy to store arbitrary information on them.
+ *
+ * \sa Pit
*/
class Entry : public StrategyInfoHost, noncopyable
{
@@ -238,7 +243,7 @@
name_tree::Entry* m_nameTreeEntry = nullptr;
- friend class name_tree::Entry;
+ friend name_tree::Entry;
};
} // namespace pit
diff --git a/daemon/table/pit-face-record.cpp b/daemon/table/pit-face-record.cpp
index 639f424..4674b8e 100644
--- a/daemon/table/pit-face-record.cpp
+++ b/daemon/table/pit-face-record.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2020, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -29,7 +29,7 @@
namespace pit {
// Impose a maximum lifetime to prevent integer overflow when calculating m_expiry.
-static const time::milliseconds MAX_LIFETIME{10_days};
+const time::milliseconds MAX_LIFETIME = 10_days;
void
FaceRecord::update(const Interest& interest)
diff --git a/daemon/table/pit-iterator.hpp b/daemon/table/pit-iterator.hpp
index 35e02c5..b788e3c 100644
--- a/daemon/table/pit-iterator.hpp
+++ b/daemon/table/pit-iterator.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -48,7 +48,7 @@
* \param iPitEntry make this iterator to dereference to the i-th PIT entry in name tree entry
*/
explicit
- Iterator(const NameTree::const_iterator& ntIt = NameTree::const_iterator(), size_t iPitEntry = 0);
+ Iterator(const NameTree::const_iterator& ntIt = {}, size_t iPitEntry = 0);
const Entry&
operator*() const
diff --git a/daemon/table/pit.hpp b/daemon/table/pit.hpp
index c998a4d..b44dce8 100644
--- a/daemon/table/pit.hpp
+++ b/daemon/table/pit.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -99,7 +99,7 @@
deleteInOutRecords(Entry* entry, const Face& face);
public: // enumeration
- typedef Iterator const_iterator;
+ using const_iterator = Iterator;
/** \return an iterator to the beginning
* \note Iteration order is implementation-defined.
diff --git a/daemon/table/strategy-choice-entry.hpp b/daemon/table/strategy-choice-entry.hpp
index f64d332..ac59234 100644
--- a/daemon/table/strategy-choice-entry.hpp
+++ b/daemon/table/strategy-choice-entry.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -40,7 +40,9 @@
namespace strategy_choice {
-/** \brief Represents a Strategy Choice entry
+/**
+ * \brief Represents an entry in the %Strategy %Choice table.
+ * \sa StrategyChoice
*/
class Entry : noncopyable
{
@@ -80,7 +82,7 @@
unique_ptr<fw::Strategy> m_strategy;
name_tree::Entry* m_nameTreeEntry = nullptr;
- friend class name_tree::Entry;
+ friend name_tree::Entry;
};
} // namespace strategy_choice