ndn::SegmentFetcher Class Reference

Utility class to fetch a versioned and segmented object. More...

#include <ndn-cxx/util/segment-fetcher.hpp>

+ Inheritance diagram for ndn::SegmentFetcher:
+ Collaboration diagram for ndn::SegmentFetcher:

Public Types

enum  ErrorCode {
  INTEREST_TIMEOUT = 1 ,
  DATA_HAS_NO_SEGMENT = 2 ,
  SEGMENT_VALIDATION_FAIL = 3 ,
  NACK_ERROR = 4 ,
  FINALBLOCKID_NOT_SEGMENT = 5
}
 Error codes passed to onError. More...
 
using Options = SegmentFetcherOptions
 

Public Member Functions

void stop ()
 Stops fetching. More...
 

Static Public Member Functions

static shared_ptr< SegmentFetcherstart (Face &face, const Interest &baseInterest, security::Validator &validator, const Options &options={})
 Initiates segment fetching. More...
 

Public Attributes

signal::Signal< SegmentFetcherafterSegmentNacked
 Emitted whenever an Interest for a data segment is nacked. More...
 
signal::Signal< SegmentFetcher, DataafterSegmentReceived
 Emitted whenever a data segment received. More...
 
signal::Signal< SegmentFetcherafterSegmentTimedOut
 Emitted whenever an Interest for a data segment times out. More...
 
signal::Signal< SegmentFetcher, DataafterSegmentValidated
 Emitted whenever a received data segment has been successfully validated. More...
 
signal::Signal< SegmentFetcher, ConstBufferPtronComplete
 Emitted upon successful retrieval of the complete object (all segments). More...
 
signal::Signal< SegmentFetcher, uint32_t, std::string > onError
 Emitted when the retrieval could not be completed due to an error. More...
 
signal::Signal< SegmentFetcheronInOrderComplete
 Emitted on successful retrieval of all segments in 'in order' mode. More...
 
signal::Signal< SegmentFetcher, ConstBufferPtronInOrderData
 Emitted after each data segment in segment order has been validated. More...
 

Detailed Description

Utility class to fetch a versioned and segmented object.

SegmentFetcher assumes that segments in the object are named /<prefix>/<version>/<segment>, where:

  • <prefix> is an arbitrary name prefix;
  • <version> is the version number (VersionNameComponent);
  • <segment> is the segment number (SegmentNameComponent).

The number of segments in the object is generally unknown until a Data packet containing a FinalBlockId field is received and validated.

The version can either be provided by the application or be discovered at the beginning of the fetching process. By default, SegmentFetcher will attempt to probe the latest version of the object by requesting only "fresh" segments during the initial discovery phase. This behavior can be turned off by setting Options::probeLatestVersion to false.

SegmentFetcher implements the following logic:

  1. If the application does not provide a <version> component and requires probing the latest version of the object, an Interest with CanBePrefix and MustBeFresh is sent to discover a fresh version. Otherwise, only CanBePrefix is set.
  2. Infer the version of the object: version = data.getName().get(-2).toVersion().
  3. Keep sending Interests for future segments until an error occurs or the number of segments indicated by the FinalBlockId in a received Data packet is reached. This retrieval will start at segment 1 if segment 0 was received in response to the Interest expressed in step 2; otherwise, retrieval will start at segment 0. By default, congestion control will be used to manage the Interest window size. Interests expressed in this step will follow this Name format: /<prefix>/<version>/<segment=(N)>.
  4. If set to 'block' mode, signal onComplete passing a memory buffer that combines the content of all segments in the object. If set to 'in order' mode, signal onInOrderData is triggered upon validation of each segment in segment order, storing later segments that arrived out of order internally until all earlier segments have arrived and have been validated.

If an error occurs during the fetching process, onError is signaled with one of the error codes from SegmentFetcher::ErrorCode.

A Validator instance must be specified to validate individual segments. Every time a segment has been successfully validated, afterSegmentValidated will be signaled.

Example:

auto fetcher = SegmentFetcher::start(face, Interest("/data/prefix"), validator);
fetcher->onComplete.connect([] (ConstBufferPtr data) {...});
fetcher->onError.connect([] (uint32_t errorCode, const std::string& errorMsg) {...});
static shared_ptr< SegmentFetcher > start(Face &face, const Interest &baseInterest, security::Validator &validator, const Options &options={})
Initiates segment fetching.
@ Interest
Definition: tlv.hpp:68
std::shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:140

Definition at line 126 of file segment-fetcher.hpp.

Member Typedef Documentation

◆ Options

Member Enumeration Documentation

◆ ErrorCode

Error codes passed to onError.

Enumerator
INTEREST_TIMEOUT 

Retrieval timed out because the maximum timeout between the successful receipt of segments was exceeded.

DATA_HAS_NO_SEGMENT 

One of the retrieved Data packets lacked a segment number in the last Name component (excl. implicit digest)

SEGMENT_VALIDATION_FAIL 

One of the retrieved segments failed user-provided validation.

NACK_ERROR 

An unrecoverable Nack was received during retrieval.

FINALBLOCKID_NOT_SEGMENT 

A received FinalBlockId did not contain a segment component.

Definition at line 132 of file segment-fetcher.hpp.

Member Function Documentation

◆ start()

shared_ptr< SegmentFetcher > ndn::SegmentFetcher::start ( Face face,
const Interest baseInterest,
security::Validator validator,
const Options options = {} 
)
static

Initiates segment fetching.

Transfer completion, failure, and progress are indicated via signals.

Parameters
faceReference to the Face that should be used to fetch data.
baseInterestInterest for the initial segment of requested data. This Interest may include certain fields, such as ForwardingHint, that will propagate to all subsequent Interests sent by this SegmentFetcher. As a special case, the initial Interest will be forced to include the CanBePrefix field, which will not be included in subsequent Interests. If Options::probeLatestVersion is true, the initial Interest will also be forced to include the MustBeFresh field, while all subsequent Interests will not include it.
validatorReference to the Validator the fetcher will use to validate data. The caller must ensure the validator remains valid until either onComplete or onError has been signaled.
optionsOptions controlling the transfer.
Returns
A shared_ptr to the constructed SegmentFetcher. This shared_ptr is kept internally for the lifetime of the transfer. Therefore, it does not need to be saved and is provided here so that the SegmentFetcher's signals can be connected to.

Definition at line 76 of file segment-fetcher.cpp.

◆ stop()

void ndn::SegmentFetcher::stop ( )

Stops fetching.

This cancels all interests that are still pending.

Definition at line 88 of file segment-fetcher.cpp.

Member Data Documentation

◆ afterSegmentNacked

signal::Signal<SegmentFetcher> ndn::SegmentFetcher::afterSegmentNacked

Emitted whenever an Interest for a data segment is nacked.

Definition at line 278 of file segment-fetcher.hpp.

◆ afterSegmentReceived

signal::Signal<SegmentFetcher, Data> ndn::SegmentFetcher::afterSegmentReceived

Emitted whenever a data segment received.

Definition at line 268 of file segment-fetcher.hpp.

◆ afterSegmentTimedOut

signal::Signal<SegmentFetcher> ndn::SegmentFetcher::afterSegmentTimedOut

Emitted whenever an Interest for a data segment times out.

Definition at line 283 of file segment-fetcher.hpp.

◆ afterSegmentValidated

signal::Signal<SegmentFetcher, Data> ndn::SegmentFetcher::afterSegmentValidated

Emitted whenever a received data segment has been successfully validated.

Definition at line 273 of file segment-fetcher.hpp.

◆ onComplete

signal::Signal<SegmentFetcher, ConstBufferPtr> ndn::SegmentFetcher::onComplete

Emitted upon successful retrieval of the complete object (all segments).

Note
Emitted only if SegmentFetcher is operating in 'block' mode.

Definition at line 256 of file segment-fetcher.hpp.

◆ onError

signal::Signal<SegmentFetcher, uint32_t, std::string> ndn::SegmentFetcher::onError

Emitted when the retrieval could not be completed due to an error.

Handlers are provided with an error code and a string error message.

Definition at line 263 of file segment-fetcher.hpp.

◆ onInOrderComplete

signal::Signal<SegmentFetcher> ndn::SegmentFetcher::onInOrderComplete

Emitted on successful retrieval of all segments in 'in order' mode.

Note
Emitted only if SegmentFetcher is operating in 'in order' mode.

Definition at line 295 of file segment-fetcher.hpp.

◆ onInOrderData

signal::Signal<SegmentFetcher, ConstBufferPtr> ndn::SegmentFetcher::onInOrderData

Emitted after each data segment in segment order has been validated.

Note
Emitted only if SegmentFetcher is operating in 'in order' mode.

Definition at line 289 of file segment-fetcher.hpp.