remove session after HolePunch received

This commit is contained in:
orignal 2022-06-30 08:37:50 -04:00
parent 83bd3b6f0b
commit 6ca9a599ff
3 changed files with 7 additions and 15 deletions

View file

@ -243,17 +243,6 @@ namespace transport
}
}
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)
{
if (session)

View file

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

View file

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