Skip to content

Some architectural cleanup#204

Merged
aarond10 merged 2 commits intomasterfrom
arch-review
May 6, 2026
Merged

Some architectural cleanup#204
aarond10 merged 2 commits intomasterfrom
arch-review

Conversation

@aarond10
Copy link
Copy Markdown
Owner

@aarond10 aarond10 commented May 5, 2026

This accomplishes a few things I have wanted to do but not had much time to get done.

  1. Move the growing set of code in main.c into it's own file (doh_proxy.{c,h}).
  2. Move the dns truncation logic into it's own file.

I was planning after this is to merge common logic across dns_listener_{tcp,udp}.{c,h}.

@aarond10
Copy link
Copy Markdown
Owner Author

aarond10 commented May 5, 2026

@baranyaib90, any chance you'd mind reviewing this one?

@baranyaib90
Copy link
Copy Markdown
Contributor

baranyaib90 commented May 5, 2026

Hi, I just had a brief look at this and I'm not happy with the timing of this refactor, because I have a lot of WIP changes on my master branch (https://github.com/baranyaib90/https_dns_proxy/commits/master/) and this will give me a huge rebase work.
Other thing: I am currently reimplementing the whole truncation logic without c-ares library and I expect, that it will be way better. (Not yet published in my repo.)
So I would be glad if you could postpone this refactor. If not, then my problem :D

Copy link
Copy Markdown
Contributor

@baranyaib90 baranyaib90 left a comment

Choose a reason for hiding this comment

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

I have checked the code good enough. Wrote a few comments about 2 stuff mainly (removing ops and dummy functions).
I like this refactor, it really makes more sense this way.
Get it in before me. I will deal with my rebase mess :)

Comment thread src/dns_listener.h Outdated
Comment thread src/dns_listener.h Outdated
Comment thread src/dns_listener_tcp.c Outdated
Comment thread src/dns_listener_udp.c Outdated
@aarond10
Copy link
Copy Markdown
Owner Author

aarond10 commented May 5, 2026

Hi, I just had a brief look at this and I'm not happy with the timing of this refactor, because I have a lot of WIP changes on my master branch (https://github.com/baranyaib90/https_dns_proxy/commits/master/) and this will give me a huge rebase work.

I'm happy to sit on this and rebase later. Your call.

aarond10 added 2 commits May 6, 2026 07:23
The per-request lifecycle (allocate state, hand to libcurl, route response
back to the originating listener, free) lived as static functions in main.c
glued together via app_state_t and an is_tcp tag in request_t. The two
listener implementations had no shared interface, so dispatch branched on
is_tcp at every step.

- dns_listener.h: transport-agnostic interface (respond/stop/destroy
  function pointers + transport tag for metrics).
- dns_listener_udp.{c,h}, dns_listener_tcp.{c,h}: adapters.
- doh_proxy.{c,h}: owns the request lifecycle, curl resolve list, and
  bootstrap-await/on-ready handshake. Listeners and dns_poller call into
  the proxy, not main.c.
- dns_common.h: shared DNS protocol constants.

main.c shrinks to assembly. The is_tcp boolean is gone.
~110 lines of EDNS0/c-ares juggling (parse OPT, drop additional+authority,
drop answers until under the limit, set TC) was buried as static functions
in the UDP listener — only reachable by booting a real UDP server.

Move to dns_truncate.{c,h} with one entry point: dns_truncate_for_udp().
The UDP listener's respond path collapses to validate-length,
truncate-for-fit, sendto. The module is now unit-testable with synthetic
byte buffers.
@baranyaib90
Copy link
Copy Markdown
Contributor

Hi @aarond10, thank you for the changes, please merge it.
I will rebase my stuff. I'm progressing quite slowly with it...

@aarond10 aarond10 merged commit 0ba0525 into master May 6, 2026
3 of 4 checks passed
@aarond10 aarond10 deleted the arch-review branch May 6, 2026 07:04
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.

2 participants