mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-24 04:37:37 +01:00
Making necessary changes to RouterInfo class
This commit is contained in:
parent
7cd13fe022
commit
8cf18fd2e3
2 changed files with 25 additions and 4 deletions
|
@ -34,14 +34,19 @@ namespace data
|
|||
ReadFromFile ();
|
||||
}
|
||||
|
||||
RouterInfo::RouterInfo (const uint8_t * buf, int len):
|
||||
m_IsUpdated (true), m_IsUnreachable (false), m_SupportedTransports (0), m_Caps (0)
|
||||
RouterInfo::RouterInfo (const uint8_t * buf, int len, bool checkSig):
|
||||
m_IsUpdated (false), m_IsUnreachable (false), m_SupportedTransports (0), m_Caps (0)
|
||||
{
|
||||
m_Addresses = boost::make_shared<Addresses>(); // create empty list
|
||||
m_Buffer = new uint8_t[MAX_RI_BUFFER_SIZE];
|
||||
memcpy (m_Buffer, buf, len);
|
||||
m_BufferLen = len;
|
||||
ReadFromBuffer (true);
|
||||
ReadFromBuffer (checkSig);
|
||||
}
|
||||
|
||||
RouterInfo::RouterInfo (const uint8_t * buf, int len): RouterInfo(buf, len, true)
|
||||
{
|
||||
m_IsUpdated = true;
|
||||
}
|
||||
|
||||
RouterInfo::~RouterInfo ()
|
||||
|
@ -553,6 +558,20 @@ namespace data
|
|||
return bufbe64toh (buf + size) > m_Timestamp;
|
||||
}
|
||||
|
||||
const uint8_t * RouterInfo::LoadBuffer(const uint8_t *buf, size_t len) //TODO: error handling
|
||||
{
|
||||
m_BufferLen = len;
|
||||
if (m_BufferLen < 40 || m_BufferLen > MAX_RI_BUFFER_SIZE)
|
||||
{
|
||||
LogPrint(eLogError, "RouterInfo: File", m_FullPath, " is malformed");
|
||||
return nullptr;
|
||||
}
|
||||
if (!m_Buffer)
|
||||
m_Buffer = new uint8_t[MAX_RI_BUFFER_SIZE];
|
||||
memcpy(m_Buffer, buf, len);
|
||||
return m_Buffer;
|
||||
}
|
||||
|
||||
const uint8_t * RouterInfo::LoadBuffer ()
|
||||
{
|
||||
if (!m_Buffer)
|
||||
|
|
|
@ -120,6 +120,7 @@ namespace data
|
|||
RouterInfo (const std::string& fullPath);
|
||||
RouterInfo (const RouterInfo& ) = default;
|
||||
RouterInfo& operator=(const RouterInfo& ) = default;
|
||||
RouterInfo (const uint8_t * buf, int len, bool);
|
||||
RouterInfo (const uint8_t * buf, int len);
|
||||
~RouterInfo ();
|
||||
|
||||
|
@ -167,6 +168,7 @@ namespace data
|
|||
|
||||
const uint8_t * GetBuffer () const { return m_Buffer; };
|
||||
const uint8_t * LoadBuffer (); // load if necessary
|
||||
const uint8_t * LoadBuffer(const uint8_t *buf, size_t len); //load from memory
|
||||
int GetBufferLen () const { return m_BufferLen; };
|
||||
void CreateBuffer (const PrivateKeys& privateKeys);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue