Browse Source

don't pick same session for PeerTest msg 2

pull/1771/head
orignal 2 years ago
parent
commit
463ed12ce8
  1. 9
      libi2pd/SSU2.cpp
  2. 3
      libi2pd/SSU2.h
  3. 3
      libi2pd/SSU2Session.cpp

9
libi2pd/SSU2.cpp

@ -291,7 +291,8 @@ namespace transport @@ -291,7 +291,8 @@ namespace transport
m_PendingOutgoingSessions.erase (ep);
}
std::shared_ptr<SSU2Session> SSU2Server::GetRandomSession (i2p::data::RouterInfo::CompatibleTransports remoteTransports) const
std::shared_ptr<SSU2Session> SSU2Server::GetRandomSession (
i2p::data::RouterInfo::CompatibleTransports remoteTransports, const i2p::data::IdentHash& excluded) const
{
if (m_Sessions.empty ()) return nullptr;
uint16_t ind;
@ -301,7 +302,8 @@ namespace transport @@ -301,7 +302,8 @@ namespace transport
std::advance (it, ind);
while (it != m_Sessions.end ())
{
if (it->second->GetRemoteTransports () & remoteTransports)
if ((it->second->GetRemoteTransports () & remoteTransports) &&
it->second->GetRemoteIdentity ()->GetIdentHash () != excluded)
return it->second;
it++;
}
@ -309,7 +311,8 @@ namespace transport @@ -309,7 +311,8 @@ namespace transport
it = m_Sessions.begin ();
while (it != m_Sessions.end () && ind)
{
if (it->second->GetRemoteTransports () & remoteTransports)
if ((it->second->GetRemoteTransports () & remoteTransports) &&
it->second->GetRemoteIdentity ()->GetIdentHash () != excluded)
return it->second;
it++; ind--;
}

3
libi2pd/SSU2.h

@ -58,7 +58,8 @@ namespace transport @@ -58,7 +58,8 @@ namespace transport
void RemovePendingOutgoingSession (const boost::asio::ip::udp::endpoint& ep);
std::shared_ptr<SSU2Session> FindSession (const i2p::data::IdentHash& ident) const;
std::shared_ptr<SSU2Session> FindPendingOutgoingSession (const boost::asio::ip::udp::endpoint& ep) const;
std::shared_ptr<SSU2Session> GetRandomSession (i2p::data::RouterInfo::CompatibleTransports remoteTransports) const;
std::shared_ptr<SSU2Session> GetRandomSession (i2p::data::RouterInfo::CompatibleTransports remoteTransports,
const i2p::data::IdentHash& excluded) const;
void AddRelay (uint32_t tag, std::shared_ptr<SSU2Session> relay);
void RemoveRelay (uint32_t tag);

3
libi2pd/SSU2Session.cpp

@ -1495,7 +1495,8 @@ namespace transport @@ -1495,7 +1495,8 @@ namespace transport
{
case 1: // Bob from Alice
{
auto session = m_Server.GetRandomSession ((buf[12] == 6) ? i2p::data::RouterInfo::eSSU2V4 : i2p::data::RouterInfo::eSSU2V6);
auto session = m_Server.GetRandomSession ((buf[12] == 6) ? i2p::data::RouterInfo::eSSU2V4 : i2p::data::RouterInfo::eSSU2V6,
GetRemoteIdentity ()->GetIdentHash ());
if (session) // session with Charlie
{
session->m_PeerTests.emplace (nonce, std::make_pair (shared_from_this (), i2p::util::GetSecondsSinceEpoch ()));

Loading…
Cancel
Save