segment-fetcher.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2017 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
22 #ifndef NDN_UTIL_SEGMENT_FETCHER_HPP
23 #define NDN_UTIL_SEGMENT_FETCHER_HPP
24 
25 #include "scheduler.hpp"
26 #include "../common.hpp"
27 #include "../face.hpp"
28 #include "../security/v2/validator.hpp"
29 
30 namespace ndn {
31 
32 class OBufferStream;
33 
34 namespace util {
35 
101 class SegmentFetcher : noncopyable
102 {
103 public:
107  static const uint32_t MAX_INTEREST_REEXPRESS;
108 
109  typedef function<void (const ConstBufferPtr& data)> CompleteCallback;
110  typedef function<void (uint32_t code, const std::string& msg)> ErrorCallback;
111 
115  enum ErrorCode {
120  };
121 
139  static
140  void
141  fetch(Face& face,
142  const Interest& baseInterest,
143  security::v2::Validator& validator,
144  const CompleteCallback& completeCallback,
145  const ErrorCallback& errorCallback);
146 
162  static
163  void
164  fetch(Face& face,
165  const Interest& baseInterest,
166  shared_ptr<security::v2::Validator> validator,
167  const CompleteCallback& completeCallback,
168  const ErrorCallback& errorCallback);
169 
170 private:
171  SegmentFetcher(Face& face,
172  shared_ptr<security::v2::Validator> validator,
173  const CompleteCallback& completeCallback,
174  const ErrorCallback& errorCallback);
175 
176  void
177  fetchFirstSegment(const Interest& baseInterest, shared_ptr<SegmentFetcher> self);
178 
179  void
180  fetchNextSegment(const Interest& origInterest, const Name& dataName, uint64_t segmentNo,
181  shared_ptr<SegmentFetcher> self);
182 
183  void
184  afterSegmentReceived(const Interest& origInterest,
185  const Data& data, bool isSegmentZeroExpected,
186  shared_ptr<SegmentFetcher> self);
187  void
188  afterValidationSuccess(const Data& data,
189  bool isSegmentZeroExpected,
190  const Interest& origInterest,
191  shared_ptr<SegmentFetcher> self);
192 
193  void
194  afterValidationFailure(const Data& data, const security::v2::ValidationError& error);
195 
196  void
197  afterNackReceived(const Interest& origInterest, const lp::Nack& nack,
198  uint32_t reExpressCount, shared_ptr<SegmentFetcher> self);
199 
200  void
201  reExpressInterest(Interest interest, uint32_t reExpressCount,
202  shared_ptr<SegmentFetcher> self);
203 
204 private:
205  Face& m_face;
206  Scheduler m_scheduler;
207  shared_ptr<security::v2::Validator> m_validator;
208  CompleteCallback m_completeCallback;
209  ErrorCallback m_errorCallback;
210 
211  shared_ptr<OBufferStream> m_buffer;
212 };
213 
214 } // namespace util
215 } // namespace ndn
216 
217 #endif // NDN_UTIL_SEGMENT_FETCHER_HPP
Copyright (c) 2013-2017 Regents of the University of California.
Definition: common.hpp:66
function< void(uint32_t code, const std::string &msg)> ErrorCallback
Utility class to fetch latest version of the segmented data.
represents an Interest packet
Definition: interest.hpp:42
represents a Network Nack
Definition: nack.hpp:40
ErrorCode
Error codes that can be passed to ErrorCallback.
static void fetch(Face &face, const Interest &baseInterest, security::v2::Validator &validator, const CompleteCallback &completeCallback, const ErrorCallback &errorCallback)
Initiate segment fetching.
Provide a communication channel with local or remote NDN forwarder.
Definition: face.hpp:95
Represents an absolute name.
Definition: name.hpp:42
Validation error code and optional detailed error message.
static const uint32_t MAX_INTEREST_REEXPRESS
Maximum number of times an interest will be reexpressed incase of NackCallback.
Represents a Data packet.
Definition: data.hpp:35
Interface for validating data and interest packets.
Definition: validator.hpp:61
function< void(const ConstBufferPtr &data)> CompleteCallback