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

A helper class that could resolve from "hosts", mDNS and finally DNS #5648

Draft
wants to merge 33 commits into
base: dev
Choose a base branch
from

Conversation

HeMan
Copy link
Contributor

@HeMan HeMan commented Nov 1, 2023

What does this implement/fix?

There are currently no way to have anything similar to an /etc/hosts-file. This adds that (would solve esphome/feature-requests#2008), but also a common way to resolve names by mDNS and regular DNS. The mDNS support is intentional simplified to search for a service with the "hostname" asked for.

Could be breaking for external components

Todo:

  • Add tests
  • Disable mDNS query with mdns disabled
  • Timeout for DNS query
  • Support for IPv6 and DNS
  • Support for IPv6 and mDNS
  • Add support to read and parse /etc/hosts-like files
  • Convert DNS queries in components, for example MQTT and SNTP
  • Documentation

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other

Related issue or feature (if applicable): fixes

Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040
  • BK72xx
  • RTL87xx

Example entry for config.yaml:

# Example config.yaml

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

std::vector<network::IPAddress> resolved;
mdns_result_t *results = nullptr;
mdns_ip_addr_t *a = nullptr;
esp_err_t err = mdns_query_ptr(("_" + servicename).c_str(), "_tcp", 3000, 20, &results);
Copy link
Member

Choose a reason for hiding this comment

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

Why query for PTR here?

Copy link
Member

Choose a reason for hiding this comment

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

I think the goal here is to look for a A/AAAA record?

https://docs.espressif.com/projects/esp-protocols/mdns/docs/latest/en/index.html#_CPPv410mdns_queryPKcPKcPKc8uint16_t8uint32_t6size_tPP13mdns_result_t

Maybe
mdns_query(servicename, NULL, NULL, MDNS_TYPE_ANY, 20, &results);

or maybe MDNS_TYPE_A, MDNS_TYPE_AAAA?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!

@codecov-commenter
Copy link

codecov-commenter commented Jan 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 53.91%. Comparing base (4d8b5ed) to head (f9ab475).
Report is 718 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #5648      +/-   ##
==========================================
+ Coverage   53.70%   53.91%   +0.20%     
==========================================
  Files          50       50              
  Lines        9408     9625     +217     
  Branches     1654     1698      +44     
==========================================
+ Hits         5053     5189     +136     
- Misses       4056     4112      +56     
- Partials      299      324      +25     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@HeMan HeMan force-pushed the resolver branch 2 times, most recently from 7a81bc9 to f438012 Compare March 29, 2024 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants