Browse Source

don't populate buffer of unreachable router

pull/1881/head
orignal 2 years ago
parent
commit
02a36a9fa8
  1. 10
      libi2pd/NetDb.cpp
  2. 2
      libi2pd/NetDb.hpp
  3. 2
      libi2pd/RouterInfo.cpp
  4. 11
      libi2pd/SSU2Session.cpp

10
libi2pd/NetDb.cpp

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

2
libi2pd/NetDb.hpp

@ -124,7 +124,7 @@ namespace data @@ -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 ()
{

2
libi2pd/RouterInfo.cpp

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

11
libi2pd/SSU2Session.cpp

@ -1872,10 +1872,9 @@ namespace transport @@ -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 @@ -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 @@ -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));

Loading…
Cancel
Save