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

refactoring mdns request parsing #340

Merged
merged 4 commits into from
May 23, 2022

Conversation

freasy
Copy link
Contributor

@freasy freasy commented May 19, 2022

mdns responses now doenst rely on the url starting with "elrs" and its now supporting multiple elrs answers in a response

freasy added 3 commits May 19, 2022 12:39
mdns responses now doenst rely on the url starting with "elrs" and its not supporting multiple elrs answers in a response
mdns responses now doenst rely on the url starting with "elrs" and its now supporting multiple elrs answers in a response
@jurgelenas jurgelenas requested a review from justinlampley May 19, 2022 10:41
Copy link
Collaborator

@justinlampley justinlampley left a comment

Choose a reason for hiding this comment

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

Changing the way we identify elrs devices from checking if the name starts with elrs to instead check if vender = elrs is good, and is the more proper way to identify the elrs device.

The rest of the refactoring seems to have been done under the impression that there could be multiple elrs devices included in a single ResponsePacket, which isn't going to occur.

@@ -120,88 +121,104 @@ export default class MulticastDnsService {

// check if any of the answers on the response have a name that starts with
// 'elrs_', which indicates that it is an elers device
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment can be removed since it is no longer applicable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

const dns: string = srvResponse.data?.target;
const port: number = srvResponse.data?.port;

if (srvResponse) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to check "if (srvResponse)" since it was already checked a few lines above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

missed that, removed

(answer) => answer.type === 'SRV'
) as SrvAnswer[];

const srvResponse: SrvAnswer | undefined = srvResponses.find((i) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is no need to check for the name to match, a responsePacket is only going to contain information about a single response, there will never be multiple devices included in a single mdns response. It doesn't hurt anything that it is being checked for, just isn't necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i thought there would be a possibility of multiple responses in a answer package. I changed them to "find" instead of "filter"

if (srvResponse) {
const aResponse: StringAnswer | undefined = items.find(
(answer) =>
answer.type === 'A' && answer.name === srvResponse.data.target
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above for the srv response, really isn't any need to check for the name to match.

@freasy
Copy link
Contributor Author

freasy commented May 20, 2022

I changed all your suggestions. Wasnt aware, that a single response can only contain one answer.

@justinlampley
Copy link
Collaborator

Yes, multicast-dns emits a response event for each individual mdns response it receives, that response can contain multiple record types like TXT, A, SRC, etc. but they all pertain to a single response from a single service. That is why the original code didn't match on name, it just looked for the TXT, A, and SRC types in the ResponsePacket since all those records correspond to a response from a single elrs device.

@freasy
Copy link
Contributor Author

freasy commented May 20, 2022

Yes, multicast-dns emits a response event for each individual mdns response it receives, that response can contain multiple record types like TXT, A, SRC, etc. but they all pertain to a single response from a single service. That is why the original code didn't match on name, it just looked for the TXT, A, and SRC types in the ResponsePacket since all those records correspond to a response from a single elrs device.

Understood, so the latest changes are reverting that, that's fine now?

@freasy freasy requested a review from justinlampley May 20, 2022 16:50
Copy link
Collaborator

@justinlampley justinlampley left a comment

Choose a reason for hiding this comment

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

Looks good.

@jurgelenas jurgelenas merged commit f62c7be into ExpressLRS:master May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants