Skip to content

Conversation

@WendelHime
Copy link
Contributor

@WendelHime WendelHime commented Sep 30, 2025

This PR is part of getlantern/engineering#2573 and the work will be broken into two other pull requests, one of them on another repository for parsing a plural set of configurations and another PR for integrating the URL parser on radiance

@WendelHime WendelHime marked this pull request as ready for review October 2, 2025 15:02
@Copilot Copilot AI review requested due to automatic review settings October 2, 2025 15:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds configuration parsing capabilities to support multiple server configuration formats, including JSON sing-box configs and URL-based configurations for popular proxy protocols like shadowsocks, trojan, vless, and vmess.

  • Implements URL parsing for various proxy protocols (shadowsocks, trojan, vless, vmess)
  • Adds AddServerByURL method to the Manager for handling both JSON and URL-based configurations
  • Includes comprehensive test coverage for the new functionality

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
servers/parser.go New file implementing URL validation and parsing logic for different proxy protocols
servers/manager.go Adds AddServerByURL method with telemetry support for parsing configurations
servers/manager_test.go Adds test cases for the new AddServerByURL functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

// AddServerByURL parse a value that can be a JSON sing-box config or a base64
// encoded config from another provider. It parses the config into a sing-box config
// and add it to the user managed group
func (m *Manager) AddServerByURL(ctx context.Context, value []byte) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should have separate functions for URL formatted configs and JSON configs, the caller will know which format it is. It will simplify this function significantly.

return o, fmt.Errorf("couldn't parse server port: %w", err)
}

switch providedURL.Scheme {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are shadowsocks, trojan, vmess, and vless the only protocols we're supporting for URL config format? If so, we should return an error if the scheme is none of these.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, for now from the repositories that I've been looking (mahsa configs, or v2ray-configs), those are the most common protocols that use the URL format. Anyway I'll remove from this PR the URL part for now because I'm moving the parser into a different repository

@WendelHime WendelHime changed the title adding config parser adding function for adding custom sing-box config from user Oct 10, 2025
@WendelHime WendelHime requested a review from garmr-ulfr October 10, 2025 14:31
@WendelHime
Copy link
Contributor Author

@garmr-ulfr I've changed the purpose of this PR so it's only related to sing-box custom config, I'll create other pull requests for the other configs

Copy link
Collaborator

@garmr-ulfr garmr-ulfr left a comment

Choose a reason for hiding this comment

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

LGTM

// AddServerWithSingboxJSON parse a value that can be a JSON sing-box config.
// It parses the config into a sing-box config and add it to the user managed group.
func (m *Manager) AddServerWithSingboxJSON(ctx context.Context, value []byte) error {
ctx, span := otel.Tracer(tracerName).Start(ctx, "Manager.AddServerByURL")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should probably change Manager.AddServerByURL to Manager.AddServerWithSingboxJSON.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, thanks for remembering!

@WendelHime WendelHime merged commit b17902b into main Oct 14, 2025
2 checks passed
@WendelHime WendelHime deleted the feat/adding-config-parser branch October 14, 2025 14:50
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