NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
segment-fetcher.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NDN_UTIL_SEGMENT_FETCHER_HPP
23 #define NDN_UTIL_SEGMENT_FETCHER_HPP
24 
25 #include "../common.hpp"
26 #include "../face.hpp"
27 
28 namespace ndn {
29 
30 class OBufferStream;
31 
32 namespace util {
33 
38 {
39 public:
40  bool
41  operator()(const Data& data) const
42  {
43  return true;
44  }
45 };
46 
112 class SegmentFetcher : noncopyable
113 {
114 public:
115  typedef function<void (const ConstBufferPtr& data)> CompleteCallback;
116  typedef function<bool (const Data& data)> VerifySegment;
117  typedef function<void (uint32_t code, const std::string& msg)> ErrorCallback;
118 
122  enum ErrorCode {
123  INTEREST_TIMEOUT = 1,
124  DATA_HAS_NO_SEGMENT = 2,
125  SEGMENT_VERIFICATION_FAIL = 3
126  };
127 
144  static
145  void
146  fetch(Face& face,
147  const Interest& baseInterest,
148  const VerifySegment& verifySegment,
149  const CompleteCallback& completeCallback,
150  const ErrorCallback& errorCallback);
151 
152 private:
153  SegmentFetcher(Face& face,
154  const VerifySegment& verifySegment,
155  const CompleteCallback& completeCallback,
156  const ErrorCallback& errorCallback);
157 
158  void
159  fetchFirstSegment(const Interest& baseInterest, const shared_ptr<SegmentFetcher>& self);
160 
161  void
162  fetchNextSegment(const Interest& origInterest, const Name& dataName, uint64_t segmentNo,
163  const shared_ptr<SegmentFetcher>& self);
164 
165  void
166  onSegmentReceived(const Interest& origInterest,
167  const Data& data, bool isSegmentZeroExpected,
168  const shared_ptr<SegmentFetcher>& self);
169 
170 private:
171  Face& m_face;
172  VerifySegment m_verifySegment;
173  CompleteCallback m_completeCallback;
174  ErrorCallback m_errorCallback;
175 
176  shared_ptr<OBufferStream> m_buffer;
177 };
178 
179 } // util
180 } // ndn
181 
182 #endif // NDN_UTIL_SEGMENT_FETCHER_HPP
Copyright (c) 2011-2015 Regents of the University of California.
function< void(uint32_t code, const std::string &msg)> ErrorCallback
Utility class to fetch latest version of the segmented data.
function< bool(const Data &data)> VerifySegment
represents an Interest packet
Definition: interest.hpp:45
bool operator()(const Data &data) const
Functor to skip validation of individual packets by SegmentFetcher.
ErrorCode
Error codes that can be passed to ErrorCallback.
Abstraction to communicate with local or remote NDN forwarder.
Definition: face.hpp:100
Name abstraction to represent an absolute name.
Definition: name.hpp:46
represents a Data packet
Definition: data.hpp:39
function< void(const ConstBufferPtr &data)> CompleteCallback