Browse Source

don't allocate buffer from netdb for LocalRouterInfo

pull/1742/head
orignal 3 years ago
parent
commit
5c15a12116
  1. 16
      libi2pd/RouterInfo.cpp
  2. 2
      libi2pd/RouterInfo.h

16
libi2pd/RouterInfo.cpp

@ -46,7 +46,7 @@ namespace data @@ -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 @@ -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 @@ -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 @@ -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> ();
}
}
}

2
libi2pd/RouterInfo.h

@ -271,6 +271,7 @@ namespace data @@ -271,6 +271,7 @@ 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:
@ -305,6 +306,7 @@ namespace data @@ -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:

Loading…
Cancel
Save