Use non-static data member initializers in more places
Change-Id: I57d90dca1cb508b1a1ed0224a4a23c5be871050c
diff --git a/ndn-cxx/ims/in-memory-storage-entry.cpp b/ndn-cxx/ims/in-memory-storage-entry.cpp
index 5720bc9..546efe7 100644
--- a/ndn-cxx/ims/in-memory-storage-entry.cpp
+++ b/ndn-cxx/ims/in-memory-storage-entry.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2019 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -23,11 +23,6 @@
namespace ndn {
-InMemoryStorageEntry::InMemoryStorageEntry()
- : m_isFresh(true)
-{
-}
-
void
InMemoryStorageEntry::release()
{
@@ -36,13 +31,6 @@
}
void
-InMemoryStorageEntry::setData(const Data& data)
-{
- m_dataPacket = data.shared_from_this();
- m_isFresh = true;
-}
-
-void
InMemoryStorageEntry::scheduleMarkStale(Scheduler& sched, time::nanoseconds after)
{
m_markStaleEventId = sched.schedule(after, [this] { m_isFresh = false; });
diff --git a/ndn-cxx/ims/in-memory-storage-entry.hpp b/ndn-cxx/ims/in-memory-storage-entry.hpp
index b412a30..a2fdb1f 100644
--- a/ndn-cxx/ims/in-memory-storage-entry.hpp
+++ b/ndn-cxx/ims/in-memory-storage-entry.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -28,20 +28,12 @@
namespace ndn {
-/** @brief Represents an in-memory storage entry
+/**
+ * @brief Represents an in-memory storage entry.
*/
class InMemoryStorageEntry : noncopyable
{
public:
- /** @brief Create an entry
- */
- InMemoryStorageEntry();
-
- /** @brief Releases reference counts on shared objects
- */
- void
- release();
-
/** @brief Returns the name of the Data packet stored in the in-memory storage entry
*/
const Name&
@@ -72,26 +64,36 @@
* This method also allows data to satisfy Interest with MustBeFresh
*/
void
- setData(const Data& data);
+ setData(const Data& data)
+ {
+ m_dataPacket = data.shared_from_this();
+ m_isFresh = true;
+ }
/** @brief Schedule an event to mark this entry as non-fresh.
*/
void
scheduleMarkStale(Scheduler& sched, time::nanoseconds after);
- /** @brief Check if the data can satisfy an interest with MustBeFresh
+ /**
+ * @brief Check if the data can satisfy an Interest with MustBeFresh.
*/
bool
- isFresh()
+ isFresh() const
{
return m_isFresh;
}
+ /**
+ * @brief Releases reference counts on shared objects.
+ */
+ void
+ release();
+
private:
shared_ptr<const Data> m_dataPacket;
-
- bool m_isFresh;
scheduler::ScopedEventId m_markStaleEventId;
+ bool m_isFresh = true;
};
} // namespace ndn
diff --git a/ndn-cxx/ims/in-memory-storage.cpp b/ndn-cxx/ims/in-memory-storage.cpp
index c4ea1cf..e795914 100644
--- a/ndn-cxx/ims/in-memory-storage.cpp
+++ b/ndn-cxx/ims/in-memory-storage.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -42,14 +42,12 @@
InMemoryStorage::InMemoryStorage(size_t limit)
: m_limit(limit)
- , m_nPackets(0)
{
init();
}
InMemoryStorage::InMemoryStorage(boost::asio::io_context& ioCtx, size_t limit)
: m_limit(limit)
- , m_nPackets(0)
{
m_scheduler = make_unique<Scheduler>(ioCtx);
init();
@@ -58,7 +56,7 @@
void
InMemoryStorage::init()
{
- // TODO consider a more suitable initial value
+ // TODO: consider a more suitable initial value
m_capacity = MIN_CAPACITY;
if (m_limit != std::numeric_limits<size_t>::max() && m_capacity > m_limit) {
@@ -124,7 +122,7 @@
if (it != m_cache.get<byFullName>().end())
return;
- //if full, double the capacity
+ // if full, double the capacity
bool doesReachLimit = (getLimit() == getCapacity());
if (isFull() && !doesReachLimit) {
// note: This is incorrect if 2*capacity overflows, but memory should run out before that
@@ -132,12 +130,12 @@
setCapacity(newCapacity);
}
- //if full and reach limitation of the capacity, employ replacement policy
+ // if full and reach limitation of the capacity, employ replacement policy
if (isFull() && doesReachLimit) {
evictItem();
}
- //insert to cache
+ // insert to cache
BOOST_ASSERT(m_freeEntries.size() > 0);
// take entry for the memory pool
InMemoryStorageEntry* entry = m_freeEntries.top();
@@ -149,7 +147,7 @@
}
m_cache.insert(entry);
- //let derived class do something with the entry
+ // let derived class do something with the entry
afterInsert(entry);
}
diff --git a/ndn-cxx/ims/in-memory-storage.hpp b/ndn-cxx/ims/in-memory-storage.hpp
index de4acde..53f3705 100644
--- a/ndn-cxx/ims/in-memory-storage.hpp
+++ b/ndn-cxx/ims/in-memory-storage.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -330,11 +330,11 @@
private:
Cache m_cache;
/// user defined maximum capacity of the in-memory storage in packets
- size_t m_limit;
+ size_t m_limit = 0;
/// current capacity of the in-memory storage in packets
- size_t m_capacity;
+ size_t m_capacity = 0;
/// current number of packets in in-memory storage
- size_t m_nPackets;
+ size_t m_nPackets = 0;
/// memory pool
std::stack<InMemoryStorageEntry*> m_freeEntries;
/// scheduler
diff --git a/ndn-cxx/mgmt/nfd/face-traits.hpp b/ndn-cxx/mgmt/nfd/face-traits.hpp
index 7816665..eed1130 100644
--- a/ndn-cxx/mgmt/nfd/face-traits.hpp
+++ b/ndn-cxx/mgmt/nfd/face-traits.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -169,23 +169,16 @@
}
protected:
- FaceTraits()
- : m_faceId(INVALID_FACE_ID)
- , m_faceScope(FACE_SCOPE_NON_LOCAL)
- , m_facePersistency(FACE_PERSISTENCY_PERSISTENT)
- , m_linkType(LINK_TYPE_POINT_TO_POINT)
- , m_flags(0)
- {
- }
+ FaceTraits() = default;
protected:
- uint64_t m_faceId;
+ uint64_t m_faceId = INVALID_FACE_ID;
std::string m_remoteUri;
std::string m_localUri;
- FaceScope m_faceScope;
- FacePersistency m_facePersistency;
- LinkType m_linkType;
- uint64_t m_flags;
+ FaceScope m_faceScope = FACE_SCOPE_NON_LOCAL;
+ FacePersistency m_facePersistency = FACE_PERSISTENCY_PERSISTENT;
+ LinkType m_linkType = LINK_TYPE_POINT_TO_POINT;
+ uint64_t m_flags = 0;
mutable Block m_wire;
};
diff --git a/ndn-cxx/net/network-interface.cpp b/ndn-cxx/net/network-interface.cpp
index 250e1d6..fbfe8e9 100644
--- a/ndn-cxx/net/network-interface.cpp
+++ b/ndn-cxx/net/network-interface.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -32,14 +32,7 @@
NDN_LOG_INIT(ndn.NetworkMonitor);
-NetworkInterface::NetworkInterface()
- : m_index(0)
- , m_type(InterfaceType::UNKNOWN)
- , m_flags(0)
- , m_state(InterfaceState::UNKNOWN)
- , m_mtu(0)
-{
-}
+NetworkInterface::NetworkInterface() = default;
bool
NetworkInterface::addNetworkAddress(const NetworkAddress& address)
diff --git a/ndn-cxx/net/network-interface.hpp b/ndn-cxx/net/network-interface.hpp
index dca92b9..c449ce2 100644
--- a/ndn-cxx/net/network-interface.hpp
+++ b/ndn-cxx/net/network-interface.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -32,7 +32,8 @@
namespace ndn::net {
-/** @brief Indicates the hardware type of a network interface
+/**
+ * @brief Indicates the hardware type of a network interface.
*/
enum class InterfaceType {
UNKNOWN,
@@ -44,7 +45,8 @@
std::ostream&
operator<<(std::ostream& os, InterfaceType type);
-/** @brief Indicates the state of a network interface
+/**
+ * @brief Indicates the state of a network interface.
*/
enum class InterfaceState {
UNKNOWN, ///< interface is in an unknown state
@@ -61,31 +63,28 @@
* @brief Represents one network interface attached to the host.
*
* Each network interface has a unique index, a name, and a set of flags indicating its
- * capabilities and current state. It may contain one hardware (Ethernet) address, and
+ * capabilities and current state. It may contain one link-layer (Ethernet) address, and
* zero or more network-layer (IP) addresses. Specific signals are emitted when the
* interface data change.
*/
class NetworkInterface
{
-public: // signals, marked 'mutable' so they can be connected on 'const NetworkInterface'
- /** @brief Fires when interface state changes
- */
+public: // signals, marked 'mutable' so they can be connected on a 'const NetworkInterface'
+ /// Fires when the interface state changes.
mutable signal::Signal<NetworkInterface, InterfaceState /*old*/, InterfaceState /*new*/> onStateChanged;
- /** @brief Fires when interface mtu changes
- */
+ /// Fires when the interface MTU changes.
mutable signal::Signal<NetworkInterface, uint32_t /*old*/, uint32_t /*new*/> onMtuChanged;
- /** @brief Fires when a network-layer address is added to the interface
- */
+ /// Fires when a network-layer address is added to the interface.
mutable signal::Signal<NetworkInterface, NetworkAddress> onAddressAdded;
- /** @brief Fires when a network-layer address is removed from the interface
- */
+ /// Fires when a network-layer address is removed from the interface.
mutable signal::Signal<NetworkInterface, NetworkAddress> onAddressRemoved;
public: // getters
- /** @brief Returns an opaque ID that uniquely identifies the interface on the system
+ /**
+ * @brief Returns an opaque ID that uniquely identifies the interface on the system.
*/
int
getIndex() const
@@ -93,7 +92,8 @@
return m_index;
}
- /** @brief Returns the name of the interface, unique on the system
+ /**
+ * @brief Returns the name of the interface, unique on the system.
*/
std::string
getName() const
@@ -101,7 +101,8 @@
return m_name;
}
- /** @brief Returns the hardware type of the interface
+ /**
+ * @brief Returns the hardware type of the interface.
*/
InterfaceType
getType() const
@@ -109,7 +110,8 @@
return m_type;
}
- /** @brief Returns a bitset of platform-specific flags enabled on the interface
+ /**
+ * @brief Returns a bitset of platform-specific flags enabled on the interface.
*/
uint32_t
getFlags() const
@@ -117,7 +119,8 @@
return m_flags;
}
- /** @brief Returns the current state of the interface
+ /**
+ * @brief Returns the current state of the interface.
*/
InterfaceState
getState() const
@@ -125,7 +128,8 @@
return m_state;
}
- /** @brief Returns the MTU (maximum transmission unit) of the interface
+ /**
+ * @brief Returns the MTU (maximum transmission unit) of the interface.
*/
uint32_t
getMtu() const
@@ -133,7 +137,8 @@
return m_mtu;
}
- /** @brief Returns the link-layer (Ethernet) address of the interface
+ /**
+ * @brief Returns the link-layer (Ethernet) address of the interface.
*/
ethernet::Address
getEthernetAddress() const
@@ -141,7 +146,8 @@
return m_etherAddress;
}
- /** @brief Returns the link-layer (Ethernet) broadcast address of the interface
+ /**
+ * @brief Returns the link-layer (Ethernet) broadcast address of the interface.
*/
ethernet::Address
getEthernetBroadcastAddress() const
@@ -149,7 +155,8 @@
return m_etherBrdAddress;
}
- /** @brief Returns a list of all network-layer addresses present on the interface
+ /**
+ * @brief Returns all network-layer addresses present on the interface.
*/
const std::set<NetworkAddress>&
getNetworkAddresses() const
@@ -157,7 +164,8 @@
return m_netAddresses;
}
- /** @brief Returns true if the interface is a loopback interface
+ /**
+ * @brief Returns true if the interface is a loopback interface.
*/
bool
isLoopback() const
@@ -165,7 +173,8 @@
return (m_flags & IFF_LOOPBACK) != 0;
}
- /** @brief Returns true if the interface is a point-to-point interface
+ /**
+ * @brief Returns true if the interface is a point-to-point interface.
*/
bool
isPointToPoint() const
@@ -173,7 +182,8 @@
return (m_flags & IFF_POINTOPOINT) != 0;
}
- /** @brief Returns true if the interface supports broadcast communication
+ /**
+ * @brief Returns true if the interface supports broadcast communication.
*/
bool
canBroadcast() const
@@ -181,7 +191,8 @@
return (m_flags & IFF_BROADCAST) != 0;
}
- /** @brief Returns true if the interface supports multicast communication
+ /**
+ * @brief Returns true if the interface supports multicast communication.
*/
bool
canMulticast() const
@@ -189,7 +200,8 @@
return (m_flags & IFF_MULTICAST) != 0;
}
- /** @brief Returns true if the interface is administratively up
+ /**
+ * @brief Returns true if the interface is administratively "up".
*/
bool
isUp() const
@@ -197,7 +209,7 @@
return (m_flags & IFF_UP) != 0;
}
-public: // modifiers: they update information on this instance, but do not change netif in the OS
+public: // modifiers: they update the info on this in-memory object, but do not modify the interface in the OS
bool
addNetworkAddress(const NetworkAddress& address);
@@ -232,12 +244,12 @@
NetworkInterface(); // accessible through NetworkMonitorImpl::makeNetworkInterface
private:
- int m_index;
+ int m_index = 0;
std::string m_name;
- InterfaceType m_type;
- uint32_t m_flags; // IFF_* in <net/if.h>
- InterfaceState m_state;
- uint32_t m_mtu;
+ InterfaceType m_type = InterfaceType::UNKNOWN;
+ uint32_t m_flags = 0; // IFF_* in <net/if.h>
+ InterfaceState m_state = InterfaceState::UNKNOWN;
+ uint32_t m_mtu = 0;
ethernet::Address m_etherAddress;
ethernet::Address m_etherBrdAddress;
std::set<NetworkAddress> m_netAddresses;
diff --git a/ndn-cxx/security/certificate-bundle-fetcher.cpp b/ndn-cxx/security/certificate-bundle-fetcher.cpp
index 36bc4bc..55c1f71 100644
--- a/ndn-cxx/security/certificate-bundle-fetcher.cpp
+++ b/ndn-cxx/security/certificate-bundle-fetcher.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -21,41 +21,29 @@
#include "ndn-cxx/security/certificate-bundle-fetcher.hpp"
-#include "ndn-cxx/face.hpp"
#include "ndn-cxx/security/certificate-request.hpp"
#include "ndn-cxx/security/certificate-storage.hpp"
#include "ndn-cxx/security/validation-state.hpp"
+#include "ndn-cxx/tag.hpp"
#include "ndn-cxx/util/logger.hpp"
+#define NDN_LOG_DEBUG_DEPTH(x) NDN_LOG_DEBUG(std::string(state->getDepth() + 1, '>') << ' ' << x)
+
namespace ndn::security {
NDN_LOG_INIT(ndn.security.CertificateBundleFetcher);
-#define NDN_LOG_DEBUG_DEPTH(x) NDN_LOG_DEBUG(std::string(state->getDepth() + 1, '>') << " " << x)
-#define NDN_LOG_TRACE_DEPTH(x) NDN_LOG_TRACE(std::string(state->getDepth() + 1, '>') << " " << x)
+using BundleNameTag = SimpleTag<Name, 1000>;
+using FinalBlockIdTag = SimpleTag<name::Component, 1001>;
-CertificateBundleFetcher::CertificateBundleFetcher(unique_ptr<CertificateFetcher> inner,
- Face& face)
+CertificateBundleFetcher::CertificateBundleFetcher(unique_ptr<CertificateFetcher> inner, Face& face)
: m_inner(std::move(inner))
, m_face(face)
- , m_bundleInterestLifetime(1000)
{
BOOST_ASSERT(m_inner != nullptr);
}
void
-CertificateBundleFetcher::setBundleInterestLifetime(time::milliseconds time)
-{
- m_bundleInterestLifetime = time;
-}
-
-time::milliseconds
-CertificateBundleFetcher::getBundleInterestLifetime() const
-{
- return m_bundleInterestLifetime;
-}
-
-void
CertificateBundleFetcher::setCertificateStorage(CertificateStorage& certStorage)
{
m_certStorage = &certStorage;
@@ -148,7 +136,7 @@
const shared_ptr<ValidationState>& state,
const ValidationContinuation& continueValidation)
{
- NDN_LOG_DEBUG_DEPTH("Fetched certificate bundle from network " << bundleData.getName());
+ NDN_LOG_DEBUG_DEPTH("Fetched certificate bundle " << bundleData.getName());
name::Component currentSegment = bundleData.getName().get(-1);
if (!currentSegment.isSegment()) {
@@ -188,7 +176,7 @@
const ValidationContinuation& continueValidation,
const Name& bundleName)
{
- NDN_LOG_DEBUG_DEPTH("NACK (" << nack.getReason() << ") while fetching certificate bundle"
+ NDN_LOG_DEBUG_DEPTH("NACK (" << nack.getReason() << ") while fetching certificate bundle "
<< bundleName);
m_inner->fetch(certRequest, state, continueValidation);
@@ -200,7 +188,7 @@
const ValidationContinuation& continueValidation,
const Name& bundleName)
{
- NDN_LOG_DEBUG_DEPTH("Timeout while fetching certificate bundle" << bundleName);
+ NDN_LOG_DEBUG_DEPTH("Timeout while fetching certificate bundle " << bundleName);
m_inner->fetch(certRequest, state, continueValidation);
}
@@ -208,9 +196,9 @@
Name
CertificateBundleFetcher::deriveBundleName(const Name& name)
{
- name::Component lastComponent = name.at(-1);
-
Name bundleName = name;
+ const auto& lastComponent = name.at(-1);
+
if (lastComponent.isImplicitSha256Digest()) {
if (name.size() >= 2 && name.get(-2).isSegment()) {
bundleName = name.getPrefix(-2);
@@ -222,9 +210,9 @@
else if (lastComponent.isSegment()) {
bundleName = name.getPrefix(-1);
}
+
bundleName.append("_BUNDLE");
bundleName.appendNumber(0);
-
return bundleName;
}
diff --git a/ndn-cxx/security/certificate-bundle-fetcher.hpp b/ndn-cxx/security/certificate-bundle-fetcher.hpp
index 1d3e4ff..b4520c1 100644
--- a/ndn-cxx/security/certificate-bundle-fetcher.hpp
+++ b/ndn-cxx/security/certificate-bundle-fetcher.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -22,14 +22,13 @@
#ifndef NDN_CXX_SECURITY_CERTIFICATE_BUNDLE_FETCHER_HPP
#define NDN_CXX_SECURITY_CERTIFICATE_BUNDLE_FETCHER_HPP
-#include "ndn-cxx/name.hpp"
-#include "ndn-cxx/tag.hpp"
-#include "ndn-cxx/security/certificate-fetcher-from-network.hpp"
+#include "ndn-cxx/face.hpp"
+#include "ndn-cxx/security/certificate-fetcher.hpp"
namespace ndn::security {
/**
- * @brief Fetch certificate bundle from the network
+ * @brief Fetch certificate bundle from the network.
*
* Currently bundle fetching is attempted only for Data validation. This may change in the
* future. Bundle fetching always goes to the infrastructure regardless of the inner
@@ -42,30 +41,36 @@
{
public:
explicit
- CertificateBundleFetcher(unique_ptr<CertificateFetcher> inner,
- Face& face);
+ CertificateBundleFetcher(unique_ptr<CertificateFetcher> inner, Face& face);
/**
- * @brief Set the lifetime of certificate bundle interest
- */
- void
- setBundleInterestLifetime(time::milliseconds time);
-
- /**
- * @return The lifetime of certificate bundle interest
+ * @return The lifetime of certificate bundle Interest.
*/
time::milliseconds
- getBundleInterestLifetime() const;
+ getBundleInterestLifetime() const
+ {
+ return m_bundleInterestLifetime;
+ }
/**
- * Set the storage for this and inner certificate fetcher
+ * @brief Set the lifetime of certificate bundle Interest.
+ */
+ void
+ setBundleInterestLifetime(time::milliseconds time)
+ {
+ m_bundleInterestLifetime = time;
+ }
+
+ /**
+ * @brief Set the storage for this and inner certificate fetcher.
*/
void
setCertificateStorage(CertificateStorage& certStorage) override;
protected:
void
- doFetch(const shared_ptr<CertificateRequest>& certRequest, const shared_ptr<ValidationState>& state,
+ doFetch(const shared_ptr<CertificateRequest>& certRequest,
+ const shared_ptr<ValidationState>& state,
const ValidationContinuation& continueValidation) override;
private:
@@ -137,9 +142,7 @@
private:
unique_ptr<CertificateFetcher> m_inner;
Face& m_face;
- using BundleNameTag = SimpleTag<Name, 1000>;
- using FinalBlockIdTag = SimpleTag<name::Component, 1001>;
- time::milliseconds m_bundleInterestLifetime;
+ time::milliseconds m_bundleInterestLifetime = 1_s;
};
} // namespace ndn::security
diff --git a/ndn-cxx/security/interest-signer.cpp b/ndn-cxx/security/interest-signer.cpp
index ae6fe9d..d70a4cc 100644
--- a/ndn-cxx/security/interest-signer.cpp
+++ b/ndn-cxx/security/interest-signer.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -24,12 +24,6 @@
namespace ndn::security {
-InterestSigner::InterestSigner(KeyChain& keyChain)
- : m_keyChain(keyChain)
- , m_lastUsedSeqNum(-1) // Will wrap around to 0 on next Interest
-{
-}
-
void
InterestSigner::makeSignedInterest(Interest& interest, SigningInfo params, uint32_t signingFlags)
{
diff --git a/ndn-cxx/security/interest-signer.hpp b/ndn-cxx/security/interest-signer.hpp
index e47e704..e278805 100644
--- a/ndn-cxx/security/interest-signer.hpp
+++ b/ndn-cxx/security/interest-signer.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -27,13 +27,19 @@
namespace ndn::security {
/**
- * @brief Helper class to create signed Interests
+ * @brief Helper class to create signed Interests.
*
* The signer generates signature elements for an Interest and signs it with the KeyChain.
*/
class InterestSigner
{
public:
+ explicit
+ InterestSigner(KeyChain& keyChain) noexcept
+ : m_keyChain(keyChain)
+ {
+ }
+
/**
* @brief Flags to indicate which elements to include in Interest signatures created with
* makeSignedInterest.
@@ -45,10 +51,6 @@
WantSeqNum = 1 << 2,
};
-public:
- explicit
- InterestSigner(KeyChain& keyChain);
-
/**
* @brief Signs an Interest (following Packet Specification v0.3 or newer)
* @param interest Interest to sign
@@ -83,7 +85,7 @@
private:
KeyChain& m_keyChain;
time::system_clock::time_point m_lastUsedTimestamp;
- uint64_t m_lastUsedSeqNum;
+ uint64_t m_lastUsedSeqNum = static_cast<uint64_t>(-1); // will wrap around to 0 on next Interest
};
} // namespace ndn::security
diff --git a/ndn-cxx/security/transform/bool-sink.cpp b/ndn-cxx/security/transform/bool-sink.cpp
index 3a86a0e..e1a8c5f 100644
--- a/ndn-cxx/security/transform/bool-sink.cpp
+++ b/ndn-cxx/security/transform/bool-sink.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -23,12 +23,6 @@
namespace ndn::security::transform {
-BoolSink::BoolSink(bool& value)
- : m_hasValue(false)
- , m_value(value)
-{
-}
-
size_t
BoolSink::doWrite(span<const uint8_t> buf)
{
@@ -39,12 +33,6 @@
return buf.size();
}
-void
-BoolSink::doEnd()
-{
- // nothing to do.
-}
-
unique_ptr<Sink>
boolSink(bool& value)
{
diff --git a/ndn-cxx/security/transform/bool-sink.hpp b/ndn-cxx/security/transform/bool-sink.hpp
index bf4b4df..ea3f5a3 100644
--- a/ndn-cxx/security/transform/bool-sink.hpp
+++ b/ndn-cxx/security/transform/bool-sink.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -39,7 +39,10 @@
* @brief Create a bool sink whose output will be stored in @p value.
*/
explicit
- BoolSink(bool& value);
+ BoolSink(bool& value)
+ : m_value(value)
+ {
+ }
private:
/**
@@ -51,13 +54,16 @@
doWrite(span<const uint8_t> buf) final;
/**
- * @brief Finalize sink processing
+ * @brief Finalize sink processing.
*/
void
- doEnd() final;
+ doEnd() final
+ {
+ // nothing to do
+ }
private:
- bool m_hasValue;
+ bool m_hasValue = false;
bool& m_value;
};
diff --git a/ndn-cxx/security/transform/hex-decode.cpp b/ndn-cxx/security/transform/hex-decode.cpp
index 97e6774..7f1fad0 100644
--- a/ndn-cxx/security/transform/hex-decode.cpp
+++ b/ndn-cxx/security/transform/hex-decode.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -45,13 +45,6 @@
};
static_assert(std::extent_v<decltype(C2H)> == 256);
-
-HexDecode::HexDecode()
- : m_hasOddByte(false)
- , m_oddByte(0)
-{
-}
-
size_t
HexDecode::convert(span<const uint8_t> hex)
{
diff --git a/ndn-cxx/security/transform/hex-decode.hpp b/ndn-cxx/security/transform/hex-decode.hpp
index 72ffb18..18d23e7 100644
--- a/ndn-cxx/security/transform/hex-decode.hpp
+++ b/ndn-cxx/security/transform/hex-decode.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -36,12 +36,6 @@
*/
class HexDecode final : public Transform
{
-public:
- /**
- * @brief Create a hex decoding module
- */
- HexDecode();
-
private:
/**
* @brief Decode data @p buf, and write the result into output buffer directly.
@@ -64,8 +58,8 @@
toBytes(const uint8_t* hex, size_t hexLen);
private:
- bool m_hasOddByte;
- uint8_t m_oddByte;
+ bool m_hasOddByte = false;
+ uint8_t m_oddByte = 0;
};
unique_ptr<Transform>
diff --git a/ndn-cxx/security/transform/hex-encode.cpp b/ndn-cxx/security/transform/hex-encode.cpp
index 1dc759a..3331bd6 100644
--- a/ndn-cxx/security/transform/hex-encode.cpp
+++ b/ndn-cxx/security/transform/hex-encode.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -35,12 +35,6 @@
};
static_assert(std::extent_v<decltype(H2CU)> == 16);
-
-HexEncode::HexEncode(bool useUpperCase)
- : m_useUpperCase(useUpperCase)
-{
-}
-
size_t
HexEncode::convert(span<const uint8_t> data)
{
diff --git a/ndn-cxx/security/transform/hex-encode.hpp b/ndn-cxx/security/transform/hex-encode.hpp
index 4d334b4..e6673b1 100644
--- a/ndn-cxx/security/transform/hex-encode.hpp
+++ b/ndn-cxx/security/transform/hex-encode.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -36,12 +36,15 @@
{
public:
/**
- * @brief Create a hex encoding module
+ * @brief Create a hex encoding module.
*
* @param useUpperCase if true, use upper case letters, otherwise lower case
*/
explicit
- HexEncode(bool useUpperCase = false);
+ HexEncode(bool useUpperCase = false)
+ : m_useUpperCase(useUpperCase)
+ {
+ }
private:
/**
@@ -59,7 +62,7 @@
toHex(const uint8_t* data, size_t dataLen);
private:
- bool m_useUpperCase;
+ bool m_useUpperCase = false;
};
unique_ptr<Transform>
diff --git a/ndn-cxx/util/notification-stream.hpp b/ndn-cxx/util/notification-stream.hpp
index dceba06..0d7d23a 100644
--- a/ndn-cxx/util/notification-stream.hpp
+++ b/ndn-cxx/util/notification-stream.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2023 Regents of the University of California.
+ * Copyright (c) 2013-2024 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -29,8 +29,9 @@
namespace ndn::util {
-/** \brief Provides a publisher of Notification Stream.
- * \sa https://redmine.named-data.net/projects/nfd/wiki/Notification
+/**
+ * \brief A facility to publish notifications.
+ * \sa https://redmine.named-data.net/projects/nfd/wiki/Notification
*/
template<typename Notification>
class NotificationStream : noncopyable
@@ -42,7 +43,6 @@
: m_face(face)
, m_prefix(prefix)
, m_keyChain(keyChain)
- , m_sequenceNo(0)
{
}
@@ -55,7 +55,7 @@
Name dataName = m_prefix;
dataName.appendSequenceNumber(m_sequenceNo);
- shared_ptr<Data> data = make_shared<Data>(dataName);
+ auto data = make_shared<Data>(dataName);
data->setContent(notification.wireEncode());
data->setFreshnessPeriod(1_s);
@@ -69,7 +69,7 @@
Face& m_face;
const Name m_prefix;
KeyChain& m_keyChain;
- uint64_t m_sequenceNo;
+ uint64_t m_sequenceNo = 0;
};
} // namespace ndn::util
diff --git a/ndn-cxx/util/notification-subscriber.cpp b/ndn-cxx/util/notification-subscriber.cpp
index ac934d1..01bfe65 100644
--- a/ndn-cxx/util/notification-subscriber.cpp
+++ b/ndn-cxx/util/notification-subscriber.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2023 Regents of the University of California,
+ * Copyright (c) 2014-2024 Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -36,10 +36,6 @@
time::milliseconds interestLifetime)
: m_face(face)
, m_prefix(prefix)
- , m_isRunning(false)
- , m_lastSequenceNum(std::numeric_limits<uint64_t>::max())
- , m_lastNackSequenceNum(std::numeric_limits<uint64_t>::max())
- , m_attempts(1)
, m_scheduler(face.getIoContext())
, m_interestLifetime(interestLifetime)
{
@@ -50,20 +46,20 @@
void
NotificationSubscriberBase::start()
{
- if (m_isRunning) // already running
+ if (m_isRunning)
return;
- m_isRunning = true;
+ m_isRunning = true;
sendInitialInterest();
}
void
NotificationSubscriberBase::stop()
{
- if (!m_isRunning) // not running
+ if (!m_isRunning)
return;
- m_isRunning = false;
+ m_isRunning = false;
m_lastInterest.cancel();
}
@@ -98,9 +94,9 @@
NotificationSubscriberBase::sendInterest(const Interest& interest)
{
m_lastInterest = m_face.expressInterest(interest,
- [this] (const auto&, const auto& d) { this->afterReceiveData(d); },
- [this] (const auto&, const auto& n) { this->afterReceiveNack(n); },
- [this] (const auto&) { this->afterTimeout(); });
+ [this] (const auto&, const auto& d) { afterReceiveData(d); },
+ [this] (const auto&, const auto& n) { afterReceiveNack(n); },
+ [this] (const auto&) { afterTimeout(); });
}
bool
@@ -148,7 +144,7 @@
onNack(nack);
- time::milliseconds delay = exponentialBackoff(nack);
+ auto delay = exponentialBackoff(nack);
m_nackEvent = m_scheduler.schedule(delay, [this] { sendInitialInterest(); });
}
@@ -159,19 +155,18 @@
return;
onTimeout();
-
sendInitialInterest();
}
time::milliseconds
-NotificationSubscriberBase::exponentialBackoff(lp::Nack nack)
+NotificationSubscriberBase::exponentialBackoff(const lp::Nack& nack)
{
- uint64_t nackSequenceNum;
+ uint64_t nackSequenceNum = 0;
try {
nackSequenceNum = nack.getInterest().getName().get(-1).toSequenceNumber();
}
catch (const tlv::Error&) {
- nackSequenceNum = 0;
+ // pass
}
if (m_lastNackSequenceNum == nackSequenceNum) {
diff --git a/ndn-cxx/util/notification-subscriber.hpp b/ndn-cxx/util/notification-subscriber.hpp
index 0d8cede..8d104a7 100644
--- a/ndn-cxx/util/notification-subscriber.hpp
+++ b/ndn-cxx/util/notification-subscriber.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2023 Regents of the University of California,
+ * Copyright (c) 2014-2024 Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -80,6 +80,13 @@
time::milliseconds interestLifetime);
private:
+ /**
+ * \brief Check if the subscriber is or should be stopped.
+ * \retval true if the subscriber is stopped.
+ */
+ bool
+ shouldStop();
+
void
sendInitialInterest();
@@ -92,12 +99,6 @@
virtual bool
hasSubscriber() const = 0;
- /** \brief Check if the subscriber is or should be stopped.
- * \return true if the subscriber is stopped.
- */
- bool
- shouldStop();
-
void
afterReceiveData(const Data& data);
@@ -114,40 +115,35 @@
afterTimeout();
time::milliseconds
- exponentialBackoff(lp::Nack nack);
+ exponentialBackoff(const lp::Nack& nack);
public:
- /**
- * \brief Fires when a Nack is received.
- */
+ /// Fires when a Nack is received.
ndn::signal::Signal<NotificationSubscriberBase, lp::Nack> onNack;
- /**
- * \brief Fires when no Notification is received within getInterestLifetime() period.
- */
+ /// Fires when no Notification is received within getInterestLifetime() period.
ndn::signal::Signal<NotificationSubscriberBase> onTimeout;
- /**
- * \brief Fires when a Data packet in the notification stream cannot be decoded as a Notification.
- */
+ /// Fires when a Data packet in the notification stream cannot be decoded as a Notification.
ndn::signal::Signal<NotificationSubscriberBase, Data> onDecodeError;
private:
Face& m_face;
Name m_prefix;
- bool m_isRunning;
- uint64_t m_lastSequenceNum;
- uint64_t m_lastNackSequenceNum;
- uint64_t m_attempts;
+ uint64_t m_lastSequenceNum = std::numeric_limits<uint64_t>::max();
+ uint64_t m_lastNackSequenceNum = std::numeric_limits<uint64_t>::max();
+ uint64_t m_attempts = 1;
Scheduler m_scheduler;
scheduler::ScopedEventId m_nackEvent;
ScopedPendingInterestHandle m_lastInterest;
time::milliseconds m_interestLifetime;
+ bool m_isRunning = false;
};
-/** \brief Provides a subscriber of Notification Stream.
- * \sa https://redmine.named-data.net/projects/nfd/wiki/Notification
- * \tparam Notification type of Notification item, appears in payload of Data packets
+/**
+ * \brief Provides the subscriber side of a Notification Stream.
+ * \tparam Notification type of Notification item, appears in payload of Data packets.
+ * \sa https://redmine.named-data.net/projects/nfd/wiki/Notification
*/
template<typename Notification>
class NotificationSubscriber : public NotificationSubscriberBase