Improve and simplify code with modern C++ features
Change-Id: I83bf5513c2a1f90ba5a59e93c473306864b27d94
diff --git a/core/common.hpp b/core/common.hpp
index b0fc450..2678a17 100644
--- a/core/common.hpp
+++ b/core/common.hpp
@@ -91,8 +91,8 @@
using std::const_pointer_cast;
using std::bind;
-using std::cref;
-using std::ref;
+
+using namespace std::string_literals;
using ndn::optional;
using ndn::nullopt;
diff --git a/core/manager-base.hpp b/core/manager-base.hpp
index cddb7c1..a19ccb2 100644
--- a/core/manager-base.hpp
+++ b/core/manager-base.hpp
@@ -161,7 +161,7 @@
m_dispatcher.addControlCommand<ControlParameters>(
makeRelPrefix(verb),
makeAuthorization(verb),
- bind(&ManagerBase::validateParameters, cref(*command), _1),
+ bind(&ManagerBase::validateParameters, std::cref(*command), _1),
bind(&ManagerBase::handleCommand, command, handler, _1, _2, _3, _4));
}
diff --git a/core/network-predicate.cpp b/core/network-predicate.cpp
index 5755f32..d10a5e3 100644
--- a/core/network-predicate.cpp
+++ b/core/network-predicate.cpp
@@ -193,8 +193,8 @@
bool
NetworkInterfacePredicate::operator()(const ndn::net::NetworkInterface& netif) const
{
- return std::any_of(m_whitelist.begin(), m_whitelist.end(), bind(&doesNetifMatchRule, cref(netif), _1)) &&
- std::none_of(m_blacklist.begin(), m_blacklist.end(), bind(&doesNetifMatchRule, cref(netif), _1));
+ return std::any_of(m_whitelist.begin(), m_whitelist.end(), bind(&doesNetifMatchRule, std::cref(netif), _1)) &&
+ std::none_of(m_blacklist.begin(), m_blacklist.end(), bind(&doesNetifMatchRule, std::cref(netif), _1));
}
static bool
@@ -214,8 +214,8 @@
bool
IpAddressPredicate::operator()(const boost::asio::ip::address& address) const
{
- return std::any_of(m_whitelist.begin(), m_whitelist.end(), bind(&doesAddressMatchRule, cref(address), _1)) &&
- std::none_of(m_blacklist.begin(), m_blacklist.end(), bind(&doesAddressMatchRule, cref(address), _1));
+ return std::any_of(m_whitelist.begin(), m_whitelist.end(), bind(&doesAddressMatchRule, std::cref(address), _1)) &&
+ std::none_of(m_blacklist.begin(), m_blacklist.end(), bind(&doesAddressMatchRule, std::cref(address), _1));
}
} // namespace nfd
diff --git a/core/rtt-estimator.hpp b/core/rtt-estimator.hpp
index 2b93880..e8a5eb9 100644
--- a/core/rtt-estimator.hpp
+++ b/core/rtt-estimator.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-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -33,7 +33,7 @@
/**
* \brief implements the Mean-Deviation RTT estimator
*
- * reference: ns3::RttMeanDeviation
+ * \sa ns3::RttMeanDeviation
*
* This RttEstimator algorithm is designed for TCP, which is a continuous stream.
* NDN Interest-Data traffic is not always a continuous stream,
@@ -43,18 +43,18 @@
class RttEstimator
{
public:
- typedef time::microseconds Duration;
-
- static Duration
- getInitialRtt(void)
- {
- return time::seconds(1);
- }
+ using Duration = time::microseconds;
RttEstimator(uint16_t maxMultiplier = 16,
- Duration minRto = time::milliseconds(1),
+ Duration minRto = 1_ms,
double gain = 0.1);
+ static Duration
+ getInitialRtt()
+ {
+ return 1_s;
+ }
+
void
addMeasurement(Duration measure);
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
diff --git a/rib/fib-updater.cpp b/rib/fib-updater.cpp
index 76a33c7..1d6328c 100644
--- a/rib/fib-updater.cpp
+++ b/rib/fib-updater.cpp
@@ -654,13 +654,11 @@
}
// Remove inherited routes from current namespace
- for (Rib::RouteSet::const_iterator removeIt = routesToRemove.begin();
- removeIt != routesToRemove.end(); )
- {
+ for (auto removeIt = routesToRemove.begin(); removeIt != routesToRemove.end(); ) {
// If a route on the namespace has the same face ID and child inheritance set,
// ignore this route
if (entry.hasChildInheritOnFaceId(removeIt->faceId)) {
- routesToRemove.erase(removeIt++);
+ removeIt = routesToRemove.erase(removeIt);
continue;
}
@@ -674,11 +672,10 @@
}
// Add inherited routes to current namespace
- for (Rib::RouteSet::const_iterator addIt = routesToAdd.begin(); addIt != routesToAdd.end(); ) {
-
+ for (auto addIt = routesToAdd.begin(); addIt != routesToAdd.end(); ) {
// If a route on the namespace has the same face ID and child inherit set, ignore this face
if (entry.hasChildInheritOnFaceId(addIt->faceId)) {
- routesToAdd.erase(addIt++);
+ addIt = routesToAdd.erase(addIt);
continue;
}
diff --git a/rib/readvertise/readvertise.cpp b/rib/readvertise/readvertise.cpp
index 53074f8..7a467ef 100644
--- a/rib/readvertise/readvertise.cpp
+++ b/rib/readvertise/readvertise.cpp
@@ -32,15 +32,15 @@
NFD_LOG_INIT(Readvertise);
-const time::milliseconds Readvertise::RETRY_DELAY_MIN = time::seconds(50);
-const time::milliseconds Readvertise::RETRY_DELAY_MAX = time::seconds(3600);
+const time::milliseconds Readvertise::RETRY_DELAY_MIN = 50_s;
+const time::milliseconds Readvertise::RETRY_DELAY_MAX = 3600_s;
static time::milliseconds
randomizeTimer(time::milliseconds baseTimer)
{
std::uniform_int_distribution<uint64_t> dist(-5, 5);
time::milliseconds newTime = baseTimer + time::milliseconds(dist(getGlobalRng()));
- return std::max(newTime, time::milliseconds(0));
+ return std::max(newTime, 0_ms);
}
Readvertise::Readvertise(Rib& rib, unique_ptr<ReadvertisePolicy> policy,
@@ -48,8 +48,8 @@
: m_policy(std::move(policy))
, m_destination(std::move(destination))
{
- m_addRouteConn = rib.afterAddRoute.connect(bind(&Readvertise::afterAddRoute, this, _1));
- m_removeRouteConn = rib.beforeRemoveRoute.connect(bind(&Readvertise::beforeRemoveRoute, this, _1));
+ m_addRouteConn = rib.afterAddRoute.connect([this] (const auto& r) { this->afterAddRoute(r); });
+ m_removeRouteConn = rib.beforeRemoveRoute.connect([this] (const auto& r) { this->beforeRemoveRoute(r); });
m_destination->afterAvailabilityChange.connect([this] (bool isAvailable) {
if (isAvailable) {
@@ -156,17 +156,17 @@
}
m_destination->advertise(*rrIt,
- [this, rrIt] {
+ [=] {
NFD_LOG_DEBUG("advertise " << rrIt->prefix << " success");
rrIt->retryDelay = RETRY_DELAY_MIN;
rrIt->retryEvt = scheduler::schedule(randomizeTimer(m_policy->getRefreshInterval()),
- bind(&Readvertise::advertise, this, rrIt));
+ [=] { advertise(rrIt); });
},
- [this, rrIt] (const std::string& msg) {
+ [=] (const std::string& msg) {
NFD_LOG_DEBUG("advertise " << rrIt->prefix << " failure " << msg);
rrIt->retryDelay = std::min(RETRY_DELAY_MAX, rrIt->retryDelay * 2);
rrIt->retryEvt = scheduler::schedule(randomizeTimer(rrIt->retryDelay),
- bind(&Readvertise::advertise, this, rrIt));
+ [=] { advertise(rrIt); });
});
}
@@ -182,15 +182,14 @@
}
m_destination->withdraw(*rrIt,
- [this, rrIt] {
+ [=] {
NFD_LOG_DEBUG("withdraw " << rrIt->prefix << " success");
m_rrs.erase(rrIt);
},
- [this, rrIt] (const std::string& msg) {
+ [=] (const std::string& msg) {
NFD_LOG_DEBUG("withdraw " << rrIt->prefix << " failure " << msg);
rrIt->retryDelay = std::min(RETRY_DELAY_MAX, rrIt->retryDelay * 2);
- rrIt->retryEvt = scheduler::schedule(randomizeTimer(rrIt->retryDelay),
- bind(&Readvertise::withdraw, this, rrIt));
+ rrIt->retryEvt = scheduler::schedule(randomizeTimer(rrIt->retryDelay), [=] { withdraw(rrIt); });
});
}
diff --git a/rib/rib-entry.cpp b/rib/rib-entry.cpp
index 7fd0ed7..ff646fa 100644
--- a/rib/rib-entry.cpp
+++ b/rib/rib-entry.cpp
@@ -56,12 +56,10 @@
}
m_routes.push_back(route);
+ return {std::prev(m_routes.end()), true};
+ }
- return std::make_pair(std::prev(m_routes.end()), true);
- }
- else {
- return std::make_pair(it, false);
- }
+ return {it, false};
}
void
@@ -96,16 +94,16 @@
void
RibEntry::addChild(shared_ptr<RibEntry> child)
{
- BOOST_ASSERT(!static_cast<bool>(child->getParent()));
+ BOOST_ASSERT(!child->getParent());
child->setParent(this->shared_from_this());
- m_children.push_back(child);
+ m_children.push_back(std::move(child));
}
void
RibEntry::removeChild(shared_ptr<RibEntry> child)
{
BOOST_ASSERT(child->getParent().get() == this);
- child->setParent(shared_ptr<RibEntry>());
+ child->setParent(nullptr);
m_children.remove(child);
}
@@ -136,9 +134,7 @@
void
RibEntry::removeInheritedRoute(const Route& route)
{
- RouteList::iterator it = std::find_if(m_inheritedRoutes.begin(), m_inheritedRoutes.end(),
- bind(&compareFaceId, _1, route.faceId));
- m_inheritedRoutes.erase(it);
+ m_inheritedRoutes.remove_if(bind(&compareFaceId, _1, route.faceId));
}
RibEntry::RouteList::const_iterator
@@ -151,9 +147,7 @@
bool
RibEntry::hasInheritedRoute(const Route& route) const
{
- RouteList::const_iterator it = findInheritedRoute(route);
-
- return (it != m_inheritedRoutes.end());
+ return findInheritedRoute(route) != m_inheritedRoutes.end();
}
bool
diff --git a/rib/rib-manager.cpp b/rib/rib-manager.cpp
index ecf20d9..5b0e0c6 100644
--- a/rib/rib-manager.cpp
+++ b/rib/rib-manager.cpp
@@ -167,14 +167,14 @@
}
if (wantReadvertiseToNlsr && m_readvertiseNlsr == nullptr) {
- NFD_LOG_DEBUG("Enabling readvertise-to-nlsr.");
- m_readvertiseNlsr.reset(new Readvertise(
+ NFD_LOG_DEBUG("Enabling readvertise-to-nlsr");
+ m_readvertiseNlsr = make_unique<Readvertise>(
m_rib,
make_unique<ClientToNlsrReadvertisePolicy>(),
- make_unique<NfdRibReadvertiseDestination>(m_nfdController, READVERTISE_NLSR_PREFIX, m_rib)));
+ make_unique<NfdRibReadvertiseDestination>(m_nfdController, READVERTISE_NLSR_PREFIX, m_rib));
}
else if (!wantReadvertiseToNlsr && m_readvertiseNlsr != nullptr) {
- NFD_LOG_DEBUG("Disabling readvertise-to-nlsr.");
+ NFD_LOG_DEBUG("Disabling readvertise-to-nlsr");
m_readvertiseNlsr.reset();
}
}
@@ -184,11 +184,11 @@
{
// register entry to the FIB
m_nfdController.start<ndn::nfd::FibAddNextHopCommand>(
- ControlParameters()
- .setName(Name(topPrefix).append(MGMT_MODULE_NAME))
- .setFaceId(0),
- bind(&RibManager::onCommandPrefixAddNextHopSuccess, this, cref(topPrefix), _1),
- bind(&RibManager::onCommandPrefixAddNextHopError, this, cref(topPrefix), _1));
+ ControlParameters()
+ .setName(Name(topPrefix).append(MGMT_MODULE_NAME))
+ .setFaceId(0),
+ [=] (const auto& res) { this->onCommandPrefixAddNextHopSuccess(topPrefix, res); },
+ [=] (const auto& res) { this->onCommandPrefixAddNextHopError(topPrefix, res); });
// add top prefix to the dispatcher
m_addTopPrefix(topPrefix);
@@ -438,8 +438,7 @@
RibManager::onEnableLocalFieldsError(const ndn::nfd::ControlResponse& response)
{
BOOST_THROW_EXCEPTION(Error("Couldn't enable local fields (code: " +
- to_string(response.getCode()) + ", info: " + response.getText() +
- ")"));
+ to_string(response.getCode()) + ", info: " + response.getText() + ")"));
}
} // namespace rib
diff --git a/rib/rib.cpp b/rib/rib.cpp
index d6b125b..6a221ea 100644
--- a/rib/rib.cpp
+++ b/rib/rib.cpp
@@ -68,16 +68,14 @@
Route*
Rib::find(const Name& prefix, const Route& route) const
{
- RibTable::const_iterator ribIt = m_rib.find(prefix);
+ auto ribIt = m_rib.find(prefix);
// Name prefix exists
if (ribIt != m_rib.end()) {
shared_ptr<RibEntry> entry = ribIt->second;
-
- RibEntry::iterator routeIt = entry->findRoute(route);
-
+ auto routeIt = entry->findRoute(route);
if (routeIt != entry->end()) {
- return &((*routeIt));
+ return &*routeIt;
}
}
@@ -87,7 +85,7 @@
void
Rib::insert(const Name& prefix, const Route& route)
{
- RibTable::iterator ribIt = m_rib.find(prefix);
+ auto ribIt = m_rib.find(prefix);
// Name prefix exists
if (ribIt != m_rib.end()) {
@@ -125,13 +123,13 @@
}
else {
// New name prefix
- shared_ptr<RibEntry> entry = make_shared<RibEntry>();
+ auto entry = make_shared<RibEntry>();
m_rib[prefix] = entry;
m_nItems++;
entry->setName(prefix);
- RibEntry::iterator routeIt = entry->insertRoute(route).first;
+ auto routeIt = entry->insertRoute(route).first;
// Find prefix's parent
shared_ptr<RibEntry> parent = findParent(prefix);
@@ -166,12 +164,12 @@
void
Rib::erase(const Name& prefix, const Route& route)
{
- RibTable::iterator ribIt = m_rib.find(prefix);
+ auto ribIt = m_rib.find(prefix);
// Name prefix exists
if (ribIt != m_rib.end()) {
shared_ptr<RibEntry> entry = ribIt->second;
- RibEntry::iterator routeIt = entry->findRoute(route);
+ auto routeIt = entry->findRoute(route);
if (routeIt != entry->end()) {
beforeRemoveRoute(RibRouteRef{entry, routeIt});
@@ -210,23 +208,21 @@
Rib::findParent(const Name& prefix) const
{
for (int i = prefix.size() - 1; i >= 0; i--) {
- RibTable::const_iterator it = m_rib.find(prefix.getPrefix(i));
-
+ auto it = m_rib.find(prefix.getPrefix(i));
if (it != m_rib.end()) {
- return (it->second);
+ return it->second;
}
}
- return shared_ptr<RibEntry>();
+ return nullptr;
}
-std::list<shared_ptr<RibEntry> >
+std::list<shared_ptr<RibEntry>>
Rib::findDescendants(const Name& prefix) const
{
- std::list<shared_ptr<RibEntry> > children;
+ std::list<shared_ptr<RibEntry>> children;
RibTable::const_iterator it = m_rib.find(prefix);
-
if (it != m_rib.end()) {
++it;
for (; it != m_rib.end(); ++it) {
@@ -247,7 +243,7 @@
{
std::list<shared_ptr<RibEntry>> children;
- for (std::pair<Name, shared_ptr<RibEntry>> pair : m_rib) {
+ for (const auto& pair : m_rib) {
if (prefix.isPrefixOf(pair.first)) {
children.push_back(pair.second);
}
@@ -288,7 +284,7 @@
}
}
- RibTable::iterator nextIt = m_rib.erase(it);
+ auto nextIt = m_rib.erase(it);
// do something after erasing an entry.
afterEraseEntry(entry->getName());
@@ -462,8 +458,7 @@
Rib::modifyInheritedRoutes(const RibUpdateList& inheritedRoutes)
{
for (const RibUpdate& update : inheritedRoutes) {
- RibTable::iterator ribIt = m_rib.find(update.getName());
-
+ auto ribIt = m_rib.find(update.getName());
BOOST_ASSERT(ribIt != m_rib.end());
shared_ptr<RibEntry> entry(ribIt->second);
@@ -485,21 +480,18 @@
{
std::list<NameAndRoute> routes;
- FaceLookupTable::iterator lookupIt = m_faceMap.find(faceId);
-
- // No RIB entries have this face
+ auto lookupIt = m_faceMap.find(faceId);
if (lookupIt == m_faceMap.end()) {
+ // No RIB entries have this face
return routes;
}
- RibEntryList& ribEntries = lookupIt->second;
-
// For each RIB entry that has faceId
- for (const shared_ptr<RibEntry>& entry : ribEntries) {
+ for (const auto& entry : lookupIt->second) {
// Find the routes in the entry
for (const Route& route : *entry) {
if (route.faceId == faceId) {
- routes.push_back(NameAndRoute(entry->getName(), route));
+ routes.emplace_back(entry->getName(), route);
}
}
}
diff --git a/rib/rib.hpp b/rib/rib.hpp
index 14ce12d..c8a0f5d 100644
--- a/rib/rib.hpp
+++ b/rib/rib.hpp
@@ -211,7 +211,7 @@
modifyInheritedRoutes(const RibUpdateList& inheritedRoutes);
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
- typedef std::pair<const Name&,const Route&> NameAndRoute;
+ using NameAndRoute = std::pair<const Name&, const Route&>;
std::list<NameAndRoute>
findRoutesWithFaceId(uint64_t faceId);
diff --git a/tests/daemon/face/factory-test-common.hpp b/tests/daemon/face/factory-test-common.hpp
index 7b7bdf6..f92d388 100644
--- a/tests/daemon/face/factory-test-common.hpp
+++ b/tests/daemon/face/factory-test-common.hpp
@@ -34,24 +34,6 @@
namespace face {
namespace tests {
-struct TestFaceParams : public FaceParams
-{
- TestFaceParams(ndn::nfd::FacePersistency persistency,
- optional<time::nanoseconds> baseCongestionMarkingInterval,
- optional<uint64_t> defaultCongestionThreshold,
- bool wantLocalFields,
- bool wantLpReliability,
- boost::logic::tribool wantCongestionMarking) noexcept
- {
- this->persistency = persistency;
- this->baseCongestionMarkingInterval = baseCongestionMarkingInterval;
- this->defaultCongestionThreshold = defaultCongestionThreshold;
- this->wantLocalFields = wantLocalFields;
- this->wantLpReliability = wantLpReliability;
- this->wantCongestionMarking = wantCongestionMarking;
- }
-};
-
struct CreateFaceExpectedResult
{
enum { FAILURE, SUCCESS } result;
@@ -63,7 +45,7 @@
createFace(ProtocolFactory& factory,
const FaceUri& remoteUri,
const optional<FaceUri>& localUri,
- const TestFaceParams& params,
+ const FaceParams& params,
const CreateFaceExpectedResult& expected,
const std::function<void(const Face&)>& extraChecks = nullptr)
{
diff --git a/tests/daemon/face/generic-link-service.t.cpp b/tests/daemon/face/generic-link-service.t.cpp
index dfb048c..2192622 100644
--- a/tests/daemon/face/generic-link-service.t.cpp
+++ b/tests/daemon/face/generic-link-service.t.cpp
@@ -57,9 +57,9 @@
: service(nullptr)
, transport(nullptr)
{
- this->initialize(GenericLinkService::Options());
// By default, GenericLinkService is created with default options.
// Test cases may invoke .initialize with alternate options.
+ this->initialize({});
}
void
@@ -67,14 +67,14 @@
ssize_t mtu = MTU_UNLIMITED,
ssize_t sendQueueCapacity = QUEUE_UNSUPPORTED)
{
- face.reset(new Face(make_unique<GenericLinkService>(options),
- make_unique<DummyTransport>("dummy://",
- "dummy://",
- ndn::nfd::FACE_SCOPE_NON_LOCAL,
- ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
- ndn::nfd::LINK_TYPE_POINT_TO_POINT,
- mtu,
- sendQueueCapacity)));
+ face = make_unique<Face>(make_unique<GenericLinkService>(options),
+ make_unique<DummyTransport>("dummy://",
+ "dummy://",
+ ndn::nfd::FACE_SCOPE_NON_LOCAL,
+ ndn::nfd::FACE_PERSISTENCY_PERSISTENT,
+ ndn::nfd::LINK_TYPE_POINT_TO_POINT,
+ mtu,
+ sendQueueCapacity));
service = static_cast<GenericLinkService*>(face->getLinkService());
transport = static_cast<DummyTransport*>(face->getTransport());
@@ -347,7 +347,7 @@
lp::Packet packet(interest->wireEncode());
// fragment the packet
- LpFragmenter fragmenter;
+ LpFragmenter fragmenter({});
size_t mtu = 100;
bool isOk = false;
std::vector<lp::Packet> frags;
diff --git a/tests/daemon/face/lp-fragmenter.t.cpp b/tests/daemon/face/lp-fragmenter.t.cpp
index 4bc7022..b3ee8d6 100644
--- a/tests/daemon/face/lp-fragmenter.t.cpp
+++ b/tests/daemon/face/lp-fragmenter.t.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-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -33,14 +33,13 @@
using namespace nfd::tests;
-BOOST_AUTO_TEST_SUITE(Face)
-
-class LpFragmenterFixture
+class LpFragmenterFixture : public BaseFixture
{
-public:
- LpFragmenter fragmenter;
+protected:
+ LpFragmenter fragmenter{{}};
};
+BOOST_AUTO_TEST_SUITE(Face)
BOOST_FIXTURE_TEST_SUITE(TestLpFragmenter, LpFragmenterFixture)
BOOST_AUTO_TEST_CASE(FragmentSingleFragment)
diff --git a/tests/daemon/face/lp-reassembler.t.cpp b/tests/daemon/face/lp-reassembler.t.cpp
index 9cfa8dd..b1140d8 100644
--- a/tests/daemon/face/lp-reassembler.t.cpp
+++ b/tests/daemon/face/lp-reassembler.t.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-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -40,13 +40,13 @@
{
reassembler.beforeTimeout.connect(
[this] (Transport::EndpointId remoteEp, size_t nDroppedFragments) {
- timeoutHistory.push_back(std::make_tuple(remoteEp, nDroppedFragments));
+ timeoutHistory.push_back({remoteEp, nDroppedFragments});
});
}
protected:
- LpReassembler reassembler;
- std::vector<std::tuple<Transport::EndpointId, size_t>> timeoutHistory;
+ LpReassembler reassembler{{}};
+ std::vector<std::pair<Transport::EndpointId, size_t>> timeoutHistory;
static const uint8_t data[10];
};
diff --git a/tests/daemon/face/websocket-transport-fixture.hpp b/tests/daemon/face/websocket-transport-fixture.hpp
index 6fd8e70..374f922 100644
--- a/tests/daemon/face/websocket-transport-fixture.hpp
+++ b/tests/daemon/face/websocket-transport-fixture.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-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -110,7 +110,7 @@
face = make_unique<Face>(
make_unique<DummyReceiveLinkService>(),
- make_unique<WebSocketTransport>(serverHdl, ref(server), pingInterval));
+ make_unique<WebSocketTransport>(serverHdl, std::ref(server), pingInterval));
transport = static_cast<WebSocketTransport*>(face->getTransport());
serverReceivedPackets = &static_cast<DummyReceiveLinkService*>(face->getLinkService())->receivedPackets;
diff --git a/tests/daemon/fw/topology-tester.cpp b/tests/daemon/fw/topology-tester.cpp
index fef3080..41d5d8c 100644
--- a/tests/daemon/fw/topology-tester.cpp
+++ b/tests/daemon/fw/topology-tester.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,
@@ -24,9 +24,10 @@
*/
#include "topology-tester.hpp"
-#include <ndn-cxx/encoding/encoding-buffer-fwd.hpp>
#include "face/generic-link-service.hpp"
+#include <ndn-cxx/encoding/encoding-buffer-fwd.hpp>
+
namespace nfd {
namespace fw {
namespace tests {
@@ -247,8 +248,8 @@
TopologyTester::addEchoProducer(ndn::Face& face, const Name& prefix)
{
face.setInterestFilter(prefix,
- [&face] (const ndn::InterestFilter&, const Interest& interest) {
- shared_ptr<Data> data = makeData(interest.getName());
+ [&face] (const auto&, const Interest& interest) {
+ auto data = makeData(interest.getName());
face.put(*data);
});
}
@@ -266,12 +267,12 @@
name.appendTimestamp();
}
- shared_ptr<Interest> interest = makeInterest(name);
+ auto interest = makeInterest(name);
face.expressInterest(*interest, nullptr, nullptr, nullptr);
if (n > 1) {
- scheduler::schedule(interval, bind(&TopologyTester::addIntervalConsumer, this,
- ref(face), prefix, interval, n - 1, seq));
+ scheduler::schedule(interval,
+ [=, &face] { addIntervalConsumer(face, prefix, interval, n - 1, seq); });
}
}
diff --git a/tests/limited-io.cpp b/tests/limited-io.cpp
index 66a0946..9f8f4dc 100644
--- a/tests/limited-io.cpp
+++ b/tests/limited-io.cpp
@@ -56,8 +56,8 @@
m_reason = NO_WORK;
m_nOpsRemaining = nOpsLimit;
- if (timeLimit >= time::nanoseconds::zero()) {
- m_timeout = scheduler::schedule(timeLimit, bind(&LimitedIo::afterTimeout, this));
+ if (timeLimit >= 0_ns) {
+ m_timeout = scheduler::schedule(timeLimit, [this] { afterTimeout(); });
}
try {
diff --git a/tools/ndn-autoconfig/ndn-fch-discovery.cpp b/tools/ndn-autoconfig/ndn-fch-discovery.cpp
index ef58ab5..abb934f 100644
--- a/tools/ndn-autoconfig/ndn-fch-discovery.cpp
+++ b/tools/ndn-autoconfig/ndn-fch-discovery.cpp
@@ -27,8 +27,8 @@
#include <boost/algorithm/string.hpp>
#include <boost/asio/ip/tcp.hpp>
-#include <boost/regex.hpp>
+#include <regex>
#include <sstream>
namespace ndn {
@@ -47,31 +47,31 @@
Url(const std::string& url)
: m_isValid(false)
{
- static const boost::regex protocolExp("(\\w+\\d?(\\+\\w+)?)://([^/]*)(\\/[^?]*)?");
- boost::smatch protocolMatch;
- if (!boost::regex_match(url, protocolMatch, protocolExp)) {
+ static const std::regex protocolExp("(\\w+\\d?(\\+\\w+)?)://([^/]*)(\\/[^?]*)?");
+ std::smatch protocolMatch;
+ if (!std::regex_match(url, protocolMatch, protocolExp)) {
return;
}
m_scheme = protocolMatch[1];
- const std::string& authority = protocolMatch[3];
+ std::string authority = protocolMatch[3];
m_path = protocolMatch[4];
// pattern for IPv6 address enclosed in [ ], with optional port number
- static const boost::regex v6Exp("^\\[([a-fA-F0-9:]+)\\](?:\\:(\\d+))?$");
+ static const std::regex v6Exp("^\\[([a-fA-F0-9:]+)\\](?:\\:(\\d+))?$");
// pattern for IPv4-mapped IPv6 address, with optional port number
- static const boost::regex v4MappedV6Exp("^\\[::ffff:(\\d+(?:\\.\\d+){3})\\](?:\\:(\\d+))?$");
+ static const std::regex v4MappedV6Exp("^\\[::ffff:(\\d+(?:\\.\\d+){3})\\](?:\\:(\\d+))?$");
// pattern for IPv4/hostname/fd/ifname, with optional port number
- static const boost::regex v4HostExp("^([^:]+)(?:\\:(\\d+))?$");
+ static const std::regex v4HostExp("^([^:]+)(?:\\:(\\d+))?$");
if (authority.empty()) {
// UNIX, internal
}
else {
- boost::smatch match;
- bool isV6 = boost::regex_match(authority, match, v6Exp);
+ std::smatch match;
+ bool isV6 = std::regex_match(authority, match, v6Exp);
if (isV6 ||
- boost::regex_match(authority, match, v4MappedV6Exp) ||
- boost::regex_match(authority, match, v4HostExp)) {
+ std::regex_match(authority, match, v4MappedV6Exp) ||
+ std::regex_match(authority, match, v4HostExp)) {
m_host = match[1];
m_port = match[2];
}