blob: a73c9eecf91290eccf15bec54d788ffd97665a14 [file] [log] [blame]
Nick Gordond5c1a372016-10-31 13:56:23 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2017, The University of Memphis,
4 * Regents of the University of California
5 *
6 * This file is part of NLSR (Named-data Link State Routing).
7 * See AUTHORS.md for complete list of NLSR authors and contributors.
8 *
9 * NLSR is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21#include "validator.hpp"
22
23namespace nlsr {
24
25void
26Validator::checkPolicy(const ndn::Data& data, int nSteps, const ndn::OnDataValidated& onValidated,
27 const ndn::OnDataValidationFailed& onValidationFailed,
28 std::vector<shared_ptr<ndn::ValidationRequest>>& nextSteps)
29{
30 if (!m_shouldValidate) {
31 onValidated(data.shared_from_this());
32 }
33 else {
34 ValidatorConfig::checkPolicy(data, nSteps, onValidated, onValidationFailed, nextSteps);
35 }
36}
37
38void
39Validator::afterCheckPolicy(const NextSteps& nextSteps, const OnFailure& onFailure)
40{
41 if (m_face == nullptr) {
42 onFailure("Require more information to validate the packet!");
43 return;
44 }
45
46 for (const std::shared_ptr<ndn::ValidationRequest>& request : nextSteps) {
47
48 ndn::Interest& interest = request->m_interest;
49
50 // Look for certificate in permanent storage
51 std::shared_ptr<const ndn::IdentityCertificate> cert = m_certStore.find(interest.getName());
52
53 if (cert != nullptr) {
54 // If the certificate is found, no reason to express interest
55 std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>(interest.getName());
56 data->setContent(cert->wireEncode());
57
58 Validator::onData(interest, *data, request);
59 }
60 else {
61 // Prepend broadcast prefix to interest name
62 ndn::Name broadcastName = m_broadcastPrefix;
63 broadcastName.append(interest.getName());
64 interest.setName(broadcastName);
65
66 // Attempt to fetch the certificate
67 m_face->expressInterest(interest,
68 std::bind(&Validator::onData, this, _1, _2, request),
69 std::bind(&Validator::onTimeout, // Nack
70 this, _1, request->m_nRetries,
71 onFailure,
72 request),
73 std::bind(&Validator::onTimeout,
74 this, _1, request->m_nRetries,
75 onFailure,
76 request));
77 }
78 }
79}
80
81std::shared_ptr<const ndn::Data>
82Validator::preCertificateValidation(const ndn::Data& data)
83{
84 std::shared_ptr<ndn::Data> internalData = std::make_shared<ndn::Data>();
85 internalData->wireDecode(data.getContent().blockFromValue());
86 return internalData;
87}
88
89} // namespace nlsr