Skip to content

Commit

Permalink
Refactor rtps participants reckon_participant_attributes_
Browse files Browse the repository at this point in the history
Signed-off-by: Lucia Echevarria <luciaechevarria@eprosima.com>
  • Loading branch information
LuciaEchevarria99 committed Sep 5, 2024
1 parent f03efef commit 25dba1b
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ class CommonParticipant
const std::shared_ptr<ParticipantConfiguration>& participant_configuration,
const std::shared_ptr<core::PayloadPool>& payload_pool,
const std::shared_ptr<core::DiscoveryDatabase>& discovery_database,
const core::types::DomainId& domain_id,
const fastdds::rtps::RTPSParticipantAttributes& participant_attributes);
const core::types::DomainId& domain_id);

/**
* @brief Auxiliary method to create the internal RTPS participant.
Expand All @@ -208,12 +207,19 @@ class CommonParticipant
// RTPS specific methods

/**
* @brief Static method that gives the std attributes for a Participant.
* @brief Virtual method that gives the common std attributes for a Participant.
*
* @note This method must be specialized from inherit classes.
*/
virtual fastdds::rtps::RTPSParticipantAttributes add_participant_att_properties_(
fastdds::rtps::RTPSParticipantAttributes& params) const;

/**
* @brief Virtual method that gives the std attributes for a Participant.
*
* @note This method must be specialized from inherit classes.
*/
static fastdds::rtps::RTPSParticipantAttributes reckon_participant_attributes_(
const ParticipantConfiguration* participant_configuration);
virtual fastdds::rtps::RTPSParticipantAttributes reckon_participant_attributes_() const;

/////
// VARIABLES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class DiscoveryServerParticipant

protected:

static fastdds::rtps::RTPSParticipantAttributes reckon_participant_attributes_(
const DiscoveryServerParticipantConfiguration* participant_configuration);
fastdds::rtps::RTPSParticipantAttributes reckon_participant_attributes_() const override;

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class InitialPeersParticipant

protected:

static fastdds::rtps::RTPSParticipantAttributes reckon_participant_attributes_(
const InitialPeersParticipantConfiguration* configuration);
fastdds::rtps::RTPSParticipantAttributes reckon_participant_attributes_() const override;

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ class SimpleParticipant : public CommonParticipant
/**
* @brief Static method that gives the attributes for a Simple Participant.
*/
static fastdds::rtps::RTPSParticipantAttributes reckon_participant_attributes_(
const SimpleParticipantConfiguration* configuration);
fastdds::rtps::RTPSParticipantAttributes reckon_participant_attributes_() const override;
};

} /* namespace rtps */
Expand Down
31 changes: 19 additions & 12 deletions ddspipe_participants/src/cpp/participant/rtps/CommonParticipant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,11 @@ CommonParticipant::CommonParticipant(
const std::shared_ptr<ParticipantConfiguration>& participant_configuration,
const std::shared_ptr<core::PayloadPool>& payload_pool,
const std::shared_ptr<core::DiscoveryDatabase>& discovery_database,
const core::types::DomainId& domain_id,
const fastdds::rtps::RTPSParticipantAttributes& participant_attributes)
const core::types::DomainId& domain_id)
: configuration_(participant_configuration)
, payload_pool_(payload_pool)
, discovery_database_(discovery_database)
, domain_id_(domain_id)
, participant_attributes_(participant_attributes)
{
// Do nothing
}
Expand All @@ -75,6 +73,7 @@ CommonParticipant::~CommonParticipant()

void CommonParticipant::init()
{
participant_attributes_ = reckon_participant_attributes_();
create_participant_(
domain_id_,
participant_attributes_);
Expand Down Expand Up @@ -487,14 +486,9 @@ std::shared_ptr<core::IReader> CommonParticipant::create_reader(
}

fastdds::rtps::RTPSParticipantAttributes
CommonParticipant::reckon_participant_attributes_(
const ParticipantConfiguration* participant_configuration)
CommonParticipant::add_participant_att_properties_(
fastdds::rtps::RTPSParticipantAttributes& params) const
{
fastdds::rtps::RTPSParticipantAttributes params;

// Add Participant name
params.setName(participant_configuration->id.c_str());

// Ignore the local endpoints so that the reader and writer of the same participant don't match.
params.properties.properties().emplace_back(
"fastdds.ignore_local_endpoints",
Expand All @@ -503,16 +497,29 @@ CommonParticipant::reckon_participant_attributes_(
// Set app properties
params.properties.properties().emplace_back(
"fastdds.application.id",
participant_configuration->app_id,
configuration_->app_id,
"true");
params.properties.properties().emplace_back(
"fastdds.application.metadata",
participant_configuration->app_metadata,
configuration_->app_metadata,
"true");

return params;
}

fastdds::rtps::RTPSParticipantAttributes
CommonParticipant::reckon_participant_attributes_() const
{
fastdds::rtps::RTPSParticipantAttributes params;

// Add Participant name
params.setName(configuration_->id.c_str());

add_participant_att_properties_(params);

return params;
}

} /* namespace rtps */
} /* namespace participants */
} /* namespace ddspipe */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,22 @@ DiscoveryServerParticipant::DiscoveryServerParticipant(
participant_configuration,
payload_pool,
discovery_database,
participant_configuration->domain,
reckon_participant_attributes_(participant_configuration.get()))
participant_configuration->domain)
{
}

fastdds::rtps::RTPSParticipantAttributes
DiscoveryServerParticipant::reckon_participant_attributes_(
const DiscoveryServerParticipantConfiguration* configuration)
DiscoveryServerParticipant::reckon_participant_attributes_() const
{
// Use default as base attributes
fastdds::rtps::RTPSParticipantAttributes params = CommonParticipant::reckon_participant_attributes_(configuration);
fastdds::rtps::RTPSParticipantAttributes params = CommonParticipant::reckon_participant_attributes_();

std::shared_ptr<DiscoveryServerParticipantConfiguration> ds_configuration =
std::static_pointer_cast<DiscoveryServerParticipantConfiguration>(configuration_);

// Auxiliary variable to save characters and improve readability
const core::types::GuidPrefix& discovery_server_guid_prefix = configuration->discovery_server_guid_prefix;
const auto& tls_config = configuration->tls_configuration;
const core::types::GuidPrefix& discovery_server_guid_prefix = ds_configuration->discovery_server_guid_prefix;
const auto& tls_config = ds_configuration->tls_configuration;

// Needed values to check at the end if descriptor must be set
bool has_listening_addresses = false;
Expand All @@ -68,14 +69,14 @@ DiscoveryServerParticipant::reckon_participant_attributes_(

/////
// Set listening addresses
for (types::Address address : configuration->listening_addresses)
for (types::Address address : ds_configuration->listening_addresses)
{
if (!address.is_valid())
{
// Invalid address, continue with next one
EPROSIMA_LOG_WARNING(DDSPIPE_DISCOVERYSERVER_PARTICIPANT,
"Discard listening address: " << address <<
" in Participant " << configuration->id << " initialization.");
" in Participant " << ds_configuration->id << " initialization.");
continue;
}

Expand Down Expand Up @@ -121,7 +122,7 @@ DiscoveryServerParticipant::reckon_participant_attributes_(
else
{
descriptor = create_descriptor<eprosima::fastdds::rtps::TCPv4TransportDescriptor>(
configuration->whitelist);
ds_configuration->whitelist);
descriptor->add_listener_port(address.port());
descriptor->set_WAN_address(address.ip());

Expand All @@ -140,7 +141,7 @@ DiscoveryServerParticipant::reckon_participant_attributes_(
has_listening_tcp_ipv6 = true;

std::shared_ptr<eprosima::fastdds::rtps::TCPv6TransportDescriptor> descriptor =
create_descriptor<eprosima::fastdds::rtps::TCPv6TransportDescriptor>(configuration->whitelist);
create_descriptor<eprosima::fastdds::rtps::TCPv6TransportDescriptor>(ds_configuration->whitelist);

descriptor->add_listener_port(address.port());

Expand Down Expand Up @@ -194,19 +195,19 @@ DiscoveryServerParticipant::reckon_participant_attributes_(
params.defaultUnicastLocatorList.push_back(locator);

logDebug(DDSPIPE_DISCOVERYSERVER_PARTICIPANT,
"Add listening address " << address << " to Participant " << configuration->id << ".");
"Add listening address " << address << " to Participant " << ds_configuration->id << ".");
}

/////
// Set connection addresses
for (types::DiscoveryServerConnectionAddress connection_address : configuration->connection_addresses)
for (types::DiscoveryServerConnectionAddress connection_address : ds_configuration->connection_addresses)
{
if (!connection_address.is_valid())
{
// Invalid connection address, continue with next one
EPROSIMA_LOG_WARNING(DDSPIPE_DISCOVERYSERVER_PARTICIPANT,
"Discard connection address with remote server in Participant " <<
configuration->id << " initialization.");
ds_configuration->id << " initialization.");
continue;
}

Expand All @@ -217,7 +218,7 @@ DiscoveryServerParticipant::reckon_participant_attributes_(
// Invalid ip address, continue with next one
EPROSIMA_LOG_WARNING(DDSPIPE_DISCOVERYSERVER_PARTICIPANT,
"Discard connection address with remote server due to invalid ip address " <<
address.ip() << " in Participant " << configuration->id <<
address.ip() << " in Participant " << ds_configuration->id <<
" initialization.");
continue;
}
Expand Down Expand Up @@ -260,7 +261,7 @@ DiscoveryServerParticipant::reckon_participant_attributes_(
params.builtin.discovery_config.m_DiscoveryServers.push_back(locator);

logDebug(DDSPIPE_DISCOVERYSERVER_PARTICIPANT,
"Add connection address " << address << " to Server Participant " << configuration->id << ".");
"Add connection address " << address << " to Server Participant " << ds_configuration->id << ".");
}
}

Expand All @@ -279,7 +280,7 @@ DiscoveryServerParticipant::reckon_participant_attributes_(
if (!has_connection_addresses)
{
EPROSIMA_LOG_WARNING(DDSPIPE_DISCOVERYSERVER_PARTICIPANT,
"Creating Participant " << configuration->id << " without listening or connection addresses. " <<
"Creating Participant " << ds_configuration->id << " without listening or connection addresses. " <<
"It will not communicate with any other Participant.");
}
}
Expand All @@ -295,7 +296,7 @@ DiscoveryServerParticipant::reckon_participant_attributes_(
if (has_connection_tcp_ipv4 && !has_listening_tcp_ipv4)
{
std::shared_ptr<eprosima::fastdds::rtps::TCPv4TransportDescriptor> descriptor =
create_descriptor<eprosima::fastdds::rtps::TCPv4TransportDescriptor>(configuration->whitelist);
create_descriptor<eprosima::fastdds::rtps::TCPv4TransportDescriptor>(ds_configuration->whitelist);

// Enable TLS
if (tls_config.is_active())
Expand All @@ -306,12 +307,12 @@ DiscoveryServerParticipant::reckon_participant_attributes_(
params.userTransports.push_back(descriptor);

logDebug(DDSPIPE_DISCOVERYSERVER_PARTICIPANT,
"Adding TCPv4 Transport to Participant " << configuration->id << ".");
"Adding TCPv4 Transport to Participant " << ds_configuration->id << ".");
}
if (has_connection_tcp_ipv6 && !has_listening_tcp_ipv6)
{
std::shared_ptr<eprosima::fastdds::rtps::TCPv6TransportDescriptor> descriptor =
create_descriptor<eprosima::fastdds::rtps::TCPv6TransportDescriptor>(configuration->whitelist);
create_descriptor<eprosima::fastdds::rtps::TCPv6TransportDescriptor>(ds_configuration->whitelist);

// Enable TLS
if (tls_config.is_active())
Expand All @@ -322,31 +323,31 @@ DiscoveryServerParticipant::reckon_participant_attributes_(
params.userTransports.push_back(descriptor);

logDebug(DDSPIPE_DISCOVERYSERVER_PARTICIPANT,
"Adding TCPv6 Transport to Participant " << configuration->id << ".");
"Adding TCPv6 Transport to Participant " << ds_configuration->id << ".");
}

// If has UDP, create descriptor because it has not been created yet
if (has_udp_ipv4)
{
std::shared_ptr<eprosima::fastdds::rtps::UDPv4TransportDescriptor> descriptor =
create_descriptor<eprosima::fastdds::rtps::UDPv4TransportDescriptor>(configuration->whitelist);
create_descriptor<eprosima::fastdds::rtps::UDPv4TransportDescriptor>(ds_configuration->whitelist);
params.userTransports.push_back(descriptor);

logDebug(DDSPIPE_DISCOVERYSERVER_PARTICIPANT,
"Adding UDPv4 Transport to Participant " << configuration->id << ".");
"Adding UDPv4 Transport to Participant " << ds_configuration->id << ".");
}
if (has_udp_ipv6)
{
std::shared_ptr<eprosima::fastdds::rtps::UDPv6TransportDescriptor> descriptor_v6 =
create_descriptor<eprosima::fastdds::rtps::UDPv6TransportDescriptor>(configuration->whitelist);
create_descriptor<eprosima::fastdds::rtps::UDPv6TransportDescriptor>(ds_configuration->whitelist);
params.userTransports.push_back(descriptor_v6);

logDebug(DDSPIPE_DISCOVERYSERVER_PARTICIPANT,
"Adding UDPv6 Transport to Participant " << configuration->id << ".");
"Adding UDPv6 Transport to Participant " << ds_configuration->id << ".");
}

logDebug(DDSPIPE_DISCOVERYSERVER_PARTICIPANT,
"Configured Participant " << configuration->id << " with server guid: " <<
"Configured Participant " << ds_configuration->id << " with server guid: " <<
discovery_server_guid_prefix);

return params;
Expand Down
Loading

0 comments on commit 25dba1b

Please sign in to comment.