NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: 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; -*- */
2 /*
3  * Copyright (c) 2013-2018 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 "../common.hpp"
26 #include "../face.hpp"
27 #include "../security/v2/validator.hpp"
28 #include "scheduler.hpp"
29 #include "signal.hpp"
30 
31 namespace ndn {
32 
33 class OBufferStream;
34 
35 namespace util {
36 
102 class SegmentFetcher : noncopyable
103 {
104 public:
108  static const uint32_t MAX_INTEREST_REEXPRESS;
109 
110  typedef function<void (const ConstBufferPtr& data)> CompleteCallback;
111  typedef function<void (uint32_t code, const std::string& msg)> ErrorCallback;
112 
116  enum ErrorCode {
121  };
122 
141  static
142  shared_ptr<SegmentFetcher>
143  fetch(Face& face,
144  const Interest& baseInterest,
145  security::v2::Validator& validator,
146  const CompleteCallback& completeCallback,
147  const ErrorCallback& errorCallback);
148 
165  static
166  shared_ptr<SegmentFetcher>
167  fetch(Face& face,
168  const Interest& baseInterest,
169  shared_ptr<security::v2::Validator> validator,
170  const CompleteCallback& completeCallback,
171  const ErrorCallback& errorCallback);
172 
173 private:
175  shared_ptr<security::v2::Validator> validator,
176  const CompleteCallback& completeCallback,
177  const ErrorCallback& errorCallback);
178 
179  void
180  fetchFirstSegment(const Interest& baseInterest, shared_ptr<SegmentFetcher> self);
181 
182  void
183  fetchNextSegment(const Interest& origInterest, const Name& dataName, uint64_t segmentNo,
184  shared_ptr<SegmentFetcher> self);
185 
186  void
187  afterSegmentReceivedCb(const Interest& origInterest,
188  const Data& data, bool isSegmentZeroExpected,
189  shared_ptr<SegmentFetcher> self);
190  void
191  afterValidationSuccess(const Data& data,
192  bool isSegmentZeroExpected,
193  const Interest& origInterest,
194  shared_ptr<SegmentFetcher> self);
195 
196  void
197  afterValidationFailure(const Data& data, const security::v2::ValidationError& error);
198 
199  void
200  afterNackReceivedCb(const Interest& origInterest, const lp::Nack& nack,
201  uint32_t reExpressCount, shared_ptr<SegmentFetcher> self);
202 
203  void
204  reExpressInterest(Interest interest, uint32_t reExpressCount,
205  shared_ptr<SegmentFetcher> self);
206 
207 public:
212 
217 
218 private:
219  Face& m_face;
220  Scheduler m_scheduler;
221  shared_ptr<security::v2::Validator> m_validator;
222  CompleteCallback m_completeCallback;
223  ErrorCallback m_errorCallback;
224 
225  shared_ptr<OBufferStream> m_buffer;
226 };
227 
228 } // namespace util
229 } // namespace ndn
230 
231 #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
static shared_ptr< SegmentFetcher > fetch(Face &face, const Interest &baseInterest, security::v2::Validator &validator, const CompleteCallback &completeCallback, const ErrorCallback &errorCallback)
Initiates segment fetching.
Utility class to fetch latest version of the segmented data.
Represents an Interest packet.
Definition: interest.hpp:42
provides a lightweight signal / event system
Definition: signal.hpp:50
represents a Network Nack
Definition: nack.hpp:40
ErrorCode
Error codes that can be passed to ErrorCallback.
Provide a communication channel with local or remote NDN forwarder.
Definition: face.hpp:90
Signal< SegmentFetcher, Data > afterSegmentValidated
Emits whenever a received data segment has been successfully validated.
Represents an absolute name.
Definition: name.hpp:42
Signal< SegmentFetcher, Data > afterSegmentReceived
Emits whenever a data segment received.
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