Alexander Afanasyev | ba2cf39 | 2017-01-13 19:05:23 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Zhiyi Zhang | a1302f6 | 2017-10-31 10:22:35 -0700 | [diff] [blame] | 2 | /* |
Alexander Afanasyev | ba2cf39 | 2017-01-13 19:05:23 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2017 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 | |
| 22 | #include "certificate-fetcher-direct-fetch.hpp" |
| 23 | #include "face.hpp" |
| 24 | #include "lp/tags.hpp" |
| 25 | |
| 26 | namespace ndn { |
| 27 | namespace security { |
| 28 | namespace v2 { |
| 29 | |
| 30 | CertificateFetcherDirectFetch::CertificateFetcherDirectFetch(Face& face) |
| 31 | : CertificateFetcherFromNetwork(face) |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | void |
| 36 | CertificateFetcherDirectFetch::doFetch(const shared_ptr<CertificateRequest>& keyRequest, |
| 37 | const shared_ptr<ValidationState>& state, |
| 38 | const ValidationContinuation& continueValidation) |
| 39 | { |
| 40 | auto interestState = dynamic_pointer_cast<InterestValidationState>(state); |
Zhiyi Zhang | a1302f6 | 2017-10-31 10:22:35 -0700 | [diff] [blame] | 41 | uint64_t incomingFaceId = 0; |
Alexander Afanasyev | ba2cf39 | 2017-01-13 19:05:23 -0800 | [diff] [blame] | 42 | if (interestState != nullptr) { |
Alexander Afanasyev | ba2cf39 | 2017-01-13 19:05:23 -0800 | [diff] [blame] | 43 | auto incomingFaceIdTag = interestState->getOriginalInterest().getTag<lp::IncomingFaceIdTag>(); |
| 44 | if (incomingFaceIdTag != nullptr) { |
| 45 | incomingFaceId = incomingFaceIdTag->get(); |
| 46 | } |
Zhiyi Zhang | a1302f6 | 2017-10-31 10:22:35 -0700 | [diff] [blame] | 47 | } |
| 48 | else { |
| 49 | auto dataState = dynamic_pointer_cast<DataValidationState>(state); |
| 50 | auto incomingFaceIdTag = dataState->getOriginalData().getTag<lp::IncomingFaceIdTag>(); |
| 51 | if (incomingFaceIdTag != nullptr) { |
| 52 | incomingFaceId = incomingFaceIdTag->get(); |
Alexander Afanasyev | ba2cf39 | 2017-01-13 19:05:23 -0800 | [diff] [blame] | 53 | } |
| 54 | } |
Zhiyi Zhang | a1302f6 | 2017-10-31 10:22:35 -0700 | [diff] [blame] | 55 | if (incomingFaceId != 0) { |
| 56 | Interest directInterest(keyRequest->m_interest); |
| 57 | directInterest.refreshNonce(); |
| 58 | directInterest.setTag(make_shared<lp::NextHopFaceIdTag>(incomingFaceId)); |
| 59 | m_face.expressInterest(directInterest, nullptr, nullptr, nullptr); |
| 60 | } |
Alexander Afanasyev | ba2cf39 | 2017-01-13 19:05:23 -0800 | [diff] [blame] | 61 | |
| 62 | // send infrastructure Interest |
| 63 | CertificateFetcherFromNetwork::doFetch(keyRequest, state, continueValidation); |
| 64 | } |
| 65 | |
| 66 | } // namespace v2 |
| 67 | } // namespace security |
| 68 | } // namespace ndn |