diff --git a/libi2pd/SSU2Session.cpp b/libi2pd/SSU2Session.cpp index 0e640021..621b400c 100644 --- a/libi2pd/SSU2Session.cpp +++ b/libi2pd/SSU2Session.cpp @@ -3407,5 +3407,21 @@ namespace transport { return m_RemoteEndpoint.address ().is_v4 () ? i2p::data::RouterInfo::eSSU2V4 : i2p::data::RouterInfo::eSSU2V6; } + + void SSU2Session::SetVersion (uint8_t version) + { + switch (version) + { + case 3: + m_Version = 3; + break; + case 4: + m_Version = (m_MaxPayloadSize >= SSU2_MLKEM768_MIN_PAYLOAD_SIZE) ? 4: 2; + break; + default: + m_Version = 2; + } + m_Version = (version >= 2 && version <= 4) ? version : 2; + } } } diff --git a/libi2pd/SSU2Session.h b/libi2pd/SSU2Session.h index eab949c7..c7801549 100644 --- a/libi2pd/SSU2Session.h +++ b/libi2pd/SSU2Session.h @@ -38,6 +38,7 @@ namespace transport const int SSU2_PEER_TEST_EXPIRATION_TIMEOUT = 60; // 60 seconds const size_t SSU2_MAX_PACKET_SIZE = 1500; const size_t SSU2_MIN_PACKET_SIZE = 1280; + const size_t SSU2_MLKEM768_MIN_PAYLOAD_SIZE = 1258; const int SSU2_HANDSHAKE_RESEND_INTERVAL = 1000; // in milliseconds const int SSU2_MAX_NUM_RESENDS = 5; const int SSU2_RESEND_ATTEMPT_MIN_INTERVAL = 3; // in milliseconds @@ -247,7 +248,7 @@ namespace transport std::shared_ptr addr = nullptr); virtual ~SSU2Session (); - void SetVersion (uint8_t version) { m_Version = (version >= 2 && version <= 4) ? version : 2; }; + void SetVersion (uint8_t version); void SetRemoteEndpoint (const boost::asio::ip::udp::endpoint& ep) { m_RemoteEndpoint = ep; }; const boost::asio::ip::udp::endpoint& GetRemoteEndpoint () const { return m_RemoteEndpoint; }; i2p::data::RouterInfo::CompatibleTransports GetRemoteTransports () const { return m_RemoteTransports; };