face: Remove reliance on exceptions during TLV decoding
Change-Id: I8e96cc9369a5702805d3856ce70dfbe64834e1df
Refs: #1379
diff --git a/daemon/face/datagram-face.hpp b/daemon/face/datagram-face.hpp
index 8050164..cbda459 100644
--- a/daemon/face/datagram-face.hpp
+++ b/daemon/face/datagram-face.hpp
@@ -233,37 +233,37 @@
<< ",endpoint:" << m_socket->local_endpoint()
<< "] Received: " << nBytesReceived << " bytes");
- /// @todo Eliminate reliance on exceptions in this path
- try {
- Block element(buffer, nBytesReceived);
+ Block element;
+ bool isOk = Block::fromBuffer(buffer, nBytesReceived, element);
+ if (!isOk)
+ {
+ NFD_LOG_WARN("[id:" << this->getId()
+ << ",endpoint:" << m_socket->local_endpoint()
+ << "] Failed to parse incoming packet");
+ // This message won't extend the face lifetime
+ return;
+ }
- if (element.size() != nBytesReceived)
- {
- NFD_LOG_WARN("[id:" << this->getId()
- << ",endpoint:" << m_socket->local_endpoint()
- << "] Received datagram size and decoded "
- << "element size don't match");
- // This message won't extend the face lifetime
- return;
- }
- if (!this->decodeAndDispatchInput(element))
- {
- NFD_LOG_WARN("[id:" << this->getId()
- << ",endpoint:" << m_socket->local_endpoint()
- << "] Received unrecognized block of type ["
- << element.type() << "]");
- // ignore unknown packet and proceed
- // This message won't extend the face lifetime
- return;
- }
- }
- catch(const tlv::Error& e) {
- NFD_LOG_WARN("[id:" << this->getId()
- << ",endpoint:" << m_socket->local_endpoint()
- << "] Received input is invalid");
- // This message won't extend the face lifetime
- return;
- }
+ if (element.size() != nBytesReceived)
+ {
+ NFD_LOG_WARN("[id:" << this->getId()
+ << ",endpoint:" << m_socket->local_endpoint()
+ << "] Received datagram size and decoded "
+ << "element size don't match");
+ // This message won't extend the face lifetime
+ return;
+ }
+
+ if (!this->decodeAndDispatchInput(element))
+ {
+ NFD_LOG_WARN("[id:" << this->getId()
+ << ",endpoint:" << m_socket->local_endpoint()
+ << "] Received unrecognized block of type ["
+ << element.type() << "]");
+ // This message won't extend the face lifetime
+ return;
+ }
+
m_hasBeenUsedRecently = true;
}