don't allocate buffer from netdb for LocalRouterInfo

This commit is contained in:
orignal 2022-03-11 19:03:00 -05:00
parent 68d015763e
commit 5c15a12116
2 changed files with 16 additions and 4 deletions

View File

@ -46,7 +46,7 @@ namespace data
m_Caps (0), m_Version (0)
{
m_Addresses = boost::make_shared<Addresses>(); // create empty list
m_Buffer = netdb.NewRouterInfoBuffer ();
m_Buffer = NewBuffer (); // always RouterInfo's
ReadFromFile (fullPath);
}
@ -134,7 +134,7 @@ namespace data
}
s.seekg(0, std::ios::beg);
if (!m_Buffer)
m_Buffer = netdb.NewRouterInfoBuffer ();
m_Buffer = NewBuffer ();
s.read((char *)m_Buffer->data (), m_BufferLen);
}
else
@ -962,12 +962,17 @@ namespace data
void RouterInfo::UpdateBuffer (const uint8_t * buf, size_t len)
{
if (!m_Buffer)
m_Buffer = netdb.NewRouterInfoBuffer ();
m_Buffer = NewBuffer ();
if (len > m_Buffer->size ()) len = m_Buffer->size ();
memcpy (m_Buffer->data (), buf, len);
m_BufferLen = len;
}
std::shared_ptr<RouterInfo::Buffer> RouterInfo::NewBuffer () const
{
return netdb.NewRouterInfoBuffer ();
}
void RouterInfo::RefreshTimestamp ()
{
m_Timestamp = i2p::util::GetMillisecondsSinceEpoch ();
@ -1276,5 +1281,10 @@ namespace data
s.write ((char *)&len, 1);
s.write (str.c_str (), len);
}
std::shared_ptr<RouterInfo::Buffer> LocalRouterInfo::NewBuffer () const
{
return std::make_shared<Buffer> ();
}
}
}

View File

@ -271,7 +271,8 @@ namespace data
uint8_t ExtractAddressCaps (const char * value) const;
template<typename Filter>
std::shared_ptr<const Address> GetAddress (Filter filter) const;
virtual std::shared_ptr<Buffer> NewBuffer () const;
private:
std::string m_Family;
@ -305,6 +306,7 @@ namespace data
void WriteToStream (std::ostream& s) const;
void UpdateCapsProperty ();
void WriteString (const std::string& str, std::ostream& s) const;
std::shared_ptr<Buffer> NewBuffer () const override;
private: