Skip to content

Commit

Permalink
-- prefix the RemoteParticipantConnectRequest with the RegistryMsgHea…
Browse files Browse the repository at this point in the history
…der and add checks for network incompatibility (#715)
  • Loading branch information
VDanielEdwards authored and GitHub Enterprise committed Nov 14, 2023
1 parent 695eb09 commit ace87da
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion SilKit/source/core/vasio/SerializedMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ void SerializedMessage::ReadNetworkHeaders()
{
case RegistryMessageKind::ParticipantAnnouncement:
case RegistryMessageKind::KnownParticipants:
case RegistryMessageKind::RemoteParticipantConnectRequest:
_registryMessageHeader = PeekRegistryMessageHeader(_buffer);
break;
case RegistryMessageKind::ParticipantAnnouncementReply:
Expand All @@ -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");
}
Expand Down
33 changes: 33 additions & 0 deletions SilKit/source/core/vasio/VAsioConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<RemoteParticipantConnectRequest>()};

if (!_capabilities.HasRequestParticipantConnectionCapability())
Expand Down Expand Up @@ -1826,6 +1856,7 @@ void VAsioConnection::OnRemoteConnectionSuccess(std::unique_ptr<SilKit::Core::IV
SILKIT_TRACE_METHOD_(_logger, "({})", vAsioPeer->GetInfo().participantName);

RemoteParticipantConnectRequest msg;
msg.messageHeader = MakeRegistryMsgHeader(_version);
msg.requestOrigin = vAsioPeer->GetInfo();
msg.requestTarget = MakePeerInfo();
msg.status = RemoteParticipantConnectRequest::ANNOUNCEMENT;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions SilKit/source/core/vasio/VAsioDatatypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions SilKit/source/core/vasio/VAsioSerdes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit ace87da

Please sign in to comment.