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