Skip to content

Commit d1ef295

Browse files
committed
RMW_IMPLEMENTATION is not needed any more
1 parent f0a457e commit d1ef295

File tree

2 files changed

+90
-88
lines changed

2 files changed

+90
-88
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Automatically generate the DDS configuration for Husarnet.
1111
Download the binary using `curl` or `wget`, which are available on most systems either preinstalled, or obtainable via package manager:
1212

1313
```bash
14-
RELEASE="v1.3.5"
14+
RELEASE="v1.3.6"
1515
ARCH="amd64"
1616

1717
sudo curl -L https://github.com/husarnet/husarnet-dds/releases/download/$RELEASE/husarnet-dds-linux-$ARCH -o /usr/local/bin/husarnet-dds
@@ -126,9 +126,8 @@ Available environment variables
126126

127127
| key | default value | description |
128128
| - | - | - |
129-
| `RMW_IMPLEMENTATION` | `rmw_fastrtps_cpp` | Choosing a default DDS implementation. Possible values `rmw_fastrtps_cpp` and `rmw_cyclonedds_cpp` |
130-
| `FASTRTPS_DEFAULT_PROFILES_FILE` | `/var/tmp/husarnet-dds/fastdds.xml` | path to the output `.xml` file if `RMW_IMPLEMENTATION=rmw_fastrtps_cpp` |
131-
| `CYCLONEDDS_URI` | `/var/tmp/husarnet-dds/cyclonedds.xml` | path to the output `.xml` file if `RMW_IMPLEMENTATION=rmw_cyclonedds_cpp` |
129+
| `FASTRTPS_DEFAULT_PROFILES_FILE` | `/var/tmp/husarnet-dds/fastdds.xml` | path to the output `.xml` file for `RMW_IMPLEMENTATION=rmw_fastrtps_cpp` |
130+
| `CYCLONEDDS_URI` | `/var/tmp/husarnet-dds/cyclonedds.xml` | path to the output `.xml` file for `RMW_IMPLEMENTATION=rmw_cyclonedds_cpp` |
132131
| `ROS_DISCOVERY_SERVER` | (unset) | set it ONLY for devices running in [Fast DDS Discovery Server](https://fast-dds.docs.eprosima.com/en/latest/fastdds/ros2/discovery_server/ros2_discovery_server.html) **"Client mode"**. The value of this env should have the following format: `<Husarnet-hostname-of-discovery-server>:<PORT>`, eg. `my-ds-server:11811` |
133132
| `DISCOVERY_SERVER_PORT` | `11811` | set it ONLY for devices running in [Fast DDS Discovery Server](https://fast-dds.docs.eprosima.com/en/latest/fastdds/ros2/discovery_server/ros2_discovery_server.html) **"Server mode"** |
134133

main.go

Lines changed: 87 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func main_loop() {
4545
var output_xml_path string
4646

4747
myos := runtime.GOOS
48-
fmt.Printf("Host OS: %s\n", myos)
48+
fmt.Printf("Host OS: %s\r\n", myos)
4949
switch myos {
5050
case "linux":
5151
husarnet_temp_dir = "/var/tmp/husarnet-dds"
@@ -82,121 +82,124 @@ func main_loop() {
8282
dir := filepath.Dir(output_xml_path)
8383
err := os.MkdirAll(dir, os.ModePerm)
8484
if err != nil {
85-
fmt.Printf("Err: can not create \"%s\" path", dir)
85+
fmt.Printf("Err: can not create \"%s\" path\r\n", dir)
8686
os.Exit(1)
8787
}
8888

8989
ioutil.WriteFile(output_xml_path, []byte(output_xml), 0644)
9090

91-
// Check the RMW_IMPLEMENTATION env
92-
rmw_implementation, ok := os.LookupEnv("RMW_IMPLEMENTATION")
93-
if ok {
94-
fmt.Println("RMW_IMPLEMENTATION:", rmw_implementation)
95-
} else {
96-
fmt.Println("RMW_IMPLEMENTATION is not set.")
97-
return
91+
// =========================================
92+
// CYCLONE DDS CONFIG
93+
// =========================================
94+
95+
input_xml = string(default_config_cyclonedds_simple)
96+
97+
// check if non-default DDS config file exists
98+
if _, err := os.Stat(template_path_cyclonedds); err == nil {
99+
input_xml_bytes, _ := ioutil.ReadFile(template_path_cyclonedds)
100+
input_xml = string(input_xml_bytes)
98101
}
99102

100-
if rmw_implementation == "rmw_cyclonedds_cpp" {
101-
// default config
102-
input_xml = string(default_config_cyclonedds_simple)
103+
// prepare XML files with Husarnet hosts
104+
output_xml = ParseCycloneDDSSimple(input_xml)
105+
106+
// defaul output path
107+
output_xml_path = husarnet_temp_dir + "/husarnet-cyclonedds.xml"
103108

104-
// check if non-default DDS config file exists
105-
if _, err := os.Stat(template_path_cyclonedds); err == nil {
106-
input_xml_bytes, _ := ioutil.ReadFile(template_path_cyclonedds)
107-
input_xml = string(input_xml_bytes)
109+
// check whether env to set non-default path is set
110+
cyclonedds_uri, ok := os.LookupEnv("CYCLONEDDS_URI")
111+
if ok {
112+
fmt.Println("CYCLONEDDS_URI:", cyclonedds_uri)
113+
if strings.Contains(cyclonedds_uri, "husarnet") {
114+
output_xml_path = strings.Split(cyclonedds_uri, "file://")[1]
108115
}
116+
}
109117

110-
// prepare XML files with Husarnet hosts
111-
output_xml = ParseCycloneDDSSimple(input_xml)
118+
// Create necessary directories
119+
dir = filepath.Dir(output_xml_path)
120+
err = os.MkdirAll(dir, os.ModePerm)
121+
if err != nil {
122+
fmt.Printf("Err: can not create \"%s\" path\r\n", dir)
123+
os.Exit(1)
124+
}
112125

113-
// defaul output path
114-
output_xml_path = husarnet_temp_dir + "/husarnet-cyclonedds.xml"
126+
ioutil.WriteFile(output_xml_path, []byte(output_xml), 0644)
127+
fmt.Printf("Cyclone DDS config saved here: \"%s\"\r\n", output_xml_path)
115128

116-
// check whether env to set non-default path is set
117-
cyclonedds_uri, ok := os.LookupEnv("CYCLONEDDS_URI")
118-
if ok {
119-
fmt.Println("CYCLONEDDS_URI:", cyclonedds_uri)
120-
if strings.Contains(cyclonedds_uri, "husarnet") {
121-
output_xml_path = strings.Split(cyclonedds_uri, "file://")[1]
122-
}
123-
}
129+
// =========================================
130+
// FAST DDS CONFIG
131+
// =========================================
132+
133+
// Load the appriopriate XML default config
134+
ros_discovery_server, is_ds_client := os.LookupEnv("ROS_DISCOVERY_SERVER")
135+
if is_ds_client {
136+
fmt.Println("ROS_DISCOVERY_SERVER:", ros_discovery_server)
137+
input_xml = string(default_config_fastdds_ds_client)
138+
} else {
139+
input_xml = string(default_config_fastdds_simple)
124140
}
125141

126-
if rmw_implementation == "rmw_fastrtps_cpp" {
142+
// check if non-default DDS config file exists
143+
if _, err := os.Stat(template_path_fastdds_simple); err == nil {
144+
input_xml_bytes, _ := ioutil.ReadFile(template_path_fastdds_simple)
145+
input_xml = string(input_xml_bytes)
146+
}
127147

128-
// Load the appriopriate XML default config
129-
ros_discovery_server, is_ds_client := os.LookupEnv("ROS_DISCOVERY_SERVER")
130-
if is_ds_client {
131-
fmt.Println("ROS_DISCOVERY_SERVER:", ros_discovery_server)
132-
input_xml = string(default_config_fastdds_ds_client)
133-
} else {
134-
input_xml = string(default_config_fastdds_simple)
135-
}
148+
// prepare XML files with Husarnet hosts
149+
if is_ds_client {
150+
var ds_server_addr string
151+
var ds_server_port string
136152

137-
// check if non-default DDS config file exists
138-
if _, err := os.Stat(template_path_fastdds_simple); err == nil {
139-
input_xml_bytes, _ := ioutil.ReadFile(template_path_fastdds_simple)
140-
input_xml = string(input_xml_bytes)
141-
}
153+
// check whether IPv6 address is provided instead of hostname
154+
ipv6 := strings.Split(ros_discovery_server, ":")
155+
156+
if ipv6[0] == "[fc94" {
157+
// IPv6 hostname is provided
158+
parts := strings.Split(ros_discovery_server, "]:")
142159

143-
// prepare XML files with Husarnet hosts
144-
if is_ds_client {
145-
var ds_server_addr string
146-
var ds_server_port string
147-
148-
// check whether IPv6 address is provided instead of hostname
149-
ipv6 := strings.Split(ros_discovery_server, ":")
150-
151-
if ipv6[0] == "[fc94" {
152-
// IPv6 hostname is provided
153-
parts := strings.Split(ros_discovery_server, "]:")
154-
155-
if len(parts) == 1 {
156-
fmt.Println("Error: Invalid string format")
157-
os.Exit(1)
158-
}
159-
160-
ds_server_addr = strings.Trim(parts[0], "[")
161-
ds_server_port = parts[1]
162-
output_xml = strings.Replace(input_xml, "$DISCOVERY_SERVER_IPV6", ds_server_addr, 1)
163-
} else {
164-
// normal hostname is provided
165-
ds_server_addr = strings.Split(ros_discovery_server, ":")[0]
166-
ds_server_port = strings.Split(ros_discovery_server, ":")[1]
167-
output_xml = strings.Replace(input_xml, "$DISCOVERY_SERVER_IPV6", GetHostIPv6(ds_server_addr), 1)
160+
if len(parts) == 1 {
161+
fmt.Println("Error: Invalid string format")
162+
os.Exit(1)
168163
}
169164

170-
output_xml = strings.Replace(output_xml, "$DISCOVERY_SERVER_PORT", ds_server_port, 1)
171-
output_xml = strings.Replace(output_xml, "$HOST_IPV6", GetOwnHusarnetIPv6(), -1)
165+
ds_server_addr = strings.Trim(parts[0], "[")
166+
ds_server_port = parts[1]
167+
output_xml = strings.Replace(input_xml, "$DISCOVERY_SERVER_IPV6", ds_server_addr, 1)
172168
} else {
173-
output_xml = ParseFastDDSSimple(input_xml)
169+
// normal hostname is provided
170+
ds_server_addr = strings.Split(ros_discovery_server, ":")[0]
171+
ds_server_port = strings.Split(ros_discovery_server, ":")[1]
172+
output_xml = strings.Replace(input_xml, "$DISCOVERY_SERVER_IPV6", GetHostIPv6(ds_server_addr), 1)
174173
}
175174

176-
// defaul output path
177-
output_xml_path = husarnet_temp_dir + "/husarnet-fastdds.xml"
175+
output_xml = strings.Replace(output_xml, "$DISCOVERY_SERVER_PORT", ds_server_port, 1)
176+
output_xml = strings.Replace(output_xml, "$HOST_IPV6", GetOwnHusarnetIPv6(), -1)
177+
} else {
178+
output_xml = ParseFastDDSSimple(input_xml)
179+
}
180+
181+
// defaul output path
182+
output_xml_path = husarnet_temp_dir + "/husarnet-fastdds.xml"
178183

179-
// check whether env to set non-default path is set
180-
fastrtps_default_profiles_file, ok := os.LookupEnv("FASTRTPS_DEFAULT_PROFILES_FILE")
181-
if ok {
182-
fmt.Println("FASTRTPS_DEFAULT_PROFILES_FILE:", fastrtps_default_profiles_file)
183-
if strings.Contains(fastrtps_default_profiles_file, "husarnet") {
184-
output_xml_path = fastrtps_default_profiles_file
185-
}
184+
// check whether env to set non-default path is set
185+
fastrtps_default_profiles_file, ok := os.LookupEnv("FASTRTPS_DEFAULT_PROFILES_FILE")
186+
if ok {
187+
fmt.Println("FASTRTPS_DEFAULT_PROFILES_FILE:", fastrtps_default_profiles_file)
188+
if strings.Contains(fastrtps_default_profiles_file, "husarnet") {
189+
output_xml_path = fastrtps_default_profiles_file
186190
}
187-
188191
}
189192

190193
// Create necessary directories
191194
dir = filepath.Dir(output_xml_path)
192195
err = os.MkdirAll(dir, os.ModePerm)
193196
if err != nil {
194-
fmt.Printf("Err: can not create \"%s\" path", dir)
197+
fmt.Printf("Err: can not create \"%s\" path\r\n", dir)
195198
os.Exit(1)
196199
}
197200

198201
ioutil.WriteFile(output_xml_path, []byte(output_xml), 0644)
199-
fmt.Printf("DDS config saved here: \"%s\"", output_xml_path)
202+
fmt.Printf("Fast DDS config saved here: \"%s\"\r\n", output_xml_path)
200203
} else {
201204
fmt.Println("can't reach Husarnet client API")
202205
os.Exit(1)
@@ -296,7 +299,7 @@ func main() {
296299
envvars := make(map[string]string)
297300

298301
for i, env := range envs {
299-
fmt.Printf("env[%d]: %s\n", i, env)
302+
fmt.Printf("env[%d]: %s\r\n", i, env)
300303
key := strings.Split(env, "=")[0]
301304
value := strings.Split(env, "=")[1]
302305

@@ -340,7 +343,7 @@ func main() {
340343

341344
installCommand.Flags().StringArrayVarP(&envs, "env", "e",
342345
[]string{
343-
"RMW_IMPLEMENTATION=rmw_fastrtps_cpp",
346+
"CYCLONEDDS_URI=file://" + husarnet_temp_dir + "/cyclonedds.xml",
344347
"FASTRTPS_DEFAULT_PROFILES_FILE=" + husarnet_temp_dir + "/fastdds.xml"},
345348
"environment variables for the service")
346349

0 commit comments

Comments
 (0)