SegmentFetcher is a utility class to the fetch latest version of segmented data. More...
#include <segment-fetcher.hpp>
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... | |
SegmentFetcher is a utility class to the fetch latest version of segmented data.
SegmentFetcher assumes that the data is named /<prefix>/<version>/<segment>, where:
FinalBlockId
field in at least the last Data packet.The following logic is implemented in SegmentFetcher:
Interest: /<prefix>?ChildSelector=1&MustBeFresh=true
Interest: /<prefix>/<version>/<segment=0>
Interest: /<prefix>/<version>/<segment=(N+1))>
If an error occurs during the fetching process, the OnError callback is called with a proper error code. The following errors are possible:
INTEREST_TIMEOUT
: if any of the Interests times outDATA_HAS_NO_SEGMENT
: if any of the retrieved Data packets don't have a segment as the last component of the name (not counting the implicit digest)SEGMENT_VERIFICATION_FAILED
: if any retrieved segment fails the user-provided VerifySegment callbackIn 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);
|
static |
Initiate segment fetching.
For more details, see the documentation for the class.
face | This calls face.expressInterest to fetch more segments. |
baseInterest | An 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. |
verifySegment | When 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. |
onComplete | When 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. |
onError | Call 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. |