util: add signals to SegmentFetcher for segment retrieval/validation
refs #4438
Change-Id: I5a92e89c733cf49790807edefa1e6c39178de438
diff --git a/src/util/segment-fetcher.cpp b/src/util/segment-fetcher.cpp
index 0d54915..b23b991 100644
--- a/src/util/segment-fetcher.cpp
+++ b/src/util/segment-fetcher.cpp
@@ -46,7 +46,7 @@
{
}
-void
+shared_ptr<SegmentFetcher>
SegmentFetcher::fetch(Face& face,
const Interest& baseInterest,
security::v2::Validator& validator,
@@ -54,10 +54,10 @@
const ErrorCallback& errorCallback)
{
shared_ptr<security::v2::Validator> validatorPtr(&validator, [] (security::v2::Validator*) {});
- fetch(face, baseInterest, validatorPtr, completeCallback, errorCallback);
+ return fetch(face, baseInterest, validatorPtr, completeCallback, errorCallback);
}
-void
+shared_ptr<SegmentFetcher>
SegmentFetcher::fetch(Face& face,
const Interest& baseInterest,
shared_ptr<security::v2::Validator> validator,
@@ -68,6 +68,8 @@
errorCallback));
fetcher->fetchFirstSegment(baseInterest, fetcher);
+
+ return fetcher;
}
void
@@ -79,8 +81,8 @@
interest.setMustBeFresh(true);
m_face.expressInterest(interest,
- bind(&SegmentFetcher::afterSegmentReceived, this, _1, _2, true, self),
- bind(&SegmentFetcher::afterNackReceived, this, _1, _2, 0, self),
+ bind(&SegmentFetcher::afterSegmentReceivedCb, this, _1, _2, true, self),
+ bind(&SegmentFetcher::afterNackReceivedCb, this, _1, _2, 0, self),
bind(m_errorCallback, INTEREST_TIMEOUT, "Timeout"));
}
@@ -95,16 +97,17 @@
interest.setMustBeFresh(false);
interest.setName(dataName.getPrefix(-1).appendSegment(segmentNo));
m_face.expressInterest(interest,
- bind(&SegmentFetcher::afterSegmentReceived, this, _1, _2, false, self),
- bind(&SegmentFetcher::afterNackReceived, this, _1, _2, 0, self),
+ bind(&SegmentFetcher::afterSegmentReceivedCb, this, _1, _2, false, self),
+ bind(&SegmentFetcher::afterNackReceivedCb, this, _1, _2, 0, self),
bind(m_errorCallback, INTEREST_TIMEOUT, "Timeout"));
}
void
-SegmentFetcher::afterSegmentReceived(const Interest& origInterest,
- const Data& data, bool isSegmentZeroExpected,
- shared_ptr<SegmentFetcher> self)
+SegmentFetcher::afterSegmentReceivedCb(const Interest& origInterest,
+ const Data& data, bool isSegmentZeroExpected,
+ shared_ptr<SegmentFetcher> self)
{
+ afterSegmentReceived(data);
m_validator->validate(data,
bind(&SegmentFetcher::afterValidationSuccess, this, _1,
isSegmentZeroExpected, origInterest, self),
@@ -127,7 +130,7 @@
else {
m_buffer->write(reinterpret_cast<const char*>(data.getContent().value()),
data.getContent().value_size());
-
+ afterSegmentValidated(data);
const name::Component& finalBlockId = data.getMetaInfo().getFinalBlockId();
if (finalBlockId.empty() || (finalBlockId > currentSegment)) {
fetchNextSegment(origInterest, data.getName(), currentSegment.toSegment() + 1, self);
@@ -151,8 +154,8 @@
void
-SegmentFetcher::afterNackReceived(const Interest& origInterest, const lp::Nack& nack,
- uint32_t reExpressCount, shared_ptr<SegmentFetcher> self)
+SegmentFetcher::afterNackReceivedCb(const Interest& origInterest, const lp::Nack& nack,
+ uint32_t reExpressCount, shared_ptr<SegmentFetcher> self)
{
if (reExpressCount >= MAX_INTEREST_REEXPRESS) {
m_errorCallback(NACK_ERROR, "Nack Error");
@@ -189,9 +192,9 @@
}
m_face.expressInterest(interest,
- bind(&SegmentFetcher::afterSegmentReceived, this, _1, _2,
+ bind(&SegmentFetcher::afterSegmentReceivedCb, this, _1, _2,
isSegmentZeroExpected, self),
- bind(&SegmentFetcher::afterNackReceived, this, _1, _2,
+ bind(&SegmentFetcher::afterNackReceivedCb, this, _1, _2,
++reExpressCount, self),
bind(m_errorCallback, INTEREST_TIMEOUT, "Timeout"));
}