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

Dns traits force caching in-flight DNS requests #89

Open
ryan-summers opened this issue Aug 22, 2023 · 1 comment
Open

Dns traits force caching in-flight DNS requests #89

ryan-summers opened this issue Aug 22, 2023 · 1 comment

Comments

@ryan-summers
Copy link
Member

ryan-summers commented Aug 22, 2023

Currently, because the Dns resolver functions return an nb::Result, this means that some higher-level has to actually cache the the hostname being looked up during repeated calls to resolve the name. However, this isn't really a great API because it enforces caching and RAM usage if the hostnames are long. Thus, if an implementation wants to support N simultanenous queries of 255 bytes, it must cache at least 255 * N bytes locally.

Ideally, we would refactor the functions to be get_host_by_name() -> Handle, where Handle is some unique ID that can be queried against in the future (and can ideally be really lightweight, like a u32).

So the API may be:

trait DnsLookup {
    type Handle;
    fn start_query(&mut self, hostname: &str, typ: QueryType) -> Result<Handle, Self::Error>;
    fn check_query(&mut self, handle: &Handle) -> Result<IpAddr, Self::Error>;
    fn cancel_query(&mut self, handle: Handle);
}

Also, it seems like get_host_by_ip() is a bit of a different DNS use-case and isn't super well-suited for embedded (I just mark it as unimplemented!() in my case because smoltcp doesn't support it). Perhaps it would be best to move this to a separate trait.

@ryan-summers ryan-summers changed the title Dns traits enforce caching in-flight DNS requests Dns traits force caching in-flight DNS requests Aug 22, 2023
@ryan-summers
Copy link
Member Author

Check out quartiq/smoltcp-nal#46 for an example implementation using smoltcp

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

No branches or pull requests

1 participant