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

RSDK-9300 - make mdns query more generic over local-ness of candidate #140

Merged
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
19 changes: 11 additions & 8 deletions src/rpc/dial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,8 @@ impl<T: AuthMethod> DialBuilder<T> {
let mut resp: Option<Response> = None;
for ipv4 in addresses {
for candidate in candidates {
let mut addr_to_send = "".to_string();
addr_to_send.push_str(candidate.as_str());
addr_to_send.push('.');
addr_to_send.push_str(VIAM_MDNS_SERVICE_NAME);

let discovery = discover::interface_with_loopback(
addr_to_send,
VIAM_MDNS_SERVICE_NAME,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See added comment re: the localness of machine URIs to understand why this is important. Basically, we were trying to discover candidates with a fully qualified name. but, the fully qualified name we were passing was non-local and, for reasons not entirely clear to me, the only candidates we could find from a micro-rdk process were the ones with a local name. By making our search more generic we can find everything that looks Viam-y, and then narrow it down based on the actual name of the machine.

Duration::from_millis(250),
ipv4,
)
Expand All @@ -344,7 +339,15 @@ impl<T: AuthMethod> DialBuilder<T> {
pin_mut!(stream);
while let Some(Ok(response)) = stream.next().await {
if let Some(hostname) = response.hostname() {
if hostname.contains(candidate.as_str()) {
// Machine uris come in local ("my-cool-robot.abcdefg.local.viam.cloud")
// and non-local ("my-cool-robot.abcdefg.viam.cloud") forms. Sometimes
// (namely with micro-rdk), our mdns query can only see one (the local) version.
// However, users are typically passing the non-local version. By splitting at
// "viam" and taking the only the first value, we can still search for
// candidates based on the actual "my-cool-robot" name without being opinionated
// on whether the candidate is locally named or not.
let local_agnostic_candidate = candidate.as_str().split("viam").next()?;
if hostname.contains(local_agnostic_candidate) {
resp = Some(response);
break;
}
Expand Down Expand Up @@ -400,7 +403,7 @@ impl<T: AuthMethod> DialBuilder<T> {

let ifaces: HashMap<&str, Vec<&IpAddr>> =
ifaces.iter().fold(HashMap::new(), |mut map, (k, v)| {
map.entry(k).or_insert(vec![]).push(v);
map.entry(k).or_default().push(v);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flyby

map
});

Expand Down
Loading