-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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(client): introduce extensible YAML config in Go #2306
Open
fortuna
wants to merge
49
commits into
master
Choose a base branch
from
fortuna-ws-config
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
c615901
Initial Implementation
fortuna a4c894d
Add DialEndpoint
fortuna 0d1b9ec
Wire new config
fortuna e81cb45
Add URL
fortuna 455a2ad
Wire Endpoint
fortuna 5a85e73
Cleanup
fortuna 87eaa89
Tweaks
fortuna fbddc57
Merge branch 'master' into fortuna-ws-config
fortuna 131e564
Progress
fortuna a26708c
Make it work
fortuna 1f89c98
Simplify
fortuna 0aa3dbc
More simplification
fortuna e3738e7
Merge branch 'master' into fortuna-ws-config
fortuna bc20623
Revert Go version
fortuna cde35c5
Progress
fortuna 0128549
Fixes
fortuna e05542f
Fix tests
fortuna 6c199bf
Fix
fortuna dbaf0a2
Add test
fortuna cffd70a
Add default provider
fortuna d46455e
Clean up
fortuna f63d2b9
Update tests
fortuna 8df547f
Revamp config
fortuna 52dcd84
Clean up and TODOs
fortuna 5b80741
Naming
fortuna abcbb42
Clean up test
fortuna 70a4a28
More tests
fortuna 5ed3701
Better test
fortuna 6141ff2
Add tcpudp
fortuna 3962502
More tests
fortuna cacf818
Add Websocket support
fortuna 2c59ed5
Fix
fortuna 7304fdc
Lint fixes
fortuna b3f7dd6
It works!
fortuna 5b0de18
Fix display
fortuna fa05c42
Try Coder
fortuna 79c0a73
Comment
fortuna 24f0544
Remove Websocket
fortuna 777da9b
Merge branch 'master' into fortuna-ws-config
fortuna 612d5db
Fix Android
fortuna ebb993f
Add net
fortuna 01d95d2
Fix Electron
fortuna 486aabb
Review changes
fortuna fdd54d5
Merge branch 'master' into fortuna-ws-config
fortuna 5ab7ea9
fixes
fortuna d18deae
Fix Linux
fortuna b4a6e1f
Fixes
fortuna 025f102
Tests
fortuna 3334519
Lint
fortuna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,21 +15,29 @@ | |
package outline | ||
|
||
import ( | ||
"fmt" | ||
"context" | ||
"net" | ||
|
||
"github.com/Jigsaw-Code/outline-apps/client/go/outline/config" | ||
"github.com/Jigsaw-Code/outline-apps/client/go/outline/platerrors" | ||
"github.com/Jigsaw-Code/outline-sdk/transport" | ||
"github.com/Jigsaw-Code/outline-sdk/transport/shadowsocks" | ||
"github.com/eycorsican/go-tun2socks/common/log" | ||
) | ||
|
||
// Client provides a transparent container for [transport.StreamDialer] and [transport.PacketListener] | ||
// that is exportable (as an opaque object) via gobind. | ||
// It's used by the connectivity test and the tun2socks handlers. | ||
// TODO: Rename to Transport. Needs to update per-platform code. | ||
type Client struct { | ||
transport.StreamDialer | ||
transport.PacketListener | ||
sd *config.Dialer[transport.StreamConn] | ||
pl *config.PacketListener | ||
} | ||
|
||
func (c *Client) DialStream(ctx context.Context, address string) (transport.StreamConn, error) { | ||
return c.sd.Dial(ctx, address) | ||
} | ||
|
||
func (c *Client) ListenPacket(ctx context.Context) (net.PacketConn, error) { | ||
return c.pl.ListenPacket(ctx) | ||
} | ||
|
||
// NewClientResult represents the result of [NewClientAndReturnError]. | ||
|
@@ -42,67 +50,33 @@ type NewClientResult struct { | |
|
||
// NewClient creates a new Outline client from a configuration string. | ||
func NewClient(transportConfig string) *NewClientResult { | ||
client, err := newClientWithBaseDialers(transportConfig, net.Dialer{KeepAlive: -1}, net.Dialer{}) | ||
return &NewClientResult{ | ||
Client: client, | ||
Error: platerrors.ToPlatformError(err), | ||
} | ||
} | ||
|
||
func newClientWithBaseDialers(transportConfig string, tcpDialer, udpDialer net.Dialer) (*Client, error) { | ||
conf, err := parseConfigFromJSON(transportConfig) | ||
if err != nil { | ||
return nil, err | ||
} | ||
prefixBytes, err := ParseConfigPrefixFromString(conf.Prefix) | ||
tcpDialer := transport.TCPDialer{Dialer: net.Dialer{KeepAlive: -1}} | ||
udpDialer := transport.UDPDialer{} | ||
client, err := newClientWithBaseDialers(transportConfig, &tcpDialer, &udpDialer) | ||
if err != nil { | ||
return nil, err | ||
return &NewClientResult{Error: platerrors.ToPlatformError(err)} | ||
} | ||
|
||
return newShadowsocksClient(conf.Host, int(conf.Port), conf.Method, conf.Password, prefixBytes, tcpDialer, udpDialer) | ||
return &NewClientResult{Client: client} | ||
} | ||
|
||
func newShadowsocksClient( | ||
host string, port int, cipherName, password string, prefix []byte, tcpDialer, udpDialer net.Dialer, | ||
) (*Client, error) { | ||
if err := validateConfig(host, port, cipherName, password); err != nil { | ||
return nil, err | ||
} | ||
|
||
// TODO: consider using net.LookupIP to get a list of IPs, and add logic for optimal selection. | ||
proxyAddress := net.JoinHostPort(host, fmt.Sprint(port)) | ||
|
||
cryptoKey, err := shadowsocks.NewEncryptionKey(cipherName, password) | ||
func newClientWithBaseDialers(transportConfig string, tcpDialer transport.StreamDialer, udpDialer transport.PacketDialer) (*Client, error) { | ||
transportYAML, err := config.ParseConfigYAML(transportConfig) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we still accepting the old JSON format here? Existing dynamic keys are still using JSON. |
||
if err != nil { | ||
return nil, newIllegalConfigErrorWithDetails("cipher&password pair is not valid", | ||
"cipher|password", cipherName+"|"+password, "valid combination", err) | ||
} | ||
|
||
// We disable Keep-Alive as per https://datatracker.ietf.org/doc/html/rfc1122#page-101, which states that it should only be | ||
// enabled in server applications. This prevents the device from unnecessarily waking up to send keep alives. | ||
streamDialer, err := shadowsocks.NewStreamDialer(&transport.TCPEndpoint{Address: proxyAddress, Dialer: tcpDialer}, cryptoKey) | ||
if err != nil { | ||
return nil, platerrors.PlatformError{ | ||
Code: platerrors.SetupTrafficHandlerFailed, | ||
Message: "failed to create TCP traffic handler", | ||
Details: platerrors.ErrorDetails{"proxy-protocol": "shadowsocks", "handler": "tcp"}, | ||
return nil, &platerrors.PlatformError{ | ||
Code: platerrors.IllegalConfig, | ||
Message: "config is not valid YAML", | ||
Cause: platerrors.ToPlatformError(err), | ||
} | ||
} | ||
if len(prefix) > 0 { | ||
log.Debugf("Using salt prefix: %s", string(prefix)) | ||
streamDialer.SaltGenerator = shadowsocks.NewPrefixSaltGenerator(prefix) | ||
} | ||
|
||
packetListener, err := shadowsocks.NewPacketListener(&transport.UDPEndpoint{Address: proxyAddress, Dialer: udpDialer}, cryptoKey) | ||
transportPair, err := config.NewDefaultTransportProvider(tcpDialer, udpDialer).Parse(context.Background(), transportYAML) | ||
if err != nil { | ||
return nil, platerrors.PlatformError{ | ||
Code: platerrors.SetupTrafficHandlerFailed, | ||
Message: "failed to create UDP traffic handler", | ||
Details: platerrors.ErrorDetails{"proxy-protocol": "shadowsocks", "handler": "udp"}, | ||
return nil, &platerrors.PlatformError{ | ||
Code: platerrors.IllegalConfig, | ||
Message: "failed to create transport", | ||
Cause: platerrors.ToPlatformError(err), | ||
} | ||
} | ||
|
||
return &Client{StreamDialer: streamDialer, PacketListener: packetListener}, nil | ||
return &Client{sd: transportPair.StreamDialer, pl: transportPair.PacketListener}, nil | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are changing the UDP handler from a
PacketListener
to aPacketDialer
here, will this cause any unexpected errors?