@@ -329,13 +329,8 @@ impl<T: AuthMethod> DialBuilder<T> {
329
329
let mut resp: Option < Response > = None ;
330
330
for ipv4 in addresses {
331
331
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
-
337
332
let discovery = discover:: interface_with_loopback (
338
- addr_to_send ,
333
+ VIAM_MDNS_SERVICE_NAME ,
339
334
Duration :: from_millis ( 250 ) ,
340
335
ipv4,
341
336
)
@@ -344,7 +339,15 @@ impl<T: AuthMethod> DialBuilder<T> {
344
339
pin_mut ! ( stream) ;
345
340
while let Some ( Ok ( response) ) = stream. next ( ) . await {
346
341
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) {
348
351
resp = Some ( response) ;
349
352
break ;
350
353
}
@@ -400,7 +403,7 @@ impl<T: AuthMethod> DialBuilder<T> {
400
403
401
404
let ifaces: HashMap < & str , Vec < & IpAddr > > =
402
405
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) ;
404
407
map
405
408
} ) ;
406
409
0 commit comments