From 5c15a12116c1e4447b94fd0f36caecfd2e5a40de Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 11 Mar 2022 19:03:00 -0500 Subject: [PATCH] don't allocate buffer from netdb for LocalRouterInfo --- libi2pd/RouterInfo.cpp | 16 +++++++++++++--- libi2pd/RouterInfo.h | 4 +++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/libi2pd/RouterInfo.cpp b/libi2pd/RouterInfo.cpp index fbdb04b9..27def6eb 100644 --- a/libi2pd/RouterInfo.cpp +++ b/libi2pd/RouterInfo.cpp @@ -46,7 +46,7 @@ namespace data m_Caps (0), m_Version (0) { m_Addresses = boost::make_shared(); // 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::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 LocalRouterInfo::NewBuffer () const + { + return std::make_shared (); + } } } diff --git a/libi2pd/RouterInfo.h b/libi2pd/RouterInfo.h index c1e2f307..4a6d29a5 100644 --- a/libi2pd/RouterInfo.h +++ b/libi2pd/RouterInfo.h @@ -271,7 +271,8 @@ namespace data uint8_t ExtractAddressCaps (const char * value) const; template std::shared_ptr GetAddress (Filter filter) const; - + virtual std::shared_ptr 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 NewBuffer () const override; private: