Skip to content

Commit

Permalink
Refs #20629: Revision - major changes
Browse files Browse the repository at this point in the history
Signed-off-by: cferreiragonz <[email protected]>
  • Loading branch information
cferreiragonz committed Jun 14, 2024
1 parent 2531343 commit 01b4fad
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@ bool DiscoveryServer::init(
pqos.wire_protocol().builtin.discovery_config.discoveryProtocol =
eprosima::fastrtps::rtps::DiscoveryProtocol_t::SERVER;

// Set SERVER's GUID prefix
set_server_client_random_guidPrefix(pqos.wire_protocol().prefix);

// Set SERVER's listening locator for PDP
pqos.wire_protocol().builtin.metatrafficUnicastLocatorList.push_back(listening_locator);

Expand Down
8 changes: 0 additions & 8 deletions include/fastdds/rtps/attributes/ServerAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,6 @@ FASTDDS_EXPORTED_API bool get_server_client_default_guidPrefix(
int id,
fastrtps::rtps::GuidPrefix_t& guid);

/**
* Returns a random generated guidPrefix.
* @param[out] guid reference to the guidPrefix to modify
*/
FASTDDS_EXPORTED_API void set_server_client_random_guidPrefix(
fastrtps::rtps::GuidPrefix_t& guid);

} // namespace rtps
} // namespace fastdds

Expand All @@ -234,7 +227,6 @@ using fastdds::rtps::ROS_SUPER_CLIENT;
using fastdds::rtps::load_environment_server_info;
using fastdds::rtps::ros_discovery_server_env;
using fastdds::rtps::get_server_client_default_guidPrefix;
using fastdds::rtps::set_server_client_random_guidPrefix;
using fastdds::rtps::ros_super_client_env;

} // fastrtps
Expand Down
13 changes: 3 additions & 10 deletions include/fastdds/rtps/common/LocatorSelectorEntry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,9 @@ struct LocatorSelectorEntry
static LocatorSelectorEntry create_fully_selected_entry(
const LocatorList_t& unicast_locators)
{
// Create an entry with space for all locators
LocatorSelectorEntry entry(unicast_locators.size(), 0);
// Add and select unicast locators
for (const Locator_t& locator : unicast_locators)
{
entry.state.unicast.push_back(entry.unicast.size());
entry.unicast.push_back(locator);
}
// Return created entry
return entry;
// Use previous overload with an empty multicast list
LocatorList_t empty_list {};
return create_fully_selected_entry(unicast_locators, empty_list);
}

//! GUID of the remote entity.
Expand Down
109 changes: 39 additions & 70 deletions src/cpp/rtps/RTPSDomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ namespace rtps {

using BaseReader = fastdds::rtps::BaseReader;

template<typename _Descriptor>
bool has_user_transport(
const RTPSParticipantAttributes& att)
{
const auto& transports = att.userTransports;
const auto end_it = transports.end();
return end_it != std::find_if(transports.begin(), end_it,
[](const decltype(*end_it)& item)
{
return nullptr != dynamic_cast<_Descriptor*>(item.get());
});
}

static void guid_prefix_create(
uint32_t ID,
GuidPrefix_t& guidP)
Expand Down Expand Up @@ -210,6 +223,11 @@ RTPSParticipant* RTPSDomainImpl::createParticipant(
}
else
{
if (PParam.builtin.discovery_config.discoveryProtocol == DiscoveryProtocol_t::BACKUP)
{
EPROSIMA_LOG_ERROR(RTPS_PARTICIPANT, "Specifying a GUID prefix is mandatory for BACKUP Discovery Servers.");
return nullptr;
}
pimpl = new RTPSParticipantImpl(domain_id, PParam, guidP, p, listen);
}

Expand Down Expand Up @@ -563,86 +581,37 @@ RTPSParticipant* RTPSDomainImpl::clientServerEnvironmentCreationOverride(
return nullptr;
}

// Check if some adress requires the UDPv6, TCPv4 or TCPv6 transport
if (server_list.has_kind<LOCATOR_KIND_UDPv6>())
// Check if some address requires the UDPv6, TCPv4 or TCPv6 transport
if (server_list.has_kind<LOCATOR_KIND_UDPv6>() &&
!has_user_transport<fastdds::rtps::UDPv6TransportDescriptor>(client_att))
{
// Extend builtin transports with the UDPv6 transport
auto descriptor = std::make_shared<fastdds::rtps::UDPv6TransportDescriptor>();
descriptor->sendBufferSize = client_att.sendSocketBufferSize;
descriptor->receiveBufferSize = client_att.listenSocketBufferSize;
client_att.userTransports.push_back(std::move(descriptor));
}
if (server_list.has_kind<LOCATOR_KIND_TCPv4>())
if (server_list.has_kind<LOCATOR_KIND_TCPv4>() &&
!has_user_transport<fastdds::rtps::TCPv4TransportDescriptor>(client_att))
{
// Check if a TCPv4 transport exists. Otherwise create it
fastdds::rtps::TCPTransportDescriptor* pT = nullptr;
std::shared_ptr<fastdds::rtps::TCPv4TransportDescriptor> p4;
bool no_tcpv4 = true;

for (auto sp : client_att.userTransports)
{
pT = dynamic_cast<fastdds::rtps::TCPTransportDescriptor*>(sp.get());

if (pT != nullptr)
{
if (!p4)
{
if ((p4 = std::dynamic_pointer_cast<fastdds::rtps::TCPv4TransportDescriptor>(sp)))
{
// TCPv4 transport already exists
no_tcpv4 = false;
break;
}
}
}
}
if (no_tcpv4)
{
// Extend builtin transports with the TCPv4 transport
auto descriptor = std::make_shared<fastdds::rtps::TCPv4TransportDescriptor>();
// Add automatic port
descriptor->add_listener_port(0);
descriptor->sendBufferSize = client_att.sendSocketBufferSize;
descriptor->receiveBufferSize = client_att.listenSocketBufferSize;
client_att.userTransports.push_back(std::move(descriptor));
}

// Extend builtin transports with the TCPv4 transport
auto descriptor = std::make_shared<fastdds::rtps::TCPv4TransportDescriptor>();
// Add automatic port
descriptor->add_listener_port(0);
descriptor->sendBufferSize = client_att.sendSocketBufferSize;
descriptor->receiveBufferSize = client_att.listenSocketBufferSize;
client_att.userTransports.push_back(std::move(descriptor));
}
if (server_list.has_kind<LOCATOR_KIND_TCPv6>())
if (server_list.has_kind<LOCATOR_KIND_TCPv6>() &&
!has_user_transport<fastdds::rtps::TCPv6TransportDescriptor>(client_att))
{
// Check if a TCPv6 transport exists. Otherwise create it
fastdds::rtps::TCPTransportDescriptor* pT = nullptr;
std::shared_ptr<fastdds::rtps::TCPv6TransportDescriptor> p6;
bool no_tcpv6 = true;

for (auto sp : client_att.userTransports)
{
pT = dynamic_cast<fastdds::rtps::TCPTransportDescriptor*>(sp.get());

if (pT != nullptr)
{
if (!p6)
{
// try to find a descriptor matching the listener port setup
if ((p6 = std::dynamic_pointer_cast<fastdds::rtps::TCPv6TransportDescriptor>(sp)))
{
// TCPv6 transport already exists
no_tcpv6 = false;
break;
}
}
}
}
if (no_tcpv6)
{
// Extend builtin transports with the TCPv6 transport
auto descriptor = std::make_shared<fastdds::rtps::TCPv6TransportDescriptor>();
// Add automatic port
descriptor->add_listener_port(0);
descriptor->sendBufferSize = client_att.sendSocketBufferSize;
descriptor->receiveBufferSize = client_att.listenSocketBufferSize;
client_att.userTransports.push_back(std::move(descriptor));
}
// Extend builtin transports with the TCPv6 transport
auto descriptor = std::make_shared<fastdds::rtps::TCPv6TransportDescriptor>();
// Add automatic port
descriptor->add_listener_port(0);
descriptor->sendBufferSize = client_att.sendSocketBufferSize;
descriptor->receiveBufferSize = client_att.listenSocketBufferSize;
client_att.userTransports.push_back(std::move(descriptor));
}

EPROSIMA_LOG_INFO(DOMAIN, "Detected auto client-server environment variable."
Expand Down
11 changes: 3 additions & 8 deletions src/cpp/rtps/builtin/discovery/database/DiscoveryDataBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace rtps {
namespace ddb {

DiscoveryDataBase::DiscoveryDataBase(
fastrtps::rtps::GuidPrefix_t server_guid_prefix)
const fastrtps::rtps::GuidPrefix_t& server_guid_prefix)
: server_guid_prefix_(server_guid_prefix)
, server_acked_by_all_(true)
, enabled_(true)
Expand Down Expand Up @@ -65,21 +65,16 @@ void DiscoveryDataBase::add_server(
{
std::lock_guard<std::recursive_mutex> guard(mutex_);
EPROSIMA_LOG_INFO(DISCOVERY_DATABASE, "Server " << server << " added");
if (std::find(servers_.begin(), servers_.end(), server) == servers_.end())
{
servers_.push_back(server);
}
servers_.insert(server);
}

void DiscoveryDataBase::remove_server(
fastrtps::rtps::GuidPrefix_t server)
{
std::lock_guard<std::recursive_mutex> guard(mutex_);
auto remove_it = std::find(servers_.begin(), servers_.end(), server);
if (remove_it != servers_.end())
if (servers_.erase(server) == 1)
{
EPROSIMA_LOG_INFO(DISCOVERY_DATABASE, "Removing server " << server);
servers_.erase(remove_it);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/rtps/builtin/discovery/database/DiscoveryDataBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class DiscoveryDataBase
friend class AckedFunctor;

DiscoveryDataBase(
fastrtps::rtps::GuidPrefix_t server_guid_prefix);
const fastrtps::rtps::GuidPrefix_t& server_guid_prefix);

~DiscoveryDataBase();

Expand Down Expand Up @@ -571,7 +571,7 @@ class DiscoveryDataBase
std::atomic<bool> server_acked_by_all_;

//! List of GUID prefixes of the connected remote servers
std::vector<fastrtps::rtps::GuidPrefix_t> servers_;
std::set<fastrtps::rtps::GuidPrefix_t> servers_;

// The virtual topic associated with virtual writers and readers
const std::string virtual_topic_ = "eprosima_server_virtual_topic";
Expand Down
7 changes: 4 additions & 3 deletions src/cpp/rtps/builtin/discovery/participant/PDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1508,9 +1508,10 @@ void PDP::resend_ininitial_announcements()
{
if (enabled_)
{
this->mp_mutex->lock();
initial_announcements_ = m_discovery.discovery_config.initial_announcements;
this->mp_mutex->unlock();
{
std::lock_guard<std::recursive_mutex> guardPDP(*mp_mutex);
initial_announcements_ = m_discovery.discovery_config.initial_announcements;
}
set_next_announcement_interval();
resetParticipantAnnouncement();
}
Expand Down
14 changes: 0 additions & 14 deletions src/cpp/rtps/builtin/discovery/participant/PDPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1376,20 +1376,6 @@ bool get_server_client_default_guidPrefix(
return false;
}

void set_server_client_random_guidPrefix(
GuidPrefix_t& guid)
{
// Random GUIDs keeps 4 first bytes from the default server GUID
eprosima::fastdds::rtps::GuidUtils::instance().guid_prefix_create(0, guid);

auto now = std::chrono::high_resolution_clock::now();
srand(static_cast<uint32_t>(now.time_since_epoch().count()));
for (auto i = 4; i < 12; i++)
{
guid.value[i] = eprosima::fastrtps::rtps::octet(rand() % 254);
}
}

bool PDPClient::remove_remote_participant(
const GUID_t& partGUID,
ParticipantDiscoveryInfo::DISCOVERY_STATUS reason)
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/rtps/builtin/discovery/participant/PDPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class PDPClient : public PDP
* Get the list of remote servers to which the client is already connected.
* @return A reference to the list of RemoteServerAttributes
*/
const std::list<eprosima::fastdds::rtps::RemoteServerAttributes>& connected_servers();
const fastdds::rtps::RemoteServerList_t& connected_servers();

protected:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ void PDPServerListener::on_new_cache_change_added(
}

std::pair<bool, bool> PDPServerListener::check_server_discovery_conditions(
ParticipantProxyData& participant_data,
const ParticipantProxyData& participant_data,
std::string& participant_type_str)
{
// is_valid, is_client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class PDPServerListener : public fastrtps::rtps::PDPListener
* The second one indicates if the remote participant data is a client.
*/
std::pair<bool, bool> check_server_discovery_conditions(
fastrtps::rtps::ParticipantProxyData& participant_data,
const fastrtps::rtps::ParticipantProxyData& participant_data,
std::string& participant_type_str);
};

Expand Down
15 changes: 5 additions & 10 deletions test/blackbox/common/DDSBlackboxTestsDiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ TEST(DDSDiscovery, AddDiscoveryServerToListTCP)
descriptor_1->add_listener_port(server_1_port);

// Init server
ASSERT_TRUE(server_1.fill_server_qos(server_1_qos, locator_server_1, server_1_port,
LOCATOR_KIND_TCPv4)
ASSERT_TRUE(server_1.fill_server_qos(server_1_qos, locator_server_1, server_1_port, LOCATOR_KIND_TCPv4)
.disable_builtin_transport()
.add_user_transport_to_pparams(descriptor_1)
.init_participant());
Expand All @@ -219,8 +218,7 @@ TEST(DDSDiscovery, AddDiscoveryServerToListTCP)
descriptor_2->add_listener_port(server_2_port);

// Init server
ASSERT_TRUE(server_2.fill_server_qos(server_2_qos, locator_server_2, server_2_port,
LOCATOR_KIND_TCPv4)
ASSERT_TRUE(server_2.fill_server_qos(server_2_qos, locator_server_2, server_2_port, LOCATOR_KIND_TCPv4)
.disable_builtin_transport()
.add_user_transport_to_pparams(descriptor_2)
.init_participant());
Expand Down Expand Up @@ -302,8 +300,7 @@ TEST(DDSDiscovery, ServersConnectionTCP)
auto descriptor_1 = std::make_shared<eprosima::fastdds::rtps::TCPv4TransportDescriptor>();
descriptor_1->add_listener_port(server_1_port);
// Init server
ASSERT_TRUE(server_1.fill_server_qos(server_1_qos, locator_server_1, server_1_port,
LOCATOR_KIND_TCPv4)
ASSERT_TRUE(server_1.fill_server_qos(server_1_qos, locator_server_1, server_1_port, LOCATOR_KIND_TCPv4)
.disable_builtin_transport()
.add_user_transport_to_pparams(descriptor_1)
.init_participant());
Expand All @@ -322,8 +319,7 @@ TEST(DDSDiscovery, ServersConnectionTCP)
server_2_qos.builtin.discovery_config.m_DiscoveryServers.push_back(locator_server_1);

// Init server
ASSERT_TRUE(server_2.fill_server_qos(server_2_qos, locator_server_2, server_2_port,
LOCATOR_KIND_TCPv4)
ASSERT_TRUE(server_2.fill_server_qos(server_2_qos, locator_server_2, server_2_port, LOCATOR_KIND_TCPv4)
.disable_builtin_transport()
.add_user_transport_to_pparams(descriptor_2)
.init_participant());
Expand All @@ -341,8 +337,7 @@ TEST(DDSDiscovery, ServersConnectionTCP)
server_3_qos.builtin.discovery_config.m_DiscoveryServers.push_back(locator_server_1);

// Init server
ASSERT_TRUE(server_3.fill_server_qos(server_3_qos, locator_server_3, server_3_port,
LOCATOR_KIND_TCPv4)
ASSERT_TRUE(server_3.fill_server_qos(server_3_qos, locator_server_3, server_3_port, LOCATOR_KIND_TCPv4)
.disable_builtin_transport()
.add_user_transport_to_pparams(descriptor_3)
.init_participant());
Expand Down
Loading

0 comments on commit 01b4fad

Please sign in to comment.