From a449dc1377e06f03958b85ff6d98dcbb859e8765 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 19 Nov 2014 16:21:40 -0500 Subject: [PATCH] read RI from buffer --- RouterInfo.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/RouterInfo.cpp b/RouterInfo.cpp index 0b7fc714..71bd9fa4 100644 --- a/RouterInfo.cpp +++ b/RouterInfo.cpp @@ -95,7 +95,16 @@ namespace data void RouterInfo::ReadFromBuffer (bool verifySignature) { - std::stringstream str (std::string ((char *)m_Buffer, m_BufferLen)); + size_t identityLen = DEFAULT_IDENTITY_SIZE; + memcpy (&m_RouterIdentity, m_Buffer, DEFAULT_IDENTITY_SIZE); + if (m_RouterIdentity.certificate.type != CERTIFICATE_TYPE_NULL) + { + LogPrint (eLogError, "Certificate type ", m_RouterIdentity.certificate.type, " is not supported"); + SetUnreachable (true); + return; + } + + std::stringstream str (std::string ((char *)m_Buffer + identityLen, m_BufferLen - identityLen)); ReadFromStream (str); if (verifySignature) { @@ -113,13 +122,6 @@ namespace data void RouterInfo::ReadFromStream (std::istream& s) { - s.read ((char *)&m_RouterIdentity, DEFAULT_IDENTITY_SIZE); - if (m_RouterIdentity.certificate.type != CERTIFICATE_TYPE_NULL) - { - LogPrint (eLogError, "Certificate type ", m_RouterIdentity.certificate.type, " is not supported"); - SetUnreachable (true); - return; - } s.read ((char *)&m_Timestamp, sizeof (m_Timestamp)); m_Timestamp = be64toh (m_Timestamp); // read addresses