diff --git a/libi2pd/NetDb.cpp b/libi2pd/NetDb.cpp index 6e586956..6357d7c3 100644 --- a/libi2pd/NetDb.cpp +++ b/libi2pd/NetDb.cpp @@ -630,7 +630,6 @@ namespace data } // m_RouterInfos iteration m_RouterInfoBuffersPool.CleanUpMt (); - m_RouterInfoAddressesPool.CleanUpMt (); if (updatedCount > 0) LogPrint (eLogInfo, "NetDb: Saved ", updatedCount, " new/updated routers"); diff --git a/libi2pd/NetDb.hpp b/libi2pd/NetDb.hpp index c2369f5e..1e029e72 100644 --- a/libi2pd/NetDb.hpp +++ b/libi2pd/NetDb.hpp @@ -122,8 +122,7 @@ namespace data void ClearRouterInfos () { m_RouterInfos.clear (); }; std::shared_ptr NewRouterInfoBuffer () { return m_RouterInfoBuffersPool.AcquireSharedMt (); }; - std::shared_ptr NewRouterInfoAddress () { return m_RouterInfoAddressesPool.AcquireSharedMt (); }; - + uint32_t GetPublishReplyToken () const { return m_PublishReplyToken; }; private: @@ -180,7 +179,6 @@ namespace data uint32_t m_PublishReplyToken = 0; i2p::util::MemoryPoolMt m_RouterInfoBuffersPool; - i2p::util::MemoryPoolMt m_RouterInfoAddressesPool; }; extern NetDb netdb; diff --git a/libi2pd/RouterInfo.cpp b/libi2pd/RouterInfo.cpp index f730086d..f07aa8e7 100644 --- a/libi2pd/RouterInfo.cpp +++ b/libi2pd/RouterInfo.cpp @@ -29,6 +29,12 @@ namespace i2p { namespace data { + RouterInfo::Buffer::Buffer (const uint8_t * buf, size_t len) + { + if (len > size ()) len = size (); + memcpy (data (), buf, len); + } + RouterInfo::RouterInfo (): m_Buffer (nullptr) { m_Addresses = boost::make_shared(); // create empty list @@ -44,15 +50,14 @@ namespace data ReadFromFile (fullPath); } - RouterInfo::RouterInfo (const uint8_t * buf, int len): + RouterInfo::RouterInfo (std::shared_ptr&& buf, size_t len): m_IsUpdated (true), m_IsUnreachable (false), m_SupportedTransports (0), m_ReachableTransports (0), m_Caps (0), m_Version (0) { - m_Addresses = boost::make_shared(); // create empty list if (len <= MAX_RI_BUFFER_SIZE) { - m_Buffer = netdb.NewRouterInfoBuffer (); - memcpy (m_Buffer->data (), buf, len); + m_Addresses = boost::make_shared(); // create empty list + m_Buffer = buf; m_BufferLen = len; ReadFromBuffer (true); } @@ -62,7 +67,12 @@ namespace data m_Buffer = nullptr; m_IsUnreachable = true; } - } + } + + RouterInfo::RouterInfo (const uint8_t * buf, size_t len): + RouterInfo (std::make_shared (buf, len), len) + { + } RouterInfo::~RouterInfo () { @@ -205,7 +215,7 @@ namespace data for (int i = 0; i < numAddresses; i++) { uint8_t supportedTransports = 0; - auto address = netdb.NewRouterInfoAddress (); + auto address = std::make_shared
(); uint8_t cost; // ignore s.read ((char *)&cost, sizeof (cost)); s.read ((char *)&address->date, sizeof (address->date)); diff --git a/libi2pd/RouterInfo.h b/libi2pd/RouterInfo.h index d807c74b..d4651e1c 100644 --- a/libi2pd/RouterInfo.h +++ b/libi2pd/RouterInfo.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2013-2021, The PurpleI2P Project +* Copyright (c) 2013-2022, The PurpleI2P Project * * This file is part of Purple i2pd project and licensed under BSD3 * @@ -54,7 +54,7 @@ namespace data const uint8_t COST_SSU_DIRECT = 9; const uint8_t COST_SSU_THROUGH_INTRODUCERS = 11; - const int MAX_RI_BUFFER_SIZE = 2048; // if RouterInfo exceeds 2048 we consider it as malformed, might be changed later + const size_t MAX_RI_BUFFER_SIZE = 2048; // if RouterInfo exceeds 2048 we consider it as malformed, might be changed later class RouterInfo: public RoutingDestination { public: @@ -158,14 +158,23 @@ namespace data bool IsV4 () const { return (caps & AddressCaps::eV4) || (host.is_v4 () && !host.is_unspecified ()); }; bool IsV6 () const { return (caps & AddressCaps::eV6) || (host.is_v6 () && !host.is_unspecified ()); }; }; + + class Buffer: public std::array + { + public: + + Buffer () = default; + Buffer (const uint8_t * buf, size_t len); + }; + typedef std::vector > Addresses; - typedef std::array Buffer; RouterInfo (); RouterInfo (const std::string& fullPath); RouterInfo (const RouterInfo& ) = default; RouterInfo& operator=(const RouterInfo& ) = default; - RouterInfo (const uint8_t * buf, int len); + RouterInfo (std::shared_ptr&& buf, size_t len); + RouterInfo (const uint8_t * buf, size_t len); ~RouterInfo (); std::shared_ptr GetRouterIdentity () const { return m_RouterIdentity; };