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,
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,
120 shared_ptr<FinalBlockIdTag> finalBlockId = state->getTag<
FinalBlockIdTag>();
121 if (finalBlockId !=
nullptr && segmentNo > finalBlockId->
get()) {
122 return m_inner->fetch(certRequest, state, continueValidation);
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,
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()));
164 if (!finalBlockId.
empty()) {
165 state->setTag(make_shared<FinalBlockIdTag>(finalBlockId));
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,
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,
198 const Name& bundleName)
202 m_inner->fetch(certRequest, state, continueValidation);
206 CertificateBundleFetcher::deriveBundleName(
const Name& name)
210 Name bundleName = name;
222 bundleName.
append(
"_BUNDLE");
time::milliseconds getBundleInterestLifetime() const
Copyright (c) 2013-2017 Regents of the University of California.
The certificate following the certificate format naming convention.
const element_container & elements() const
Get container of sub elements.
#define NDN_LOG_DEBUG_DEPTH(x)
Interest & setMustBeFresh(bool mustBeFresh)
void setBundleInterestLifetime(time::milliseconds time)
Set the lifetime of certificate bundle interest.
CertificateStorage * m_certStorage
void cacheUnverifiedCert(Certificate &&cert)
Cache unverified certificate for a period of time (5 minutes)
Represents a TLV element of NDN packet format.
represents an Interest packet
const MetaInfo & getMetaInfo() const
Get MetaInfo.
std::function< void(const Certificate &cert, const shared_ptr< ValidationState > &state)> ValidationContinuation
CertificateBundleFetcher(unique_ptr< CertificateFetcher > inner, Face &face)
#define NDN_LOG_INIT(name)
declare a log module
const Certificate * find(const Name &certPrefix) const
Get certificate given key name.
Name & appendNumber(uint64_t number)
Append a component with a nonNegativeInteger.
Name & append(const Component &component)
Append a component.
represents a Network Nack
Validation state for a data packet.
provides a tag type for simple types
NackReason getReason() const
static Component fromSegment(uint64_t segmentNo)
Create segment number component using NDN naming conventions.
bool isSegment() const
Check if the component is segment number per NDN naming conventions.
const CertificateCache & getUnverifiedCertCache() const
Interest & setChildSelector(int childSelector)
Storage for trusted anchors, verified certificate cache, and unverified certificate cache...
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.
const Block & get(uint32_t type) const
Get the first sub element of specified TLV-TYPE.
size_t size() const
Get number of components.
Represents an absolute name.
const Component & at(ssize_t i) const
Get the component at the given index.
Fetch certificate bundle from the network.
void parse() const
Parse TLV-VALUE into sub elements.
Component getSuccessor() const
const Name & getName() const
Get name.
Component holds a read-only name component value.
Interest & setInterestLifetime(time::milliseconds interestLifetime)
Set Interest's lifetime.
const Block & getContent() const
Get Content.
bool empty() const
Check if name is empty.
PartialName getPrefix(ssize_t nComponents) const
Extract a prefix of the name.
const PendingInterestId * expressInterest(const Interest &interest, const DataCallback &afterSatisfied, const NackCallback &afterNacked, const TimeoutCallback &afterTimeout)
Express Interest.
Represents a Data packet.
const Component & get(ssize_t i) const
Get the component at the given index.
void setCertificateStorage(CertificateStorage &certStorage) override
Set the storage for this and inner certificate fetcher.
bool isImplicitSha256Digest() const
Check if the component is ImplicitSha256DigestComponent.