mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 13:27:17 +01:00
update introducer's iTag is session to introducer was replaced to new one
This commit is contained in:
parent
c3a1631319
commit
64e4b3871a
|
@ -557,6 +557,12 @@ namespace i2p
|
||||||
UpdateRouterInfo ();
|
UpdateRouterInfo ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RouterContext::UpdateSSU2Introducer (const i2p::data::IdentHash& h, bool v4, uint32_t iTag, uint32_t iExp)
|
||||||
|
{
|
||||||
|
if (m_RouterInfo.UpdateSSU2Introducer (h, v4, iTag, iExp))
|
||||||
|
UpdateRouterInfo ();
|
||||||
|
}
|
||||||
|
|
||||||
void RouterContext::ClearSSU2Introducers (bool v4)
|
void RouterContext::ClearSSU2Introducers (bool v4)
|
||||||
{
|
{
|
||||||
auto addr = m_RouterInfo.GetSSU2Address (v4);
|
auto addr = m_RouterInfo.GetSSU2Address (v4);
|
||||||
|
|
|
@ -154,6 +154,7 @@ namespace garlic
|
||||||
void PublishSSU2Address (int port, bool publish, bool v4, bool v6);
|
void PublishSSU2Address (int port, bool publish, bool v4, bool v6);
|
||||||
bool AddSSU2Introducer (const i2p::data::RouterInfo::Introducer& introducer, bool v4);
|
bool AddSSU2Introducer (const i2p::data::RouterInfo::Introducer& introducer, bool v4);
|
||||||
void RemoveSSU2Introducer (const i2p::data::IdentHash& h, bool v4);
|
void RemoveSSU2Introducer (const i2p::data::IdentHash& h, bool v4);
|
||||||
|
void UpdateSSU2Introducer (const i2p::data::IdentHash& h, bool v4, uint32_t iTag, uint32_t iExp);
|
||||||
void ClearSSU2Introducers (bool v4);
|
void ClearSSU2Introducers (bool v4);
|
||||||
bool IsUnreachable () const;
|
bool IsUnreachable () const;
|
||||||
void SetUnreachable (bool v4, bool v6);
|
void SetUnreachable (bool v4, bool v6);
|
||||||
|
|
|
@ -1554,5 +1554,23 @@ namespace data
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LocalRouterInfo::UpdateSSU2Introducer (const IdentHash& h, bool v4, uint32_t iTag, uint32_t iExp)
|
||||||
|
{
|
||||||
|
auto addresses = GetAddresses ();
|
||||||
|
if (!addresses) return false;
|
||||||
|
auto addr = (*addresses)[v4 ? eSSU2V4Idx : eSSU2V6Idx];
|
||||||
|
if (addr)
|
||||||
|
{
|
||||||
|
for (auto& it: addr->ssu->introducers)
|
||||||
|
if (h == it.iH)
|
||||||
|
{
|
||||||
|
it.iTag = iTag;
|
||||||
|
it.iExp = iExp;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -380,6 +380,7 @@ namespace data
|
||||||
|
|
||||||
bool AddSSU2Introducer (const Introducer& introducer, bool v4);
|
bool AddSSU2Introducer (const Introducer& introducer, bool v4);
|
||||||
bool RemoveSSU2Introducer (const IdentHash& h, bool v4);
|
bool RemoveSSU2Introducer (const IdentHash& h, bool v4);
|
||||||
|
bool UpdateSSU2Introducer (const IdentHash& h, bool v4, uint32_t iTag, uint32_t iExp);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -1212,14 +1212,14 @@ namespace transport
|
||||||
void SSU2Server::UpdateIntroducers (bool v4)
|
void SSU2Server::UpdateIntroducers (bool v4)
|
||||||
{
|
{
|
||||||
uint32_t ts = i2p::util::GetSecondsSinceEpoch ();
|
uint32_t ts = i2p::util::GetSecondsSinceEpoch ();
|
||||||
std::list<i2p::data::IdentHash> newList, impliedList;
|
std::list<std::pair<i2p::data::IdentHash, uint32_t> > newList, impliedList;
|
||||||
auto& introducers = v4 ? m_Introducers : m_IntroducersV6;
|
auto& introducers = v4 ? m_Introducers : m_IntroducersV6;
|
||||||
std::unordered_set<i2p::data::IdentHash> excluded;
|
std::unordered_set<i2p::data::IdentHash> excluded;
|
||||||
for (const auto& it : introducers)
|
for (const auto& [ident, tag] : introducers)
|
||||||
{
|
{
|
||||||
std::shared_ptr<SSU2Session> session = FindSession (it);
|
std::shared_ptr<SSU2Session> session = FindSession (ident);
|
||||||
if (session)
|
if (session)
|
||||||
excluded.insert (it);
|
excluded.insert (ident);
|
||||||
if (session)
|
if (session)
|
||||||
{
|
{
|
||||||
if (session->IsEstablished () && session->GetRelayTag () && session->IsOutgoing () && // still session with introducer?
|
if (session->IsEstablished () && session->GetRelayTag () && session->IsOutgoing () && // still session with introducer?
|
||||||
|
@ -1227,19 +1227,27 @@ namespace transport
|
||||||
{
|
{
|
||||||
session->SendKeepAlive ();
|
session->SendKeepAlive ();
|
||||||
if (ts < session->GetCreationTime () + SSU2_TO_INTRODUCER_SESSION_DURATION)
|
if (ts < session->GetCreationTime () + SSU2_TO_INTRODUCER_SESSION_DURATION)
|
||||||
newList.push_back (it);
|
{
|
||||||
|
newList.push_back ({ident, session->GetRelayTag ()});
|
||||||
|
if (tag != session->GetRelayTag ())
|
||||||
|
{
|
||||||
|
LogPrint (eLogDebug, "SSU2: Introducer session to ", session->GetIdentHashBase64() , " was replaced. iTag ", tag, "->", session->GetRelayTag ());
|
||||||
|
i2p::context.UpdateSSU2Introducer (ident, v4, session->GetRelayTag (),
|
||||||
|
session->GetCreationTime () + SSU2_TO_INTRODUCER_SESSION_EXPIRATION);
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
impliedList.push_back (it); // keep in introducers list, but not publish
|
impliedList.push_back ({ident, session->GetRelayTag ()}); // keep in introducers list, but not publish
|
||||||
session = nullptr;
|
session = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
session = nullptr;
|
session = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!session)
|
if (!session)
|
||||||
i2p::context.RemoveSSU2Introducer (it, v4);
|
i2p::context.RemoveSSU2Introducer (ident, v4);
|
||||||
}
|
}
|
||||||
if (newList.size () < SSU2_MAX_NUM_INTRODUCERS)
|
if (newList.size () < SSU2_MAX_NUM_INTRODUCERS)
|
||||||
{
|
{
|
||||||
|
@ -1249,13 +1257,14 @@ namespace transport
|
||||||
// bump creation time for previous introducers if no new sessions found
|
// bump creation time for previous introducers if no new sessions found
|
||||||
LogPrint (eLogDebug, "SSU2: No new introducers found. Trying to reuse existing");
|
LogPrint (eLogDebug, "SSU2: No new introducers found. Trying to reuse existing");
|
||||||
impliedList.clear ();
|
impliedList.clear ();
|
||||||
for (auto& it : introducers)
|
for (const auto& [ident, tag] : introducers)
|
||||||
{
|
{
|
||||||
auto session = FindSession (it);
|
auto session = FindSession (ident);
|
||||||
if (session && session->IsEstablished () && session->GetRelayTag () && session->IsOutgoing ())
|
if (session && session->IsEstablished () && session->GetRelayTag () && session->IsOutgoing ())
|
||||||
{
|
{
|
||||||
session->SetCreationTime (session->GetCreationTime () + SSU2_TO_INTRODUCER_SESSION_DURATION);
|
session->SetCreationTime (session->GetCreationTime () + SSU2_TO_INTRODUCER_SESSION_DURATION);
|
||||||
if (std::find (newList.begin (), newList.end (), it) == newList.end ())
|
if (std::find_if (newList.begin (), newList.end (),
|
||||||
|
[&ident](const auto& s){ return ident == s.first; }) == newList.end ())
|
||||||
sessions.push_back (session);
|
sessions.push_back (session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1276,7 +1285,7 @@ namespace transport
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "SSU2: Introducer added ", it->GetRelayTag (), " at ",
|
LogPrint (eLogDebug, "SSU2: Introducer added ", it->GetRelayTag (), " at ",
|
||||||
i2p::data::GetIdentHashAbbreviation (it->GetRemoteIdentity ()->GetIdentHash ()));
|
i2p::data::GetIdentHashAbbreviation (it->GetRemoteIdentity ()->GetIdentHash ()));
|
||||||
newList.push_back (it->GetRemoteIdentity ()->GetIdentHash ());
|
newList.push_back ({ it->GetRemoteIdentity ()->GetIdentHash (), tag });
|
||||||
if (newList.size () >= SSU2_MAX_NUM_INTRODUCERS) break;
|
if (newList.size () >= SSU2_MAX_NUM_INTRODUCERS) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,7 +170,7 @@ namespace transport
|
||||||
mutable std::mutex m_PendingOutgoingSessionsMutex;
|
mutable std::mutex m_PendingOutgoingSessionsMutex;
|
||||||
std::map<boost::asio::ip::udp::endpoint, std::pair<uint64_t, uint32_t> > m_IncomingTokens, m_OutgoingTokens; // remote endpoint -> (token, expires in seconds)
|
std::map<boost::asio::ip::udp::endpoint, std::pair<uint64_t, uint32_t> > m_IncomingTokens, m_OutgoingTokens; // remote endpoint -> (token, expires in seconds)
|
||||||
std::unordered_map<uint32_t, std::weak_ptr<SSU2Session> > m_Relays; // we are introducer, relay tag -> session
|
std::unordered_map<uint32_t, std::weak_ptr<SSU2Session> > m_Relays; // we are introducer, relay tag -> session
|
||||||
std::list<i2p::data::IdentHash> m_Introducers, m_IntroducersV6; // introducers we are connected to
|
std::list<std::pair<i2p::data::IdentHash, uint32_t> > m_Introducers, m_IntroducersV6; // introducers we are connected to
|
||||||
i2p::util::MemoryPoolMt<Packet> m_PacketsPool;
|
i2p::util::MemoryPoolMt<Packet> m_PacketsPool;
|
||||||
i2p::util::MemoryPool<SSU2SentPacket> m_SentPacketsPool;
|
i2p::util::MemoryPool<SSU2SentPacket> m_SentPacketsPool;
|
||||||
i2p::util::MemoryPool<SSU2IncompleteMessage> m_IncompleteMessagesPool;
|
i2p::util::MemoryPool<SSU2IncompleteMessage> m_IncompleteMessagesPool;
|
||||||
|
|
Loading…
Reference in a new issue