Browse Source

remove session after HolePunch received

pull/1771/head
orignal 2 years ago
parent
commit
6ca9a599ff
  1. 11
      libi2pd/SSU2.cpp
  2. 1
      libi2pd/SSU2.h
  3. 10
      libi2pd/SSU2Session.cpp

11
libi2pd/SSU2.cpp

@ -242,17 +242,6 @@ namespace transport
m_Sessions.erase (it); m_Sessions.erase (it);
} }
} }
void SSU2Server::UpdateSessionConnID (uint64_t oldConnID)
{
auto it = m_Sessions.find (oldConnID);
if (it != m_Sessions.end ())
{
auto session = it->second;
m_Sessions.erase (it);
m_Sessions.emplace (session->GetConnID (), session);
}
}
void SSU2Server::AddSessionByRouterHash (std::shared_ptr<SSU2Session> session) void SSU2Server::AddSessionByRouterHash (std::shared_ptr<SSU2Session> session)
{ {

1
libi2pd/SSU2.h

@ -53,7 +53,6 @@ namespace transport
void AddSession (std::shared_ptr<SSU2Session> session); void AddSession (std::shared_ptr<SSU2Session> session);
void RemoveSession (uint64_t connID); void RemoveSession (uint64_t connID);
void UpdateSessionConnID (uint64_t oldConnID); // session has new connID
void AddSessionByRouterHash (std::shared_ptr<SSU2Session> session); void AddSessionByRouterHash (std::shared_ptr<SSU2Session> session);
bool AddPendingOutgoingSession (std::shared_ptr<SSU2Session> session); bool AddPendingOutgoingSession (std::shared_ptr<SSU2Session> session);
void RemovePendingOutgoingSession (const boost::asio::ip::udp::endpoint& ep); void RemovePendingOutgoingSession (const boost::asio::ip::udp::endpoint& ep);

10
libi2pd/SSU2Session.cpp

@ -51,14 +51,17 @@ namespace transport
void SSU2Session::Connect () void SSU2Session::Connect ()
{ {
if (m_State == eSSU2SessionStateUnknown) if (m_State == eSSU2SessionStateUnknown || m_State == eSSU2SessionStateTokenReceived)
{ {
ScheduleConnectTimer (); ScheduleConnectTimer ();
auto token = m_Server.FindOutgoingToken (m_RemoteEndpoint); auto token = m_Server.FindOutgoingToken (m_RemoteEndpoint);
if (token) if (token)
SendSessionRequest (token); SendSessionRequest (token);
else else
{
m_State = eSSU2SessionStateUnknown;
SendTokenRequest (); SendTokenRequest ();
}
} }
} }
@ -959,9 +962,10 @@ namespace transport
uint64_t oldConnID = GetConnID (); uint64_t oldConnID = GetConnID ();
RAND_bytes ((uint8_t *)&m_DestConnID, 8); RAND_bytes ((uint8_t *)&m_DestConnID, 8);
RAND_bytes ((uint8_t *)&m_SourceConnID, 8); RAND_bytes ((uint8_t *)&m_SourceConnID, 8);
m_Server.UpdateSessionConnID (oldConnID);
// connect // connect
m_State = eSSU2SessionStateUnknown; m_State = eSSU2SessionStateTokenReceived;
m_Server.AddPendingOutgoingSession (shared_from_this ());
m_Server.RemoveSession (oldConnID);
Connect (); Connect ();
} }

Loading…
Cancel
Save