Skip to content

Implement Hickroy-dns - #18

Draft
Vizonex wants to merge 3 commits into
compio-rs:mainfrom
Vizonex:dns
Draft

Vizonex wants to merge 3 commits into
compio-rs:mainfrom
Vizonex:dns

Conversation

@Vizonex

@Vizonex Vizonex commented Nov 18, 2026

Copy link
Copy Markdown

This is still a rough draft as I have not found a safe and reliable way to wrap asynchronous rust functions yet but I have a general idea of how getaddrinfo needs to work.

What I understand so far

  • if AF_INET flag is set do ipv4_lookup
  • if AF_INET6 is set do ipv6_lookup
  • otherwise calling for both which should be tied to AF_UNSPEC should call both ipv6 and ipv4
  • port number should be used to filter our results.

PR closes #17


#[pyclass(subclass)]
pub struct CompioLoop {
dns: OwnedRefCell<Resolver<CompioRuntimeProvider>>,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It's cool that hickory has compio support! But I'm wild-guessing from my phone that it's the standard compio-runtime that is supported, not the Python-specific one that compio-py forged.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@fantix
Yeah it's a limitation and the second limitation is that we have to come up with our own getaddrinfo function as most lookups I've done about how to do one are not excactly said in detail however with a bit of guessing I did manage to figure out how we could go about it as outlined in my original plan. Know that my rust skills are a bit flakey compared to my Cython and C skills so I'm limited on what my ideas here are.

async fn async_getaddrinfo<'py>(
    r#loop: &CompioLoop,
    host: String,
    family: i32,
) -> PyResult<Vec<Lookup>> {
    let dns = r#loop.dns()?;
    let mut results = Vec::new();

    if (family & AF_INET) > 0 || family == 0 {
        let ipv4 = dns.ipv4_lookup(&host).await;
        match ipv4 {
            Ok(ipv4_result) => {results.push(ipv4_result)},
            Err(e) => {return Err(PyOSError::new_err(e.to_string()));}
        }
    }

    if (family & AF_INET6) > 0 || family == 0 {
        let ipv6 = dns.ipv6_lookup(&host).await;
        match ipv6 {
            Ok(ipv6_result) => {results.push(ipv6_result)},
            Err(e) => {return Err(PyOSError::new_err(e.to_string()));}
        }
    }
    Ok(results)
}
``

@Vizonex Vizonex Nov 18, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

If needed I can always ask hickory-dns maintainers to see if they would like to help us create something for implementing getaddrinfo and getnameinfo functions which would make this task a bit less of a headache than it needs to be. as AAAA ipv6 and A ipv4 is always done under the hood. The wiki article linked shows this although I havent fully skimmed through it yet.

Maybe there is an RFC on how a getaddrinfo function works which would be helpful to me if anybody finds me one. I love RFCs because they give me a clear blueprint and the keep all the details cut and dry. c-ares leaves me a bit clueless on how it works (probably due to how optimized it is)

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.

Add Hickory-DNS Rust Crate to Compio for dns related functions loop.getaddrinfo and loop.getnameinfo

2 participants