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/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
{