Public Types | Static Public Member Functions | List of all members
ndn::SegmentFetcher Class Reference

SegmentFetcher is a utility class to the fetch latest version of segmented data. More...

#include <segment-fetcher.hpp>

Inheritance diagram for ndn::SegmentFetcher:

Public Types

enum  ErrorCode { INTEREST_TIMEOUT = 1, DATA_HAS_NO_SEGMENT = 2, SEGMENT_VERIFICATION_FAILED = 3 }
 
typedef func_lib::function< bool(const ptr_lib::shared_ptr< Data > &)> VerifySegment
 
typedef func_lib::function< void(const Blob &)> OnComplete
 
typedef func_lib::function< void(ErrorCode errorCode, const std::string &message)> OnError
 

Static Public Member Functions

static bool DontVerifySegment (const ptr_lib::shared_ptr< Data > &data)
 DontVerifySegment may be used in fetch to skip validation of Data packets.
 
static void fetch (Face &face, const Interest &baseInterest, const VerifySegment &verifySegment, const OnComplete &onComplete, const OnError &onError)
 Initiate segment fetching. More...
 

Detailed Description

SegmentFetcher is a utility class to the fetch latest version of segmented data.

SegmentFetcher assumes that the data is named /<prefix>/<version>/<segment>, where:

The following logic is implemented in SegmentFetcher:

  1. Express the first Interest to discover the version:

Interest: /<prefix>?ChildSelector=1&MustBeFresh=true

  1. Infer the latest version of the Data: <version> = Data.getName().get(-2)
  2. If the segment number in the retrieved packet == 0, go to step 5.
  3. Send an Interest for segment 0:

Interest: /<prefix>/<version>/<segment=0>

  1. Keep sending Interests for the next segment while the retrieved Data does not have a FinalBlockId or the FinalBlockId != Data.getName().get(-1).

Interest: /<prefix>/<version>/<segment=(N+1))>

  1. Call the OnComplete callback with a blob that concatenates the content from all the segmented objects.

If an error occurs during the fetching process, the OnError callback is called with a proper error code. The following errors are possible:

In order to validate individual segments, a VerifySegment callback needs to be specified. If the callback returns false, the fetching process is aborted with SEGMENT_VERIFICATION_FAILED. If data validation is not required, the provided DontVerifySegment object can be used.

Example: void onComplete(const Blob& encodedMessage);

void onError(SegmentFetcher::ErrorCode errorCode, const string& message);

Interest interest(Name("/data/prefix")); interest.setInterestLifetimeMilliseconds(1000);

SegmentFetcher.fetch (face, interest, SegmentFetcher::DontVerifySegment, onComplete, onError);

Member Function Documentation

void ndn::SegmentFetcher::fetch ( Face face,
const Interest baseInterest,
const VerifySegment &  verifySegment,
const OnComplete &  onComplete,
const OnError &  onError 
)
static

Initiate segment fetching.

For more details, see the documentation for the class.

Parameters
faceThis calls face.expressInterest to fetch more segments.
baseInterestAn Interest for the initial segment of the requested data, where baseInterest.getName() has the name prefix. This interest may include a custom InterestLifetime and selectors that will propagate to all subsequent Interests. The only exception is that the initial Interest will be forced to include selectors "ChildSelector=1" and "MustBeFresh=true" which will be turned off in subsequent Interests.
verifySegmentWhen a Data packet is received this calls verifySegment(data). If it returns false then abort fetching and call onError with SEGMENT_VERIFICATION_FAILED. If data validation is not required, use DontVerifySegment. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.
onCompleteWhen all segments are received, call onComplete(content) where content is the concatenation of the content of all the segments. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.
onErrorCall onError(errorCode, message) for timeout or an error processing segments. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.

The documentation for this class was generated from the following files: