Skip to content

Commit f2e738f

Browse files
authored
Fix tcp listening address descriptors (#265)
* Fix tcp listening addresses Signed-off-by: RaulSanchez <raul@eprosima.com> * Apply changes to initial peers participant Signed-off-by: RaulSanchez <raul@eprosima.com> Signed-off-by: RaulSanchez <raul@eprosima.com>
1 parent 8a22625 commit f2e738f

2 files changed

Lines changed: 78 additions & 14 deletions

File tree

ddsrouter_core/src/cpp/participant/implementations/rtps/DiscoveryServerParticipant.cpp

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,48 @@ DiscoveryServerParticipant::participant_attributes_(
9191
{
9292
has_listening_tcp_ipv4 = true;
9393

94-
std::shared_ptr<eprosima::fastdds::rtps::TCPv4TransportDescriptor> descriptor =
95-
std::make_shared<eprosima::fastdds::rtps::TCPv4TransportDescriptor>();
94+
std::shared_ptr<eprosima::fastdds::rtps::TCPv4TransportDescriptor> descriptor;
9695

97-
descriptor->add_listener_port(address.port());
98-
descriptor->set_WAN_address(address.ip());
96+
// We check if several descriptors share a WAN address.
97+
// If so, we add a new port to the previously created descriptor.
98+
bool same_wan_addr = false;
9999

100-
// Enable TLS
101-
if (tls_config.is_active())
100+
auto it = params.userTransports.begin();
101+
while (it != params.userTransports.end())
102102
{
103-
tls_config.enable_tls(descriptor);
103+
std::shared_ptr<eprosima::fastdds::rtps::TCPv4TransportDescriptor> tmp_descriptor =
104+
std::dynamic_pointer_cast<eprosima::fastdds::rtps::TCPv4TransportDescriptor>(*it);
105+
106+
if ((tmp_descriptor != nullptr) && (address.ip() == tmp_descriptor->get_WAN_address()))
107+
{
108+
// Save in the new descriptor the previously added descriptor with the same WAN address
109+
descriptor = tmp_descriptor;
110+
// Set that a descriptor with same WAN address was found
111+
same_wan_addr = true;
112+
// Remove the previously added descriptor as this will be replaced by the same one updated with
113+
// more locators.
114+
params.userTransports.erase(it);
115+
break;
116+
}
117+
}
118+
119+
// Add the new locator to the descriptor if another with the same wan address was found
120+
if (same_wan_addr)
121+
{
122+
descriptor->add_listener_port(address.port());
123+
}
124+
else
125+
{
126+
descriptor = std::make_shared<eprosima::fastdds::rtps::TCPv4TransportDescriptor>();
127+
descriptor->add_listener_port(address.port());
128+
descriptor->set_WAN_address(address.ip());
129+
130+
// Enable TLS
131+
if (tls_config.is_active())
132+
{
133+
tls_config.enable_tls(descriptor);
134+
}
135+
104136
}
105137

106138
params.userTransports.push_back(descriptor);

ddsrouter_core/src/cpp/participant/implementations/rtps/InitialPeersParticipant.cpp

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,48 @@ fastrtps::rtps::RTPSParticipantAttributes InitialPeersParticipant::participant_a
8888
{
8989
has_listening_tcp_ipv4 = true;
9090

91-
std::shared_ptr<eprosima::fastdds::rtps::TCPv4TransportDescriptor> descriptor =
92-
std::make_shared<eprosima::fastdds::rtps::TCPv4TransportDescriptor>();
91+
std::shared_ptr<eprosima::fastdds::rtps::TCPv4TransportDescriptor> descriptor;
9392

94-
descriptor->add_listener_port(address.port());
95-
descriptor->set_WAN_address(address.ip());
93+
// We check if several descriptors share a WAN address.
94+
// If so, we add a new port to the previously created descriptor.
95+
bool same_wan_addr = false;
9696

97-
// Enable TLS
98-
if (tls_config.is_active())
97+
auto it = params.userTransports.begin();
98+
while (it != params.userTransports.end())
9999
{
100-
tls_config.enable_tls(descriptor);
100+
std::shared_ptr<eprosima::fastdds::rtps::TCPv4TransportDescriptor> tmp_descriptor =
101+
std::dynamic_pointer_cast<eprosima::fastdds::rtps::TCPv4TransportDescriptor>(*it);
102+
103+
if ((tmp_descriptor != nullptr) && (address.ip() == tmp_descriptor->get_WAN_address()))
104+
{
105+
// Save in the new descriptor the previously added descriptor with the same WAN address
106+
descriptor = tmp_descriptor;
107+
// Set that a descriptor with same WAN address was found
108+
same_wan_addr = true;
109+
// Remove the previously added descriptor as this will be replaced by the same one updated with
110+
// more locators.
111+
params.userTransports.erase(it);
112+
break;
113+
}
114+
}
115+
116+
// Add the new locator to the descriptor if another with the same wan address was found
117+
if (same_wan_addr)
118+
{
119+
descriptor->add_listener_port(address.port());
120+
}
121+
else
122+
{
123+
descriptor = std::make_shared<eprosima::fastdds::rtps::TCPv4TransportDescriptor>();
124+
descriptor->add_listener_port(address.port());
125+
descriptor->set_WAN_address(address.ip());
126+
127+
// Enable TLS
128+
if (tls_config.is_active())
129+
{
130+
tls_config.enable_tls(descriptor);
131+
}
132+
101133
}
102134

103135
params.userTransports.push_back(descriptor);

0 commit comments

Comments
 (0)