mirror of
https://github.com/hickory-dns/hickory-dns.git
synced 2026-04-25 03:05:51 +03:00
[GH-ISSUE #1653] Custom ConnectionProvider #725
Labels
No labels
blocked
breaking-change
bug
bug:critical
bug:tests
cleanup
compliance
compliance
compliance
crate:all
crate:client
crate:native-tls
crate:proto
crate:recursor
crate:resolver
crate:resolver
crate:rustls
crate:server
crate:util
dependencies
docs
duplicate
easy
easy
enhance
enhance
enhance
feature:dns-over-https
feature:dns-over-quic
feature:dns-over-tls
feature:dnsssec
feature:global_lb
feature:mdns
feature:tsig
features:edns
has workaround
ops
perf
platform:WASM
platform:android
platform:fuchsia
platform:linux
platform:macos
platform:windows
pull-request
question
test
tools
tools
trust
unclear
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hickory-dns#725
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Noah-Kennedy on GitHub (Feb 28, 2022).
Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/1653
Is there a way to write custom connection providers for the
AsyncResolverintrust-dns-resolver? It looks likeAsyncResolveronly implements its methods forGenericConnectionandGenericConnectionProvider<TokioRuntime>, which is unfortunate, as those types do not seem to be publicly exposed.I am looking to attach custom headers (authorization) to DOH requests, as well as mess around with DNS over QUIC.
@bluejekyll commented on GitHub (Mar 1, 2022):
Theoretically, yes it is possible. If you look at some of the test code, you'll notice more usage patterns for the
ConnectionProvidertype.But the last time that this came up, folks have tended to find it simpler to implement the reimplement from the
Runtimeup, see theAsyncStdRuntimefor an example: https://github.com/bluejekyll/trust-dns/blob/main/crates/async-std-resolver/src/runtime.rs@bluejekyll commented on GitHub (Mar 1, 2022):
Btw, for DoQ, I've been thinking for a while about implementing that, perhaps @djc has some suggestions? It would be really nice to add that, I would think the DoH implementation would be a good starting point for how to do it: https://github.com/bluejekyll/trust-dns/blob/main/crates/proto/src/https/https_client_stream.rs
@djc commented on GitHub (Mar 1, 2022):
I'm guessing @Noah-Kennedy will want to use Quiche as the DoQ substrate? @Noah-Kennedy also if you're looking into building tokio-uring support for trust-dns, that's probably something we'd like to have upstreamed.
@Noah-Kennedy commented on GitHub (Mar 1, 2022):
@bluejekyll I'd like to start first by trying to implement some custom connection providers in a crate consuming this library. Is this possible to do in a manner which would allow me to leverage the AsyncResolver?
@bluejekyll commented on GitHub (Mar 1, 2022):
Yes, it's possible. See my first response to you able examples for that. I'm not sure which is your best option, i.e. defining a new Runtime or implementing a custom ConnectionProvider. Here's a mocked ConnectionProvider example that might be simpler to follow than the actual implementations. Since it's implemented as an integration test all the pieces you need should be in the public API:
github.com/bluejekyll/trust-dns@aaf726e556/tests/integration-tests/tests/name_server_pool_tests.rs (L37)@Noah-Kennedy commented on GitHub (Mar 1, 2022):
I've implemented a custom connection provider. How do I construct an
AsyncResolverwhich uses it? I don't see anything in those tests which demonstrates how to do this.@bluejekyll commented on GitHub (Mar 1, 2022):
Maybe the "trick" is that
ConnectionProvideris a static parameter on the declared types, e.g. here we have it bound toGenericConnectionProviderand this new method is used:github.com/bluejekyll/trust-dns@8515a4321f/crates/resolver/src/async_resolver.rs (L164)Such that when the TokioAsyncResolver calls here:
github.com/bluejekyll/trust-dns@8515a4321f/crates/resolver/src/async_resolver.rs (L131)So the ConnectionProvider is associated through the type bounds on this impl:
github.com/bluejekyll/trust-dns@8515a4321f/crates/resolver/src/async_resolver.rs (L148)And that is
GenericConnection, GenericConnectionProvider<R>whereRis theRuntimein this case Tokio...Does that help?
@Noah-Kennedy commented on GitHub (Mar 2, 2022):
Maybe it's best for me to show what I did for my proof of concept intended to show how to use custom providers for the AsyncResolver:
I implemented a provider and a handle, however I cannot meaningfully use AsyncResolver with them, as I cannot construct an AsyncResolver with any type parameters other than GenericConnection or GenericConnectionProvider, as there are no constructors in trustdns for other type parameters and the fields within AsyncResolver are private.
Is there a different way that I should go about doing this?
@bluejekyll commented on GitHub (Mar 2, 2022):
Ah, sorry, I missed this. I'm not sure why this isn't public (I guess I wasn't sure if people would use it, so didn't want to expose it unnecessarily), you need this constructor:
github.com/bluejekyll/trust-dns@8515a4321f/crates/resolver/src/async_resolver.rs (L212-L216)or this one:
github.com/bluejekyll/trust-dns@8515a4321f/crates/resolver/src/async_resolver.rs (L262-L265)Actually, that now has me wondering how the integration tests have access to those methods... Anyway, we'll need to make those public for you.
@Noah-Kennedy commented on GitHub (Mar 2, 2022):
Should I file an issue and open a PR for making these public?
@djc commented on GitHub (Mar 2, 2022):
Just go straight for the PR!
@Noah-Kennedy commented on GitHub (Mar 2, 2022):
https://github.com/bluejekyll/trust-dns/pull/1654
@bluejekyll commented on GitHub (Mar 2, 2022):
@Noah-Kennedy can you work off of
mainfor your needs or do you need a release for those interfaces?@Noah-Kennedy commented on GitHub (Mar 2, 2022):
Since #1654 is in, I will point my code at master and have a go again.
@Noah-Kennedy commented on GitHub (Mar 2, 2022):
At least for the POC.
@Noah-Kennedy commented on GitHub (Mar 2, 2022):
A release would probably be best though IMO, since others may be interested in using custom providers as well.
@Noah-Kennedy commented on GitHub (Mar 11, 2022):
@bluejekyll when does the AsyncResolver create a new connection from a provider?
@bluejekyll commented on GitHub (Mar 12, 2022):
It should be on first use, ie the first time a query is made and when the connection is disconnected.
are you seeing something unexpected?
@Noah-Kennedy commented on GitHub (Mar 12, 2022):
Nope, just wanted to know if it ever dropped the connections for whatever reason.
@Noah-Kennedy commented on GitHub (Mar 12, 2022):
What exactly does a "connection" mean in the context of DNS?
@bluejekyll commented on GitHub (Mar 12, 2022):
Depends on the connection type. For UDP it doesn't mean much, an open socket awaiting a response, but a new socket will be used for every request to ensure we are rotating ports (to help reduce DNS response spoofing). For TCP, HTTPS, and TLS, those are long lived and if I remember correctly, we have a timeout that keeps them open for a period of time in case they will be reused.