Avoid deprecated ndn-cxx functions
Change-Id: Ib148262999a691760821a2ce1c05a5e6332e7e34
diff --git a/examples/consumer.cpp b/examples/consumer.cpp
index ae79848..359f17b 100644
--- a/examples/consumer.cpp
+++ b/examples/consumer.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2018, Regents of the University of California
+/*
+ * Copyright (c) 2014-2022, Regents of the University of California
*
* NAC library is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@@ -35,9 +35,8 @@
{
public:
Consumer()
- : m_face(nullptr, m_keyChain)
- , m_validator(m_face)
- , m_decryptor(m_keyChain.getPib().getDefaultIdentity().getDefaultKey(), m_validator, m_keyChain, m_face)
+ : m_decryptor(m_keyChain.getPib().getDefaultIdentity().getDefaultKey(),
+ m_validator, m_keyChain, m_face)
{
m_validator.load(R"CONF(
trust-anchor
@@ -51,58 +50,57 @@
run()
{
Interest interest(Name("/example/testApp/randomData"));
- interest.setInterestLifetime(2_s); // 2 seconds
interest.setMustBeFresh(true);
+ interest.setInterestLifetime(3_s); // 3 seconds
+ std::cout << "Sending Interest " << interest << std::endl;
m_face.expressInterest(interest,
- bind(&Consumer::onData, this, _1, _2),
- bind(&Consumer::onNack, this, _1, _2),
- bind(&Consumer::onTimeout, this, _1));
+ std::bind(&Consumer::onData, this, _1, _2),
+ std::bind(&Consumer::onNack, this, _1, _2),
+ std::bind(&Consumer::onTimeout, this, _1));
- std::cout << "Sending " << interest << std::endl;
-
- // processEvents will block until the requested data received or timeout occurs
+ // processEvents will block until the requested data is received or a timeout occurs
m_face.processEvents();
}
private:
void
- onData(const Interest& interest, const Data& data)
+ onData(const Interest&, const Data& data)
{
m_validator.validate(data,
[=] (const Data& data) {
m_decryptor.decrypt(data.getContent().blockFromValue(),
- [=] (ConstBufferPtr content) {
+ [] (const ConstBufferPtr& content) {
std::cout << "Decrypted content: "
<< std::string(reinterpret_cast<const char*>(content->data()), content->size())
<< std::endl;
},
- [=] (const ErrorCode&, const std::string& error) {
+ [] (const ErrorCode&, const std::string& error) {
std::cerr << "Cannot decrypt data: " << error << std::endl;
});
},
- [=] (const Data& data, const ValidationError& error) {
+ [] (const Data&, const ValidationError& error) {
std::cerr << "Cannot validate retrieved data: " << error << std::endl;
});
}
void
- onNack(const Interest& interest, const lp::Nack& nack)
+ onNack(const Interest& interest, const lp::Nack& nack) const
{
- std::cout << "received Nack with reason " << nack.getReason()
+ std::cout << "Received Nack with reason " << nack.getReason()
<< " for interest " << interest << std::endl;
}
void
- onTimeout(const Interest& interest)
+ onTimeout(const Interest& interest) const
{
- std::cout << "Timeout " << interest << std::endl;
+ std::cout << "Timeout for " << interest << std::endl;
}
private:
KeyChain m_keyChain;
- Face m_face;
- ValidatorConfig m_validator;
+ Face m_face{nullptr, m_keyChain};
+ ValidatorConfig m_validator{m_face};
Decryptor m_decryptor;
};
@@ -113,12 +111,13 @@
int
main(int argc, char** argv)
{
- ndn::nac::examples::Consumer consumer;
try {
+ ndn::nac::examples::Consumer consumer;
consumer.run();
+ return 0;
}
catch (const std::exception& e) {
std::cerr << "ERROR: " << e.what() << std::endl;
+ return 1;
}
- return 0;
}
diff --git a/examples/producer.cpp b/examples/producer.cpp
index a1f3422..9c9d95b 100644
--- a/examples/producer.cpp
+++ b/examples/producer.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2020, Regents of the University of California
+ * Copyright (c) 2014-2022, Regents of the University of California
*
* NAC library is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@@ -37,15 +37,12 @@
{
public:
Producer()
- : m_face(nullptr, m_keyChain)
- , m_validator(m_face)
- , m_accessManager(m_keyChain.createIdentity("/nac/example", RsaKeyParams()), "test",
+ : m_accessManager(m_keyChain.createIdentity("/nac/example", RsaKeyParams()), "test",
m_keyChain, m_face)
, m_encryptor("/nac/example/NAC/test",
"/nac/example/CK", signingWithSha256(),
- [] (auto...) {
- std::cerr << "Failed to publish CK";
- }, m_validator, m_keyChain, m_face)\
+ [] (auto&&...) { std::cerr << "Failed to publish CK"; },
+ m_validator, m_keyChain, m_face)
{
m_validator.load(R"CONF(
trust-anchor
@@ -58,19 +55,19 @@
void
run()
{
- // give access to default identity. If consumer uses the same default identity, he will be able to decrypt
+ // Give access to default identity. If consumer uses the same default identity, it will be able to decrypt
m_accessManager.addMember(m_keyChain.getPib().getDefaultIdentity().getDefaultKey().getDefaultCertificate());
m_face.setInterestFilter("/example/testApp",
- bind(&Producer::onInterest, this, _1, _2),
- RegisterPrefixSuccessCallback(),
- bind(&Producer::onRegisterFailed, this, _1, _2));
+ std::bind(&Producer::onInterest, this, _1, _2),
+ nullptr, // RegisterPrefixSuccessCallback is optional
+ std::bind(&Producer::onRegisterFailed, this, _1, _2));
m_face.processEvents();
}
private:
void
- onInterest(const InterestFilter& filter, const Interest& interest)
+ onInterest(const InterestFilter&, const Interest& interest)
{
std::cout << "<< I: " << interest << std::endl;
@@ -80,14 +77,13 @@
.append("testApp") // add "testApp" component to Interest name
.appendVersion(); // add "version" component (current UNIX timestamp in milliseconds)
- static const std::string content = "HELLO KITTY";
-
// Create Data packet
- shared_ptr<Data> data = make_shared<Data>();
+ auto data = std::make_shared<Data>();
data->setName(dataName);
data->setFreshnessPeriod(10_s); // 10 seconds
- auto blob = m_encryptor.encrypt(reinterpret_cast<const uint8_t*>(content.data()), content.size());
+ static const std::string content = "HELLO KITTY";
+ auto blob = m_encryptor.encrypt({reinterpret_cast<const uint8_t*>(content.data()), content.size()});
data->setContent(blob.wireEncode());
// Sign Data packet with default identity
@@ -104,16 +100,15 @@
void
onRegisterFailed(const Name& prefix, const std::string& reason)
{
- std::cerr << "ERROR: Failed to register prefix \""
- << prefix << "\" in local hub's daemon (" << reason << ")"
- << std::endl;
+ std::cerr << "ERROR: Failed to register prefix '" << prefix
+ << "' with the local forwarder (" << reason << ")" << std::endl;
m_face.shutdown();
}
private:
KeyChain m_keyChain;
- Face m_face;
- ValidatorConfig m_validator;
+ Face m_face{nullptr, m_keyChain};
+ ValidatorConfig m_validator{m_face};
AccessManager m_accessManager;
Encryptor m_encryptor;
};
@@ -125,12 +120,13 @@
int
main(int argc, char** argv)
{
- ndn::nac::examples::Producer producer;
try {
+ ndn::nac::examples::Producer producer;
producer.run();
+ return 0;
}
catch (const std::exception& e) {
std::cerr << "ERROR: " << e.what() << std::endl;
+ return 1;
}
- return 0;
}