Improve and simplify code with modern C++ features
Change-Id: I83bf5513c2a1f90ba5a59e93c473306864b27d94
diff --git a/daemon/face/channel.hpp b/daemon/face/channel.hpp
index 5b870fe..db97cc8 100644
--- a/daemon/face/channel.hpp
+++ b/daemon/face/channel.hpp
@@ -84,25 +84,14 @@
* Parameters are passed as a struct rather than individually, so that a future change in the list
* of parameters does not require an update to the method signature in all subclasses.
*/
-class FaceParams
+struct FaceParams
{
-public:
- // get rid of this constructor and use aggregate init + NSDMIs when we switch to C++14
- FaceParams() noexcept
- : persistency(ndn::nfd::FACE_PERSISTENCY_PERSISTENT)
- , wantLocalFields(false)
- , wantLpReliability(false)
- , wantCongestionMarking(boost::logic::indeterminate)
- {
- }
-
-public:
- ndn::nfd::FacePersistency persistency;
+ ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT;
optional<time::nanoseconds> baseCongestionMarkingInterval;
optional<uint64_t> defaultCongestionThreshold;
- bool wantLocalFields;
- bool wantLpReliability;
- boost::logic::tribool wantCongestionMarking;
+ bool wantLocalFields = false;
+ bool wantLpReliability = false;
+ boost::logic::tribool wantCongestionMarking = boost::logic::indeterminate;
};
/** \brief invokes a callback when the face is closed
diff --git a/daemon/face/datagram-transport.hpp b/daemon/face/datagram-transport.hpp
index 0b375ad..669b46e 100644
--- a/daemon/face/datagram-transport.hpp
+++ b/daemon/face/datagram-transport.hpp
@@ -72,12 +72,10 @@
doSend(Transport::Packet&& packet) override;
void
- handleSend(const boost::system::error_code& error,
- size_t nBytesSent, const Block& payload);
+ handleSend(const boost::system::error_code& error, size_t nBytesSent);
void
- handleReceive(const boost::system::error_code& error,
- size_t nBytesReceived);
+ handleReceive(const boost::system::error_code& error, size_t nBytesReceived);
void
processErrorCode(const boost::system::error_code& error);
@@ -120,9 +118,9 @@
}
m_socket.async_receive_from(boost::asio::buffer(m_receiveBuffer), m_sender,
- bind(&DatagramTransport<T, U>::handleReceive, this,
- boost::asio::placeholders::error,
- boost::asio::placeholders::bytes_transferred));
+ [this] (auto&&... args) {
+ this->handleReceive(std::forward<decltype(args)>(args)...);
+ });
}
template<class T, class U>
@@ -164,10 +162,10 @@
NFD_LOG_FACE_TRACE(__func__);
m_socket.async_send(boost::asio::buffer(packet.packet),
- bind(&DatagramTransport<T, U>::handleSend, this,
- boost::asio::placeholders::error,
- boost::asio::placeholders::bytes_transferred,
- packet.packet));
+ // packet.packet is copied into the lambda to retain the underlying Buffer
+ [this, p = packet.packet] (auto&&... args) {
+ this->handleSend(std::forward<decltype(args)>(args)...);
+ });
}
template<class T, class U>
@@ -202,23 +200,20 @@
template<class T, class U>
void
-DatagramTransport<T, U>::handleReceive(const boost::system::error_code& error,
- size_t nBytesReceived)
+DatagramTransport<T, U>::handleReceive(const boost::system::error_code& error, size_t nBytesReceived)
{
receiveDatagram(m_receiveBuffer.data(), nBytesReceived, error);
if (m_socket.is_open())
m_socket.async_receive_from(boost::asio::buffer(m_receiveBuffer), m_sender,
- bind(&DatagramTransport<T, U>::handleReceive, this,
- boost::asio::placeholders::error,
- boost::asio::placeholders::bytes_transferred));
+ [this] (auto&&... args) {
+ this->handleReceive(std::forward<decltype(args)>(args)...);
+ });
}
template<class T, class U>
void
-DatagramTransport<T, U>::handleSend(const boost::system::error_code& error,
- size_t nBytesSent, const Block& payload)
-// 'payload' is unused; it's needed to retain the underlying Buffer
+DatagramTransport<T, U>::handleSend(const boost::system::error_code& error, size_t nBytesSent)
{
if (error)
return processErrorCode(error);
@@ -266,7 +261,7 @@
template<class T, class U>
Transport::EndpointId
-DatagramTransport<T, U>::makeEndpointId(const typename protocol::endpoint& ep)
+DatagramTransport<T, U>::makeEndpointId(const typename protocol::endpoint&)
{
return 0;
}
diff --git a/daemon/face/ethernet-channel.cpp b/daemon/face/ethernet-channel.cpp
index 3791d44..69c6f45 100644
--- a/daemon/face/ethernet-channel.cpp
+++ b/daemon/face/ethernet-channel.cpp
@@ -65,7 +65,7 @@
catch (const boost::system::system_error& e) {
NFD_LOG_CHAN_DEBUG("Face creation for " << remoteEndpoint << " failed: " << e.what());
if (onConnectFailed)
- onConnectFailed(504, std::string("Face creation failed: ") + e.what());
+ onConnectFailed(504, "Face creation failed: "s + e.what());
return;
}
@@ -102,9 +102,7 @@
const FaceCreationFailedCallback& onReceiveFailed)
{
m_socket.async_read_some(boost::asio::null_buffers(),
- bind(&EthernetChannel::handleRead, this,
- boost::asio::placeholders::error,
- onFaceCreated, onReceiveFailed));
+ [=] (const auto& e, auto) { this->handleRead(e, onFaceCreated, onReceiveFailed); });
}
void
@@ -172,7 +170,7 @@
catch (const EthernetTransport::Error& e) {
NFD_LOG_CHAN_DEBUG("Face creation for " << sender << " failed: " << e.what());
if (onReceiveFailed)
- onReceiveFailed(504, std::string("Face creation failed: ") + e.what());
+ onReceiveFailed(504, "Face creation failed: "s + e.what());
return;
}
diff --git a/daemon/face/ethernet-factory.cpp b/daemon/face/ethernet-factory.cpp
index d921855..f9767df 100644
--- a/daemon/face/ethernet-factory.cpp
+++ b/daemon/face/ethernet-factory.cpp
@@ -46,11 +46,10 @@
EthernetFactory::EthernetFactory(const CtorParams& params)
: ProtocolFactory(params)
{
- m_netifAddConn = netmon->onInterfaceAdded.connect(
- [this] (const shared_ptr<const ndn::net::NetworkInterface>& netif) {
- this->applyUnicastConfigToNetif(netif);
- this->applyMcastConfigToNetif(*netif);
- });
+ m_netifAddConn = netmon->onInterfaceAdded.connect([this] (const auto& netif) {
+ this->applyUnicastConfigToNetif(netif);
+ this->applyMcastConfigToNetif(*netif);
+ });
}
void
diff --git a/daemon/face/ethernet-transport.cpp b/daemon/face/ethernet-transport.cpp
index a7e8907..e2ba043 100644
--- a/daemon/face/ethernet-transport.cpp
+++ b/daemon/face/ethernet-transport.cpp
@@ -122,8 +122,7 @@
EthernetTransport::asyncRead()
{
m_socket.async_read_some(boost::asio::null_buffers(),
- bind(&EthernetTransport::handleRead, this,
- boost::asio::placeholders::error));
+ [this] (const auto& e, auto) { this->handleRead(e); });
}
void
diff --git a/daemon/face/face-system.cpp b/daemon/face/face-system.cpp
index 1d2db37..872efef 100644
--- a/daemon/face/face-system.cpp
+++ b/daemon/face/face-system.cpp
@@ -47,7 +47,7 @@
ProtocolFactoryCtorParams
FaceSystem::makePFCtorParams()
{
- auto addFace = bind(&FaceTable::add, &m_faceTable, _1);
+ auto addFace = [&ft = m_faceTable] (auto face) { ft.add(std::move(face)); };
return {addFace, m_netmon};
}
diff --git a/daemon/face/generic-link-service.cpp b/daemon/face/generic-link-service.cpp
index 5122755..e2f7e0e 100644
--- a/daemon/face/generic-link-service.cpp
+++ b/daemon/face/generic-link-service.cpp
@@ -36,17 +36,6 @@
constexpr uint32_t DEFAULT_CONGESTION_THRESHOLD_DIVISOR = 2;
-GenericLinkService::Options::Options()
- : allowLocalFields(false)
- , allowFragmentation(false)
- , allowReassembly(false)
- , allowCongestionMarking(false)
- , baseCongestionMarkingInterval(time::milliseconds(100)) // Interval from RFC 8289 (CoDel)
- , defaultCongestionThreshold(65536) // This default value works well for a queue capacity of 200KiB
- , allowSelfLearning(false)
-{
-}
-
GenericLinkService::GenericLinkService(const GenericLinkService::Options& options)
: m_options(options)
, m_fragmenter(m_options.fragmenterOptions, this)
@@ -57,8 +46,8 @@
, m_lastMarkTime(time::steady_clock::TimePoint::min())
, m_nMarkedSinceInMarkingState(0)
{
- m_reassembler.beforeTimeout.connect(bind([this] { ++this->nReassemblyTimeouts; }));
- m_reliability.onDroppedInterest.connect([this] (const Interest& i) { this->notifyDroppedInterest(i); });
+ m_reassembler.beforeTimeout.connect([this] (auto...) { ++this->nReassemblyTimeouts; });
+ m_reliability.onDroppedInterest.connect([this] (const auto& i) { this->notifyDroppedInterest(i); });
nReassembling.observe(&m_reassembler);
}
@@ -226,7 +215,7 @@
void
GenericLinkService::assignSequences(std::vector<lp::Packet>& pkts)
{
- std::for_each(pkts.begin(), pkts.end(), bind(&GenericLinkService::assignSequence, this, _1));
+ std::for_each(pkts.begin(), pkts.end(), [this] (auto& pkt) { this->assignSequence(pkt); });
}
void
diff --git a/daemon/face/generic-link-service.hpp b/daemon/face/generic-link-service.hpp
index d0eb3dd..c8eea37 100644
--- a/daemon/face/generic-link-service.hpp
+++ b/daemon/face/generic-link-service.hpp
@@ -98,16 +98,19 @@
class Options
{
public:
- Options();
+ constexpr
+ Options() noexcept
+ {
+ }
public:
/** \brief enables encoding of IncomingFaceId, and decoding of NextHopFaceId and CachePolicy
*/
- bool allowLocalFields;
+ bool allowLocalFields = false;
/** \brief enables fragmentation
*/
- bool allowFragmentation;
+ bool allowFragmentation = false;
/** \brief options for fragmentation
*/
@@ -115,7 +118,7 @@
/** \brief enables reassembly
*/
- bool allowReassembly;
+ bool allowReassembly = false;
/** \brief options for reassembly
*/
@@ -127,19 +130,23 @@
/** \brief enables send queue congestion detection and marking
*/
- bool allowCongestionMarking;
+ bool allowCongestionMarking = false;
/** \brief starting value for congestion marking interval
+ *
+ * The default value (100 ms) is taken from RFC 8289 (CoDel).
*/
- time::nanoseconds baseCongestionMarkingInterval;
+ time::nanoseconds baseCongestionMarkingInterval = 100_ms;
/** \brief default congestion threshold in bytes
+ *
+ * The default value (64 KiB) works well for a queue capacity of 200 KiB.
*/
- size_t defaultCongestionThreshold;
+ size_t defaultCongestionThreshold = 65536;
/** \brief enables self-learning forwarding support
*/
- bool allowSelfLearning;
+ bool allowSelfLearning = false;
};
/** \brief counters provided by GenericLinkService
@@ -147,7 +154,7 @@
using Counters = GenericLinkServiceCounters;
explicit
- GenericLinkService(const Options& options = Options());
+ GenericLinkService(const Options& options = {});
/** \brief get Options used by GenericLinkService
*/
@@ -283,6 +290,7 @@
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
/// CongestionMark TLV-TYPE (3 octets) + CongestionMark TLV-LENGTH (1 octet) + sizeof(uint64_t)
static constexpr size_t CONGESTION_MARK_SIZE = 3 + 1 + sizeof(uint64_t);
+
/// Time to mark next packet due to send queue congestion
time::steady_clock::TimePoint m_nextMarkTime;
/// Time last packet was marked
diff --git a/daemon/face/lp-fragmenter.cpp b/daemon/face/lp-fragmenter.cpp
index 1928bf5..7494ca7 100644
--- a/daemon/face/lp-fragmenter.cpp
+++ b/daemon/face/lp-fragmenter.cpp
@@ -57,11 +57,6 @@
1 + 1 + 8 + // FragCount TLV
1 + 9; // Fragment TLV-TYPE and TLV-LENGTH
-LpFragmenter::Options::Options()
- : nMaxFragments(400)
-{
-}
-
LpFragmenter::LpFragmenter(const LpFragmenter::Options& options, const LinkService* linkService)
: m_options(options)
, m_linkService(linkService)
@@ -122,7 +117,7 @@
// compute FragCount
if (fragCount > m_options.nMaxFragments) {
NFD_LOG_FACE_WARN("fragmentation error, FragCount over limit: DROP");
- return std::make_pair(false, std::vector<lp::Packet>{});
+ return std::make_tuple(false, std::vector<lp::Packet>{});
}
// populate fragments
@@ -135,7 +130,7 @@
lp::Packet& frag = frags[fragIndex];
frag.add<lp::FragIndexField>(fragIndex);
frag.add<lp::FragCountField>(fragCount);
- frag.set<lp::FragmentField>(std::make_pair(fragBegin, fragEnd));
+ frag.set<lp::FragmentField>({fragBegin, fragEnd});
BOOST_ASSERT(frag.wireEncode().size() <= mtu);
++fragIndex;
@@ -144,7 +139,7 @@
}
BOOST_ASSERT(fragIndex == fragCount);
- return std::make_pair(true, frags);
+ return std::make_tuple(true, frags);
}
std::ostream&
diff --git a/daemon/face/lp-fragmenter.hpp b/daemon/face/lp-fragmenter.hpp
index 40d32cb..51d14d9 100644
--- a/daemon/face/lp-fragmenter.hpp
+++ b/daemon/face/lp-fragmenter.hpp
@@ -44,19 +44,15 @@
public:
/** \brief Options that control the behavior of LpFragmenter
*/
- class Options
+ struct Options
{
- public:
- Options();
-
- public:
/** \brief maximum number of fragments in a packet
*/
- size_t nMaxFragments;
+ size_t nMaxFragments = 400;
};
explicit
- LpFragmenter(const Options& options = Options(), const LinkService* linkService = nullptr);
+ LpFragmenter(const Options& options, const LinkService* linkService = nullptr);
/** \brief set options for fragmenter
*/
diff --git a/daemon/face/lp-reassembler.cpp b/daemon/face/lp-reassembler.cpp
index a6d1c60..cd6f873 100644
--- a/daemon/face/lp-reassembler.cpp
+++ b/daemon/face/lp-reassembler.cpp
@@ -33,12 +33,6 @@
NFD_LOG_INIT(LpReassembler);
-LpReassembler::Options::Options()
- : nMaxFragments(400)
- , reassemblyTimeout(time::milliseconds(500))
-{
-}
-
LpReassembler::LpReassembler(const LpReassembler::Options& options, const LinkService* linkService)
: m_options(options)
, m_linkService(linkService)
@@ -119,8 +113,7 @@
}
// set drop timer
- pp.dropTimer = scheduler::schedule(m_options.reassemblyTimeout,
- bind(&LpReassembler::timeoutPartialPacket, this, key));
+ pp.dropTimer = scheduler::schedule(m_options.reassemblyTimeout, [=] { timeoutPartialPacket(key); });
return FALSE_RETURN;
}
@@ -130,7 +123,7 @@
{
PartialPacket& pp = m_partialPackets[key];
- size_t payloadSize = std::accumulate(pp.fragments.begin(), pp.fragments.end(), 0,
+ 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>();
@@ -138,7 +131,7 @@
});
ndn::Buffer fragBuffer(payloadSize);
- ndn::Buffer::iterator it = fragBuffer.begin();
+ auto it = fragBuffer.begin();
for (const lp::Packet& frag : pp.fragments) {
ndn::Buffer::const_iterator fragBegin, fragEnd;
diff --git a/daemon/face/lp-reassembler.hpp b/daemon/face/lp-reassembler.hpp
index fd0d874..f416b2c 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-2015, Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -38,32 +38,28 @@
class LinkService;
/** \brief reassembles fragmented network-layer packets
- * \sa http://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
+ * \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
*/
class LpReassembler : noncopyable
{
public:
/** \brief Options that control the behavior of LpReassembler
*/
- class Options
+ struct Options
{
- public:
- Options();
-
- public:
/** \brief maximum number of fragments in a packet
*
* LpPackets with FragCount over this limit are dropped.
*/
- size_t nMaxFragments;
+ size_t nMaxFragments = 400;
/** \brief timeout before a partially reassembled packet is dropped
*/
- time::nanoseconds reassemblyTimeout;
+ time::nanoseconds reassemblyTimeout = 500_ms;
};
explicit
- LpReassembler(const Options& options = Options(), const LinkService* linkService = nullptr);
+ LpReassembler(const Options& options, const LinkService* linkService = nullptr);
/** \brief set options for reassembler
*/
diff --git a/daemon/face/lp-reliability.cpp b/daemon/face/lp-reliability.cpp
index 5a4621d..7b248fb 100644
--- a/daemon/face/lp-reliability.cpp
+++ b/daemon/face/lp-reliability.cpp
@@ -39,13 +39,13 @@
{
BOOST_ASSERT(m_linkService != nullptr);
- BOOST_ASSERT(m_options.idleAckTimerPeriod > time::nanoseconds::zero());
+ BOOST_ASSERT(m_options.idleAckTimerPeriod > 0_ns);
}
void
LpReliability::setOptions(const Options& options)
{
- BOOST_ASSERT(options.idleAckTimerPeriod > time::nanoseconds::zero());
+ BOOST_ASSERT(options.idleAckTimerPeriod > 0_ns);
if (m_options.isEnabled && !options.isEnabled) {
this->stopIdleAckTimer();
@@ -81,8 +81,7 @@
std::forward_as_tuple(txSeq),
std::forward_as_tuple(frag));
unackedFragsIt->second.sendTime = sendTime;
- unackedFragsIt->second.rtoTimer =
- scheduler::schedule(m_rto.computeRto(), bind(&LpReliability::onLpPacketLost, this, txSeq));
+ unackedFragsIt->second.rtoTimer = scheduler::schedule(m_rto.computeRto(), [=] { onLpPacketLost(txSeq); });
unackedFragsIt->second.netPkt = netPkt;
if (m_unackedFrags.size() == 1) {
@@ -305,8 +304,7 @@
m_linkService->sendLpPacket(lp::Packet(newTxFrag.pkt));
// Start RTO timer for this sequence
- newTxFrag.rtoTimer = scheduler::schedule(m_rto.computeRto(),
- bind(&LpReliability::onLpPacketLost, this, newTxSeq));
+ newTxFrag.rtoTimer = scheduler::schedule(m_rto.computeRto(), [=] { onLpPacketLost(newTxSeq); });
}
return removedThisTxSeq;
diff --git a/daemon/face/lp-reliability.hpp b/daemon/face/lp-reliability.hpp
index 896cc0e..9521183 100644
--- a/daemon/face/lp-reliability.hpp
+++ b/daemon/face/lp-reliability.hpp
@@ -57,7 +57,7 @@
/** \brief period between sending pending Acks in an IDLE packet
*/
- time::nanoseconds idleAckTimerPeriod = time::milliseconds(5);
+ time::nanoseconds idleAckTimerPeriod = 5_ms;
/** \brief a fragment is considered lost if this number of fragments with greater sequence
* numbers are acknowledged
diff --git a/daemon/face/multicast-udp-transport.cpp b/daemon/face/multicast-udp-transport.cpp
index 3574158..a01063b 100644
--- a/daemon/face/multicast-udp-transport.cpp
+++ b/daemon/face/multicast-udp-transport.cpp
@@ -87,10 +87,10 @@
NFD_LOG_FACE_TRACE(__func__);
m_sendSocket.async_send_to(boost::asio::buffer(packet.packet), m_multicastGroup,
- bind(&MulticastUdpTransport::handleSend, this,
- boost::asio::placeholders::error,
- boost::asio::placeholders::bytes_transferred,
- packet.packet));
+ // packet.packet is copied into the lambda to retain the underlying Buffer
+ [this, p = packet.packet] (auto&&... args) {
+ this->handleSend(std::forward<decltype(args)>(args)...);
+ });
}
void
diff --git a/daemon/face/stream-transport.hpp b/daemon/face/stream-transport.hpp
index d70e4f6..9daf29e 100644
--- a/daemon/face/stream-transport.hpp
+++ b/daemon/face/stream-transport.hpp
@@ -200,9 +200,7 @@
StreamTransport<T>::sendFromQueue()
{
boost::asio::async_write(m_socket, boost::asio::buffer(m_sendQueue.front()),
- bind(&StreamTransport<T>::handleSend, this,
- boost::asio::placeholders::error,
- boost::asio::placeholders::bytes_transferred));
+ [this] (auto&&... args) { this->handleSend(std::forward<decltype(args)>(args)...); });
}
template<class T>
@@ -232,9 +230,7 @@
m_socket.async_receive(boost::asio::buffer(m_receiveBuffer + m_receiveBufferSize,
ndn::MAX_NDN_PACKET_SIZE - m_receiveBufferSize),
- bind(&StreamTransport<T>::handleReceive, this,
- boost::asio::placeholders::error,
- boost::asio::placeholders::bytes_transferred));
+ [this] (auto&&... args) { this->handleReceive(std::forward<decltype(args)>(args)...); });
}
template<class T>
diff --git a/daemon/face/tcp-channel.cpp b/daemon/face/tcp-channel.cpp
index 1e6b410..639b27d 100644
--- a/daemon/face/tcp-channel.cpp
+++ b/daemon/face/tcp-channel.cpp
@@ -83,15 +83,15 @@
return;
}
- auto clientSocket = make_shared<ip::tcp::socket>(ref(getGlobalIoService()));
- auto timeoutEvent = scheduler::schedule(timeout, bind(&TcpChannel::handleConnectTimeout, this,
- remoteEndpoint, clientSocket, onConnectFailed));
+ auto clientSocket = make_shared<ip::tcp::socket>(std::ref(getGlobalIoService()));
+ auto timeoutEvent = scheduler::schedule(timeout, [=] {
+ handleConnectTimeout(remoteEndpoint, clientSocket, onConnectFailed);
+ });
NFD_LOG_CHAN_TRACE("Connecting to " << remoteEndpoint);
- clientSocket->async_connect(remoteEndpoint,
- bind(&TcpChannel::handleConnect, this,
- boost::asio::placeholders::error, remoteEndpoint, clientSocket,
- params, timeoutEvent, onFaceCreated, onConnectFailed));
+ clientSocket->async_connect(remoteEndpoint, [=] (const auto& e) {
+ this->handleConnect(e, remoteEndpoint, clientSocket, params, timeoutEvent, onFaceCreated, onConnectFailed);
+ });
}
void
@@ -151,9 +151,7 @@
TcpChannel::accept(const FaceCreatedCallback& onFaceCreated,
const FaceCreationFailedCallback& onAcceptFailed)
{
- m_acceptor.async_accept(m_socket, bind(&TcpChannel::handleAccept, this,
- boost::asio::placeholders::error,
- onFaceCreated, onAcceptFailed));
+ m_acceptor.async_accept(m_socket, [=] (const auto& e) { this->handleAccept(e, onFaceCreated, onAcceptFailed); });
}
void
diff --git a/daemon/face/tcp-transport.cpp b/daemon/face/tcp-transport.cpp
index ad1be5d..78d7097 100644
--- a/daemon/face/tcp-transport.cpp
+++ b/daemon/face/tcp-transport.cpp
@@ -35,8 +35,8 @@
NFD_LOG_MEMBER_INIT_SPECIALIZED(StreamTransport<boost::asio::ip::tcp>, TcpTransport);
-time::milliseconds TcpTransport::s_initialReconnectWait = time::seconds(1);
-time::milliseconds TcpTransport::s_maxReconnectWait = time::minutes(5);
+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)
@@ -134,10 +134,8 @@
this->resetReceiveBuffer();
this->resetSendQueue();
- m_reconnectEvent = scheduler::schedule(m_nextReconnectWait,
- [this] { handleReconnectTimeout(); });
- m_socket.async_connect(m_remoteEndpoint,
- [this] (const boost::system::error_code& error) { handleReconnect(error); });
+ m_reconnectEvent = scheduler::schedule(m_nextReconnectWait, [this] { this->handleReconnectTimeout(); });
+ m_socket.async_connect(m_remoteEndpoint, [this] (const auto& e) { this->handleReconnect(e); });
}
void
diff --git a/daemon/face/udp-channel.cpp b/daemon/face/udp-channel.cpp
index 3d6e6b8..b87e697 100644
--- a/daemon/face/udp-channel.cpp
+++ b/daemon/face/udp-channel.cpp
@@ -60,7 +60,7 @@
catch (const boost::system::system_error& e) {
NFD_LOG_CHAN_DEBUG("Face creation for " << remoteEndpoint << " failed: " << e.what());
if (onConnectFailed)
- onConnectFailed(504, std::string("Face creation failed: ") + e.what());
+ onConnectFailed(504, "Face creation failed: "s + e.what());
return;
}
@@ -94,10 +94,9 @@
const FaceCreationFailedCallback& onReceiveFailed)
{
m_socket.async_receive_from(boost::asio::buffer(m_receiveBuffer), m_remoteEndpoint,
- bind(&UdpChannel::handleNewPeer, this,
- boost::asio::placeholders::error,
- boost::asio::placeholders::bytes_transferred,
- onFaceCreated, onReceiveFailed));
+ [=] (auto&&... args) {
+ this->handleNewPeer(std::forward<decltype(args)>(args)..., onFaceCreated, onReceiveFailed);
+ });
}
void
@@ -127,7 +126,7 @@
catch (const boost::system::system_error& e) {
NFD_LOG_CHAN_DEBUG("Face creation for " << m_remoteEndpoint << " failed: " << e.what());
if (onReceiveFailed)
- onReceiveFailed(504, std::string("Face creation failed: ") + e.what());
+ onReceiveFailed(504, "Face creation failed: "s + e.what());
return;
}
diff --git a/daemon/face/udp-factory.cpp b/daemon/face/udp-factory.cpp
index 5d28bed..3660db5 100644
--- a/daemon/face/udp-factory.cpp
+++ b/daemon/face/udp-factory.cpp
@@ -50,7 +50,9 @@
UdpFactory::UdpFactory(const CtorParams& params)
: ProtocolFactory(params)
{
- m_netifAddConn = netmon->onInterfaceAdded.connect(bind(&UdpFactory::applyMcastConfigToNetif, this, _1));
+ m_netifAddConn = netmon->onInterfaceAdded.connect([this] (const auto& netif) {
+ this->applyMcastConfigToNetif(netif);
+ });
}
void
@@ -414,7 +416,7 @@
NFD_LOG_DEBUG("Not creating multicast faces on " << netif->getName() << ": no viable IP address");
// keep an eye on new addresses
m_netifConns[netif->getIndex()].addrAddConn =
- netif->onAddressAdded.connect(bind(&UdpFactory::applyMcastConfigToNetif, this, netif));
+ netif->onAddressAdded.connect([=] (auto...) { this->applyMcastConfigToNetif(netif); });
return {};
}
diff --git a/daemon/face/unix-stream-channel.cpp b/daemon/face/unix-stream-channel.cpp
index a127c84..8c58c55 100644
--- a/daemon/face/unix-stream-channel.cpp
+++ b/daemon/face/unix-stream-channel.cpp
@@ -101,7 +101,7 @@
m_acceptor.bind(m_endpoint);
m_acceptor.listen(backlog);
- if (::chmod(m_endpoint.path().c_str(), 0666) < 0) {
+ if (::chmod(m_endpoint.path().data(), 0666) < 0) {
BOOST_THROW_EXCEPTION(Error("chmod(" + m_endpoint.path() + ") failed: " + std::strerror(errno)));
}
@@ -113,9 +113,7 @@
UnixStreamChannel::accept(const FaceCreatedCallback& onFaceCreated,
const FaceCreationFailedCallback& onAcceptFailed)
{
- m_acceptor.async_accept(m_socket, bind(&UnixStreamChannel::handleAccept, this,
- boost::asio::placeholders::error,
- onFaceCreated, onAcceptFailed));
+ m_acceptor.async_accept(m_socket, [=] (const auto& e) { this->handleAccept(e, onFaceCreated, onAcceptFailed); });
}
void
diff --git a/daemon/face/websocket-channel.cpp b/daemon/face/websocket-channel.cpp
index 2ac9384..ca149b3 100644
--- a/daemon/face/websocket-channel.cpp
+++ b/daemon/face/websocket-channel.cpp
@@ -117,7 +117,7 @@
NFD_LOG_CHAN_TRACE("Incoming connection from " << m_server.get_con_from_hdl(hdl)->get_remote_endpoint());
auto linkService = make_unique<GenericLinkService>();
- auto transport = make_unique<WebSocketTransport>(hdl, ref(m_server), m_pingInterval);
+ auto transport = make_unique<WebSocketTransport>(hdl, std::ref(m_server), m_pingInterval);
auto face = make_shared<Face>(std::move(linkService), std::move(transport));
BOOST_ASSERT(m_channelFaces.count(hdl) == 0);
diff --git a/daemon/face/websocket-transport.cpp b/daemon/face/websocket-transport.cpp
index 97af039..4262287 100644
--- a/daemon/face/websocket-transport.cpp
+++ b/daemon/face/websocket-transport.cpp
@@ -97,7 +97,7 @@
bool isOk = false;
Block element;
- std::tie(isOk, element) = Block::fromBuffer(reinterpret_cast<const uint8_t*>(msg.c_str()), msg.size());
+ std::tie(isOk, element) = Block::fromBuffer(reinterpret_cast<const uint8_t*>(msg.data()), msg.size());
if (!isOk) {
NFD_LOG_FACE_WARN("Failed to parse message payload");
return;
@@ -109,7 +109,7 @@
void
WebSocketTransport::schedulePing()
{
- m_pingEventId = scheduler::schedule(m_pingInterval, bind(&WebSocketTransport::sendPing, this));
+ m_pingEventId = scheduler::schedule(m_pingInterval, [this] { sendPing(); });
}
void
diff --git a/daemon/fw/access-strategy.cpp b/daemon/fw/access-strategy.cpp
index a766424..8460a00 100644
--- a/daemon/fw/access-strategy.cpp
+++ b/daemon/fw/access-strategy.cpp
@@ -35,8 +35,7 @@
AccessStrategy::AccessStrategy(Forwarder& forwarder, const Name& name)
: Strategy(forwarder)
- , m_removeFaceInfoConn(this->beforeRemoveFace.connect(
- bind(&AccessStrategy::removeFaceInfo, this, _1)))
+ , m_removeFaceInfoConn(beforeRemoveFace.connect([this] (const Face& face) { removeFaceInfo(face); }))
{
ParsedInstanceName parsed = parseInstanceName(name);
if (!parsed.parameters.empty()) {
@@ -177,14 +176,13 @@
return;
}
- pit::InRecordCollection::iterator inRecord = pitEntry->getInRecord(*inFace);
+ auto inRecord = pitEntry->getInRecord(*inFace);
BOOST_ASSERT(inRecord != pitEntry->in_end());
// in-record is erased only if Interest is satisfied, and RTO timer should have been cancelled
// note: if this strategy is extended to send Nacks, that would also erase in-record,
// and RTO timer should be cancelled in that case as well
const Interest& interest = inRecord->getInterest();
-
const fib::Entry& fibEntry = this->lookupFib(*pitEntry);
NFD_LOG_DEBUG(pitEntry->getInterest() << " timeoutFrom " << firstOutFaceId <<
@@ -227,14 +225,14 @@
return;
}
- pit::OutRecordCollection::iterator outRecord = pitEntry->getOutRecord(inFace);
+ auto outRecord = pitEntry->getOutRecord(inFace);
if (outRecord == pitEntry->out_end()) { // no out-record
NFD_LOG_DEBUG(pitEntry->getInterest() << " dataFrom " << inFace.getId() <<
" no-out-record");
return;
}
- time::steady_clock::Duration rtt = time::steady_clock::now() - outRecord->getLastRenewed();
+ auto rtt = time::steady_clock::now() - outRecord->getLastRenewed();
NFD_LOG_DEBUG(pitEntry->getInterest() << " dataFrom " << inFace.getId() <<
" rtt=" << time::duration_cast<time::microseconds>(rtt).count());
this->updateMeasurements(inFace, data, time::duration_cast<RttEstimator::Duration>(rtt));
@@ -260,7 +258,7 @@
AccessStrategy::MtInfo::MtInfo()
: lastNexthop(face::INVALID_FACEID)
- , rtt(1, time::milliseconds(1), 0.1)
+ , rtt(1, 1_ms, 0.1)
{
}
@@ -292,14 +290,13 @@
BOOST_ASSERT(me != nullptr);
}
- static const time::nanoseconds ME_LIFETIME = time::seconds(8);
- this->getMeasurements().extendLifetime(*me, ME_LIFETIME);
+ this->getMeasurements().extendLifetime(*me, 8_s);
return me->insertStrategyInfo<MtInfo>().first;
}
AccessStrategy::FaceInfo::FaceInfo()
- : rtt(1, time::milliseconds(1), 0.1)
+ : rtt(1, 1_ms, 0.1)
{
}
diff --git a/daemon/fw/asf-measurements.cpp b/daemon/fw/asf-measurements.cpp
index 0d772ac..f743e06 100644
--- a/daemon/fw/asf-measurements.cpp
+++ b/daemon/fw/asf-measurements.cpp
@@ -168,7 +168,7 @@
FaceInfo* info = nullptr;
if (it == m_fit.end()) {
- const auto& pair = m_fit.insert(std::make_pair(faceId, FaceInfo()));
+ const auto& pair = m_fit.emplace(faceId, FaceInfo());
info = &pair.first->second;
extendFaceInfoLifetime(*info, faceId);
@@ -193,9 +193,7 @@
scheduler::cancel(info.getMeasurementExpirationEventId());
// Refresh measurement
- scheduler::EventId id = scheduler::schedule(AsfMeasurements::MEASUREMENTS_LIFETIME,
- bind(&NamespaceInfo::expireFaceInfo, this, faceId));
-
+ auto id = scheduler::schedule(AsfMeasurements::MEASUREMENTS_LIFETIME, [=] { expireFaceInfo(faceId); });
info.setMeasurementExpirationEventId(id);
}
diff --git a/daemon/fw/asf-measurements.hpp b/daemon/fw/asf-measurements.hpp
index ee5885d..b5b1f8e 100644
--- a/daemon/fw/asf-measurements.hpp
+++ b/daemon/fw/asf-measurements.hpp
@@ -254,8 +254,7 @@
const FaceInfoTable::iterator
insert(FaceId faceId)
{
- const auto& pair = m_fit.insert(std::make_pair(faceId, FaceInfo()));
- return pair.first;
+ return m_fit.emplace(faceId, FaceInfo()).first;
}
bool
@@ -317,7 +316,7 @@
extendLifetime(measurements::Entry& me);
public:
- static constexpr time::microseconds MEASUREMENTS_LIFETIME = time::seconds(300);
+ static constexpr time::microseconds MEASUREMENTS_LIFETIME = 300_s;
private:
MeasurementsAccessor& m_measurements;
diff --git a/daemon/fw/asf-probing-module.cpp b/daemon/fw/asf-probing-module.cpp
index 24b4577..63f9867 100644
--- a/daemon/fw/asf-probing-module.cpp
+++ b/daemon/fw/asf-probing-module.cpp
@@ -70,7 +70,7 @@
const Face& faceUsed)
{
FaceInfoFacePairSet rankedFaces(
- [] (FaceInfoFacePair pairLhs, FaceInfoFacePair pairRhs) -> bool {
+ [] (const auto& pairLhs, const auto& pairRhs) -> bool {
// Sort by RTT
// If a face has timed-out, rank it behind non-timed-out faces
FaceInfo& lhs = *pairLhs.first;
@@ -93,14 +93,13 @@
}
FaceInfo* info = m_measurements.getFaceInfo(fibEntry, interest, hopFace.getId());
-
// If no RTT has been recorded, probe this face
if (info == nullptr || !info->hasSrttMeasurement()) {
return &hopFace;
}
// Add FaceInfo to container sorted by RTT
- rankedFaces.insert(std::make_pair(info, &hopFace));
+ rankedFaces.insert({info, &hopFace});
}
if (rankedFaces.empty()) {
@@ -149,7 +148,7 @@
uint64_t rank = 1;
double offset = 0.0;
- for (const FaceInfoFacePair pair : rankedFaces) {
+ for (const auto& pair : rankedFaces) {
double probability = getProbingProbability(rank++, rankSum, rankedFaces.size());
// Is the random number within the bounds of this face's probability + the previous faces'
diff --git a/daemon/fw/asf-probing-module.hpp b/daemon/fw/asf-probing-module.hpp
index 785abd8..02ef155 100644
--- a/daemon/fw/asf-probing-module.hpp
+++ b/daemon/fw/asf-probing-module.hpp
@@ -80,8 +80,8 @@
getRandomNumber(double start, double end);
public:
- static constexpr time::milliseconds DEFAULT_PROBING_INTERVAL = time::milliseconds(60000);
- static constexpr time::milliseconds MIN_PROBING_INTERVAL = time::milliseconds(1000);
+ static constexpr time::milliseconds DEFAULT_PROBING_INTERVAL = 1_min;
+ static constexpr time::milliseconds MIN_PROBING_INTERVAL = 1_s;
private:
time::milliseconds m_probingInterval;
diff --git a/daemon/fw/best-route-strategy.cpp b/daemon/fw/best-route-strategy.cpp
index 69cbec7..e4462e4 100644
--- a/daemon/fw/best-route-strategy.cpp
+++ b/daemon/fw/best-route-strategy.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-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -44,10 +44,8 @@
}
const fib::Entry& fibEntry = this->lookupFib(*pitEntry);
- const fib::NextHopList& nexthops = fibEntry.getNextHops();
-
- for (fib::NextHopList::const_iterator it = nexthops.begin(); it != nexthops.end(); ++it) {
- Face& outFace = it->getFace();
+ for (const auto& nexthop : fibEntry.getNextHops()) {
+ Face& outFace = nexthop.getFace();
if (!wouldViolateScope(inFace, interest, outFace) &&
canForwardToLegacy(*pitEntry, outFace)) {
this->sendInterest(pitEntry, outFace, interest);
diff --git a/daemon/fw/best-route-strategy2.cpp b/daemon/fw/best-route-strategy2.cpp
index 2956ed7..0ab6b25 100644
--- a/daemon/fw/best-route-strategy2.cpp
+++ b/daemon/fw/best-route-strategy2.cpp
@@ -69,7 +69,7 @@
* \param wantUnused if true, NextHop must not have unexpired out-record
* \param now time::steady_clock::now(), ignored if !wantUnused
*/
-static inline bool
+static bool
isNextHopEligible(const Face& inFace, const Interest& interest,
const fib::NextHop& nexthop,
const shared_ptr<pit::Entry>& pitEntry,
@@ -88,7 +88,7 @@
if (wantUnused) {
// nexthop must not have unexpired out-record
- pit::OutRecordCollection::iterator outRecord = pitEntry->getOutRecord(outFace);
+ auto outRecord = pitEntry->getOutRecord(outFace);
if (outRecord != pitEntry->out_end() && outRecord->getExpiry() > now) {
return false;
}
@@ -100,23 +100,26 @@
/** \brief pick an eligible NextHop with earliest out-record
* \note It is assumed that every nexthop has an out-record.
*/
-static inline fib::NextHopList::const_iterator
+static fib::NextHopList::const_iterator
findEligibleNextHopWithEarliestOutRecord(const Face& inFace, const Interest& interest,
const fib::NextHopList& nexthops,
const shared_ptr<pit::Entry>& pitEntry)
{
- fib::NextHopList::const_iterator found = nexthops.end();
- time::steady_clock::TimePoint earliestRenewed = time::steady_clock::TimePoint::max();
- for (fib::NextHopList::const_iterator it = nexthops.begin(); it != nexthops.end(); ++it) {
+ auto found = nexthops.end();
+ auto earliestRenewed = time::steady_clock::TimePoint::max();
+
+ for (auto it = nexthops.begin(); it != nexthops.end(); ++it) {
if (!isNextHopEligible(inFace, interest, *it, pitEntry))
continue;
- pit::OutRecordCollection::iterator outRecord = pitEntry->getOutRecord(it->getFace());
+
+ auto outRecord = pitEntry->getOutRecord(it->getFace());
BOOST_ASSERT(outRecord != pitEntry->out_end());
if (outRecord->getLastRenewed() < earliestRenewed) {
found = it;
earliestRenewed = outRecord->getLastRenewed();
}
}
+
return found;
}
@@ -133,13 +136,13 @@
const fib::Entry& fibEntry = this->lookupFib(*pitEntry);
const fib::NextHopList& nexthops = fibEntry.getNextHops();
- fib::NextHopList::const_iterator it = nexthops.end();
+ auto it = nexthops.end();
if (suppression == RetxSuppressionResult::NEW) {
// forward to nexthop with lowest cost except downstream
- it = std::find_if(nexthops.begin(), nexthops.end(),
- bind(&isNextHopEligible, cref(inFace), interest, _1, pitEntry,
- false, time::steady_clock::TimePoint::min()));
+ it = std::find_if(nexthops.begin(), nexthops.end(), [&] (const auto& nexthop) {
+ return isNextHopEligible(inFace, interest, nexthop, pitEntry);
+ });
if (it == nexthops.end()) {
NFD_LOG_DEBUG(interest << " from=" << inFace.getId() << " noNextHop");
@@ -160,9 +163,10 @@
}
// find an unused upstream with lowest cost except downstream
- it = std::find_if(nexthops.begin(), nexthops.end(),
- bind(&isNextHopEligible, cref(inFace), interest, _1, pitEntry,
- true, time::steady_clock::now()));
+ it = std::find_if(nexthops.begin(), nexthops.end(), [&] (const auto& nexthop) {
+ return isNextHopEligible(inFace, interest, nexthop, pitEntry, true, time::steady_clock::now());
+ });
+
if (it != nexthops.end()) {
Face& outFace = it->getFace();
this->sendInterest(pitEntry, outFace, interest);
diff --git a/daemon/fw/face-table.cpp b/daemon/fw/face-table.cpp
index 3e19dd1..7e1880f 100644
--- a/daemon/fw/face-table.cpp
+++ b/daemon/fw/face-table.cpp
@@ -86,7 +86,7 @@
" remote=" << face->getRemoteUri() <<
" local=" << face->getLocalUri());
- connectFaceClosedSignal(*face, bind(&FaceTable::remove, this, faceId));
+ connectFaceClosedSignal(*face, [=] { remove(faceId); });
this->afterAdd(*face);
}
diff --git a/daemon/fw/forwarder.cpp b/daemon/fw/forwarder.cpp
index accfb38..7e28db2 100644
--- a/daemon/fw/forwarder.cpp
+++ b/daemon/fw/forwarder.cpp
@@ -132,8 +132,8 @@
// is pending?
if (!pitEntry->hasInRecords()) {
m_cs.find(interest,
- bind(&Forwarder::onContentStoreHit, this, ref(inFace), pitEntry, _1, _2),
- bind(&Forwarder::onContentStoreMiss, this, ref(inFace), pitEntry, _1));
+ bind(&Forwarder::onContentStoreHit, this, std::ref(inFace), pitEntry, _1, _2),
+ bind(&Forwarder::onContentStoreMiss, this, std::ref(inFace), pitEntry, _1));
}
else {
this->onContentStoreMiss(inFace, pitEntry, interest);
@@ -511,15 +511,7 @@
scheduler::cancel(pitEntry->expiryTimer);
- pitEntry->expiryTimer = scheduler::schedule(duration,
- bind(&Forwarder::onInterestFinalize, this, pitEntry));
-}
-
-static inline void
-insertNonceToDnl(DeadNonceList& dnl, const pit::Entry& pitEntry,
- const pit::OutRecord& outRecord)
-{
- dnl.add(pitEntry.getName(), outRecord.getLastNonce());
+ pitEntry->expiryTimer = scheduler::schedule(duration, [=] { onInterestFinalize(pitEntry); });
}
void
@@ -540,13 +532,14 @@
// Dead Nonce List insert
if (upstream == nullptr) {
// insert all outgoing Nonces
- const pit::OutRecordCollection& outRecords = pitEntry.getOutRecords();
- std::for_each(outRecords.begin(), outRecords.end(),
- bind(&insertNonceToDnl, ref(m_deadNonceList), cref(pitEntry), _1));
+ const auto& outRecords = pitEntry.getOutRecords();
+ std::for_each(outRecords.begin(), outRecords.end(), [&] (const auto& outRecord) {
+ m_deadNonceList.add(pitEntry.getName(), outRecord.getLastNonce());
+ });
}
else {
// insert outgoing Nonce of a specific face
- pit::OutRecordCollection::iterator outRecord = pitEntry.getOutRecord(*upstream);
+ auto outRecord = pitEntry.getOutRecord(*upstream);
if (outRecord != pitEntry.getOutRecords().end()) {
m_deadNonceList.add(pitEntry.getName(), outRecord->getLastNonce());
}
diff --git a/daemon/fw/ncc-strategy.cpp b/daemon/fw/ncc-strategy.cpp
index bdb322a..0f7f4e1 100644
--- a/daemon/fw/ncc-strategy.cpp
+++ b/daemon/fw/ncc-strategy.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-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -32,9 +32,9 @@
NFD_REGISTER_STRATEGY(NccStrategy);
-const time::microseconds NccStrategy::DEFER_FIRST_WITHOUT_BEST_FACE = time::microseconds(4000);
-const time::microseconds NccStrategy::DEFER_RANGE_WITHOUT_BEST_FACE = time::microseconds(75000);
-const time::nanoseconds NccStrategy::MEASUREMENTS_LIFETIME = time::seconds(16);
+const time::microseconds NccStrategy::DEFER_FIRST_WITHOUT_BEST_FACE = 4_ms;
+const time::microseconds NccStrategy::DEFER_RANGE_WITHOUT_BEST_FACE = 75_ms;
+const time::nanoseconds NccStrategy::MEASUREMENTS_LIFETIME = 16_s;
NccStrategy::NccStrategy(Forwarder& forwarder, const Name& name)
: Strategy(forwarder)
@@ -118,7 +118,7 @@
}
if (nUpstreams > 0) {
- pitEntryInfo->maxInterval = std::max(time::microseconds(1),
+ pitEntryInfo->maxInterval = std::max(1_us,
time::microseconds((2 * deferRange.count() + nUpstreams - 1) / nUpstreams));
}
else {
@@ -142,7 +142,7 @@
if (pitEntry == nullptr) {
return;
}
- pit::InRecordCollection::const_iterator inRecord = pitEntry->getInRecord(*inFace);
+ auto inRecord = pitEntry->getInRecord(*inFace);
if (inRecord == pitEntry->in_end()) {
return;
}
@@ -163,10 +163,9 @@
this->sendInterest(pitEntry, *previousFace, interest);
}
- const fib::NextHopList& nexthops = fibEntry.getNextHops();
bool isForwarded = false;
- for (fib::NextHopList::const_iterator it = nexthops.begin(); it != nexthops.end(); ++it) {
- Face& face = it->getFace();
+ for (const auto& nexthop : fibEntry.getNextHops()) {
+ Face& face = nexthop.getFace();
if (!wouldViolateScope(*inFace, interest, face) &&
canForwardToLegacy(*pitEntry, face)) {
isForwarded = true;
@@ -271,9 +270,9 @@
return *info;
}
-const time::microseconds NccStrategy::MeasurementsEntryInfo::INITIAL_PREDICTION = time::microseconds(8192);
-const time::microseconds NccStrategy::MeasurementsEntryInfo::MIN_PREDICTION = time::microseconds(127);
-const time::microseconds NccStrategy::MeasurementsEntryInfo::MAX_PREDICTION = time::milliseconds(160);
+const time::microseconds NccStrategy::MeasurementsEntryInfo::INITIAL_PREDICTION = 8192_us;
+const time::microseconds NccStrategy::MeasurementsEntryInfo::MIN_PREDICTION = 127_us;
+const time::microseconds NccStrategy::MeasurementsEntryInfo::MAX_PREDICTION = 160_ms;
NccStrategy::MeasurementsEntryInfo::MeasurementsEntryInfo()
: prediction(INITIAL_PREDICTION)
diff --git a/daemon/fw/retx-suppression-exponential.cpp b/daemon/fw/retx-suppression-exponential.cpp
index f2ff1b2..b110588 100644
--- a/daemon/fw/retx-suppression-exponential.cpp
+++ b/daemon/fw/retx-suppression-exponential.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-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -28,11 +28,9 @@
namespace nfd {
namespace fw {
-const RetxSuppressionExponential::Duration RetxSuppressionExponential::DEFAULT_INITIAL_INTERVAL =
- time::milliseconds(1);
-const float RetxSuppressionExponential::DEFAULT_MULTIPLIER = 2.0;
-const RetxSuppressionExponential::Duration RetxSuppressionExponential::DEFAULT_MAX_INTERVAL =
- time::milliseconds(250);
+const RetxSuppressionExponential::Duration RetxSuppressionExponential::DEFAULT_INITIAL_INTERVAL = 1_ms;
+const RetxSuppressionExponential::Duration RetxSuppressionExponential::DEFAULT_MAX_INTERVAL = 250_ms;
+const float RetxSuppressionExponential::DEFAULT_MULTIPLIER = 2.0f;
class RetxSuppressionExponential::PitInfo : public StrategyInfo
{
@@ -63,8 +61,8 @@
, m_multiplier(multiplier)
, m_maxInterval(maxInterval)
{
- BOOST_ASSERT(initialInterval > time::milliseconds::zero());
- BOOST_ASSERT(multiplier >= 1.0);
+ BOOST_ASSERT(initialInterval > 0_us);
+ BOOST_ASSERT(multiplier >= 1.0f);
BOOST_ASSERT(maxInterval >= initialInterval);
}
@@ -76,9 +74,9 @@
return RetxSuppressionResult::NEW;
}
- time::steady_clock::TimePoint lastOutgoing = getLastOutgoing(pitEntry);
- time::steady_clock::TimePoint now = time::steady_clock::now();
- time::steady_clock::Duration sinceLastOutgoing = now - lastOutgoing;
+ auto lastOutgoing = getLastOutgoing(pitEntry);
+ auto now = time::steady_clock::now();
+ auto sinceLastOutgoing = now - lastOutgoing;
PitInfo* pi = pitEntry.insertStrategyInfo<PitInfo>(m_initialInterval).first;
bool shouldSuppress = sinceLastOutgoing < pi->suppressionInterval;
@@ -102,9 +100,9 @@
return RetxSuppressionResult::NEW;
}
- time::steady_clock::TimePoint lastOutgoing = outRecord->getLastRenewed();
- time::steady_clock::TimePoint now = time::steady_clock::now();
- time::steady_clock::Duration sinceLastOutgoing = now - lastOutgoing;
+ auto lastOutgoing = outRecord->getLastRenewed();
+ auto now = time::steady_clock::now();
+ auto sinceLastOutgoing = now - lastOutgoing;
// insertStrategyInfo does not insert m_initialInterval again if it already exists
PitInfo* pi = outRecord->insertStrategyInfo<PitInfo>(m_initialInterval).first;
diff --git a/daemon/fw/retx-suppression-fixed.cpp b/daemon/fw/retx-suppression-fixed.cpp
index 6245ae3..dddd742 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-2017, Regents of the University of California,
+ * Copyright (c) 2014-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -28,12 +28,12 @@
namespace nfd {
namespace fw {
-const time::milliseconds RetxSuppressionFixed::DEFAULT_MIN_RETX_INTERVAL(100);
+const time::milliseconds RetxSuppressionFixed::DEFAULT_MIN_RETX_INTERVAL = 100_ms;
RetxSuppressionFixed::RetxSuppressionFixed(const time::milliseconds& minRetxInterval)
: m_minRetxInterval(minRetxInterval)
{
- BOOST_ASSERT(minRetxInterval > time::milliseconds::zero());
+ BOOST_ASSERT(minRetxInterval > 0_ms);
}
RetxSuppressionResult
diff --git a/daemon/nfd.cpp b/daemon/nfd.cpp
index f96720f..28f6989 100644
--- a/daemon/nfd.cpp
+++ b/daemon/nfd.cpp
@@ -89,7 +89,7 @@
m_netmon->onNetworkStateChanged.connect([this] {
// delay stages, so if multiple events are triggered in short sequence,
// only one auto-detection procedure is triggered
- m_reloadConfigEvent = scheduler::schedule(time::seconds(5),
+ m_reloadConfigEvent = scheduler::schedule(5_s,
[this] {
NFD_LOG_INFO("Network change detected, reloading face section of the config file...");
this->reloadConfigFileFaceSection();
diff --git a/daemon/table/cs-policy-priority-fifo.cpp b/daemon/table/cs-policy-priority-fifo.cpp
index 934d759..7984739 100644
--- a/daemon/table/cs-policy-priority-fifo.cpp
+++ b/daemon/table/cs-policy-priority-fifo.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-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -118,7 +118,7 @@
else {
entryInfo->queueType = QUEUE_FIFO;
entryInfo->moveStaleEventId = scheduler::schedule(i->getData().getFreshnessPeriod(),
- bind(&PriorityFifoPolicy::moveToStaleQueue, this, i));
+ [=] { moveToStaleQueue(i); });
}
Queue& queue = m_queues[entryInfo->queueType];
diff --git a/daemon/table/cs.cpp b/daemon/table/cs.cpp
index 00dc9ee..1663d8f 100644
--- a/daemon/table/cs.cpp
+++ b/daemon/table/cs.cpp
@@ -155,7 +155,7 @@
iterator
Cs::findLeftmost(const Interest& interest, iterator first, iterator last) const
{
- return std::find_if(first, last, bind(&cs::EntryImpl::canSatisfy, _1, interest));
+ return std::find_if(first, last, [&interest] (const auto& entry) { return entry.canSatisfy(interest); });
}
iterator
@@ -193,7 +193,7 @@
iterator
Cs::findRightmostAmongExact(const Interest& interest, iterator first, iterator last) const
{
- return find_last_if(first, last, bind(&EntryImpl::canSatisfy, _1, interest));
+ return find_last_if(first, last, [&interest] (const auto& entry) { return entry.canSatisfy(interest); });
}
void
diff --git a/daemon/table/dead-nonce-list.cpp b/daemon/table/dead-nonce-list.cpp
index d732a90..144e68e 100644
--- a/daemon/table/dead-nonce-list.cpp
+++ b/daemon/table/dead-nonce-list.cpp
@@ -31,8 +31,8 @@
NFD_LOG_INIT(DeadNonceList);
-const time::nanoseconds DeadNonceList::DEFAULT_LIFETIME = time::seconds(6);
-const time::nanoseconds DeadNonceList::MIN_LIFETIME = time::milliseconds(1);
+const time::nanoseconds DeadNonceList::DEFAULT_LIFETIME = 6_s;
+const time::nanoseconds DeadNonceList::MIN_LIFETIME = 1_ms;
const size_t DeadNonceList::INITIAL_CAPACITY = (1 << 7);
const size_t DeadNonceList::MIN_CAPACITY = (1 << 3);
const size_t DeadNonceList::MAX_CAPACITY = (1 << 24);
@@ -58,9 +58,8 @@
m_queue.push_back(MARK);
}
- m_markEvent = scheduler::schedule(m_markInterval, bind(&DeadNonceList::mark, this));
- m_adjustCapacityEvent = scheduler::schedule(m_adjustCapacityInterval,
- bind(&DeadNonceList::adjustCapacity, this));
+ m_markEvent = scheduler::schedule(m_markInterval, [this] { mark(); });
+ m_adjustCapacityEvent = scheduler::schedule(m_adjustCapacityInterval, [this] { adjustCapacity(); });
}
DeadNonceList::~DeadNonceList()
@@ -125,15 +124,13 @@
NFD_LOG_TRACE("mark nMarks=" << nMarks);
- scheduler::schedule(m_markInterval, bind(&DeadNonceList::mark, this));
+ m_markEvent = scheduler::schedule(m_markInterval, [this] { mark(); });
}
void
DeadNonceList::adjustCapacity()
{
- std::pair<std::multiset<size_t>::iterator, std::multiset<size_t>::iterator> equalRange =
- m_actualMarkCounts.equal_range(EXPECTED_MARK_COUNT);
-
+ auto equalRange = m_actualMarkCounts.equal_range(EXPECTED_MARK_COUNT);
if (equalRange.second == m_actualMarkCounts.begin()) {
// all counts are above expected count, adjust down
m_capacity = std::max(MIN_CAPACITY,
@@ -148,11 +145,9 @@
}
m_actualMarkCounts.clear();
-
this->evictEntries();
- m_adjustCapacityEvent = scheduler::schedule(m_adjustCapacityInterval,
- bind(&DeadNonceList::adjustCapacity, this));
+ m_adjustCapacityEvent = scheduler::schedule(m_adjustCapacityInterval, [this] { adjustCapacity(); });
}
void
diff --git a/daemon/table/fib.cpp b/daemon/table/fib.cpp
index 0a9522a..7b6d21a 100644
--- a/daemon/table/fib.cpp
+++ b/daemon/table/fib.cpp
@@ -93,12 +93,12 @@
name_tree::Entry& nte = m_nameTree.lookup(prefix);
Entry* entry = nte.getFibEntry();
if (entry != nullptr) {
- return std::make_pair(entry, false);
+ return {entry, false};
}
nte.setFibEntry(make_unique<Entry>(prefix));
++m_nItems;
- return std::make_pair(nte.getFibEntry(), true);
+ return {nte.getFibEntry(), true};
}
void
diff --git a/daemon/table/measurements.cpp b/daemon/table/measurements.cpp
index 4d84746..651a83b 100644
--- a/daemon/table/measurements.cpp
+++ b/daemon/table/measurements.cpp
@@ -50,8 +50,7 @@
entry = nte.getMeasurementsEntry();
entry->m_expiry = time::steady_clock::now() + getInitialLifetime();
- entry->m_cleanup = scheduler::schedule(getInitialLifetime(),
- bind(&Measurements::cleanup, this, ref(*entry)));
+ entry->m_cleanup = scheduler::schedule(getInitialLifetime(), [=] { cleanup(*entry); });
return *entry;
}
@@ -137,7 +136,7 @@
scheduler::cancel(entry.m_cleanup);
entry.m_expiry = expiry;
- entry.m_cleanup = scheduler::schedule(lifetime, bind(&Measurements::cleanup, this, ref(entry)));
+ entry.m_cleanup = scheduler::schedule(lifetime, [&] { cleanup(entry); });
}
void
diff --git a/daemon/table/measurements.hpp b/daemon/table/measurements.hpp
index d110ed6..c72ba28 100644
--- a/daemon/table/measurements.hpp
+++ b/daemon/table/measurements.hpp
@@ -167,7 +167,7 @@
inline time::nanoseconds
Measurements::getInitialLifetime()
{
- return time::seconds(4);
+ return 4_s;
}
inline size_t
diff --git a/daemon/table/name-tree-iterator.cpp b/daemon/table/name-tree-iterator.cpp
index 56c0360..f295d9c 100644
--- a/daemon/table/name-tree-iterator.cpp
+++ b/daemon/table/name-tree-iterator.cpp
@@ -46,7 +46,7 @@
}
Iterator::Iterator(shared_ptr<EnumerationImpl> impl, const Entry* ref)
- : m_impl(impl)
+ : m_impl(std::move(impl))
, m_entry(nullptr)
, m_ref(ref)
, m_state(0)
diff --git a/daemon/table/name-tree-iterator.hpp b/daemon/table/name-tree-iterator.hpp
index 87a93f7..973c961 100644
--- a/daemon/table/name-tree-iterator.hpp
+++ b/daemon/table/name-tree-iterator.hpp
@@ -69,9 +69,15 @@
/** \brief NameTree iterator
*/
-class Iterator : public std::iterator<std::forward_iterator_tag, const Entry>
+class Iterator
{
public:
+ using iterator_category = std::forward_iterator_tag;
+ using value_type = const Entry;
+ using difference_type = std::ptrdiff_t;
+ using pointer = value_type*;
+ using reference = value_type&;
+
Iterator();
Iterator(shared_ptr<EnumerationImpl> impl, const Entry* ref);
diff --git a/daemon/table/pit-iterator.hpp b/daemon/table/pit-iterator.hpp
index 434dfd0..35e02c5 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-2016, Regents of the University of California,
+/*
+ * Copyright (c) 2014-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -34,9 +34,15 @@
/** \brief PIT iterator
*/
-class Iterator : public std::iterator<std::forward_iterator_tag, const Entry>
+class Iterator
{
public:
+ using iterator_category = std::forward_iterator_tag;
+ using value_type = const Entry;
+ using difference_type = std::ptrdiff_t;
+ using pointer = value_type*;
+ using reference = value_type&;
+
/** \brief constructor
* \param ntIt a name tree iterator that visits name tree entries with one or more PIT entries
* \param iPitEntry make this iterator to dereference to the i-th PIT entry in name tree entry