fix all unit tests
Change-Id: I81ddefe248a563f0dda79b6bb27897599b84ce59
diff --git a/src/ca-module.cpp b/src/ca-module.cpp
index 8b1c72a..0f1d800 100644
--- a/src/ca-module.cpp
+++ b/src/ca-module.cpp
@@ -184,41 +184,38 @@
// PROBE Naming Convention: /<CA-Prefix>/CA/PROBE/[ParametersSha256DigestComponent]
_LOG_TRACE("Received PROBE request");
- // process PROBE requests: find an available name
- std::string availableId = "";
- const auto& parameterTLV = request.getApplicationParameters();
- parameterTLV.parse();
- if (!parameterTLV.hasValue()) {
- _LOG_ERROR("Empty TLV obtained from the Interest parameter.");
- return;
+ // process PROBE requests: collect probe parameters
+ auto parameters = PROBE::decodeApplicationParameters(request.getApplicationParameters());
+ std::vector<std::string> availableComponents;
+ if (m_config.m_nameAssignmentFunc) {
+ try {
+ availableComponents = m_config.m_nameAssignmentFunc(parameters);
+ }
+ catch (const std::exception& e) {
+ _LOG_TRACE("Cannot parse probe parameters: " << e.what());
+ m_face.put(generateErrorDataPacket(request.getName(), ErrorCode::INVALID_PARAMETER,
+ "Cannot parse probe parameters: " + std::string(e.what())));
+ return;
+ }
+ }
+ else {
+ // if there is no app-specified name lookup, use a random name id
+ availableComponents.push_back(std::to_string(random::generateSecureWord64()));
+ }
+ std::vector<Name> availableNames;
+ for (const auto& component : availableComponents) {
+ Name newIdentityName = m_config.m_caItem.m_caPrefix;
+ newIdentityName.append(component);
+ availableNames.push_back(newIdentityName);
}
- // if (m_config.m_caItem.m_nameAssignmentFunc) {
- // try {
- // availableId = m_config.m_caItem.m_nameAssignmentFunc(parameterTLV);
- // }
- // catch (const std::exception& e) {
- // _LOG_TRACE("Cannot find PROBE input from PROBE parameters: " << e.what());
- // return;
- // }
- // }
- // else {
- // // if there is no app-specified name lookup, use a random name id
- // availableId = std::to_string(random::generateSecureWord64());
- // }
- // Name newIdentityName = m_config.m_caItem.m_caPrefix;
- // newIdentityName.append(availableId);
- // _LOG_TRACE("Handle PROBE: generate an identity " << newIdentityName);
-
- // Block contentTLV = PROBE::encodeDataContent(newIdentityName.toUri(), m_config.m_caItem.m_probe, parameterTLV);
-
- // Data result;
- // result.setName(request.getName());
- // result.setContent(contentTLV);
- // result.setFreshnessPeriod(DEFAULT_DATA_FRESHNESS_PERIOD);
- // m_keyChain.sign(result, signingByIdentity(m_config.m_caItem.m_caPrefix));
- // m_face.put(result);
- // _LOG_TRACE("Handle PROBE: send out the PROBE response");
+ Data result;
+ result.setName(request.getName());
+ result.setContent(PROBE::encodeDataContent(availableNames, m_config.m_caItem.m_maxSuffixLength));
+ result.setFreshnessPeriod(DEFAULT_DATA_FRESHNESS_PERIOD);
+ m_keyChain.sign(result, signingByIdentity(m_config.m_caItem.m_caPrefix));
+ m_face.put(result);
+ _LOG_TRACE("Handle PROBE: send out the PROBE response");
}
void
diff --git a/src/client-module.cpp b/src/client-module.cpp
index 0e7810e..8fdb7b2 100644
--- a/src/client-module.cpp
+++ b/src/client-module.cpp
@@ -68,7 +68,7 @@
ClientModule::verifyInfoResponse(const Data& reply)
{
// parse the ca item
- auto caItem = INFO::decodeDataContentToCaProfile(reply.getContent());
+ auto caItem = INFO::decodeDataContent(reply.getContent());
// verify the probe Data's sig
if (!security::verifySignature(reply, *caItem.m_cert)) {
@@ -84,7 +84,7 @@
const Block& contentBlock = reply.getContent();
// parse the ca item
- auto caItem = INFO::decodeDataContentToCaProfile(contentBlock);
+ auto caItem = INFO::decodeDataContent(contentBlock);
// update the local config
bool findItem = false;
diff --git a/src/protocol-detail/info.cpp b/src/protocol-detail/info.cpp
index da8b969..06eba0e 100644
--- a/src/protocol-detail/info.cpp
+++ b/src/protocol-detail/info.cpp
@@ -49,7 +49,7 @@
}
CaConfigItem
-INFO::decodeDataContentToCaProfile(const Block& block)
+INFO::decodeDataContent(const Block& block)
{
CaConfigItem result;
block.parse();
diff --git a/src/protocol-detail/info.hpp b/src/protocol-detail/info.hpp
index 1c375bb..03f0d61 100644
--- a/src/protocol-detail/info.hpp
+++ b/src/protocol-detail/info.hpp
@@ -38,7 +38,7 @@
* Decode CA configuration from the TLV block of INFO Data packet content.
*/
static CaConfigItem
- decodeDataContentToCaProfile(const Block& block);
+ decodeDataContent(const Block& block);
};
} // namespace ndncert
diff --git a/src/protocol-detail/probe.cpp b/src/protocol-detail/probe.cpp
index 93ba020..c7b72d5 100644
--- a/src/protocol-detail/probe.cpp
+++ b/src/protocol-detail/probe.cpp
@@ -19,8 +19,9 @@
*/
#include "probe.hpp"
-#include <ndn-cxx/encoding/tlv.hpp>
+
#include <boost/throw_exception.hpp>
+#include <ndn-cxx/encoding/tlv.hpp>
namespace ndn {
namespace ndncert {
@@ -38,7 +39,19 @@
return content;
}
-// For CA
+std::vector<std::tuple<std::string, std::string>>
+PROBE::decodeApplicationParameters(const Block& block)
+{
+ std::vector<std::tuple<std::string, std::string>> result;
+ block.parse();
+ for (size_t i = 0; i < block.elements().size() - 1; ++i) {
+ if (block.elements().at(i).type() == tlv_parameter_key && block.elements().at(i + 1).type() == tlv_parameter_value) {
+ result.push_back(std::make_tuple(readString(block.elements().at(i)), readString(block.elements().at(i + 1))));
+ }
+ }
+ return result;
+}
+
Block
PROBE::encodeDataContent(const std::vector<Name>& identifiers, boost::optional<size_t> maxSuffixLength)
{
@@ -53,5 +66,18 @@
return content;
}
+std::vector<Name>
+PROBE::decodeDataContent(const Block& block)
+{
+ std::vector<Name> result;
+ block.parse();
+ for (const auto& item : block.elements()) {
+ if (item.type() == tlv_probe_response) {
+ result.push_back(Name(item.blockFromValue()));
+ }
+ }
+ return result;
+}
+
} // namespace ndncert
} // namespace ndn
\ No newline at end of file
diff --git a/src/protocol-detail/probe.hpp b/src/protocol-detail/probe.hpp
index 126fba4..8d08e4b 100644
--- a/src/protocol-detail/probe.hpp
+++ b/src/protocol-detail/probe.hpp
@@ -28,11 +28,19 @@
class PROBE {
public:
+ // For CA use
static Block
encodeApplicationParameters(std::vector<std::tuple<std::string, std::string>>&& parameters);
+ static std::vector<Name>
+ decodeDataContent(const Block& block);
+
+ // For client use
static Block
encodeDataContent(const std::vector<Name>& identifiers, boost::optional<size_t> maxSuffixLength);
+
+ static std::vector<std::tuple<std::string, std::string>>
+ decodeApplicationParameters(const Block& block);
};
} // namespace ndncert