Random name components now generated with generateRandomNameComponent()
refs #3
Change-Id: Idcab4e9e7d2dc11233de930b3fd4976641b85abd
diff --git a/src/ndn-traffic-client.cpp b/src/ndn-traffic-client.cpp
index cfd6933..91e8115 100644
--- a/src/ndn-traffic-client.cpp
+++ b/src/ndn-traffic-client.cpp
@@ -509,13 +509,14 @@
return randomNonce;
}
- static std::string
- getRandomByteString(std::size_t randomSize)
+ static name::Component
+ generateRandomNameComponent(size_t length)
{
- std::string randomString;
- for (std::size_t i = 0; i < randomSize; i++)
- randomString += static_cast<char>(std::rand() % 128);
- return randomString;
+ Buffer buffer(length);
+ for (size_t i = 0; i < length; i++) {
+ buffer[i] = static_cast<uint8_t>(std::rand() % 256);
+ }
+ return name::Component(buffer);
}
void
@@ -607,7 +608,7 @@
Name interestName(m_trafficPatterns[patternId].m_name);
if (m_trafficPatterns[patternId].m_nameAppendBytes > 0)
interestName.append(
- getRandomByteString(m_trafficPatterns[patternId].m_nameAppendBytes));
+ generateRandomNameComponent(m_trafficPatterns[patternId].m_nameAppendBytes));
if (m_trafficPatterns[patternId].m_nameAppendSequenceNumber >= 0)
{
interestName.append(
@@ -649,28 +650,24 @@
m_trafficPatterns[patternId].m_excludeAfterBytes > 0)
{
exclude.excludeRange(
- name::Component(
- getRandomByteString(
- m_trafficPatterns[patternId].m_excludeAfterBytes)),
- name::Component(
- getRandomByteString(
- m_trafficPatterns[patternId].m_excludeBeforeBytes)));
+ generateRandomNameComponent(
+ m_trafficPatterns[patternId].m_excludeAfterBytes),
+ generateRandomNameComponent(
+ m_trafficPatterns[patternId].m_excludeBeforeBytes));
interest.setExclude(exclude);
}
else if (m_trafficPatterns[patternId].m_excludeBeforeBytes > 0)
{
exclude.excludeBefore(
- name::Component(
- getRandomByteString(
- m_trafficPatterns[patternId].m_excludeBeforeBytes)));
+ generateRandomNameComponent(
+ m_trafficPatterns[patternId].m_excludeBeforeBytes));
interest.setExclude(exclude);
}
else if (m_trafficPatterns[patternId].m_excludeAfterBytes > 0)
{
exclude.excludeAfter(
- name::Component(
- getRandomByteString(
- m_trafficPatterns[patternId].m_excludeAfterBytes)));
+ generateRandomNameComponent(
+ m_trafficPatterns[patternId].m_excludeAfterBytes));
interest.setExclude(exclude);
}