diff --git a/SilKit/source/core/vasio/SerializedMessage.cpp b/SilKit/source/core/vasio/SerializedMessage.cpp index 975695437..c9a74ee8c 100644 --- a/SilKit/source/core/vasio/SerializedMessage.cpp +++ b/SilKit/source/core/vasio/SerializedMessage.cpp @@ -122,6 +122,7 @@ void SerializedMessage::ReadNetworkHeaders() { case RegistryMessageKind::ParticipantAnnouncement: case RegistryMessageKind::KnownParticipants: + case RegistryMessageKind::RemoteParticipantConnectRequest: _registryMessageHeader = PeekRegistryMessageHeader(_buffer); break; case RegistryMessageKind::ParticipantAnnouncementReply: @@ -141,7 +142,6 @@ void SerializedMessage::ReadNetworkHeaders() throw ProtocolError("SerializedMessage: Unsupported protocol version encountered during handshake"); } break; - case RegistryMessageKind::RemoteParticipantConnectRequest: break; // nothing to do case RegistryMessageKind::Invalid: throw ProtocolError("SerializedMessage: ReadNetworkHeaders() encountered RegistryMessageKind::Invalid"); } diff --git a/SilKit/source/core/vasio/VAsioConnection.cpp b/SilKit/source/core/vasio/VAsioConnection.cpp index 453bf97a9..968f51057 100755 --- a/SilKit/source/core/vasio/VAsioConnection.cpp +++ b/SilKit/source/core/vasio/VAsioConnection.cpp @@ -829,6 +829,36 @@ void VAsioConnection::ReceiveRemoteParticipantConnectRequest(IVAsioPeer* peer, S { SILKIT_TRACE_METHOD_(_logger, "(...)"); + const auto registryMsgHeader = buffer.GetRegistryMessageHeader(); + + // check if we support the remote peer's protocol version or signal a handshake failure + if (ProtocolVersionSupported(registryMsgHeader)) + { + if (peer->GetInfo().participantId != RegistryParticipantId) + { + peer->SetProtocolVersion(ExtractProtocolVersion(registryMsgHeader)); + } + } + else + { + Log::Warn(_logger, + "Received RemoteParticipantConnectRequest from peer {} ({}) with unsupported protocol version {}.{}", + peer->GetInfo().participantName, peer->GetRemoteAddress(), registryMsgHeader.versionHigh, + registryMsgHeader.versionLow); + + // ignore the request if it is sent via the registry (we cannot deserialize it anyway) + if (peer->GetInfo().participantId == RegistryParticipantId) + { + Log::Debug(_logger, "Dropping invalid RemoteParticipantConnectRequest from registry"); + return; + } + + // it is not safe to decode the RemoteParticipantConnectRequest + LogAndPrintNetworkIncompatibility(registryMsgHeader, peer->GetRemoteAddress()); + + return; + } + auto msg{buffer.Deserialize()}; if (!_capabilities.HasRequestParticipantConnectionCapability()) @@ -1826,6 +1856,7 @@ void VAsioConnection::OnRemoteConnectionSuccess(std::unique_ptrGetInfo().participantName); RemoteParticipantConnectRequest msg; + msg.messageHeader = MakeRegistryMsgHeader(_version); msg.requestOrigin = vAsioPeer->GetInfo(); msg.requestTarget = MakePeerInfo(); msg.status = RemoteParticipantConnectRequest::ANNOUNCEMENT; @@ -1841,6 +1872,7 @@ void VAsioConnection::OnRemoteConnectionFailure(SilKit::Core::VAsioPeerInfo peer SILKIT_TRACE_METHOD_(_logger, "({})", peerInfo.participantName); RemoteParticipantConnectRequest msg; + msg.messageHeader = MakeRegistryMsgHeader(_version); msg.requestOrigin = std::move(peerInfo); msg.requestTarget = MakePeerInfo(); msg.status = RemoteParticipantConnectRequest::FAILED_TO_CONNECT; @@ -1890,6 +1922,7 @@ bool VAsioConnection::TryRemoteConnectRequest(VAsioPeerInfo const& peerInfo) } RemoteParticipantConnectRequest request; + request.messageHeader = MakeRegistryMsgHeader(_version); request.requestOrigin = MakePeerInfo(); request.requestTarget = peerInfo; request.status = RemoteParticipantConnectRequest::REQUEST; diff --git a/SilKit/source/core/vasio/VAsioDatatypes.hpp b/SilKit/source/core/vasio/VAsioDatatypes.hpp index 3df7d4acc..f1a83c116 100755 --- a/SilKit/source/core/vasio/VAsioDatatypes.hpp +++ b/SilKit/source/core/vasio/VAsioDatatypes.hpp @@ -106,6 +106,8 @@ struct RemoteParticipantConnectRequest ANNOUNCEMENT = 4, }; + RegistryMsgHeader messageHeader; + //! Peer that initially attempted to connect directly, but failed. SilKit::Core::VAsioPeerInfo requestOrigin; //! The peer that could not be connected to directly. This peer is instructed to initiate the remote connection. diff --git a/SilKit/source/core/vasio/VAsioSerdes.cpp b/SilKit/source/core/vasio/VAsioSerdes.cpp index ce66dd05c..798e67f37 100755 --- a/SilKit/source/core/vasio/VAsioSerdes.cpp +++ b/SilKit/source/core/vasio/VAsioSerdes.cpp @@ -285,6 +285,7 @@ inline MessageBuffer& operator>>(MessageBuffer& buffer, ProxyMessage& out) inline MessageBuffer& operator<<(MessageBuffer& buffer, const RemoteParticipantConnectRequest& msg) { buffer + << msg.messageHeader << msg.requestOrigin << msg.requestTarget << msg.status; @@ -293,6 +294,7 @@ inline MessageBuffer& operator<<(MessageBuffer& buffer, const RemoteParticipantC inline MessageBuffer& operator>>(MessageBuffer& buffer, RemoteParticipantConnectRequest& out) { buffer + >> out.messageHeader >> out.requestOrigin >> out.requestTarget >> out.status;