Utility class to fetch the latest version of a segmented object. More...
#include <segment-fetcher.hpp>
Classes | |
class | Options |
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... | |
Public Member Functions | |
void | stop () |
Stops fetching. More... | |
Static Public Member Functions | |
static shared_ptr< SegmentFetcher > | start (Face &face, const Interest &baseInterest, security::Validator &validator, const Options &options=Options()) |
Initiates segment fetching. More... | |
Public Attributes | |
Signal< SegmentFetcher, ConstBufferPtr > | onComplete |
Emitted upon successful retrieval of the complete object (all segments). More... | |
Signal< SegmentFetcher, uint32_t, std::string > | onError |
Emitted when the retrieval could not be completed due to an error. More... | |
Signal< SegmentFetcher, Data > | afterSegmentReceived |
Emitted whenever a data segment received. More... | |
Signal< SegmentFetcher, Data > | afterSegmentValidated |
Emitted whenever a received data segment has been successfully validated. More... | |
Signal< SegmentFetcher > | afterSegmentNacked |
Emitted whenever an Interest for a data segment is nacked. More... | |
Signal< SegmentFetcher > | afterSegmentTimedOut |
Emitted whenever an Interest for a data segment times out. More... | |
Signal< SegmentFetcher, ConstBufferPtr > | onInOrderData |
Emitted after each data segment in segment order has been validated. More... | |
Signal< SegmentFetcher > | onInOrderComplete |
Emitted on successful retrieval of all segments in 'in order' mode. More... | |
Utility class to fetch the latest version of a segmented object.
SegmentFetcher assumes that segments in the object are named /<prefix>/<version>/<segment>
, where:
<prefix>
is the specified prefix,<version>
is an unknown version that needs to be discovered, and<segment>
is a segment number (the number of segments in the object is unknown until a Data packet containing the FinalBlockId
field is received).SegmentFetcher implements the following logic:
Express an Interest to discover the latest version of the object:
Interest: /<prefix>?CanBePrefix&MustBeFresh
<version> = Data.getName().get(-2)
./<prefix>/<version>/<segment=(N)>
.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:
Definition at line 80 of file segment-fetcher.hpp.
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 86 of file segment-fetcher.hpp.
|
static |
Initiates segment fetching.
Transfer completion, failure, and progress are indicated via signals.
face | Reference to the Face that should be used to fetch data. |
baseInterest | Interest for the initial segment of requested data. This interest may include a custom InterestLifetime and parameters that will propagate to all subsequent Interests. The only exception is that the initial Interest will be forced to include the "CanBePrefix=true" and "MustBeFresh=true" parameters, which will not be included in subsequent Interests. |
validator | Reference 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. |
options | Options controlling the transfer. |
Definition at line 77 of file segment-fetcher.cpp.
Referenced by ndn::nfd::Controller::~Controller().
void ndn::util::SegmentFetcher::stop | ( | ) |
Stops fetching.
This cancels all interests that are still pending.
Definition at line 89 of file segment-fetcher.cpp.
References afterSegmentNacked, afterSegmentReceived, afterSegmentTimedOut, afterSegmentValidated, ndn::OBufferStream::buf(), ndn::lp::CONGESTION, DATA_HAS_NO_SEGMENT, ndn::lp::DUPLICATE, FINALBLOCKID_NOT_SEGMENT, ndn::Name::get(), ndn::PacketBase::getCongestionMark(), ndn::Data::getContent(), ndn::Data::getFinalBlock(), ndn::Data::getName(), ndn::Interest::getName(), ndn::Name::getPrefix(), ndn::lp::Nack::getReason(), INTEREST_TIMEOUT, ndn::name::Component::isSegment(), nonstd::optional_lite::std11::move(), NACK_ERROR, ns3::ndn::Name, ndn::time::steady_clock::now(), onComplete, onError, onInOrderComplete, onInOrderData, ndn::Interest::refreshNonce(), SEGMENT_VALIDATION_FAIL, ndn::Interest::setCanBePrefix(), ndn::Interest::setInterestLifetime(), ndn::Interest::setMustBeFresh(), ndn::Interest::setName(), nonstd::span_lite::size(), websocketpp::transport::error::timeout, ndn::name::Component::toSegment(), ndn::Block::value_begin(), ndn::Block::value_end(), and ndn::Block::value_size().
Signal<SegmentFetcher, ConstBufferPtr> ndn::util::SegmentFetcher::onComplete |
Emitted upon successful retrieval of the complete object (all segments).
Definition at line 235 of file segment-fetcher.hpp.
Referenced by stop().
Signal<SegmentFetcher, uint32_t, std::string> ndn::util::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 242 of file segment-fetcher.hpp.
Referenced by stop().
Signal<SegmentFetcher, Data> ndn::util::SegmentFetcher::afterSegmentReceived |
Emitted whenever a data segment received.
Definition at line 247 of file segment-fetcher.hpp.
Referenced by stop().
Signal<SegmentFetcher, Data> ndn::util::SegmentFetcher::afterSegmentValidated |
Emitted whenever a received data segment has been successfully validated.
Definition at line 252 of file segment-fetcher.hpp.
Referenced by stop().
Signal<SegmentFetcher> ndn::util::SegmentFetcher::afterSegmentNacked |
Emitted whenever an Interest for a data segment is nacked.
Definition at line 257 of file segment-fetcher.hpp.
Referenced by stop().
Signal<SegmentFetcher> ndn::util::SegmentFetcher::afterSegmentTimedOut |
Emitted whenever an Interest for a data segment times out.
Definition at line 262 of file segment-fetcher.hpp.
Referenced by stop().
Signal<SegmentFetcher, ConstBufferPtr> ndn::util::SegmentFetcher::onInOrderData |
Emitted after each data segment in segment order has been validated.
Definition at line 268 of file segment-fetcher.hpp.
Referenced by stop().
Signal<SegmentFetcher> ndn::util::SegmentFetcher::onInOrderComplete |
Emitted on successful retrieval of all segments in 'in order' mode.
Definition at line 274 of file segment-fetcher.hpp.
Referenced by stop().