Utility class to fetch latest version of the segmented data. More...
#include <segment-fetcher.hpp>
Public Types | |
enum | ErrorCode { INTEREST_TIMEOUT = 1, DATA_HAS_NO_SEGMENT = 2, SEGMENT_VERIFICATION_FAIL = 3 } |
Error codes that can be passed to ErrorCallback. More... | |
typedef function< void(const ConstBufferPtr &data)> | CompleteCallback |
typedef function< bool(const Data &data)> | VerifySegment |
typedef function< void(uint32_t code, const std::string &msg)> | ErrorCallback |
Static Public Member Functions | |
static void | fetch (Face &face, const Interest &baseInterest, const VerifySegment &verifySegment, const CompleteCallback &completeCallback, const ErrorCallback &errorCallback) |
Initiate segment fetching. More... | |
Utility class to fetch latest version of the segmented data.
SegmentFetcher assumes that the data is named /<prefix>/<version>/<segment>, where:
FinalBlockId
field in at least the last Data packetThe following logic is implemented in SegmentFetcher:
Interest: /<prefix>?ChildSelector=1&MustBeFresh=yes
Interest: /<prefix>/<version>/<segment=0>
Interest: /<prefix>/<version>/<segment=(N+1))>
If an error occurs during the fetching process, an error callback is fired 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 segment as a last component of the name (not counting implicit digest)SEGMENT_VERIFICATION_FAIL
: if any retrieved segment fails user-provided validationIn order to validate individual segments, an VerifySegment callback needs to be specified. If the callback returns false, fetching process is aborted with SEGMENT_VERIFICATION_FAIL. If data validation is not required, provided DontVerifySegment() functor can be used.
Examples:
void onComplete(const ConstBufferPtr& data) { ... } void onError(uint32_t errorCode, const std::string& errorMsg) { ... } ... SegmentFetcher::fetch(face, Interest("/data/prefix", time::seconds(1000)), DontVerifySegment(), bind(&onComplete, this, _1), bind(&onError, this, _1, _2));
Definition at line 112 of file segment-fetcher.hpp.
typedef function<void (const ConstBufferPtr& data)> ndn::util::SegmentFetcher::CompleteCallback |
Definition at line 115 of file segment-fetcher.hpp.
typedef function<bool (const Data& data)> ndn::util::SegmentFetcher::VerifySegment |
Definition at line 116 of file segment-fetcher.hpp.
typedef function<void (uint32_t code, const std::string& msg)> ndn::util::SegmentFetcher::ErrorCallback |
Definition at line 117 of file segment-fetcher.hpp.
Error codes that can be passed to ErrorCallback.
Enumerator | |
---|---|
INTEREST_TIMEOUT | |
DATA_HAS_NO_SEGMENT | |
SEGMENT_VERIFICATION_FAIL |
Definition at line 122 of file segment-fetcher.hpp.
|
static |
Initiate segment fetching.
face | Reference to the Face that should be used to fetch data |
baseInterest | An Interest for the initial segment of requested data. This interest may include custom InterestLifetime and selectors that will propagate to all subsequent Interests. The only exception is that the initial Interest will be forced to include "ChildSelector=1" and "MustBeFresh=true" selectors, which will be turned off in subsequent Interests. |
verifySegment | Functor to be called when Data segment is received. If functor return false, fetching will be aborted with SEGMENT_VERIFICATION_FAIL error |
completeCallback | Callback to be fired when all segments are fetched |
errorCallback | Callback to be fired when an error occurs ( |
Definition at line 42 of file segment-fetcher.cpp.
References ndn::Name::appendSegment(), ndn::name::Component::empty(), ndn::Name::get(), ndn::Data::getContent(), ndn::MetaInfo::getFinalBlockId(), ndn::Data::getMetaInfo(), ndn::Data::getName(), ndn::Name::getPrefix(), ndn::Interest::refreshNonce(), ndn::Interest::setChildSelector(), ndn::Interest::setMustBeFresh(), ndn::Interest::setName(), ndn::name::Component::toSegment(), ndn::Block::value(), and ndn::Block::value_size().