Finalize switch to v2 security
Change-Id: I1da06c817a7b3455fda1033ee530cde3221f02b7
Refs: #4091
diff --git a/src/handles/delete-handle.cpp b/src/handles/delete-handle.cpp
index d062399..5c06015 100644
--- a/src/handles/delete-handle.cpp
+++ b/src/handles/delete-handle.cpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2014-2017, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
@@ -33,48 +33,47 @@
DeleteHandle::onInterest(const Name& prefix, const Interest& interest)
{
m_validator.validate(interest, bind(&DeleteHandle::onValidated, this, _1, prefix),
- bind(&DeleteHandle::onValidationFailed, this, _1, _2));
+ bind(&DeleteHandle::onValidationFailed, this, _1, _2));
}
void
-DeleteHandle::onValidated(const shared_ptr<const Interest>& interest, const Name& prefix)
+DeleteHandle::onValidated(const Interest& interest, const Name& prefix)
{
RepoCommandParameter parameter;
try {
- extractParameter(*interest, prefix, parameter);
+ extractParameter(interest, prefix, parameter);
}
catch (RepoCommandParameter::Error) {
- negativeReply(*interest, 403);
+ negativeReply(interest, 403);
return;
}
if (parameter.hasSelectors()) {
if (parameter.hasStartBlockId() || parameter.hasEndBlockId()) {
- negativeReply(*interest, 402);
+ negativeReply(interest, 402);
return;
}
//choose data with selector and delete it
- processSelectorDeleteCommand(*interest, parameter);
+ processSelectorDeleteCommand(interest, parameter);
return;
}
if (!parameter.hasStartBlockId() && !parameter.hasEndBlockId()) {
- processSingleDeleteCommand(*interest, parameter);
+ processSingleDeleteCommand(interest, parameter);
return;
}
- processSegmentDeleteCommand(*interest, parameter);
+ processSegmentDeleteCommand(interest, parameter);
}
void
-DeleteHandle::onValidationFailed(const shared_ptr<const Interest>& interest,
- const std::string& reason)
+DeleteHandle::onValidationFailed(const Interest& interest, const ValidationError& error)
{
- std::cerr << reason << std::endl;
- negativeReply(*interest, 401);
+ std::cerr << error << std::endl;
+ negativeReply(interest, 401);
}
//listen change the setinterestfilter
void
diff --git a/src/handles/delete-handle.hpp b/src/handles/delete-handle.hpp
index 265d5ef..17cb48a 100644
--- a/src/handles/delete-handle.hpp
+++ b/src/handles/delete-handle.hpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2014-2017, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
@@ -50,10 +50,10 @@
onInterest(const Name& prefix, const Interest& interest);
void
- onValidated(const std::shared_ptr<const Interest>& interest, const Name& prefix);
+ onValidated(const Interest& interest, const Name& prefix);
void
- onValidationFailed(const std::shared_ptr<const Interest>& interest, const std::string& reason);
+ onValidationFailed(const Interest& interest, const ValidationError& error);
/**
* @todo delete check has not been realized due to the while loop of segmented data deletion.
diff --git a/src/handles/watch-handle.cpp b/src/handles/watch-handle.cpp
index 91eaac4..bee036f 100644
--- a/src/handles/watch-handle.cpp
+++ b/src/handles/watch-handle.cpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2014-2017, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
@@ -53,18 +53,18 @@
}
void
-WatchHandle::onValidated(const shared_ptr<const Interest>& interest, const Name& prefix)
+WatchHandle::onValidated(const Interest& interest, const Name& prefix)
{
RepoCommandParameter parameter;
try {
- extractParameter(*interest, prefix, parameter);
+ extractParameter(interest, prefix, parameter);
}
catch (RepoCommandParameter::Error) {
- negativeReply(*interest, 403);
+ negativeReply(interest, 403);
return;
}
- processWatchCommand(*interest, parameter);
+ processWatchCommand(interest, parameter);
}
void WatchHandle::watchStop(const Name& name)
@@ -79,11 +79,10 @@
}
void
-WatchHandle::onValidationFailed(const shared_ptr<const Interest>& interest,
- const std::string& reason)
+WatchHandle::onValidationFailed(const Interest& interest, const ValidationError& error)
{
- std::cerr << reason << std::endl;
- negativeReply(*interest, 401);
+ std::cerr << error << std::endl;
+ negativeReply(interest, 401);
}
void
@@ -95,13 +94,12 @@
}
void
-WatchHandle::onDataValidated(const Interest& interest, const shared_ptr<const Data>& data,
- const Name& name)
+WatchHandle::onDataValidated(const Interest& interest, const Data& data, const Name& name)
{
if (!m_processes[name].second) {
return;
}
- if (getStorageHandle().insertData(*data)) {
+ if (getStorageHandle().insertData(data)) {
m_size++;
if (!onRunning(name))
return;
@@ -113,7 +111,7 @@
// update selectors
// if data name is equal to interest name, use MinSuffixComponents selecor to exclude this data
- if (data->getName().size() == interest.getName().size()) {
+ if (data.getName().size() == interest.getName().size()) {
fetchInterest.setMinSuffixComponents(2);
}
else {
@@ -122,7 +120,7 @@
exclude = interest.getExclude();
}
- exclude.excludeBefore(data->getName()[interest.getName().size()]);
+ exclude.excludeBefore(data.getName()[interest.getName().size()]);
fetchInterest.setExclude(exclude);
}
@@ -139,10 +137,10 @@
}
void
-WatchHandle::onDataValidationFailed(const Interest& interest, const shared_ptr<const Data>& data,
- const std::string& reason, const Name& name)
+WatchHandle::onDataValidationFailed(const Interest& interest, const Data& data,
+ const ValidationError& error, const Name& name)
{
- std::cerr << reason << std::endl;
+ std::cerr << error << std::endl;
if (!m_processes[name].second) {
return;
}
@@ -156,7 +154,7 @@
// update selectors
// if data name is equal to interest name, use MinSuffixComponents selecor to exclude this data
- if (data->getName().size() == interest.getName().size()) {
+ if (data.getName().size() == interest.getName().size()) {
fetchInterest.setMinSuffixComponents(2);
}
else {
@@ -165,7 +163,7 @@
exclude = interest.getExclude();
}
// Only exclude this data since other data whose names are smaller may be validated and satisfied
- exclude.excludeBefore(data->getName()[interest.getName().size()]);
+ exclude.excludeBefore(data.getName()[interest.getName().size()]);
fetchInterest.setExclude(exclude);
}
@@ -219,27 +217,26 @@
}
void
-WatchHandle::onStopValidated(const shared_ptr<const Interest>& interest, const Name& prefix)
+WatchHandle::onStopValidated(const Interest& interest, const Name& prefix)
{
RepoCommandParameter parameter;
try {
- extractParameter(*interest, prefix, parameter);
+ extractParameter(interest, prefix, parameter);
}
catch (RepoCommandParameter::Error) {
- negativeReply(*interest, 403);
+ negativeReply(interest, 403);
return;
}
watchStop(parameter.getName());
- negativeReply(*interest, 101);
+ negativeReply(interest, 101);
}
void
-WatchHandle::onStopValidationFailed(const shared_ptr<const Interest>& interest,
- const std::string& reason)
+WatchHandle::onStopValidationFailed(const Interest& interest, const ValidationError& error)
{
- std::cerr << reason << std::endl;
- negativeReply(*interest, 401);
+ std::cerr << error << std::endl;
+ negativeReply(interest, 401);
}
void
@@ -251,26 +248,26 @@
}
void
-WatchHandle::onCheckValidated(const shared_ptr<const Interest>& interest, const Name& prefix)
+WatchHandle::onCheckValidated(const Interest& interest, const Name& prefix)
{
RepoCommandParameter parameter;
try {
- extractParameter(*interest, prefix, parameter);
+ extractParameter(interest, prefix, parameter);
}
catch (RepoCommandParameter::Error) {
- negativeReply(*interest, 403);
+ negativeReply(interest, 403);
return;
}
if (!parameter.hasName()) {
- negativeReply(*interest, 403);
+ negativeReply(interest, 403);
return;
}
//check whether this process exists
Name name = parameter.getName();
if (m_processes.count(name) == 0) {
std::cerr << "no such process name: " << name << std::endl;
- negativeReply(*interest, 404);
+ negativeReply(interest, 404);
return;
}
@@ -279,16 +276,15 @@
response.setStatusCode(101);
}
- reply(*interest, response);
+ reply(interest, response);
}
void
-WatchHandle::onCheckValidationFailed(const shared_ptr<const Interest>& interest,
- const std::string& reason)
+WatchHandle::onCheckValidationFailed(const Interest& interest, const ValidationError& error)
{
- std::cerr << reason << std::endl;
- negativeReply(*interest, 401);
+ std::cerr << error << std::endl;
+ negativeReply(interest, 401);
}
void
diff --git a/src/handles/watch-handle.hpp b/src/handles/watch-handle.hpp
index 5768e06..c7071df 100644
--- a/src/handles/watch-handle.hpp
+++ b/src/handles/watch-handle.hpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2014-2017, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
@@ -68,10 +68,10 @@
onInterest(const Name& prefix, const Interest& interest);
void
- onValidated(const std::shared_ptr<const Interest>& interest, const Name& prefix);
+ onValidated(const Interest& interest, const Name& prefix);
void
- onValidationFailed(const std::shared_ptr<const Interest>& interest, const std::string& reason);
+ onValidationFailed(const Interest& interest, const ValidationError& error);
private: // data fetching
/**
@@ -87,15 +87,14 @@
onTimeout(const Interest& interest, const Name& name);
void
- onDataValidated(const Interest& interest, const std::shared_ptr<const Data>& data,
- const Name& name);
+ onDataValidated(const Interest& interest, const Data& data, const Name& name);
/**
* @brief failure of validation
*/
void
- onDataValidationFailed(const Interest& interest, const std::shared_ptr<const Data>& data,
- const std::string& reason, const Name& name);
+ onDataValidationFailed(const Interest& interest, const Data& data,
+ const ValidationError& error, const Name& name);
void
@@ -112,11 +111,10 @@
onCheckInterest(const Name& prefix, const Interest& interest);
void
- onCheckValidated(const std::shared_ptr<const Interest>& interest, const Name& prefix);
+ onCheckValidated(const Interest& interest, const Name& prefix);
void
- onCheckValidationFailed(const std::shared_ptr<const Interest>& interest,
- const std::string& reason);
+ onCheckValidationFailed(const Interest& interest, const ValidationError& error);
private: // watch stop command
/**
@@ -126,11 +124,10 @@
onStopInterest(const Name& prefix, const Interest& interest);
void
- onStopValidated(const std::shared_ptr<const Interest>& interest, const Name& prefix);
+ onStopValidated(const Interest& interest, const Name& prefix);
void
- onStopValidationFailed(const std::shared_ptr<const Interest>& interest,
- const std::string& reason);
+ onStopValidationFailed(const Interest& interest, const ValidationError& error);
private:
void
diff --git a/src/handles/write-handle.cpp b/src/handles/write-handle.cpp
index a398f0b..4586bad 100644
--- a/src/handles/write-handle.cpp
+++ b/src/handles/write-handle.cpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2014-2017, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
@@ -55,38 +55,37 @@
}
void
-WriteHandle::onValidated(const std::shared_ptr<const Interest>& interest, const Name& prefix)
+WriteHandle::onValidated(const Interest& interest, const Name& prefix)
{
//m_validResult = 1;
RepoCommandParameter parameter;
try {
- extractParameter(*interest, prefix, parameter);
+ extractParameter(interest, prefix, parameter);
}
catch (RepoCommandParameter::Error) {
- negativeReply(*interest, 403);
+ negativeReply(interest, 403);
return;
}
if (parameter.hasStartBlockId() || parameter.hasEndBlockId()) {
if (parameter.hasSelectors()) {
- negativeReply(*interest, 402);
+ negativeReply(interest, 402);
return;
}
- processSegmentedInsertCommand(*interest, parameter);
+ processSegmentedInsertCommand(interest, parameter);
}
else {
- processSingleInsertCommand(*interest, parameter);
+ processSingleInsertCommand(interest, parameter);
}
if (parameter.hasInterestLifetime())
m_interestLifetime = parameter.getInterestLifetime();
}
void
-WriteHandle::onValidationFailed(const std::shared_ptr<const Interest>& interest,
- const std::string& reason)
+WriteHandle::onValidationFailed(const Interest& interest, const ValidationError& error)
{
- std::cerr << reason << std::endl;
- negativeReply(*interest, 401);
+ std::cerr << error << std::endl;
+ negativeReply(interest, 401);
}
void
@@ -98,9 +97,7 @@
}
void
-WriteHandle::onDataValidated(const Interest& interest,
- const std::shared_ptr<const Data>& data,
- ProcessId processId)
+WriteHandle::onDataValidated(const Interest& interest, const Data& data, ProcessId processId)
{
if (m_processes.count(processId) == 0) {
return;
@@ -110,9 +107,9 @@
RepoCommandResponse& response = process.response;
if (response.getInsertNum() == 0) {
- getStorageHandle().insertData(*data);
- // getStorageHandle().insertEntry(*data);
- // getStoreIndex().insert(*data);
+ getStorageHandle().insertData(data);
+ // getStorageHandle().insertEntry(data);
+ // getStoreIndex().insert(data);
response.setInsertNum(1);
}
@@ -120,10 +117,9 @@
}
void
-WriteHandle::onDataValidationFailed(const std::shared_ptr<const Data>& data,
- const std::string& reason)
+WriteHandle::onDataValidationFailed(const Data& data, const ValidationError& error)
{
- std::cerr << reason << std::endl;
+ std::cerr << error << std::endl;
}
void
@@ -135,9 +131,7 @@
}
void
-WriteHandle::onSegmentDataValidated(const Interest& interest,
- const std::shared_ptr<const Data>& data,
- ProcessId processId)
+WriteHandle::onSegmentDataValidated(const Interest& interest, const Data& data, ProcessId processId)
{
if (m_processes.count(processId) == 0) {
return;
@@ -145,7 +139,7 @@
RepoCommandResponse& response = m_processes[processId].response;
//refresh endBlockId
- Name::Component finalBlockId = data->getFinalBlockId();
+ Name::Component finalBlockId = data.getFinalBlockId();
if (!finalBlockId.empty()) {
SegmentNo final = finalBlockId.toSegment();
@@ -160,7 +154,7 @@
}
//insert data
- if (getStorageHandle().insertData(*data)) {
+ if (getStorageHandle().insertData(data)) {
response.setInsertNum(response.getInsertNum() + 1);
}
@@ -386,26 +380,26 @@
}
void
-WriteHandle::onCheckValidated(const shared_ptr<const Interest>& interest, const Name& prefix)
+WriteHandle::onCheckValidated(const Interest& interest, const Name& prefix)
{
RepoCommandParameter parameter;
try {
- extractParameter(*interest, prefix, parameter);
+ extractParameter(interest, prefix, parameter);
}
catch (RepoCommandParameter::Error) {
- negativeReply(*interest, 403);
+ negativeReply(interest, 403);
return;
}
if (!parameter.hasProcessId()) {
- negativeReply(*interest, 403);
+ negativeReply(interest, 403);
return;
}
//check whether this process exists
ProcessId processId = parameter.getProcessId();
if (m_processes.count(processId) == 0) {
std::cerr << "no such processId: " << processId << std::endl;
- negativeReply(*interest, 404);
+ negativeReply(interest, 404);
return;
}
@@ -416,27 +410,26 @@
//Check whether it is single data fetching
if (!response.hasStartBlockId() &&
!response.hasEndBlockId()) {
- reply(*interest, response);
+ reply(interest, response);
return;
}
//read if noEndtimeout
if (!response.hasEndBlockId()) {
extendNoEndTime(process);
- reply(*interest, response);
+ reply(interest, response);
return;
}
else {
- reply(*interest, response);
+ reply(interest, response);
}
}
void
-WriteHandle::onCheckValidationFailed(const shared_ptr<const Interest>& interest,
- const std::string& reason)
+WriteHandle::onCheckValidationFailed(const Interest& interest, const ValidationError& error)
{
- std::cerr << reason << std::endl;
- negativeReply(*interest, 401);
+ std::cerr << error << std::endl;
+ negativeReply(interest, 401);
}
void
diff --git a/src/handles/write-handle.hpp b/src/handles/write-handle.hpp
index 1e7a007..c6622d9 100644
--- a/src/handles/write-handle.hpp
+++ b/src/handles/write-handle.hpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2014-2017, Regents of the University of California.
*
* This file is part of NDN repo-ng (Next generation of NDN repository).
@@ -107,10 +107,10 @@
onInterest(const Name& prefix, const Interest& interest);
void
- onValidated(const std::shared_ptr<const Interest>& interest, const Name& prefix);
+ onValidated(const Interest& interest, const Name& prefix);
void
- onValidationFailed(const std::shared_ptr<const Interest>& interest, const std::string& reason);
+ onValidationFailed(const Interest& interest, const ValidationError& error);
private: // single data fetching
/**
@@ -120,8 +120,7 @@
onData(const Interest& interest, const Data& data, ProcessId processId);
void
- onDataValidated(const Interest& interest, const std::shared_ptr<const Data>& data,
- ProcessId processId);
+ onDataValidated(const Interest& interest, const Data& data, ProcessId processId);
/**
* @brief handle when fetching one data timeout
@@ -140,8 +139,7 @@
onSegmentData(const Interest& interest, const Data& data, ProcessId processId);
void
- onSegmentDataValidated(const Interest& interest, const std::shared_ptr<const Data>& data,
- ProcessId processId);
+ onSegmentDataValidated(const Interest& interest, const Data& data, ProcessId processId);
/**
* @brief Timeout when fetching segmented data. Data can be fetched RETRY_TIMEOUT times.
@@ -175,7 +173,7 @@
* @brief failure of validation for both one or segmented data
*/
void
- onDataValidationFailed(const std::shared_ptr<const Data>& data, const std::string& reason);
+ onDataValidationFailed(const Data& data, const ValidationError& error);
/**
* @brief extends noEndTime of process if not noEndTimeout, set StatusCode 405
@@ -194,11 +192,10 @@
onCheckInterest(const Name& prefix, const Interest& interest);
void
- onCheckValidated(const std::shared_ptr<const Interest>& interest, const Name& prefix);
+ onCheckValidated(const Interest& interest, const Name& prefix);
void
- onCheckValidationFailed(const std::shared_ptr<const Interest>& interest,
- const std::string& reason);
+ onCheckValidationFailed(const Interest& interest, const ValidationError& error);
private:
void