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: enable custom transports in configs #213

Merged
merged 5 commits into from
Apr 19, 2024
Merged

feat: enable custom transports in configs #213

merged 5 commits into from
Apr 19, 2024

Conversation

fortuna
Copy link
Contributor

@fortuna fortuna commented Apr 3, 2024

This PR makes the config parser configurable. This way people can extend it with new protocols. For example, one may add an "Intra" wrapper, or a "V2Ray" wrapper, or a "Psiphon" wrapper that is configured with a separate file. Here is a hypothetical example:

go run myproxy -transport 'smart|ss://$SECRET@$HOST:$PORT' -smart_config 'config.json'

Or:

go run myproxy -transport 'smart:///usr/home/config.json|ss://$SECRET@$HOST:$PORT'

This will help @amircybersec, who wanted to add v2ray to his app and still reuse our config.

@fortuna fortuna requested review from jyyi1 and amircybersec April 3, 2024 21:26
@fortuna
Copy link
Contributor Author

fortuna commented Apr 5, 2024

Any thoughts?

@amircybersec
Copy link
Contributor

This is super cool! so basically to define a new wrapper (for example vless), I need to do something like this in my code:

configParser := config.NewDefaultConfigParser()
configParser.RegisterStreamDialerWrapper("vless", wrapStreamDialerWithVLESS)

and implement wrapStreamDialerWithVLESS.

I think there are other places in the SDK where config is used and it needs to get updated. I will double check and add them to the PR.

I can also update doc.go to show some examples for this.

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.

Code LGTM, please update the PR title to "refactor: make configs dynamically configurable".

For your example in the PR description, I'd prefer to include the config file name in the URL:

go run myproxy -transport 'smart:///usr/home/config.json|ss://$SECRET@$HOST:$PORT'

}

// NewDefaultConfigParser creates a [ConfigParser] with a set of default wrappers already registered.
func NewDefaultConfigParser() *ConfigParser {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can have another NewEmptyConfigParser()? This can be used by OutlineCLI (NewEmptyConfigParser().RegisterShadowsocksDialerWrappers()), because it only expects the ss:// config.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jyyi1 I also think having NewEmptyConfigParser() is useful in general but in the case of Outline CLI why do we want to limit the config to ss:// only? I am working on a sock5-over-tls server that I believe would be useful to folks who are using Outline CLI.

https://github.com/amircybersec/socks5-over-tls

This way CLI users can also use fragmentation and packet split capability of the Outline SDK.

Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds good to me, we don't have to limit the config type of Outline CLI, we can enable other VPN protocols (such as socks5 or maybe vmess) if we support them. Now we only have ss.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jyyi1 BTW, since ConfigParser type is exported, one could just do p := new(ConfigParser) to create an empty config parser instead of NewEmptyConfigParser() but the explicit method can help too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the zero struct is valid and can be used.

x/config/config.go Outdated Show resolved Hide resolved
x/config/config.go Outdated Show resolved Hide resolved
@fortuna fortuna changed the title Configurable Configs feat: enable custom transports in configs Apr 6, 2024
@amircybersec
Copy link
Contributor

@fortuna I added a section at the end of the doc file on creating a custom config. Everything else looks good to me.

Copy link
Contributor

@amircybersec amircybersec left a comment

Choose a reason for hiding this comment

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

All looks good to me; I added a section to doc.go with explanation on how to define and register a new config.

Co-authored-by: J. Yi <93548144+jyyi1@users.noreply.github.com>
@fortuna fortuna requested a review from jyyi1 April 19, 2024 21:27
@fortuna
Copy link
Contributor Author

fortuna commented Apr 19, 2024

@jyyi1 I added your example, but this is a feature in the sense of new functionality, not a refactor.

@fortuna fortuna merged commit 2318bba into main Apr 19, 2024
6 checks passed
@fortuna fortuna deleted the fortuna-config2 branch April 19, 2024 21:35
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.

3 participants