Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve understandability of participant transport setup. #14

Merged
merged 1 commit into from
May 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 25 additions & 28 deletions ihmc-ros2-library/src/main/java/us/ihmc/ros2/ROS2NodeInterface.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package us.ihmc.ros2;

import java.net.InetAddress;
import java.util.Arrays;
import java.util.UUID;
import java.util.function.Consumer;

import com.eprosima.xmlschemas.fastrtps_profiles.AddressListType;
import com.eprosima.xmlschemas.fastrtps_profiles.RtpsTransportDescriptorType;

import us.ihmc.log.LogTools;
Expand All @@ -24,45 +24,42 @@ static ParticipantAttributes createParticipantAttributes(int domainId, boolean u
{
ParticipantAttributes participantAttributes = ParticipantAttributes.create().domainId(domainId).discoveryLeaseDuration(Time.Infinite);

boolean restrictedToAddress = false;
if (addressRestriction != null)
// Always override the transport so we're sure what it is
participantAttributes.useBuiltinTransports(false);

// If this is false then shared memory will be disabled
if (useSharedMemory)
{
if (addressRestriction.length > 0)
{
if (addressRestriction[0] != null) // Check for null on the first element, to make sure passing in null works as usual -> no address restrictions
{
participantAttributes.bindToAddressRestrictions(useSharedMemory, Arrays.asList(addressRestriction));
restrictedToAddress = true;
}
}
participantAttributes.addSharedMemoryTransport();
}

// If not restricted to an address, disable shared memory if useSharedMemory is false
if(!restrictedToAddress)
{
if(!useSharedMemory)
{
// Disable default transports
participantAttributes.useBuiltinTransports(false);

// Add custom UDPv4 transport
String transportName = UUID.randomUUID().toString();
RtpsTransportDescriptorType transportDescriptor = new RtpsTransportDescriptorType();
transportDescriptor.setTransportId(transportName);
transportDescriptor.setType("UDPv4");

participantAttributes.addTransport(transportDescriptor);
// Add custom UDPv4 transport
String transportName = UUID.randomUUID().toString();
RtpsTransportDescriptorType transportDescriptor = new RtpsTransportDescriptorType();
transportDescriptor.setTransportId(transportName);
transportDescriptor.setType("UDPv4");

// Apply address restrictions
// Check for null on the first element, to make sure passing in null works as usual -> no address restrictions
if (addressRestriction != null && addressRestriction.length > 0 && addressRestriction[0] != null)
{
AddressListType addressWhitelist = new AddressListType();
for (InetAddress address : addressRestriction)
{
addressWhitelist.getAddress().add(address.getHostAddress());
}
transportDescriptor.setInterfaceWhiteList(addressWhitelist);
}


participantAttributes.addTransport(transportDescriptor);

return participantAttributes;
}

static boolean useSHMFromEnvironment()
{
String disableSharedMemoryTransportEnv = System.getenv("ROS_DISABLE_SHARED_MEMORY_TRANSPORT");
if(disableSharedMemoryTransportEnv == null)
if (disableSharedMemoryTransportEnv == null)
{
return false;
}
Expand Down
Loading