Skip to content

Commit

Permalink
Refs #20628: Check loc.kind and methods in RTPSPartImpl
Browse files Browse the repository at this point in the history
Signed-off-by: cferreiragonz <[email protected]>
  • Loading branch information
cferreiragonz committed Apr 3, 2024
1 parent fb03491 commit ccc44e6
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 78 deletions.
39 changes: 5 additions & 34 deletions src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,17 +445,11 @@ bool PDPClient::create_ds_pdp_reliable_endpoints(
eprosima::shared_lock<eprosima::shared_mutex> 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);
}
}

Expand Down Expand Up @@ -858,7 +852,7 @@ void PDPClient::update_remote_servers_list()
eprosima::shared_lock<eprosima::shared_mutex> 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)
{
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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<TCPTransportDescriptor*>(transportDescriptor.get());
if (pT)
{
set_logicals = true;
break;
}
}

return set_logicals;
}

} /* namespace rtps */
} /* namespace fastdds */
} /* namespace eprosima */
5 changes: 0 additions & 5 deletions src/cpp/rtps/builtin/discovery/participant/PDPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 5 additions & 34 deletions src/cpp/rtps/builtin/discovery/participant/PDPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,17 +517,11 @@ bool PDPServer::create_ds_pdp_reliable_endpoints(
eprosima::shared_lock<eprosima::shared_mutex> 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);
}
}

Expand Down Expand Up @@ -1203,7 +1197,7 @@ void PDPServer::update_remote_servers_list()
eprosima::shared_lock<eprosima::shared_mutex> 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)
{
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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<TCPTransportDescriptor*>(transportDescriptor.get());
if (pT)
{
set_logicals = true;
break;
}
}

return set_logicals;
}

} // namespace rtps
} // namespace fastdds
} // namespace eprosima
5 changes: 0 additions & 5 deletions src/cpp/rtps/builtin/discovery/participant/PDPServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;

Expand Down
32 changes: 32 additions & 0 deletions src/cpp/rtps/participant/RTPSParticipantImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TCPTransportDescriptor*>(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)
{
Expand Down
13 changes: 13 additions & 0 deletions src/cpp/rtps/participant/RTPSParticipantImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit ccc44e6

Please sign in to comment.