face: avoid deprecated Block::fromBuffer overloads
This commit also does some cleanups in NDNLP PartialMessageStore.
refs #2553
Change-Id: I6a74929e58d38bde1a9ac365f7d5c42862d37592
diff --git a/daemon/face/ndnlp-partial-message-store.cpp b/daemon/face/ndnlp-partial-message-store.cpp
index 082f678..252e77d 100644
--- a/daemon/face/ndnlp-partial-message-store.cpp
+++ b/daemon/face/ndnlp-partial-message-store.cpp
@@ -78,9 +78,7 @@
}
BOOST_ASSERT(buf == buffer->end());
- Block reassembled;
- bool isBlockOk = Block::fromBuffer(buffer, 0, reassembled);
- return std::make_tuple(isBlockOk, reassembled);
+ return Block::fromBuffer(buffer, 0);
}
std::tuple<bool, Block>
@@ -88,10 +86,12 @@
{
BOOST_ASSERT(fragment.fragCount == 1);
- Block reassembled;
- bool isBlockOk = Block::fromBuffer(fragment.payload.value(), fragment.payload.value_size(),
- reassembled);
- return std::make_tuple(isBlockOk, reassembled);
+ try {
+ return std::make_tuple(true, fragment.payload.blockFromValue());
+ }
+ catch (tlv::Error&) {
+ return std::make_tuple(false, Block());
+ }
}
PartialMessageStore::PartialMessageStore(const time::nanoseconds& idleDuration)
@@ -104,34 +104,33 @@
{
bool isReassembled = false;
Block reassembled;
+
if (pkt.fragCount == 1) { // single fragment
std::tie(isReassembled, reassembled) = PartialMessage::reassembleSingle(pkt);
- if (!isReassembled) {
- NFD_LOG_TRACE(pkt.seq << " reassemble error");
+ }
+ else {
+ uint64_t messageIdentifier = pkt.seq - pkt.fragIndex;
+ PartialMessage& pm = m_partialMessages[messageIdentifier];
+ this->scheduleCleanup(messageIdentifier, pm);
+
+ pm.add(pkt.fragIndex, pkt.fragCount, pkt.payload);
+
+ if (pm.isComplete()) {
+ std::tie(isReassembled, reassembled) = pm.reassemble();
+ m_partialMessages.erase(messageIdentifier);
+ }
+ else {
return;
}
+ }
- NFD_LOG_TRACE(pkt.seq << " deliver");
- this->onReceive(reassembled);
+ if (!isReassembled) {
+ NFD_LOG_TRACE(pkt.seq << " reassemble error");
return;
}
- uint64_t messageIdentifier = pkt.seq - pkt.fragIndex;
- PartialMessage& pm = m_partialMessages[messageIdentifier];
- this->scheduleCleanup(messageIdentifier, pm);
-
- pm.add(pkt.fragIndex, pkt.fragCount, pkt.payload);
- if (pm.isComplete()) {
- std::tie(isReassembled, reassembled) = pm.reassemble();
- if (!isReassembled) {
- NFD_LOG_TRACE(messageIdentifier << " reassemble error");
- return;
- }
-
- NFD_LOG_TRACE(messageIdentifier << " deliver");
- this->onReceive(reassembled);
- m_partialMessages.erase(messageIdentifier);
- }
+ NFD_LOG_TRACE(pkt.seq << " deliver");
+ this->onReceive(reassembled);
}
void