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,
68 auto dataValidationState = dynamic_pointer_cast<DataValidationState>(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));
132 dataCallback(data,
false, certRequest, state, continueValidation);
135 nackCallback(nack, certRequest, state, continueValidation, fullBundleName);
138 timeoutCallback(certRequest, state, continueValidation, fullBundleName);
143 CertificateBundleFetcher::dataCallback(
const Data& bundleData,
144 bool isSegmentZeroExpected,
145 const shared_ptr<CertificateRequest>& certRequest,
146 const shared_ptr<ValidationState>& state,
147 const ValidationContinuation& continueValidation)
153 return m_inner->fetch(certRequest, state, continueValidation);
156 if (isSegmentZeroExpected && currentSegment.
toSegment() != 0) {
159 certRequest, state, continueValidation);
162 state->setTag(make_shared<BundleNameTag>(bundleData.getName()));
164 const auto& finalBlockId = bundleData.getFinalBlock();
166 state->setTag(make_shared<FinalBlockIdTag>(*finalBlockId));
169 Block bundleContent = bundleData.getContent();
170 bundleContent.parse();
173 for (
const auto& block : bundleContent.elements()) {
178 continueValidation(*cert, state);
183 CertificateBundleFetcher::nackCallback(
const lp::Nack& nack,
184 const shared_ptr<CertificateRequest>& certRequest,
185 const shared_ptr<ValidationState>& state,
186 const ValidationContinuation& continueValidation,
187 const Name& bundleName)
192 m_inner->fetch(certRequest, state, continueValidation);
196 CertificateBundleFetcher::timeoutCallback(
const shared_ptr<CertificateRequest>& certRequest,
197 const shared_ptr<ValidationState>& state,
198 const ValidationContinuation& continueValidation,
199 const Name& bundleName)
203 m_inner->fetch(certRequest, state, continueValidation);
207 CertificateBundleFetcher::deriveBundleName(
const Name&
name)
213 if (
name.size() >= 2 &&
name.get(-2).isSegment()) {
214 bundleName =
name.getPrefix(-2);
217 bundleName =
name.getPrefix(-1);
221 bundleName =
name.getPrefix(-1);
223 bundleName.append(
"_BUNDLE");
224 bundleName.appendNumber(00);