Skip to content

Commit

Permalink
Add safety check
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Lopez Fernandez <[email protected]>
  • Loading branch information
juanlofer-eprosima committed Feb 2, 2024
1 parent f7f1390 commit 79f136f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 30 deletions.
33 changes: 18 additions & 15 deletions src/cpp/fastdds/publisher/PublisherImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,22 +245,25 @@ DataWriter* PublisherImpl::create_datawriter(
}

// Check netmask filtering preconditions
fastrtps::rtps::RTPSParticipantImpl* rtps_impl = fastrtps::rtps::RTPSDomainImpl::find_local_participant(
rtps_participant()->getGuid());
if (nullptr != rtps_impl)
{
std::vector<fastdds::rtps::NetmaskFilterUtils::TransportNetmaskFilterInfo> netmask_filter_info =
rtps_impl->network_factory().netmask_filter_info();
std::string error_msg;
if (!fastdds::rtps::NetmaskFilterUtils::check_preconditions(netmask_filter_info,
qos.endpoint().ignore_non_matching_locators,
error_msg) ||
!fastdds::rtps::NetmaskFilterUtils::check_preconditions(netmask_filter_info,
qos.endpoint().external_unicast_locators, error_msg))
if (nullptr != rtps_participant())
{
fastrtps::rtps::RTPSParticipantImpl* rtps_impl = fastrtps::rtps::RTPSDomainImpl::find_local_participant(
rtps_participant()->getGuid());
if (nullptr != rtps_impl)
{
EPROSIMA_LOG_ERROR(PUBLISHER,
"Failed to create publisher -> " << error_msg);
return nullptr;
std::vector<fastdds::rtps::NetmaskFilterUtils::TransportNetmaskFilterInfo> netmask_filter_info =
rtps_impl->network_factory().netmask_filter_info();
std::string error_msg;
if (!fastdds::rtps::NetmaskFilterUtils::check_preconditions(netmask_filter_info,
qos.endpoint().ignore_non_matching_locators,
error_msg) ||
!fastdds::rtps::NetmaskFilterUtils::check_preconditions(netmask_filter_info,
qos.endpoint().external_unicast_locators, error_msg))
{
EPROSIMA_LOG_ERROR(PUBLISHER,
"Failed to create publisher -> " << error_msg);
return nullptr;
}
}
}

Expand Down
33 changes: 18 additions & 15 deletions src/cpp/fastdds/subscriber/SubscriberImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,22 +214,25 @@ DataReader* SubscriberImpl::create_datareader(
}

// Check netmask filtering preconditions
fastrtps::rtps::RTPSParticipantImpl* rtps_impl = fastrtps::rtps::RTPSDomainImpl::find_local_participant(
rtps_participant()->getGuid());
if (nullptr != rtps_impl)
{
std::vector<fastdds::rtps::NetmaskFilterUtils::TransportNetmaskFilterInfo> netmask_filter_info =
rtps_impl->network_factory().netmask_filter_info();
std::string error_msg;
if (!fastdds::rtps::NetmaskFilterUtils::check_preconditions(netmask_filter_info,
qos.endpoint().ignore_non_matching_locators,
error_msg) ||
!fastdds::rtps::NetmaskFilterUtils::check_preconditions(netmask_filter_info,
qos.endpoint().external_unicast_locators, error_msg))
if (nullptr != rtps_participant())
{
fastrtps::rtps::RTPSParticipantImpl* rtps_impl = fastrtps::rtps::RTPSDomainImpl::find_local_participant(
rtps_participant()->getGuid());
if (nullptr != rtps_impl)
{
EPROSIMA_LOG_ERROR(SUBSCRIBER,
"Failed to create subscriber -> " << error_msg);
return nullptr;
std::vector<fastdds::rtps::NetmaskFilterUtils::TransportNetmaskFilterInfo> netmask_filter_info =
rtps_impl->network_factory().netmask_filter_info();
std::string error_msg;
if (!fastdds::rtps::NetmaskFilterUtils::check_preconditions(netmask_filter_info,
qos.endpoint().ignore_non_matching_locators,
error_msg) ||
!fastdds::rtps::NetmaskFilterUtils::check_preconditions(netmask_filter_info,
qos.endpoint().external_unicast_locators, error_msg))
{
EPROSIMA_LOG_ERROR(SUBSCRIBER,
"Failed to create subscriber -> " << error_msg);
return nullptr;
}
}
}

Expand Down

0 comments on commit 79f136f

Please sign in to comment.