All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
generalized-content.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_GENERALIZED_CONTENT_HPP
23 #define NDN_GENERALIZED_CONTENT_HPP
24 
25 #include <ndn-cpp/face.hpp>
26 #include <ndn-cpp/util/segment-fetcher.hpp>
27 #include <ndn-cpp/util/memory-content-cache.hpp>
28 #include "content-meta-info.hpp"
29 
30 namespace ndntools {
31 
37 class GeneralizedContent : public ndn::ptr_lib::enable_shared_from_this<GeneralizedContent> {
38 public:
39  enum ErrorCode {
40  // Repeat the error codes from SegmentFetcher.
41  INTEREST_TIMEOUT = 1,
42  DATA_HAS_NO_SEGMENT = 2,
43  SEGMENT_VERIFICATION_FAILED = 3,
44 
45  META_INFO_DECODING_FAILED = 4
46  };
47 
48  typedef ndn::func_lib::function<void
49  (const ndn::ptr_lib::shared_ptr<ContentMetaInfo>& metaInfo,
50  const ndn::Blob& content)> OnComplete;
51 
52  typedef ndn::func_lib::function<void
53  (ErrorCode errorCode, const std::string& message)> OnError;
54 
76  static void
77  publish
78  (ndn::MemoryContentCache& contentCache, const ndn::Name& prefix,
79  ndn::Milliseconds freshnessPeriod, ndn::KeyChain* signingKeyChain,
80  const ndn::Name& signingCertificateName, const ContentMetaInfo& metaInfo,
81  const ndn::Blob& content, size_t contentSegmentSize);
82 
113  static void
114  fetch
115  (ndn::Face& face, const ndn::Name& prefix, ndn::KeyChain* validatorKeyChain,
116  const OnComplete& onComplete, const OnError& onError,
117  ndn::Milliseconds interestLifetimeMilliseconds = 4000.0);
118 
119 private:
125  (ndn::Face& face, const ndn::Name& prefix, ndn::KeyChain* validatorKeyChain,
126  const OnComplete& onComplete, const OnError& onError,
127  ndn::Milliseconds interestLifetimeMilliseconds)
128  : face_(face), prefix_(prefix), validatorKeyChain_(validatorKeyChain),
129  onComplete_(onComplete), onError_(onError),
130  interestLifetimeMilliseconds_(interestLifetimeMilliseconds)
131  {
132  }
133 
134  void
135  fetchMetaInfo();
136 
137  void
138  onMetaInfoReceived
139  (const ndn::ptr_lib::shared_ptr<const ndn::Interest>& originalInterest,
140  const ndn::ptr_lib::shared_ptr<ndn::Data>& data);
141 
142  void
143  onMetaInfoTimeout(const ndn::ptr_lib::shared_ptr<const ndn::Interest>& interest);
144 
145  void
146  onContentReceived(const ndn::Blob& content);
147 
148  void
149  onSegmentFetcherError
150  (ndn::SegmentFetcher::ErrorCode errorCode, const std::string& message);
151 
152  ndn::Face& face_;
153  ndn::Name prefix_;
154  ndn::KeyChain* validatorKeyChain_;
155  OnComplete onComplete_;
156  OnError onError_;
157  ndn::Milliseconds interestLifetimeMilliseconds_;
158  ndn::ptr_lib::shared_ptr<ContentMetaInfo> metaInfo_;
159 };
160 
161 }
162 
163 #endif
double Milliseconds
A time interval represented as the number of milliseconds.
Definition: common.hpp:114
A MemoryContentCache holds a set of Data packets and answers an Interest to return the correct Data p...
Definition: memory-content-cache.hpp:38
The Face class provides the main methods for NDN communication.
Definition: face.hpp:86
KeyChain is the main class of the security library.
Definition: key-chain.hpp:53
ContentMetaInfo represents the information in the _meta packet of a Generalized Content.
Definition: content-meta-info.hpp:33
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:40
A Blob holds a pointer to an immutable byte array implemented as const std::vector<uint8_t>.
Definition: blob.hpp:42
static void fetch(ndn::Face &face, const ndn::Name &prefix, ndn::KeyChain *validatorKeyChain, const OnComplete &onComplete, const OnError &onError, ndn::Milliseconds interestLifetimeMilliseconds=4000.0)
Initiate meta info and segmented content fetching.
Definition: generalized-content.cpp:83
static void publish(ndn::MemoryContentCache &contentCache, const ndn::Name &prefix, ndn::Milliseconds freshnessPeriod, ndn::KeyChain *signingKeyChain, const ndn::Name &signingCertificateName, const ContentMetaInfo &metaInfo, const ndn::Blob &content, size_t contentSegmentSize)
Use the contentCache to publish a Data packet named [prefix]/_meta whose content is the encoded metaI...
Definition: generalized-content.cpp:35
GeneralizedContent has the static publish and fetch methods which fetches meta info and segmented con...
Definition: generalized-content.hpp:37