diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp b/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp index 4ca1f215003..8e33bfa1d81 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp @@ -445,17 +445,11 @@ bool PDPClient::create_ds_pdp_reliable_endpoints( eprosima::shared_lock disc_lock(mp_builtin->getDiscoveryMutex()); // TCP Clients need to handle logical ports - if (handle_logical_ports_required()) + if (mp_RTPSParticipant->has_tcp_transports()) { - for (eprosima::fastdds::rtps::RemoteServerAttributes& it : mp_builtin->m_DiscoveryServers) + for (const eprosima::fastdds::rtps::RemoteServerAttributes& it : mp_builtin->m_DiscoveryServers) { - // Set logical port to 0 and call createSenderResources to allow opening a TCP CONNECT channel in the transport - for (const Locator_t& loc : it.metatrafficUnicastLocatorList) - { - Locator_t loc_with_logical_zero = loc; - IPLocator::setLogicalPort(loc_with_logical_zero, 0); - mp_RTPSParticipant->createSenderResources(loc_with_logical_zero); - } + mp_RTPSParticipant->create_tcp_connections(it.metatrafficUnicastLocatorList); } } @@ -858,7 +852,7 @@ void PDPClient::update_remote_servers_list() eprosima::shared_lock disc_lock(mp_builtin->getDiscoveryMutex()); // TCP Clients need to handle logical ports - bool set_logicals = handle_logical_ports_required(); + bool set_logicals = mp_RTPSParticipant->has_tcp_transports(); for (const eprosima::fastdds::rtps::RemoteServerAttributes& it : mp_builtin->m_DiscoveryServers) { @@ -867,13 +861,7 @@ void PDPClient::update_remote_servers_list() { if (set_logicals) { - // Set logical port to 0 and call createSenderResources to allow opening a TCP CONNECT channel in the transport - for (const Locator_t& loc : it.metatrafficUnicastLocatorList) - { - Locator_t loc_with_logical_zero = loc; - IPLocator::setLogicalPort(loc_with_logical_zero, 0); - mp_RTPSParticipant->createSenderResources(loc_with_logical_zero); - } + mp_RTPSParticipant->create_tcp_connections(it.metatrafficUnicastLocatorList); } } @@ -1449,23 +1437,6 @@ bool PDPClient::remove_remote_participant( return false; } -bool PDPClient::handle_logical_ports_required() -{ - const RTPSParticipantAttributes& pattr = mp_RTPSParticipant->getRTPSParticipantAttributes(); - bool set_logicals = false; - for (auto& transportDescriptor : pattr.userTransports) - { - TCPTransportDescriptor* pT = dynamic_cast(transportDescriptor.get()); - if (pT) - { - set_logicals = true; - break; - } - } - - return set_logicals; -} - } /* namespace rtps */ } /* namespace fastdds */ } /* namespace eprosima */ diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPClient.h b/src/cpp/rtps/builtin/discovery/participant/PDPClient.h index 349fe164fea..ca4be4ef530 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPClient.h +++ b/src/cpp/rtps/builtin/discovery/participant/PDPClient.h @@ -244,11 +244,6 @@ class PDPClient : public PDP void perform_builtin_endpoints_matching( const ParticipantProxyData& pdata); - /** - * Check if the user transports of the RTPSParticipant requires logical ports (only TCP transport). - */ - bool handle_logical_ports_required(); - /** * TimedEvent for server synchronization: * first stage: periodically resend the local RTPSParticipant information until diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp b/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp index 934ec2b8272..d6e6d260207 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp @@ -517,17 +517,11 @@ bool PDPServer::create_ds_pdp_reliable_endpoints( eprosima::shared_lock disc_lock(mp_builtin->getDiscoveryMutex()); // TCP Clients need to handle logical ports - if (handle_logical_ports_required()) + if (mp_RTPSParticipant->has_tcp_transports()) { - for (eprosima::fastdds::rtps::RemoteServerAttributes& it : mp_builtin->m_DiscoveryServers) + for (const eprosima::fastdds::rtps::RemoteServerAttributes& it : mp_builtin->m_DiscoveryServers) { - // Set logical port to 0 and call createSenderResources to allow opening a TCP CONNECT channel in the transport - for (const Locator_t& loc : it.metatrafficUnicastLocatorList) - { - Locator_t loc_with_logical_zero = loc; - IPLocator::setLogicalPort(loc_with_logical_zero, 0); - mp_RTPSParticipant->createSenderResources(loc_with_logical_zero); - } + mp_RTPSParticipant->create_tcp_connections(it.metatrafficUnicastLocatorList); } } @@ -1203,7 +1197,7 @@ void PDPServer::update_remote_servers_list() eprosima::shared_lock disc_lock(mp_builtin->getDiscoveryMutex()); // TCP Clients need to handle logical ports - bool set_logicals = handle_logical_ports_required(); + bool set_logicals = mp_RTPSParticipant->has_tcp_transports(); for (const eprosima::fastdds::rtps::RemoteServerAttributes& it : mp_builtin->m_DiscoveryServers) { @@ -1212,13 +1206,7 @@ void PDPServer::update_remote_servers_list() { if (set_logicals) { - // Set logical port to 0 and call createSenderResources to allow opening a TCP CONNECT channel in the transport - for (const Locator_t& loc : it.metatrafficUnicastLocatorList) - { - Locator_t loc_with_logical_zero = loc; - IPLocator::setLogicalPort(loc_with_logical_zero, 0); - mp_RTPSParticipant->createSenderResources(loc_with_logical_zero); - } + mp_RTPSParticipant->create_tcp_connections(it.metatrafficUnicastLocatorList); } } @@ -2091,23 +2079,6 @@ void PDPServer::release_change_from_writer( endpoints->writer.writer_->release_change(change); } -bool PDPServer::handle_logical_ports_required() -{ - const RTPSParticipantAttributes& pattr = mp_RTPSParticipant->getRTPSParticipantAttributes(); - bool set_logicals = false; - for (auto& transportDescriptor : pattr.userTransports) - { - TCPTransportDescriptor* pT = dynamic_cast(transportDescriptor.get()); - if (pT) - { - set_logicals = true; - break; - } - } - - return set_logicals; -} - } // namespace rtps } // namespace fastdds } // namespace eprosima diff --git a/src/cpp/rtps/builtin/discovery/participant/PDPServer.hpp b/src/cpp/rtps/builtin/discovery/participant/PDPServer.hpp index 885fb320977..5b9fdcfd7d2 100644 --- a/src/cpp/rtps/builtin/discovery/participant/PDPServer.hpp +++ b/src/cpp/rtps/builtin/discovery/participant/PDPServer.hpp @@ -367,11 +367,6 @@ class PDPServer : public fastrtps::rtps::PDP void match_reliable_pdp_endpoints( const fastrtps::rtps::ParticipantProxyData& pdata); - /** - * Check if the user transports of the RTPSParticipant requires logical ports (only TCP transport). - */ - bool handle_logical_ports_required(); - //! Server thread eprosima::fastrtps::rtps::ResourceEvent resource_event_thread_; diff --git a/src/cpp/rtps/participant/RTPSParticipantImpl.cpp b/src/cpp/rtps/participant/RTPSParticipantImpl.cpp index 4b75c4b195e..adc2e0adfe3 100644 --- a/src/cpp/rtps/participant/RTPSParticipantImpl.cpp +++ b/src/cpp/rtps/participant/RTPSParticipantImpl.cpp @@ -2324,6 +2324,38 @@ fastdds::dds::builtin::TypeLookupManager* RTPSParticipantImpl::typelookup_manage return mp_builtinProtocols->tlm_; } +bool RTPSParticipantImpl::has_tcp_transports() +{ + const RTPSParticipantAttributes& pattr = getRTPSParticipantAttributes(); + bool has_tcp_transports = false; + for (auto& transportDescriptor : pattr.userTransports) + { + TCPTransportDescriptor* pT = dynamic_cast(transportDescriptor.get()); + if (pT) + { + has_tcp_transports = true; + break; + } + } + + return has_tcp_transports; +} + +void RTPSParticipantImpl::create_tcp_connections( + const LocatorList_t& locators) +{ + for (const Locator_t& loc : locators) + { + if (loc.kind == LOCATOR_KIND_TCPv4 || loc.kind == LOCATOR_KIND_TCPv6) + { + // Set logical port to 0 and call createSenderResources to allow opening a TCP CONNECT channel in the transport + Locator_t loc_with_logical_zero = loc; + IPLocator::setLogicalPort(loc_with_logical_zero, 0); + createSenderResources(loc_with_logical_zero); + } + } +} + IPersistenceService* RTPSParticipantImpl::get_persistence_service( const EndpointAttributes& param) { diff --git a/src/cpp/rtps/participant/RTPSParticipantImpl.h b/src/cpp/rtps/participant/RTPSParticipantImpl.h index 951fa092948..71b66ad35a5 100644 --- a/src/cpp/rtps/participant/RTPSParticipantImpl.h +++ b/src/cpp/rtps/participant/RTPSParticipantImpl.h @@ -461,6 +461,19 @@ class RTPSParticipantImpl return has_shm_transport_; } + //! Check if the participant has at least one TCP transport + bool has_tcp_transports(); + + /** + * This method creates the needed sender resources for a locator list, but forces + * each logical port to be zero. It is used to enforce the proper creation of a + * CONNECT channel in TCP scenarios. + * + * @param locators List of unicast locators. + */ + void create_tcp_connections( + const LocatorList_t& locators); + uint32_t get_min_network_send_buffer_size() { return m_network_Factory.get_min_send_buffer_size();