-
Notifications
You must be signed in to change notification settings - Fork 24
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
njooma
merged 1 commit into
viamrobotics:main
from
stuqdog:fix-local-signaling-connection-for-micro-rdk
Jan 27, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
Duration::from_millis(250), | ||
ipv4, | ||
) | ||
|
@@ -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; | ||
} | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. flyby |
||
map | ||
}); | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.