interest: flip default value of CanBePrefix to false
Refs: #4582
Change-Id: Ifc703e3c50d91954cd82ade8664e8fe9ec3a8154
diff --git a/ndn-cxx/interest.cpp b/ndn-cxx/interest.cpp
index dccf4a2..d4bdcf5 100644
--- a/ndn-cxx/interest.cpp
+++ b/ndn-cxx/interest.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2021 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -27,14 +27,9 @@
#include "ndn-cxx/security/transform/stream-sink.hpp"
#include "ndn-cxx/util/random.hpp"
-#ifdef NDN_CXX_HAVE_STACKTRACE
-#include <boost/stacktrace/stacktrace.hpp>
-#endif
-
#include <boost/range/adaptor/reversed.hpp>
#include <cstring>
-#include <iostream>
#include <sstream>
namespace ndn {
@@ -45,9 +40,6 @@
static_assert(std::is_base_of<tlv::Error, Interest::Error>::value,
"Interest::Error must inherit from tlv::Error");
-#ifdef NDN_CXX_HAVE_TESTS
-bool Interest::s_errorIfCanBePrefixUnset = true;
-#endif // NDN_CXX_HAVE_TESTS
boost::logic::tribool Interest::s_defaultCanBePrefix = boost::logic::indeterminate;
bool Interest::s_autoCheckParametersDigest = true;
@@ -68,35 +60,10 @@
// ---- encode and decode ----
-static void
-warnOnceCanBePrefixUnset()
-{
- static bool didWarn = false;
- if (!didWarn) {
- didWarn = true;
- std::cerr << "WARNING: Interest.CanBePrefix will be set to false in the near future. "
- << "Please declare a preferred setting via Interest::setDefaultCanBePrefix.\n";
-#ifdef NDN_CXX_HAVE_STACKTRACE
- if (std::getenv("NDN_CXX_VERBOSE_CANBEPREFIX_UNSET_WARNING") != nullptr) {
- std::cerr << boost::stacktrace::stacktrace(2, 64);
- }
-#endif
- }
-}
-
template<encoding::Tag TAG>
size_t
Interest::wireEncode(EncodingImpl<TAG>& encoder) const
{
- if (!m_isCanBePrefixSet) {
- warnOnceCanBePrefixUnset();
-#ifdef NDN_CXX_HAVE_TESTS
- if (s_errorIfCanBePrefixUnset) {
- NDN_THROW(std::logic_error("Interest.CanBePrefix is unset"));
- }
-#endif // NDN_CXX_HAVE_TESTS
- }
-
// Interest = INTEREST-TYPE TLV-LENGTH
// Name
// [CanBePrefix]
@@ -218,7 +185,6 @@
}
m_name = std::move(tempName);
- m_isCanBePrefixSet = true; // don't trigger warning from decoded packet
m_canBePrefix = m_mustBeFresh = false;
m_forwardingHint = {};
m_nonce.reset();
diff --git a/ndn-cxx/interest.hpp b/ndn-cxx/interest.hpp
index fde93c6..5a8a96f 100644
--- a/ndn-cxx/interest.hpp
+++ b/ndn-cxx/interest.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2021 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -218,7 +218,6 @@
{
m_canBePrefix = canBePrefix;
m_wire.reset();
- m_isCanBePrefixSet = true;
return *this;
}
@@ -495,12 +494,6 @@
std::vector<Block>::const_iterator
findFirstParameter(uint32_t type) const;
-#ifdef NDN_CXX_HAVE_TESTS
-public:
- /// If true, not setting CanBePrefix results in an error in wireEncode().
- static bool s_errorIfCanBePrefixUnset;
-#endif // NDN_CXX_HAVE_TESTS
-
private:
static boost::logic::tribool s_defaultCanBePrefix;
static bool s_autoCheckParametersDigest;
@@ -510,8 +503,7 @@
mutable optional<Nonce> m_nonce;
time::milliseconds m_interestLifetime;
optional<uint8_t> m_hopLimit;
- mutable bool m_isCanBePrefixSet = false;
- bool m_canBePrefix = true;
+ bool m_canBePrefix = false;
bool m_mustBeFresh = false;
// Stores the "Interest parameters", i.e., all maybe-unrecognized non-critical TLV
diff --git a/tests/integration/default-can-be-prefix-unset.cpp b/tests/integration/default-can-be-prefix-unset.cpp
deleted file mode 100644
index 6c97feb..0000000
--- a/tests/integration/default-can-be-prefix-unset.cpp
+++ /dev/null
@@ -1,40 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2013-2020 Regents of the University of California.
- *
- * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
- *
- * ndn-cxx 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
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- *
- * You should have received copies of the GNU General Public License and GNU Lesser
- * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- */
-
-#define BOOST_TEST_MODULE ndn-cxx Integration (DefaultCanBePrefix)
-#include "tests/boost-test.hpp"
-
-#include "ndn-cxx/interest.hpp"
-
-namespace ndn {
-namespace tests {
-
-BOOST_AUTO_TEST_CASE(DefaultCanBePrefixUnset)
-{
- Interest interest1("/I");
- BOOST_CHECK_THROW(interest1.wireEncode(), std::logic_error);
- Interest::s_errorIfCanBePrefixUnset = false;
- Interest interest2(interest1.wireEncode());
- BOOST_CHECK_EQUAL(interest2.getCanBePrefix(), true);
-}
-
-} // namespace tests
-} // namespace ndn
diff --git a/tests/unit/interest.t.cpp b/tests/unit/interest.t.cpp
index 33c4eb2..f119792 100644
--- a/tests/unit/interest.t.cpp
+++ b/tests/unit/interest.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2021 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -52,7 +52,7 @@
Interest i;
BOOST_CHECK_EQUAL(i.hasWire(), false);
BOOST_CHECK_EQUAL(i.getName(), "/");
- BOOST_CHECK_EQUAL(i.getCanBePrefix(), true);
+ BOOST_CHECK_EQUAL(i.getCanBePrefix(), false);
BOOST_CHECK_EQUAL(i.getMustBeFresh(), false);
BOOST_CHECK_EQUAL(i.getForwardingHint().empty(), true);
BOOST_CHECK_EQUAL(i.hasNonce(), false);
@@ -737,11 +737,11 @@
BOOST_AUTO_TEST_CASE(SetCanBePrefix)
{
Interest i;
- BOOST_CHECK_EQUAL(i.getCanBePrefix(), true);
- i.setCanBePrefix(false);
BOOST_CHECK_EQUAL(i.getCanBePrefix(), false);
i.setCanBePrefix(true);
BOOST_CHECK_EQUAL(i.getCanBePrefix(), true);
+ i.setCanBePrefix(false);
+ BOOST_CHECK_EQUAL(i.getCanBePrefix(), false);
}
BOOST_AUTO_TEST_CASE(SetMustBeFresh)
diff --git a/tests/unit/security/certificate-cache.t.cpp b/tests/unit/security/certificate-cache.t.cpp
index 7d60506..f3b400e 100644
--- a/tests/unit/security/certificate-cache.t.cpp
+++ b/tests/unit/security/certificate-cache.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2021 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -75,13 +75,18 @@
{
BOOST_CHECK_NO_THROW(certCache.insert(cert));
- // Find by interest
- BOOST_CHECK(certCache.find(Interest(cert.getIdentity())) != nullptr);
- BOOST_CHECK(certCache.find(Interest(cert.getKeyName())) != nullptr);
- BOOST_CHECK(certCache.find(Interest(Name(cert.getName()).appendVersion())) == nullptr);
+ Interest i;
+ i.setCanBePrefix(true);
+ i.setName(cert.getIdentity());
+ BOOST_CHECK(certCache.find(i) != nullptr);
+ i.setName(cert.getKeyName());
+ BOOST_CHECK(certCache.find(i) != nullptr);
+ i.setName(Name(cert.getName()).appendVersion());
+ BOOST_CHECK(certCache.find(i) == nullptr);
advanceClocks(12_s);
- BOOST_CHECK(certCache.find(Interest(cert.getIdentity())) == nullptr);
+ i.setName(cert.getIdentity());
+ BOOST_CHECK(certCache.find(i) == nullptr);
}
BOOST_AUTO_TEST_SUITE_END() // TestCertificateCache
diff --git a/tests/unit/security/trust-anchor-container.t.cpp b/tests/unit/security/trust-anchor-container.t.cpp
index 18da58a..17151c8 100644
--- a/tests/unit/security/trust-anchor-container.t.cpp
+++ b/tests/unit/security/trust-anchor-container.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2021 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -150,12 +150,14 @@
BOOST_AUTO_TEST_CASE(FindByInterest)
{
anchorContainer.insert("group1", certPath1.string(), 1_s);
- Interest interest(identity1.getName());
- BOOST_CHECK(anchorContainer.find(interest) != nullptr);
- Interest interest1(identity1.getName().getPrefix(-1));
+ Interest interest1;
+ interest1.setCanBePrefix(true);
+ interest1.setName(identity1.getName());
BOOST_CHECK(anchorContainer.find(interest1) != nullptr);
- Interest interest2(Name(identity1.getName()).appendVersion());
- BOOST_CHECK(anchorContainer.find(interest2) == nullptr);
+ interest1.setName(identity1.getName().getPrefix(-1));
+ BOOST_CHECK(anchorContainer.find(interest1) != nullptr);
+ interest1.setName(Name(identity1.getName()).appendVersion());
+ BOOST_CHECK(anchorContainer.find(interest1) == nullptr);
auto cert3 = makeCert(identity1.getDefaultKey(), "3");
auto cert4 = makeCert(identity1.getDefaultKey(), "4");
@@ -166,7 +168,7 @@
anchorContainer.insert("group3", std::move(cert4));
anchorContainer.insert("group4", std::move(cert5));
- Interest interest3(cert3.getKeyName());
+ auto interest3 = Interest(cert3.getKeyName()).setCanBePrefix(true);
const Certificate* foundCert = anchorContainer.find(interest3);
BOOST_REQUIRE(foundCert != nullptr);
BOOST_CHECK(interest3.getName().isPrefixOf(foundCert->getName()));