check if updated router is still introducer. Remove non-introducer sessions from introducers list

This commit is contained in:
orignal 2024-06-13 18:10:45 -04:00
parent 362edc68ad
commit 6caec6b551
3 changed files with 43 additions and 22 deletions

View File

@ -1104,22 +1104,21 @@ namespace transport
session = it1->second; session = it1->second;
excluded.insert (it); excluded.insert (it);
} }
if (session && session->IsEstablished () && session->GetRelayTag () && session->IsOutgoing ()) // still session with introducer? if (session && session->IsEstablished () && session->GetRelayTag () && session->IsOutgoing () && // still session with introducer?
{ ts < session->GetCreationTime () + SSU2_TO_INTRODUCER_SESSION_EXPIRATION)
if (ts < session->GetCreationTime () + SSU2_TO_INTRODUCER_SESSION_EXPIRATION) {
session->SendKeepAlive ();
if (ts < session->GetCreationTime () + SSU2_TO_INTRODUCER_SESSION_DURATION)
newList.push_back (it);
else
{ {
session->SendKeepAlive (); impliedList.push_back (it); // keep in introducers list, but not publish
if (ts < session->GetCreationTime () + SSU2_TO_INTRODUCER_SESSION_DURATION) session = nullptr;
newList.push_back (it); }
else }
{ else
impliedList.push_back (it); // keep in introducers list, but not publish session = nullptr;
session = nullptr;
}
}
else
session = nullptr;
}
if (!session) if (!session)
i2p::context.RemoveSSU2Introducer (it, v4); i2p::context.RemoveSSU2Introducer (it, v4);
} }

View File

@ -1575,14 +1575,9 @@ namespace transport
LogPrint (eLogDebug, "SSU2: Options"); LogPrint (eLogDebug, "SSU2: Options");
break; break;
case eSSU2BlkRouterInfo: case eSSU2BlkRouterInfo:
{
// not from SessionConfirmed, we must add it instantly to use in next block
LogPrint (eLogDebug, "SSU2: RouterInfo"); LogPrint (eLogDebug, "SSU2: RouterInfo");
auto ri = ExtractRouterInfo (buf + offset, size); HandleRouterInfo (buf + offset, size);
if (ri) break;
i2p::data::netdb.AddRouterInfo (ri->GetBuffer (), ri->GetBufferLen ()); // TODO: add ri
break;
}
case eSSU2BlkI2NPMessage: case eSSU2BlkI2NPMessage:
{ {
LogPrint (eLogDebug, "SSU2: I2NP message"); LogPrint (eLogDebug, "SSU2: I2NP message");
@ -1742,6 +1737,32 @@ namespace transport
}; };
} }
void SSU2Session::HandleRouterInfo (const uint8_t * buf, size_t len)
{
auto ri = ExtractRouterInfo (buf, len);
if (ri)
{
// not from SessionConfirmed, we must add it instantly to use in next block
auto newRi = i2p::data::netdb.AddRouterInfo (ri->GetBuffer (), ri->GetBufferLen ()); // TODO: add ri
if (newRi)
{
auto remoteIdentity = GetRemoteIdentity ();
if (remoteIdentity && remoteIdentity->GetIdentHash () == newRi->GetIdentHash ())
{
// peer's RouterInfo update
SetRemoteIdentity (newRi->GetIdentity ());
auto address = m_RemoteEndpoint.address ().is_v6 () ? newRi->GetSSU2V6Address () : newRi->GetSSU2V4Address ();
if (address)
{
m_Address = address;
if (IsOutgoing () && m_RelayTag && !address->IsIntroducer ())
m_RelayTag = 0; // not longer introducer
}
}
}
}
}
void SSU2Session::HandleAck (const uint8_t * buf, size_t len) void SSU2Session::HandleAck (const uint8_t * buf, size_t len)
{ {
if (m_State == eSSU2SessionStateSessionConfirmedSent) if (m_State == eSSU2SessionStateSessionConfirmedSent)

View File

@ -303,6 +303,7 @@ namespace transport
void HandlePayload (const uint8_t * buf, size_t len); void HandlePayload (const uint8_t * buf, size_t len);
void HandleDateTime (const uint8_t * buf, size_t len); void HandleDateTime (const uint8_t * buf, size_t len);
void HandleRouterInfo (const uint8_t * buf, size_t len);
void HandleAck (const uint8_t * buf, size_t len); void HandleAck (const uint8_t * buf, size_t len);
void HandleAckRange (uint32_t firstPacketNum, uint32_t lastPacketNum, uint64_t ts); void HandleAckRange (uint32_t firstPacketNum, uint32_t lastPacketNum, uint64_t ts);
void HandleAddress (const uint8_t * buf, size_t len); void HandleAddress (const uint8_t * buf, size_t len);