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

refactor: add service package and start splitting HTTP handling #1427

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

ThinkChaos
Copy link
Collaborator

Progress for #1206.

No user visible changes in this PR: it's just refactoring and the new config cannot be set from the YAML file.
Instead the new config structs are filled with the info from ports: until we're ready to deprecate ports fully.

The first part of the commits refactor how we setup the HTTP listeners.
The second part adds a new service package with interfaces used to split up server.Server.
The commits after adding that package refactor the DoH, metrics, and API to be services.

Here's the docs that package as an overview of the design:

Package service exposes types to abstract services from the networking.

The idea is that we build a set of services and a set of network
endpoints (Listener). The services are then assigned to endpoints based
on the address(es) they were configured for.

Actual service to endpoint binding is not handled by the abstractions in
this package as it is protocol specific.
The general pattern is to make a "server" that wraps a service, and can
then be started on an endpoint using a Serve method,
similar to http.Server.

To support exposing multiple compatible services on a single endpoint
(example: DoH + metrics on a single port), services can implement Merger.

This doesn't touch DNS listener/server code (besides moving the TLS config to a single spot), but I think we'll be able to re-use the same code to setup DNS listeners, and split the DNS server logic into a bunch of services + one server.

The follow-up work is to continue removing things from configureHTTPRouter until it's empty and we can remove the transitional httpMiscService.
At that point we'll be ready to deprecate ports and switch to the new services config format under discussion in #1206.

Package service exposes types to abstract services from the networking.

The idea is that we build a set of services and a set of network
endpoints (Listener). The services are then assigned to endpoints based
on the address(es) they were configured for.

Actual service to endpoint binding is not handled by the abstractions in
this package as it is protocol specific.
The general pattern is to make a "server" that wraps a service, and can
then be started on an endpoint using a `Serve` method,
similar to `http.Server`.

To support exposing multiple compatible services on a single endpoint
(example: DoH + metrics on a single port),
services can implement `Merger`.
@ThinkChaos
Copy link
Collaborator Author

I still need to write tests for the new package, and the various new "services", but besides that it's in a reviewable state :)

@0xERR0R
Copy link
Owner

0xERR0R commented Apr 10, 2024

Skimmed over your PR and it looks very good! 👍

Copy link
Collaborator

@kwitsch kwitsch left a comment

Choose a reason for hiding this comment

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

Read through it and I think you did an amazing job. 👍

This approach looks like a really good foundation for a step wise implementation without end-user obstruction.

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.

None yet

3 participants