From 5ee4f136e2c018966f6bcc711727af2203d294f5 Mon Sep 17 00:00:00 2001 From: "Edwards, Daniel" Date: Thu, 23 Nov 2023 09:28:08 +0100 Subject: [PATCH] SILKIT-1435: Fix local-domain connection with registry when using hostnames in the listen URI and/or registry URI (#722) --- SilKit/source/core/vasio/CMakeLists.txt | 1 + .../source/core/vasio/Test_VAsioRegistry.cpp | 67 +++++++++++++++++++ SilKit/source/core/vasio/VAsioRegistry.cpp | 2 +- docs/CHANGELOG.rst | 1 + 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 SilKit/source/core/vasio/Test_VAsioRegistry.cpp diff --git a/SilKit/source/core/vasio/CMakeLists.txt b/SilKit/source/core/vasio/CMakeLists.txt index c4b520182..3d40131ca 100644 --- a/SilKit/source/core/vasio/CMakeLists.txt +++ b/SilKit/source/core/vasio/CMakeLists.txt @@ -151,6 +151,7 @@ if(MINGW) endif() add_silkit_test_to_executable(SilKitUnitTests SOURCES Test_VAsioConnection.cpp LIBS S_SilKitImpl I_SilKit_Core_Mock_Participant) +add_silkit_test_to_executable(SilKitUnitTests SOURCES Test_VAsioRegistry.cpp LIBS S_SilKitImpl) add_silkit_test_to_executable(SilKitUnitTests SOURCES Test_VAsioSerdes.cpp LIBS S_SilKitImpl) add_silkit_test_to_executable(SilKitUnitTests SOURCES Test_SerializedMessage.cpp LIBS S_SilKitImpl) diff --git a/SilKit/source/core/vasio/Test_VAsioRegistry.cpp b/SilKit/source/core/vasio/Test_VAsioRegistry.cpp new file mode 100644 index 000000000..269ae7f9f --- /dev/null +++ b/SilKit/source/core/vasio/Test_VAsioRegistry.cpp @@ -0,0 +1,67 @@ +/* Copyright (c) 2022 Vector Informatik GmbH + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#include "ConfigurationTestUtils.hpp" + +#include "Uri.hpp" + +#include "VAsioRegistry.hpp" + +#include "gtest/gtest.h" +#include "gmock/gmock.h" + + +namespace { + + +TEST(Test_VAsioRegistry, check_start_listening) +{ + using UriType = SilKit::Core::Uri::UriType; + + auto configuration{SilKit::Config::MakeEmptyParticipantConfigurationImpl()}; + + { + SilKit::Core::VAsioRegistry vAsioRegistry{configuration}; + SilKit::Core::Uri registryUri{vAsioRegistry.StartListening("silkit://localhost:0")}; + ASSERT_EQ(registryUri.Type(), UriType::Tcp); + ASSERT_EQ(registryUri.Host(), "localhost"); + ASSERT_NE(registryUri.Port(), 0); + } + + { + SilKit::Core::VAsioRegistry vAsioRegistry{configuration}; + SilKit::Core::Uri registryUri{vAsioRegistry.StartListening("silkit://0.0.0.0:0")}; + ASSERT_EQ(registryUri.Type(), UriType::Tcp); + ASSERT_EQ(registryUri.Host(), "0.0.0.0"); + ASSERT_NE(registryUri.Port(), 0); + } + + { + SilKit::Core::VAsioRegistry vAsioRegistry{configuration}; + SilKit::Core::Uri registryUri{vAsioRegistry.StartListening("silkit://127.0.0.1:0")}; + ASSERT_EQ(registryUri.Type(), UriType::Tcp); + ASSERT_EQ(registryUri.Host(), "127.0.0.1"); + ASSERT_NE(registryUri.Port(), 0); + } +} + + +} // namespace diff --git a/SilKit/source/core/vasio/VAsioRegistry.cpp b/SilKit/source/core/vasio/VAsioRegistry.cpp index 473c61123..2532eb7dc 100755 --- a/SilKit/source/core/vasio/VAsioRegistry.cpp +++ b/SilKit/source/core/vasio/VAsioRegistry.cpp @@ -59,7 +59,7 @@ auto VAsioRegistry::StartListening(const std::string& listenUri) -> std::string // Resolve the configured hostname and accept on the given port: auto tcpHostPort = _connection.AcceptTcpConnectionsOn(uri.Host(), uri.Port()); // Update the URI to the actually used address and port: - uri = Uri{tcpHostPort.first, tcpHostPort.second}; + uri = Uri{uri.Host(), tcpHostPort.second}; hasTcpSocket = true; } diff --git a/docs/CHANGELOG.rst b/docs/CHANGELOG.rst index 3e4cd2d75..eaf8dbbd5 100644 --- a/docs/CHANGELOG.rst +++ b/docs/CHANGELOG.rst @@ -20,6 +20,7 @@ Fixed ~~~~~ - The LIN demo does not skip the first entry (sending frame 16) on all but the first iteration through the schedule anymore. +- The name of the domain-socket used by the registry will use the hostname passed in the listen URI, not the resolved IP address (if any), for generating the name of the domain-socket. [4.0.39] - 2023-11-14