NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
certificate-fetcher-direct-fetch.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2020 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
23 
24 #include "ndn-cxx/face.hpp"
25 #include "ndn-cxx/lp/tags.hpp"
28 
29 namespace ndn {
30 namespace security {
31 inline namespace v2 {
32 
35 {
36 }
37 
38 void
40 {
41  m_wantDirectInterestOnly = wantDirectInterestOnly;
42 }
43 
44 void
45 CertificateFetcherDirectFetch::doFetch(const shared_ptr<CertificateRequest>& keyRequest,
46  const shared_ptr<ValidationState>& state,
47  const ValidationContinuation& continueValidation)
48 {
49  auto interestState = dynamic_pointer_cast<InterestValidationState>(state);
50  uint64_t incomingFaceId = 0;
51  if (interestState != nullptr) {
52  auto incomingFaceIdTag = interestState->getOriginalInterest().getTag<lp::IncomingFaceIdTag>();
53  if (incomingFaceIdTag != nullptr) {
54  incomingFaceId = incomingFaceIdTag->get();
55  }
56  }
57  else {
58  auto dataState = dynamic_pointer_cast<DataValidationState>(state);
59  auto incomingFaceIdTag = dataState->getOriginalData().getTag<lp::IncomingFaceIdTag>();
60  if (incomingFaceIdTag != nullptr) {
61  incomingFaceId = incomingFaceIdTag->get();
62  }
63  }
64  if (incomingFaceId != 0) {
65  Interest directInterest(keyRequest->interest);
66  directInterest.refreshNonce();
67  directInterest.setTag(make_shared<lp::NextHopFaceIdTag>(incomingFaceId));
68 
69  if (!m_wantDirectInterestOnly) {
70  // disable callbacks
71  m_face.expressInterest(directInterest, nullptr, nullptr, nullptr);
72  }
73  else {
74  m_face.expressInterest(directInterest,
75  [=] (const Interest&, const Data& data) {
76  dataCallback(data, keyRequest, state, continueValidation);
77  },
78  [=] (const Interest&, const lp::Nack& nack) {
79  nackCallback(nack, keyRequest, state, continueValidation);
80  },
81  [=] (const Interest&) {
82  timeoutCallback(keyRequest, state, continueValidation);
83  });
84  }
85  }
86 
87  if (!m_wantDirectInterestOnly) {
88  // send infrastructure Interest
89  CertificateFetcherFromNetwork::doFetch(keyRequest, state, continueValidation);
90  }
91  else if (incomingFaceId == 0) {
92  state->fail({ValidationError::Code::CANNOT_RETRIEVE_CERT,
93  "Cannot direct fetch certificate as IncomingFaceId tag is not set"});
94  }
95 }
96 
97 } // inline namespace v2
98 } // namespace security
99 } // namespace ndn
void setTag(shared_ptr< T > tag) const
set a tag item
Definition: tag-host.hpp:79
Copyright (c) 2011-2015 Regents of the University of California.
shared_ptr< T > getTag() const
get a tag item
Definition: tag-host.hpp:66
void nackCallback(const lp::Nack &nack, const shared_ptr< CertificateRequest > &certRequest, const shared_ptr< ValidationState > &state, const ValidationContinuation &continueValidation)
Callback invoked when interest for fetching certificate gets NACKed.
void refreshNonce()
Change nonce value.
Definition: interest.cpp:422
Represents an Interest packet.
Definition: interest.hpp:48
std::function< void(const Certificate &cert, const shared_ptr< ValidationState > &state)> ValidationContinuation
represents a Network Nack
Definition: nack.hpp:38
Validation state for a data packet.
void doFetch(const shared_ptr< CertificateRequest > &keyRequest, const shared_ptr< ValidationState > &state, const ValidationContinuation &continueValidation) override
Asynchronous certificate fetching implementation.
provides a tag type for simple types
Definition: tag.hpp:58
Validation state for an interest packet.
constexpr const T & get() const noexcept
Definition: tag.hpp:86
Provide a communication channel with local or remote NDN forwarder.
Definition: face.hpp:90
void dataCallback(const Data &data, const shared_ptr< CertificateRequest > &certRequest, const shared_ptr< ValidationState > &state, const ValidationContinuation &continueValidation)
Callback invoked when certificate is retrieved.
PendingInterestHandle expressInterest(const Interest &interest, const DataCallback &afterSatisfied, const NackCallback &afterNacked, const TimeoutCallback &afterTimeout)
Express Interest.
Definition: face.cpp:123
void timeoutCallback(const shared_ptr< CertificateRequest > &certRequest, const shared_ptr< ValidationState > &state, const ValidationContinuation &continueValidation)
Callback invoked when interest for fetching certificate times out.
Represents a Data packet.
Definition: data.hpp:37
void setSendDirectInterestOnly(bool wantDirectInterestOnly)
If wantDirectInterestOnly, only the direct Interest will be sent out.
void doFetch(const shared_ptr< CertificateRequest > &certRequest, const shared_ptr< ValidationState > &state, const ValidationContinuation &continueValidation) override
Asynchronous certificate fetching implementation.