|
|
|
@ -26,7 +26,7 @@ namespace data
@@ -26,7 +26,7 @@ namespace data
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
RouterInfo::RouterInfo (const std::string& fullPath): |
|
|
|
|
m_FullPath (fullPath), m_IsUpdated (false), m_IsUnreachable (false), |
|
|
|
|
m_FullPath (fullPath), m_Buffer (nullptr), m_IsUpdated (false), m_IsUnreachable (false), |
|
|
|
|
m_SupportedTransports (0), m_Caps (0) |
|
|
|
|
{ |
|
|
|
|
m_Addresses = boost::make_shared<Addresses>(); // create empty list
|
|
|
|
@ -38,18 +38,27 @@ namespace data
@@ -38,18 +38,27 @@ namespace data
|
|
|
|
|
m_IsUpdated (true), m_IsUnreachable (false), m_SupportedTransports (0), m_Caps (0) |
|
|
|
|
{ |
|
|
|
|
m_Addresses = boost::make_shared<Addresses>(); // create empty list
|
|
|
|
|
if (len <= MAX_RI_BUFFER_SIZE) |
|
|
|
|
{ |
|
|
|
|
m_Buffer = new uint8_t[len]; |
|
|
|
|
memcpy (m_Buffer, buf, len); |
|
|
|
|
m_BufferLen = len; |
|
|
|
|
ReadFromBuffer (true); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
LogPrint (eLogError, "RouterInfo: Buffer is too long ", len, ". Ignored"); |
|
|
|
|
m_Buffer = nullptr; |
|
|
|
|
m_IsUnreachable = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
RouterInfo::~RouterInfo () |
|
|
|
|
{ |
|
|
|
|
delete[] m_Buffer; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void RouterInfo::Update (const uint8_t * buf, int len) |
|
|
|
|
void RouterInfo::Update (const uint8_t * buf, size_t len) |
|
|
|
|
{ |
|
|
|
|
// verify signature since we have identity already
|
|
|
|
|
int l = len - m_RouterIdentity->GetSignatureLen (); |
|
|
|
@ -62,9 +71,15 @@ namespace data
@@ -62,9 +71,15 @@ namespace data
|
|
|
|
|
m_Caps = 0; |
|
|
|
|
// don't clean up m_Addresses, it will be replaced in ReadFromStream
|
|
|
|
|
m_Properties.clear (); |
|
|
|
|
// check if existing buffer long enough
|
|
|
|
|
if (m_Buffer && len > m_BufferLen) |
|
|
|
|
{ |
|
|
|
|
delete[] m_Buffer; |
|
|
|
|
m_Buffer = nullptr; |
|
|
|
|
} |
|
|
|
|
// copy buffer
|
|
|
|
|
if (!m_Buffer) |
|
|
|
|
m_Buffer = new uint8_t[MAX_RI_BUFFER_SIZE]; |
|
|
|
|
m_Buffer = new uint8_t[len]; |
|
|
|
|
memcpy (m_Buffer, buf, len); |
|
|
|
|
m_BufferLen = len; |
|
|
|
|
// skip identity
|
|
|
|
@ -100,7 +115,7 @@ namespace data
@@ -100,7 +115,7 @@ namespace data
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
s.seekg(0, std::ios::beg); |
|
|
|
|
if (!m_Buffer) |
|
|
|
|
if (m_Buffer) delete[] m_Buffer; |
|
|
|
|
m_Buffer = new uint8_t[m_BufferLen]; |
|
|
|
|
s.read((char *)m_Buffer, m_BufferLen); |
|
|
|
|
} |
|
|
|
@ -607,15 +622,21 @@ namespace data
@@ -607,15 +622,21 @@ namespace data
|
|
|
|
|
std::stringstream s; |
|
|
|
|
uint8_t ident[1024]; |
|
|
|
|
auto identLen = privateKeys.GetPublic ()->ToBuffer (ident, 1024); |
|
|
|
|
auto signatureLen = privateKeys.GetPublic ()->GetSignatureLen (); |
|
|
|
|
s.write ((char *)ident, identLen); |
|
|
|
|
WriteToStream (s); |
|
|
|
|
m_BufferLen = s.str ().size (); |
|
|
|
|
if (!m_Buffer) |
|
|
|
|
m_Buffer = new uint8_t[MAX_RI_BUFFER_SIZE]; |
|
|
|
|
if (m_BufferLen + signatureLen < MAX_RI_BUFFER_SIZE) |
|
|
|
|
{ |
|
|
|
|
memcpy (m_Buffer, s.str ().c_str (), m_BufferLen); |
|
|
|
|
// signature
|
|
|
|
|
privateKeys.Sign ((uint8_t *)m_Buffer, m_BufferLen, (uint8_t *)m_Buffer + m_BufferLen); |
|
|
|
|
m_BufferLen += privateKeys.GetPublic ()->GetSignatureLen (); |
|
|
|
|
m_BufferLen += signatureLen; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
LogPrint (eLogError, "RouterInfo: Our RouterInfo is too long ", m_BufferLen + signatureLen); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool RouterInfo::SaveToFile (const std::string& fullPath) |
|
|
|
|