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

feat(x): make config support PacketListeners and make dependencies explicit and decoupled #304

Merged
merged 31 commits into from
Nov 1, 2024

Conversation

fortuna
Copy link
Contributor

@fortuna fortuna commented Oct 28, 2024

Properly Support PacketListeners in the Config

As I design the advanced config for Outline, I ran into the issue that we need to support PacketListeners for both the Outline Client and to use QUIC. This PR allows PacketListeners to have a nested config like we have for dialers. I also added support to register types.

Explicit and decouples dependencies

The factory functions used to take as input factory functions for stream and packet dialers, regardless whether they needed them or not. This made dependencies unclear and not enforceable at compile time.

It also doesn't scale well, as more advanced strategies may need dependencies of different types. With the introduction of PacketListeners, I already ran into that issue. However, instead of adding a PacketListener factory to the factory function, I simplified the registration function to only take the context and config. The extra dependencies are passed explicitly then you create the factory function. This ensures compile checks, and allows us to inject any dependency we want, without needing to change the API.

Include Context

I now pass a Context to factory functions. This will allow us to inject deadlines or cancel creation for dialers that take long (e.g. Smart Dialer, Psiphon). It may also allow us to inject a structure for "named dialers" in the future.

@fortuna fortuna requested a review from jyyi1 October 28, 2024 22:25
@fortuna
Copy link
Contributor Author

fortuna commented Oct 28, 2024

BTW, I believe it's possible to reduce some of the duplication with Generics. I'll explore that in parallel, but I wanted to advance this PR regardless of that.

@fortuna
Copy link
Contributor Author

fortuna commented Oct 28, 2024

BTW, I am not changing the config format yet, but I introduced a Config object. That can encapsulate the intermediate format for the future config.

The flow is:
string -> intermediate/generic Config -> actual type config.

@fortuna
Copy link
Contributor Author

fortuna commented Oct 29, 2024

FYI, example QUIC support using this change: #305

@fortuna
Copy link
Contributor Author

fortuna commented Oct 29, 2024

Changed the code to use Generics and save coding.

Copy link
Contributor

@jyyi1 jyyi1 left a comment

Choose a reason for hiding this comment

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

Thanks for the refactoring, it is great!

x/configurl/config.go Outdated Show resolved Hide resolved
x/configurl/config.go Show resolved Hide resolved
x/configurl/config.go Outdated Show resolved Hide resolved
x/configurl/config.go Show resolved Hide resolved
x/configurl/config.go Outdated Show resolved Hide resolved
x/configurl/tls_test.go Outdated Show resolved Hide resolved
x/configurl/tlsfrag.go Outdated Show resolved Hide resolved
x/configurl/dns.go Outdated Show resolved Hide resolved
x/configurl/dns.go Outdated Show resolved Hide resolved
x/configurl/shadowsocks.go Show resolved Hide resolved
Copy link
Contributor Author

@fortuna fortuna left a comment

Choose a reason for hiding this comment

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

Another look?

x/configurl/config.go Show resolved Hide resolved
x/configurl/config.go Show resolved Hide resolved
x/configurl/config.go Outdated Show resolved Hide resolved
x/configurl/config.go Outdated Show resolved Hide resolved
x/configurl/doc.go Outdated Show resolved Hide resolved
x/configurl/tlsfrag.go Outdated Show resolved Hide resolved
x/configurl/module.go Outdated Show resolved Hide resolved
x/configurl/config.go Outdated Show resolved Hide resolved
x/configurl/dns.go Outdated Show resolved Hide resolved
x/configurl/dns.go Outdated Show resolved Hide resolved
@fortuna fortuna requested a review from jyyi1 October 30, 2024 22:38
@fortuna
Copy link
Contributor Author

fortuna commented Nov 1, 2024

Any thoughts?

Copy link
Contributor

@jyyi1 jyyi1 left a comment

Choose a reason for hiding this comment

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

Thanks for the update! Approved with some updates to the doc.

x/configurl/doc.go Outdated Show resolved Hide resolved
x/configurl/doc.go Outdated Show resolved Hide resolved
fortuna and others added 2 commits November 1, 2024 15:29
Co-authored-by: J. Yi <93548144+jyyi1@users.noreply.github.com>
Co-authored-by: J. Yi <93548144+jyyi1@users.noreply.github.com>
@fortuna fortuna merged commit c4b0461 into main Nov 1, 2024
6 checks passed
@fortuna fortuna deleted the fortuna-config branch November 1, 2024 21:36
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