change PROBE format for max-suffix-length for each suggested name

Change-Id: Ie0823963fd3c56e40d825e0e80dfadf164f08ca3
diff --git a/src/protocol-detail/probe.cpp b/src/protocol-detail/probe.cpp
index b0ac75c..8132e28 100644
--- a/src/protocol-detail/probe.cpp
+++ b/src/protocol-detail/probe.cpp
@@ -54,10 +54,12 @@
 {
   Block content = makeEmptyBlock(tlv::Content);
   for (const auto& name : identifiers) {
-    content.push_back(makeNestedBlock(tlv_probe_response, name));
-  }
-  if (maxSuffixLength) {
-    content.push_back(makeNonNegativeIntegerBlock(tlv_max_suffix_length, *maxSuffixLength));
+    Block item(tlv_probe_response);
+    item.push_back(name.wireEncode());
+    if (maxSuffixLength) {
+      item.push_back(makeNonNegativeIntegerBlock(tlv_max_suffix_length, *maxSuffixLength));
+    }
+    content.push_back(item);
   }
   if (redirectionItems) {
     for (const auto& item : *redirectionItems) {
@@ -70,16 +72,32 @@
 
 void
 PROBE::decodeDataContent(const Block& block,
-                         std::vector<Name>& availableNames,
+                         std::vector<std::pair<Name, int>>& availableNames,
                          std::vector<Name>& availableRedirection)
 {
   block.parse();
   for (const auto& item : block.elements()) {
     if (item.type() == tlv_probe_response) {
-      availableNames.push_back(Name(item.blockFromValue()));
+      item.parse();
+      Name elementName;
+      int maxSuffixLength = 0;
+      for (const auto& subBlock: item.elements()) {
+          if (subBlock.type() == tlv::Name) {
+              if (!elementName.empty()) {
+                  BOOST_THROW_EXCEPTION(std::runtime_error("Invalid probe format"));
+              }
+              elementName.wireDecode(subBlock);
+          } else if (subBlock.type() == tlv_max_suffix_length) {
+              maxSuffixLength = readNonNegativeInteger(subBlock);
+          }
+      }
+      if (elementName.empty()) {
+          BOOST_THROW_EXCEPTION(std::runtime_error("Invalid probe format"));
+      }
+      availableNames.emplace_back(elementName, maxSuffixLength);
     }
     if (item.type() == tlv_probe_redirect) {
-      availableRedirection.push_back(Name(item.blockFromValue()));
+      availableRedirection.emplace_back(Name(item.blockFromValue()));
     }
   }
 }
diff --git a/src/protocol-detail/probe.hpp b/src/protocol-detail/probe.hpp
index 7d61461..e6ff022 100644
--- a/src/protocol-detail/probe.hpp
+++ b/src/protocol-detail/probe.hpp
@@ -33,7 +33,7 @@
   encodeApplicationParameters(std::vector<std::tuple<std::string, std::string>>&& parameters);
 
   static void
-  decodeDataContent(const Block& block, std::vector<Name>& availableNames,
+  decodeDataContent(const Block& block, std::vector<std::pair<Name, int>>& availableNames,
                     std::vector<Name>& availableRedirection);
 
   // For CA use
diff --git a/src/requester.cpp b/src/requester.cpp
index 0b5a6c5..2e6a517 100644
--- a/src/requester.cpp
+++ b/src/requester.cpp
@@ -107,7 +107,7 @@
 
 void
 Requester::onProbeResponse(const Data& reply, const CaProfile& ca,
-                           std::vector<Name>& identityNames, std::vector<Name>& otherCas)
+                           std::vector<std::pair<Name, int>>& identityNames, std::vector<Name>& otherCas)
 {
   if (!security::verifySignature(reply, *ca.m_cert)) {
     _LOG_ERROR("Cannot verify replied Data packet signature.");
diff --git a/src/requester.hpp b/src/requester.hpp
index 1b64d4b..f08e579 100644
--- a/src/requester.hpp
+++ b/src/requester.hpp
@@ -158,7 +158,7 @@
    */
   static void
   onProbeResponse(const Data& reply, const CaProfile& ca,
-                  std::vector<Name>& identityNames, std::vector<Name>& otherCas);
+                  std::vector<std::pair<Name, int>>& identityNames, std::vector<Name>& otherCas);
 
   // NEW/REVOKE/RENEW related helpers
   /**
diff --git a/tests/unit-tests/protocol-detail.t.cpp b/tests/unit-tests/protocol-detail.t.cpp
index 881a040..91436ed 100644
--- a/tests/unit-tests/protocol-detail.t.cpp
+++ b/tests/unit-tests/protocol-detail.t.cpp
@@ -63,9 +63,11 @@
   std::vector<Name> ids;
   ids.push_back(Name("/example"));
   auto contentTlv = PROBE::encodeDataContent(ids, 2, config.m_redirection);
-  std::vector<Name> decodedIds, decodedRedirectionItems;
+  std::vector<Name> decodedRedirectionItems;
+  std::vector<std::pair<Name, int>> decodedIds;
   PROBE::decodeDataContent(contentTlv, decodedIds, decodedRedirectionItems);
-  BOOST_CHECK_EQUAL(decodedIds[0], Name("/example"));
+  BOOST_CHECK_EQUAL(decodedIds[0].first, Name("/example"));
+  BOOST_CHECK_EQUAL(decodedIds[0].second, 2);
   BOOST_CHECK_EQUAL(decodedRedirectionItems[0], config.m_redirection->at(0)->getFullName());
 }
 
diff --git a/tests/unit-tests/requester.t.cpp b/tests/unit-tests/requester.t.cpp
index 44a4b7f..95b892f 100644
--- a/tests/unit-tests/requester.t.cpp
+++ b/tests/unit-tests/requester.t.cpp
@@ -83,13 +83,16 @@
   reply.setContent(PROBE::encodeDataContent(availableNames, 3, ca.m_config.m_redirection));
   m_keyChain.sign(reply, signingByIdentity(identity));
 
-  std::vector<Name> names, redirects;
+  std::vector<std::pair<Name, int>> names;
+  std::vector<Name> redirects;
   Requester::onProbeResponse(reply, ca_profile, names, redirects);
 
   // Test names and redirects are properly stored
   BOOST_CHECK_EQUAL(names.size(), 2);
-  BOOST_CHECK_EQUAL(names[0].toUri(), "/site1");
-  BOOST_CHECK_EQUAL(names[1].toUri(), "/site2");
+  BOOST_CHECK_EQUAL(names[0].first.toUri(), "/site1");
+  BOOST_CHECK_EQUAL(names[0].second, 3);
+  BOOST_CHECK_EQUAL(names[1].first.toUri(), "/site2");
+  BOOST_CHECK_EQUAL(names[1].second, 3);
 
   BOOST_CHECK_EQUAL(redirects.size(), 2);
   BOOST_CHECK_EQUAL(security::extractIdentityFromCertName(redirects[0].getPrefix(-1)), "/ndn/site1");
@@ -113,7 +116,8 @@
   errorPacket.setContent(ErrorTLV::encodeDataContent(ErrorCode::INVALID_PARAMETER, "This is a test."));
   m_keyChain.sign(errorPacket, signingByIdentity(identity));
 
-  std::vector<Name> ids, cas;
+  std::vector<std::pair<Name, int>> ids;
+  std::vector<Name> cas;
   BOOST_CHECK_THROW(Requester::onProbeResponse(errorPacket, item, ids, cas), std::runtime_error);
   BOOST_CHECK_THROW(Requester::onNewRenewRevokeResponse(state, errorPacket), std::runtime_error);
   BOOST_CHECK_THROW(Requester::onChallengeResponse(state, errorPacket), std::runtime_error);
diff --git a/tools/ndncert-client.cpp b/tools/ndncert-client.cpp
index d948854..50af81e 100644
--- a/tools/ndncert-client.cpp
+++ b/tools/ndncert-client.cpp
@@ -238,7 +238,7 @@
 static void
 probeCb(const Data& reply, CaProfile profile)
 {
-  std::vector<Name> names;
+  std::vector<std::pair<Name, int>> names;
   std::vector<Name> redirects;
   Requester::onProbeResponse(reply, profile, names, redirects);
   size_t count = 0;
@@ -247,7 +247,8 @@
             << ": You can either select one of the following names suggested by the CA: " << std::endl;
   for (const auto& name : names) {
     std::cerr << "> Index: " << count++ << std::endl
-              << ">> Suggested name: " << name.toUri() << std::endl;
+              << ">> Suggested name: " << name.first.toUri() << std::endl
+              << ">> Corresponding Max sufiix length: " << name.second << std::endl;
   }
   std::cerr << "\nOr choose another trusted CA suggested by the CA: " << std::endl;
   for (const auto& redirect : redirects) {
@@ -271,8 +272,9 @@
   }
   if (index < names.size()) {
     //names
-    std::cerr << "You selected name: " << names[index].toUri() << std::endl;
-    runNew(profile, names[index]);
+    std::cerr << "You selected name: " << names[index].first.toUri() << std::endl;
+    //TODO add prompt to "add suffix"
+    runNew(profile, names[index].first);
   }
   else {
     //redirects