Skip to content

Commit 5564862

Browse files
authored
RSDK-9300 - make mdns query more generic over local-ness of candidate (#140)
1 parent 60bff87 commit 5564862

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

Diff for: src/rpc/dial.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,8 @@ impl<T: AuthMethod> DialBuilder<T> {
329329
let mut resp: Option<Response> = None;
330330
for ipv4 in addresses {
331331
for candidate in candidates {
332-
let mut addr_to_send = "".to_string();
333-
addr_to_send.push_str(candidate.as_str());
334-
addr_to_send.push('.');
335-
addr_to_send.push_str(VIAM_MDNS_SERVICE_NAME);
336-
337332
let discovery = discover::interface_with_loopback(
338-
addr_to_send,
333+
VIAM_MDNS_SERVICE_NAME,
339334
Duration::from_millis(250),
340335
ipv4,
341336
)
@@ -344,7 +339,15 @@ impl<T: AuthMethod> DialBuilder<T> {
344339
pin_mut!(stream);
345340
while let Some(Ok(response)) = stream.next().await {
346341
if let Some(hostname) = response.hostname() {
347-
if hostname.contains(candidate.as_str()) {
342+
// Machine uris come in local ("my-cool-robot.abcdefg.local.viam.cloud")
343+
// and non-local ("my-cool-robot.abcdefg.viam.cloud") forms. Sometimes
344+
// (namely with micro-rdk), our mdns query can only see one (the local) version.
345+
// However, users are typically passing the non-local version. By splitting at
346+
// "viam" and taking the only the first value, we can still search for
347+
// candidates based on the actual "my-cool-robot" name without being opinionated
348+
// on whether the candidate is locally named or not.
349+
let local_agnostic_candidate = candidate.as_str().split("viam").next()?;
350+
if hostname.contains(local_agnostic_candidate) {
348351
resp = Some(response);
349352
break;
350353
}
@@ -400,7 +403,7 @@ impl<T: AuthMethod> DialBuilder<T> {
400403

401404
let ifaces: HashMap<&str, Vec<&IpAddr>> =
402405
ifaces.iter().fold(HashMap::new(), |mut map, (k, v)| {
403-
map.entry(k).or_insert(vec![]).push(v);
406+
map.entry(k).or_default().push(v);
404407
map
405408
});
406409

0 commit comments

Comments
 (0)