Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Support localhost only communication (#373)
Browse files Browse the repository at this point in the history
* Support localhost only communication

Signed-off-by: Brian Ezequiel Marchi <[email protected]>

* Fix identation and give proper error message to user

Signed-off-by: Brian Ezequiel Marchi <[email protected]>
  • Loading branch information
BMarchi authored and hidmic committed Oct 18, 2019
1 parent 394d9cf commit 1af5298
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
6 changes: 4 additions & 2 deletions rmw_connext_cpp/src/rmw_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ rmw_create_node(
const char * name,
const char * namespace_,
size_t domain_id,
const rmw_node_security_options_t * security_options)
const rmw_node_security_options_t * security_options,
bool localhost_only)
{
return create_node(
rti_connext_identifier, context, name, namespace_, domain_id, security_options);
rti_connext_identifier, context, name, namespace_, domain_id, security_options,
localhost_only);
}

rmw_ret_t
Expand Down
6 changes: 4 additions & 2 deletions rmw_connext_dynamic_cpp/src/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,12 @@ rmw_create_node(
const char * name,
const char * namespace_,
size_t domain_id,
const rmw_node_security_options_t * security_options)
const rmw_node_security_options_t * security_options,
bool localhost_only)
{
return create_node(
rti_connext_dynamic_identifier, context, name, namespace_, domain_id, security_options);
rti_connext_dynamic_identifier, context, name, namespace_, domain_id, security_options,
localhost_only);
}

rmw_ret_t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ create_node(
const char * name,
const char * namespace_,
size_t domain_id,
const rmw_node_security_options_t * options);
const rmw_node_security_options_t * options,
bool localhost_only);

RMW_CONNEXT_SHARED_CPP_PUBLIC
rmw_ret_t
Expand Down
16 changes: 15 additions & 1 deletion rmw_connext_shared_cpp/src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ create_node(
const char * name,
const char * namespace_,
size_t domain_id,
const rmw_node_security_options_t * security_options)
const rmw_node_security_options_t * security_options,
bool localhost_only)
{
RCUTILS_CHECK_ARGUMENT_FOR_NULL(context, NULL);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
Expand All @@ -58,6 +59,19 @@ create_node(
RMW_SET_ERROR_MSG("failed to get default participant qos");
return NULL;
}

if (localhost_only) {
status = DDS::PropertyQosPolicyHelper::add_property(
participant_qos.property,
"dds.transport.UDPv4.builtin.parent.allow_interfaces",
"127.0.0.1",
DDS::BOOLEAN_FALSE);
if (status != DDS::RETCODE_OK) {
RMW_SET_ERROR_MSG(
"failed to add qos property to set localhost as the only network interface");
return NULL;
}
}
// This String_dup is not matched with a String_free because DDS appears to
// free this automatically.
participant_qos.participant_name.name = DDS::String_dup(name);
Expand Down

0 comments on commit 1af5298

Please sign in to comment.