32 #define NDN_LOG_DEBUG_DEPTH(x) NDN_LOG_DEBUG(std::string(state->getDepth() + 1, '>') << " " << x) 33 #define NDN_LOG_TRACE_DEPTH(x) NDN_LOG_TRACE(std::string(state->getDepth() + 1, '>') << " " << x) 37 : m_inner(
std::move(inner))
39 , m_bundleInterestLifetime(1000)
41 BOOST_ASSERT(m_inner !=
nullptr);
47 m_bundleInterestLifetime =
time;
53 return m_bundleInterestLifetime;
60 m_inner->setCertificateStorage(certStorage);
65 const shared_ptr<ValidationState>& state,
69 if (dataValidationState ==
nullptr) {
70 return m_inner->fetch(certRequest, state, continueValidation);
74 shared_ptr<BundleNameTag> bundleNameTag = state->getTag<
BundleNameTag>();
75 if (bundleNameTag ==
nullptr) {
76 const Name& originalDataName = dataValidationState->getOriginalData().getName();
77 if (originalDataName.
empty()) {
78 return m_inner->fetch(certRequest, state, continueValidation);
81 Name bundleNamePrefix = deriveBundleName(originalDataName);
82 fetchFirstBundleSegment(bundleNamePrefix, certRequest, state, continueValidation);
85 Name fullBundleName = bundleNameTag->
get();
86 fetchNextBundleSegment(fullBundleName, fullBundleName.
get(-1).
getSuccessor(),
87 certRequest, state, continueValidation);
92 CertificateBundleFetcher::fetchFirstBundleSegment(
const Name& bundleNamePrefix,
93 const shared_ptr<CertificateRequest>& certRequest,
94 const shared_ptr<ValidationState>& state,
95 const ValidationContinuation& continueValidation)
104 dataCallback(data,
true, certRequest, state, continueValidation);
107 nackCallback(nack, certRequest, state, continueValidation, bundleNamePrefix);
110 timeoutCallback(certRequest, state, continueValidation, bundleNamePrefix);
115 CertificateBundleFetcher::fetchNextBundleSegment(
const Name& fullBundleName,
const name::Component& segmentNo,
116 const shared_ptr<CertificateRequest>& certRequest,
117 const shared_ptr<ValidationState>& state,
118 const ValidationContinuation& continueValidation)
120 shared_ptr<FinalBlockIdTag> finalBlockId = state->getTag<FinalBlockIdTag>();
121 if (finalBlockId !=
nullptr && segmentNo > finalBlockId->get()) {
122 return m_inner->fetch(certRequest, state, continueValidation);
125 Interest bundleInterest(fullBundleName.getPrefix(-1).append(segmentNo));
131 dataCallback(data,
false, certRequest, state, continueValidation);
134 nackCallback(nack, certRequest, state, continueValidation, fullBundleName);
137 timeoutCallback(certRequest, state, continueValidation, fullBundleName);
142 CertificateBundleFetcher::dataCallback(
const Data& bundleData,
143 bool isSegmentZeroExpected,
144 const shared_ptr<CertificateRequest>& certRequest,
145 const shared_ptr<ValidationState>& state,
146 const ValidationContinuation& continueValidation)
151 if (!currentSegment.isSegment()) {
152 return m_inner->fetch(certRequest, state, continueValidation);
155 if (isSegmentZeroExpected && currentSegment.toSegment() != 0) {
158 certRequest, state, continueValidation);
161 state->setTag(make_shared<BundleNameTag>(bundleData.getName()));
163 const auto& finalBlockId = bundleData.getFinalBlock();
165 state->setTag(make_shared<FinalBlockIdTag>(*finalBlockId));
168 Block bundleContent = bundleData.getContent();
169 bundleContent.parse();
172 for (
const auto& block : bundleContent.elements()) {
177 continueValidation(*cert, state);
182 CertificateBundleFetcher::nackCallback(
const lp::Nack& nack,
183 const shared_ptr<CertificateRequest>& certRequest,
184 const shared_ptr<ValidationState>& state,
185 const ValidationContinuation& continueValidation,
186 const Name& bundleName)
191 m_inner->fetch(certRequest, state, continueValidation);
195 CertificateBundleFetcher::timeoutCallback(
const shared_ptr<CertificateRequest>& certRequest,
196 const shared_ptr<ValidationState>& state,
197 const ValidationContinuation& continueValidation,
198 const Name& bundleName)
202 m_inner->fetch(certRequest, state, continueValidation);
206 CertificateBundleFetcher::deriveBundleName(
const Name&
name)
212 if (
name.size() >= 2 &&
name.get(-2).isSegment()) {
213 bundleName =
name.getPrefix(-2);
216 bundleName =
name.getPrefix(-1);
220 bundleName =
name.getPrefix(-1);
222 bundleName.append(
"_BUNDLE");
223 bundleName.appendNumber(00);
Copyright (c) 2011-2015 Regents of the University of California.
#define NDN_LOG_DEBUG_DEPTH(x)
Interest & setMustBeFresh(bool mustBeFresh)
Add or remove MustBeFresh element.
const Certificate * find(const Name &certPrefix) const
Get certificate given key name.
const Component & get(ssize_t i) const
Get the component at the given index.
void setBundleInterestLifetime(time::milliseconds time)
Set the lifetime of certificate bundle interest.
CertificateStorage * m_certStorage
NDN_CXX_DEPRECATED Interest & setChildSelector(int childSelector)
void cacheUnverifiedCert(Certificate &&cert)
Cache unverified certificate for a period of time (5 minutes)
Represents an Interest packet.
std::function< void(const Certificate &cert, const shared_ptr< ValidationState > &state)> ValidationContinuation
CertificateBundleFetcher(unique_ptr< CertificateFetcher > inner, Face &face)
represents a Network Nack
Validation state for a data packet.
NackReason getReason() const
provides a tag type for simple types
static Component fromSegment(uint64_t segmentNo)
Create segment number component using NDN naming conventions.
Component getSuccessor() const
#define NDN_LOG_INIT(name)
declare a log module
const CertificateCache & getUnverifiedCertCache() const
const Block & get(uint32_t type) const
Get the first sub element of specified TLV-TYPE.
Storage for trusted anchors, verified certificate cache, and unverified certificate cache...
bool isSegment() const
Check if the component is segment number per NDN naming conventions.
Provide a communication channel with local or remote NDN forwarder.
void doFetch(const shared_ptr< CertificateRequest > &certRequest, const shared_ptr< ValidationState > &state, const ValidationContinuation &continueValidation) override
Asynchronous certificate fetching implementation.
bool isImplicitSha256Digest() const
Check if the component is ImplicitSha256DigestComponent.
Represents an absolute name.
Fetch certificate bundle from the network.
Represents a name component.
bool empty() const
Check if name is empty.
Interest & setInterestLifetime(time::milliseconds lifetime)
Set Interest's lifetime.
const PendingInterestId * expressInterest(const Interest &interest, const DataCallback &afterSatisfied, const NackCallback &afterNacked, const TimeoutCallback &afterTimeout)
Express Interest.
Represents a Data packet.
void setCertificateStorage(CertificateStorage &certStorage) override
Set the storage for this and inner certificate fetcher.
time::milliseconds getBundleInterestLifetime() const