Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ booster_sdk = { path = "booster_sdk" }

tokio = { version = "1.42", features = ["full"] }
futures = "0.3"
rustdds = "0.11.8"
rustdds = { git = "https://github.com/oxkitsune/RustDDS.git", branch = "gijs/localhost-only"}
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"
Expand Down
18 changes: 16 additions & 2 deletions booster_sdk/src/dds/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use serde::{Serialize, de::DeserializeOwned};
use tokio::sync::mpsc;

use rustdds::{DomainParticipant, Publisher, QosPolicyBuilder, Subscriber};
use rustdds::{DomainParticipant, DomainParticipantBuilder, Publisher, QosPolicyBuilder, Subscriber};

use crate::types::{DdsError, Result};

Expand All @@ -12,6 +12,9 @@ use super::topics::TopicSpec;
#[derive(Default, Debug, Clone)]
pub struct DdsConfig {
pub domain_id: u16,
/// If set, restricts DDS discovery and traffic to the named network interfaces only
/// (e.g. `vec!["eth0".into()]`). When `None`, all multicast-capable interfaces are used.
pub only_networks: Option<Vec<String>>,
}

#[derive(Clone)]
Expand All @@ -23,7 +26,18 @@ pub struct DdsNode {

impl DdsNode {
pub fn new(config: DdsConfig) -> Result<Self> {
let participant = DomainParticipant::new(config.domain_id)
let loopback = if cfg!(target_os = "macos") {
"lo0"
} else {
"lo"
};
let mut builder =
DomainParticipantBuilder::new(config.domain_id).with_only_networks(vec![loopback.into()]);
if let Some(networks) = config.only_networks {
builder = builder.with_only_networks(networks);
}
let participant = builder
.build()
.map_err(|err| DdsError::InitializationFailed(err.to_string()))?;
let qos = QosPolicyBuilder::new().build();
let publisher = participant
Expand Down
3 changes: 3 additions & 0 deletions booster_sdk/src/dds/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct RpcClientOptions {
pub default_timeout: Duration,
pub startup_wait: Duration,
pub service_topic: String,
pub only_networks: Option<Vec<String>>,
}

impl Default for RpcClientOptions {
Expand All @@ -33,6 +34,7 @@ impl Default for RpcClientOptions {
// Wait once before the first RPC call so endpoint discovery can settle.
startup_wait: Duration::from_millis(3000),
service_topic: LOCO_API_TOPIC.to_owned(),
only_networks: None,
}
}
}
Expand Down Expand Up @@ -146,6 +148,7 @@ impl RpcClient {
pub fn new(options: RpcClientOptions) -> Result<Self> {
let node = DdsNode::new(super::DdsConfig {
domain_id: options.domain_id,
only_networks: options.only_networks.clone(),
})?;

let service_topic = normalize_service_topic(&options.service_topic);
Expand Down
Loading