Skip to content

Split the state machine out of DnsOverHttps#9569

Merged
swankjesse merged 3 commits into
masterfrom
jwilson.0721.split_out_state_machine
Jul 21, 2026
Merged

Split the state machine out of DnsOverHttps#9569
swankjesse merged 3 commits into
masterfrom
jwilson.0721.split_out_state_machine

Conversation

@swankjesse

Copy link
Copy Markdown
Collaborator

There's a few things that are a bit awkward, but overall it seems like it'll afford swapping in UDP or Android's resolver.

@swankjesse
swankjesse force-pushed the jwilson.0721.split_out_state_machine branch from 9d29761 to 9b10942 Compare July 21, 2026 15:30
Base automatically changed from jwilson.0721.lookup_on_call to master July 21, 2026 15:31
There's a few things that are a bit awkward, but overall it seems
like it'll afford swapping in UDP or Android's resolver.
@swankjesse
swankjesse force-pushed the jwilson.0721.split_out_state_machine branch from 9b10942 to d5aa220 Compare July 21, 2026 15:32
import okhttp3.Protocol

/**
* State machine for DNS calls. This is intended for use with any transport for the queries, such

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.

Thanks!

add(DnsMessage.query(call.request.hostname, TYPE_HTTPS))
}
if (includeIPv6) {
add(DnsMessage.query(call.request.hostname, TYPE_AAAA))

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.

If I wanted to use this for Android and I have two calls to make

a) async blocking InetAddress.getAllByName
b) DnsResolver rawQuery

is that stretching it past being a useful correct abstraction?

What would the calls be? and what would the Transport return as Q?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Could you use DnsResolver for TYPE_A, TYPE_AAAA, and TYPE_HTTPS ?

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.

No, we lose a lot of caching and RFC level sorting if we do that.

Even if we break out the RFCs and fix a bunch of things, I've been advised that will perform worse.

We should call either InetAddress.getAllByName() or Network.getAllByName()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Gotcha.

Does that drawback apply to DnsOverHttps also? Might be worth fixing regardless.

I suspect the ‘perform worse’ is gonna be due to operating system-layer caching? (I can’t think of anything else that’d allow the syscall to run faster than what we can do.)

@yschimke yschimke Jul 21, 2026

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.

No, sort of, maybe, yes?

perform worse is likely

  • Android caching in the java layer, avoiding actual DNS work, and resetting when network changes. and other things.
  • OkHttp does not correctly sort ip addresses in a way that would avoid some obvious bad patterns.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Let’s correctly sort IP addresses!

@swankjesse
swankjesse merged commit d120673 into master Jul 21, 2026
43 of 47 checks passed
@swankjesse
swankjesse deleted the jwilson.0721.split_out_state_machine branch July 21, 2026 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants