Browse Source

insert RouterInfo from SessionConfirmed into netdb immediately

pull/1786/head
orignal 2 years ago
parent
commit
a3e19931f0
  1. 14
      libi2pd/NetDb.cpp
  2. 2
      libi2pd/NetDb.hpp
  3. 10
      libi2pd/SSU2Session.cpp

14
libi2pd/NetDb.cpp

@ -240,11 +240,10 @@ namespace data @@ -240,11 +240,10 @@ namespace data
m_HiddenMode = hide;
}
bool NetDb::AddRouterInfo (const uint8_t * buf, int len)
std::shared_ptr<const RouterInfo> NetDb::AddRouterInfo (const uint8_t * buf, int len)
{
bool updated;
AddRouterInfo (buf, len, updated);
return updated;
return AddRouterInfo (buf, len, updated);
}
std::shared_ptr<const RouterInfo> NetDb::AddRouterInfo (const uint8_t * buf, int len, bool& updated)
@ -436,12 +435,15 @@ namespace data @@ -436,12 +435,15 @@ namespace data
// try reseeding from floodfill first if specified
std::string riPath;
if(i2p::config::GetOption("reseed.floodfill", riPath)) {
if(i2p::config::GetOption("reseed.floodfill", riPath))
{
auto ri = std::make_shared<RouterInfo>(riPath);
if (ri->IsFloodfill()) {
if (ri->IsFloodfill())
{
const uint8_t * riData = ri->GetBuffer();
int riLen = ri->GetBufferLen();
if(!i2p::data::netdb.AddRouterInfo(riData, riLen)) {
if (!i2p::data::netdb.AddRouterInfo(riData, riLen))
{
// bad router info
LogPrint(eLogError, "NetDb: Bad router info");
return;

2
libi2pd/NetDb.hpp

@ -69,7 +69,7 @@ namespace data @@ -69,7 +69,7 @@ namespace data
void Start ();
void Stop ();
bool AddRouterInfo (const uint8_t * buf, int len);
std::shared_ptr<const RouterInfo> AddRouterInfo (const uint8_t * buf, int len);
bool AddRouterInfo (const IdentHash& ident, const uint8_t * buf, int len);
bool AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len);
bool AddLeaseSet2 (const IdentHash& ident, const uint8_t * buf, int len, uint8_t storeType);

10
libi2pd/SSU2Session.cpp

@ -827,17 +827,23 @@ namespace transport @@ -827,17 +827,23 @@ namespace transport
LogPrint (eLogError, "SSU2: SessionConfirmed malformed RouterInfo block");
return false;
}
SetRemoteIdentity (ri->GetRouterIdentity ());
m_Address = ri->GetSSU2AddressWithStaticKey (S, m_RemoteEndpoint.address ().is_v6 ());
if (!m_Address)
{
LogPrint (eLogError, "SSU2: No SSU2 address with static key found in SessionConfirmed");
return false;
}
// update RouterInfo in netdb
ri = i2p::data::netdb.AddRouterInfo (ri->GetBuffer (), ri->GetBufferLen ()); // ri points to one from netdb now
if (!ri)
{
LogPrint (eLogError, "SSU2: Couldn't update RouterInfo from SessionConfirmed in netdb");
return false;
}
SetRemoteIdentity (ri->GetRouterIdentity ());
AdjustMaxPayloadSize ();
m_Server.AddSessionByRouterHash (shared_from_this ()); // we know remote router now
m_RemoteTransports = ri->GetCompatibleTransports (false);
i2p::data::netdb.PostI2NPMsg (CreateDatabaseStoreMsg (ri)); // TODO: should insert ri
// handle other blocks
HandlePayload (decryptedPayload.data () + riSize + 3, decryptedPayload.size () - riSize - 3);
Established ();

Loading…
Cancel
Save