interest: auto-generating random nonce if not set
Change-Id: Ib3aac0b7d4b1fd38f13dff2c57a4d1dfc77592ff
diff --git a/src/interest.cpp b/src/interest.cpp
index 0c77d88..85ce0c1 100644
--- a/src/interest.cpp
+++ b/src/interest.cpp
@@ -9,10 +9,24 @@
#include <ndn-cpp/common.hpp>
#include <ndn-cpp/interest.hpp>
+#include <cryptopp/osrng.h>
+
using namespace std;
namespace ndn {
+uint32_t
+Interest::getNonce() const
+{
+ static CryptoPP::AutoSeededRandomPool rng;
+
+ if (nonce_ == 0)
+ nonce_ = rng.GenerateWord32();
+
+ return nonce_;
+}
+
+
bool
Interest::matchesName(const Name &name) const
{
@@ -121,8 +135,11 @@
(booleanBlock(Tlv::MustBeFresh));
}
- selectors.encode();
- wire_.push_back(selectors);
+ if (!selectors.getAll().empty())
+ {
+ selectors.encode();
+ wire_.push_back(selectors);
+ }
}
// Nonce