don't populate buffer of unreachable router

This commit is contained in:
orignal 2023-02-14 15:44:35 -05:00
parent 77142e59ee
commit 02a36a9fa8
4 changed files with 13 additions and 12 deletions

View File

@ -1043,8 +1043,7 @@ namespace data
if (router && !router->IsUnreachable ())
{
LogPrint (eLogDebug, "NetDb: Requested RouterInfo ", key, " found");
PopulateRouterInfoBuffer (router);
if (router->GetBuffer ())
if (PopulateRouterInfoBuffer (router))
replyMsg = CreateDatabaseStoreMsg (router);
}
}
@ -1481,10 +1480,11 @@ namespace data
m_LeasesPool.CleanUpMt ();
}
void NetDb::PopulateRouterInfoBuffer (std::shared_ptr<RouterInfo> r)
bool NetDb::PopulateRouterInfoBuffer (std::shared_ptr<RouterInfo> r)
{
if (!r || r->GetBuffer ()) return;
r->LoadBuffer (m_Storage.Path (r->GetIdentHashBase64 ()));
if (!r) return false;
if (r->GetBuffer ()) return true;
return r->LoadBuffer (m_Storage.Path (r->GetIdentHashBase64 ()));
}
}
}

View File

@ -124,7 +124,7 @@ namespace data
void ClearRouterInfos () { m_RouterInfos.clear (); };
std::shared_ptr<RouterInfo::Buffer> NewRouterInfoBuffer () { return m_RouterInfoBuffersPool.AcquireSharedMt (); };
void PopulateRouterInfoBuffer (std::shared_ptr<RouterInfo> r);
bool PopulateRouterInfoBuffer (std::shared_ptr<RouterInfo> r);
std::shared_ptr<RouterInfo::Address> NewRouterInfoAddress () { return m_RouterInfoAddressesPool.AcquireSharedMt (); };
boost::shared_ptr<RouterInfo::Addresses> NewRouterInfoAddresses ()
{

View File

@ -589,6 +589,8 @@ namespace data
{
if (LoadFile (fullPath))
LogPrint (eLogDebug, "RouterInfo: Buffer for ", GetIdentHashAbbreviation (GetIdentHash ()), " loaded from file");
else
return nullptr;
}
return m_Buffer->data ();
}

View File

@ -1872,10 +1872,9 @@ namespace transport
// send relay intro to Charlie
auto r = i2p::data::netdb.FindRouter (GetRemoteIdentity ()->GetIdentHash ()); // Alice's RI
if (r)
i2p::data::netdb.PopulateRouterInfoBuffer (r);
else
LogPrint (eLogWarning, "SSU2: RelayRequest Alice's router info not found");
if (r && (r->IsUnreachable () || !i2p::data::netdb.PopulateRouterInfoBuffer (r))) r = nullptr;
if (!r) LogPrint (eLogWarning, "SSU2: RelayRequest Alice's router info not found");
uint8_t payload[SSU2_MAX_PACKET_SIZE];
size_t payloadSize = r ? CreateRouterInfoBlock (payload, m_MaxPayloadSize - len - 32, r) : 0;
if (!payloadSize && r)
@ -2069,7 +2068,7 @@ namespace transport
auto packet = m_Server.GetSentPacketsPool ().AcquireShared ();
// Alice's RouterInfo
auto r = i2p::data::netdb.FindRouter (GetRemoteIdentity ()->GetIdentHash ());
if (r) i2p::data::netdb.PopulateRouterInfoBuffer (r);
if (r && (r->IsUnreachable () || !i2p::data::netdb.PopulateRouterInfoBuffer (r))) r = nullptr;
packet->payloadSize = r ? CreateRouterInfoBlock (packet->payload, m_MaxPayloadSize - len - 32, r) : 0;
if (!packet->payloadSize && r)
session->SendFragmentedMessage (CreateDatabaseStoreMsg (r));
@ -2173,7 +2172,7 @@ namespace transport
uint8_t payload[SSU2_MAX_PACKET_SIZE];
// Charlie's RouterInfo
auto r = i2p::data::netdb.FindRouter (GetRemoteIdentity ()->GetIdentHash ());
if (r) i2p::data::netdb.PopulateRouterInfoBuffer (r);
if (r && (r->IsUnreachable () || !i2p::data::netdb.PopulateRouterInfoBuffer (r))) r = nullptr;
size_t payloadSize = r ? CreateRouterInfoBlock (payload, m_MaxPayloadSize - len - 32, r) : 0;
if (!payloadSize && r)
it->second.first->SendFragmentedMessage (CreateDatabaseStoreMsg (r));