Update validation related codes to security v2
Change-Id: I5467b87092820666c04f22623f0f1665ce9a1194
diff --git a/src/clients/iterative-query-controller.cpp b/src/clients/iterative-query-controller.cpp
index 5a143a5..54bbb9a 100644
--- a/src/clients/iterative-query-controller.cpp
+++ b/src/clients/iterative-query-controller.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016, Regents of the University of California.
+/*
+ * Copyright (c) 2014-2017, Regents of the University of California.
*
* This file is part of NDNS (Named Data Networking Domain Name Service).
* See AUTHORS.md for complete list of NDNS authors and contributors.
@@ -17,8 +17,8 @@
* NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "validator.hpp"
#include "iterative-query-controller.hpp"
+#include "validator.hpp"
#include "logger.hpp"
#include <iostream>
@@ -32,7 +32,7 @@
const QuerySucceedCallback& onSucceed,
const QueryFailCallback& onFail,
Face& face,
- Validator* validator)
+ security::v2::Validator* validator)
: QueryController(dstLabel, rrType, interestLifetime, onSucceed, onFail, face)
, m_validator(validator)
, m_step(QUERY_STEP_QUERY_NS)
@@ -68,20 +68,20 @@
NDNS_LOG_TRACE("[* -> *] get a " << contentType
<< " Response: " << data.getName());
if (m_validator == nullptr) {
- this->onDataValidated(make_shared<Data>(data), contentType);
+ this->onDataValidated(data, contentType);
}
else {
m_validator->validate(data,
bind(&IterativeQueryController::onDataValidated, this, _1, contentType),
- [this] (const shared_ptr<const Data>& data, const std::string& str) {
- NDNS_LOG_WARN("data: " << data->getName() << " fails verification");
+ [this] (const Data& data, const security::v2::ValidationError& err) {
+ NDNS_LOG_WARN("data: " << data.getName() << " fails verification");
this->abort();
}
);
}
}
void
-IterativeQueryController::onDataValidated(const shared_ptr<const Data>& data, NdnsContentType contentType)
+IterativeQueryController::onDataValidated(const Data& data, NdnsContentType contentType)
{
switch (m_step) {
case QUERY_STEP_QUERY_NS:
@@ -89,11 +89,12 @@
m_step = QUERY_STEP_QUERY_RR;
}
else if (contentType == NDNS_LINK) {
- Link link(data->wireEncode());
- if (link.getDelegations().empty()) {
+ Link link(data.wireEncode());
+ if (link.getDelegationList().empty()) {
m_lastLink = Block();
- } else {
- m_lastLink = data->wireEncode();
+ }
+ else {
+ m_lastLink = data.wireEncode();
}
// for NS query, if already received, just return, instead of more queries until NACK
@@ -113,7 +114,8 @@
std::ostringstream oss;
oss << *this;
NDNS_LOG_WARN("get unexpected Response: NDNS_BLOB for QUERY_NS: " << oss.str());
- } else {
+ }
+ else {
std::ostringstream oss;
oss << *this;
NDNS_LOG_WARN("get unexpected Response for QUERY_NS: " << oss.str());
@@ -142,9 +144,9 @@
this->express(this->makeLatestInterest()); // express new Expres
else if (m_step == QUERY_STEP_ANSWER_STUB) {
NDNS_LOG_TRACE("query ends: " << *this);
- Response re = this->parseFinalResponse(*data);
+ Response re = this->parseFinalResponse(data);
if (m_onSucceed != nullptr)
- m_onSucceed(*data, re);
+ m_onSucceed(data, re);
else
NDNS_LOG_TRACE("succeed callback is nullptr");
}
@@ -202,7 +204,7 @@
// addLink
if (m_lastLink.hasWire()) {
- query.setLink(m_lastLink);
+ query.setDelegationListFromLink(Link(m_lastLink));
}
switch (m_step) {
@@ -226,7 +228,8 @@
std::ostringstream oss;
oss << *this;
NDNS_LOG_WARN("unexpected state: " << oss.str());
- throw std::runtime_error("call makeLatestInterest() unexpected: " + oss.str());
+ BOOST_THROW_EXCEPTION(std::runtime_error("call makeLatestInterest() unexpected: "
+ + oss.str()));
}
Interest interest = query.toInterest();
diff --git a/src/clients/iterative-query-controller.hpp b/src/clients/iterative-query-controller.hpp
index 7f975da..8a15d98 100644
--- a/src/clients/iterative-query-controller.hpp
+++ b/src/clients/iterative-query-controller.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016, Regents of the University of California.
+/*
+ * Copyright (c) 2014-2017, Regents of the University of California.
*
* This file is part of NDNS (Named Data Networking Domain Name Service).
* See AUTHORS.md for complete list of NDNS authors and contributors.
@@ -61,7 +61,7 @@
IterativeQueryController(const Name& dstLabel, const name::Component& rrType,
const time::milliseconds& interestLifetime,
const QuerySucceedCallback& onSucceed, const QueryFailCallback& onFail,
- Face& face, Validator* validator = nullptr);
+ Face& face, security::v2::Validator* validator = nullptr);
virtual void
start();
@@ -78,7 +78,7 @@
onData(const ndn::Interest& interest, const Data& data);
void
- onDataValidated(const shared_ptr<const Data>& data, NdnsContentType contentType);
+ onDataValidated(const Data& data, NdnsContentType contentType);
/**
* @brief change the Controller state according to timeout. For current,
@@ -92,7 +92,7 @@
/**
* @brief get the Interest according to current Controller state.
- * Only be valid on State QueryNS & QueryRR, or throw exception
+ * Only be valid on State QueryNS and QueryRR, or throw exception
*/
const Interest
makeLatestInterest();
@@ -129,7 +129,7 @@
}
protected:
- Validator* m_validator;
+ security::v2::Validator* m_validator;
/**
* @brief current query step
*/
@@ -160,4 +160,4 @@
} // namespace ndns
} // namespace ndn
-#endif // NDNS_CLIENTS_ITERATIVE_QUERY_HPP
+#endif // NDNS_CLIENTS_ITERATIVE_QUERY_CONTROLLER_HPP
diff --git a/src/clients/query.cpp b/src/clients/query.cpp
index 9853672..8a133bb 100644
--- a/src/clients/query.cpp
+++ b/src/clients/query.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016, Regents of the University of California.
+/*
+ * Copyright (c) 2014-2017, Regents of the University of California.
*
* This file is part of NDNS (Named Data Networking Domain Name Service).
* See AUTHORS.md for complete list of NDNS authors and contributors.
@@ -47,10 +47,11 @@
m_zone = zone;
- if (interest.hasLink()) {
- m_link = interest.getLink().wireEncode();
- } else {
- m_link = Block();
+ if (!interest.getForwardingHint().empty()) {
+ m_delegationList = interest.getForwardingHint();
+ }
+ else {
+ m_delegationList = DelegationList();
}
@@ -74,13 +75,19 @@
Interest interest;
interest.setName(name);
interest.setInterestLifetime(m_interestLifetime);
- if (m_link.hasWire()) {
- interest.setLink(m_link);
+ if (!m_delegationList.empty()) {
+ interest.setForwardingHint(m_delegationList);
}
return interest;
}
+void
+Query::setDelegationListFromLink(const Link& link)
+{
+ m_delegationList = link.getDelegationList();
+}
+
std::ostream&
operator<<(std::ostream& os, const Query& query)
{
diff --git a/src/clients/query.hpp b/src/clients/query.hpp
index d96d58c..f933eeb 100644
--- a/src/clients/query.hpp
+++ b/src/clients/query.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016, Regents of the University of California.
+/*
+ * Copyright (c) 2014-2017, Regents of the University of California.
*
* This file is part of NDNS (Named Data Networking Domain Name Service).
* See AUTHORS.md for complete list of NDNS authors and contributors.
@@ -59,6 +59,9 @@
bool
fromInterest(const Name& zone, const Interest& interest);
+ void
+ setDelegationListFromLink(const Link& link);
+
bool
operator==(const Query& other) const
{
@@ -170,18 +173,18 @@
* @brief set link object
*/
void
- setLink(const Block& link)
+ setDelegationList(const DelegationList& delegations)
{
- m_link = link;
+ m_delegationList = delegations;
}
/**
* @brief get Link object
*/
- const Block&
- getLink() const
+ const DelegationList&
+ getDelegationList() const
{
- return m_link;
+ return m_delegationList;
}
private:
@@ -190,7 +193,7 @@
Name m_rrLabel;
name::Component m_rrType;
time::milliseconds m_interestLifetime;
- Block m_link;
+ DelegationList m_delegationList;
};
std::ostream&
diff --git a/src/clients/response.cpp b/src/clients/response.cpp
index b1c3865..a23bc3c 100644
--- a/src/clients/response.cpp
+++ b/src/clients/response.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016, Regents of the University of California.
+/*
+ * Copyright (c) 2014-2017, Regents of the University of California.
*
* This file is part of NDNS (Named Data Networking Domain Name Service).
* See AUTHORS.md for complete list of NDNS authors and contributors.
@@ -39,7 +39,7 @@
{
}
-template<bool T>
+template<encoding::Tag T>
inline size_t
Response::wireEncode(EncodingImpl<T>& block) const
{
@@ -180,8 +180,10 @@
{
if (block.type() != ndn::tlv::Content) {
m_appContent = Block(ndn::tlv::Content, block);
- } else
+ }
+ else {
m_appContent = block;
+ }
m_appContent.encode(); // this is a must
}
diff --git a/src/clients/response.hpp b/src/clients/response.hpp
index 9f2138f..a33e42a 100644
--- a/src/clients/response.hpp
+++ b/src/clients/response.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016, Regents of the University of California.
+/*
+ * Copyright (c) 2014-2017, Regents of the University of California.
*
* This file is part of NDNS (Named Data Networking Domain Name Service).
* See AUTHORS.md for complete list of NDNS authors and contributors.
@@ -108,9 +108,9 @@
/**
* @brief encode app-level data
*/
- template<bool T>
+ template<encoding::Tag T>
size_t
- wireEncode(EncodingImpl<T> & block) const;
+ wireEncode(EncodingImpl<T>& block) const;
public:
///////////////////////////////////////////////