From 000e0358a7120efd67307337aa06fb165953a9b4 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 19 Jul 2022 16:09:16 -0400 Subject: [PATCH] resend SessionConfirmed immediately if another SessionCreated received --- libi2pd/SSU2Session.cpp | 25 ++++++++++++++++++------- libi2pd/SSU2Session.h | 3 ++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/libi2pd/SSU2Session.cpp b/libi2pd/SSU2Session.cpp index 42aa01e9..fb5dd1e6 100644 --- a/libi2pd/SSU2Session.cpp +++ b/libi2pd/SSU2Session.cpp @@ -336,13 +336,8 @@ namespace transport if (m_SentHandshakePacket && ts >= m_SentHandshakePacket->nextResendTime) { LogPrint (eLogDebug, "SSU2: Resending ", (int)m_State); - m_Server.Send (m_SentHandshakePacket->header.buf, 16, m_SentHandshakePacket->headerX, 48, - m_SentHandshakePacket->payload, m_SentHandshakePacket->payloadSize, m_RemoteEndpoint); + ResendHandshakePacket (); m_SentHandshakePacket->nextResendTime = ts + SSU2_HANDSHAKE_RESEND_INTERVAL; - if (m_SessionConfirmedFragment && m_State == eSSU2SessionStateSessionConfirmedSent) - // resend second fragment of SessionConfirmed - m_Server.Send (m_SessionConfirmedFragment->header.buf, 16, - m_SessionConfirmedFragment->payload, m_SessionConfirmedFragment->payloadSize, m_RemoteEndpoint); return; } // resend data packets @@ -382,6 +377,19 @@ namespace transport SendQueue (); } + void SSU2Session::ResendHandshakePacket () + { + if (m_SentHandshakePacket) + { + m_Server.Send (m_SentHandshakePacket->header.buf, 16, m_SentHandshakePacket->headerX, 48, + m_SentHandshakePacket->payload, m_SentHandshakePacket->payloadSize, m_RemoteEndpoint); + if (m_SessionConfirmedFragment && m_State == eSSU2SessionStateSessionConfirmedSent) + // resend second fragment of SessionConfirmed + m_Server.Send (m_SessionConfirmedFragment->header.buf, 16, + m_SessionConfirmedFragment->payload, m_SessionConfirmedFragment->payloadSize, m_RemoteEndpoint); + } + } + bool SSU2Session::ProcessFirstIncomingMessage (uint64_t connID, uint8_t * buf, size_t len) { // we are Bob @@ -1190,7 +1198,10 @@ namespace transport if (header.h.type != eSSU2Data) { LogPrint (eLogWarning, "SSU2: Unexpected message type ", (int)header.h.type, " instead ", (int)eSSU2Data); - SendQuickAck (); // in case it was SessionConfirmed + if (IsEstablished ()) + SendQuickAck (); // in case it was SessionConfirmed + else + ResendHandshakePacket (); // assume we receive return; } uint8_t payload[SSU2_MAX_PACKET_SIZE]; diff --git a/libi2pd/SSU2Session.h b/libi2pd/SSU2Session.h index e7fcabac..79640177 100644 --- a/libi2pd/SSU2Session.h +++ b/libi2pd/SSU2Session.h @@ -252,7 +252,8 @@ namespace transport void PostI2NPMessages (std::vector > msgs); bool SendQueue (); void SendFragmentedMessage (std::shared_ptr msg); - + void ResendHandshakePacket (); + void ProcessSessionRequest (Header& header, uint8_t * buf, size_t len); void ProcessTokenRequest (Header& header, uint8_t * buf, size_t len);