Skip to content

Commit

Permalink
Add tls to config.
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuna committed Oct 27, 2023
1 parent b80e484 commit 0e9afd8
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions x/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,22 @@ import (
"github.com/Jigsaw-Code/outline-sdk/transport"
"github.com/Jigsaw-Code/outline-sdk/transport/socks5"
"github.com/Jigsaw-Code/outline-sdk/transport/split"
"github.com/Jigsaw-Code/outline-sdk/transport/tls"
"github.com/Jigsaw-Code/outline-sdk/x/tls"
)

func parseConfigPart(oneDialerConfig string) (*url.URL, error) {
// Make it "<scheme>:" it it's only "<scheme>" to parse as a URL.
if !strings.Contains(oneDialerConfig, ":") {
oneDialerConfig += ":"
}
url, err := url.Parse(oneDialerConfig)
if err != nil {
return nil, fmt.Errorf("failed to parse config part: %w", err)
}
return url, nil
}

// NewStreamDialer creates a new [transport.StreamDialer] according to the given config.
func NewStreamDialer(transportConfig string) (dialer transport.StreamDialer, err error) {
dialer = &transport.TCPStreamDialer{}
Expand All @@ -51,19 +65,17 @@ func newStreamDialerFromPart(innerDialer transport.StreamDialer, oneDialerConfig
return nil, errors.New("empty config part")
}

url, err := url.Parse(oneDialerConfig)
url, err := parseConfigPart(oneDialerConfig)
if err != nil {
return nil, fmt.Errorf("failed to parse config part: %w", err)
}

// Please keep scheme list sorted.
switch url.Scheme {
case "socks5":
endpoint := transport.StreamDialerEndpoint{Dialer: innerDialer, Address: url.Host}
return socks5.NewStreamDialer(&endpoint)

case "ss":
return newShadowsocksStreamDialerFromURL(innerDialer, url)

case "split":
prefixBytesStr := url.Opaque
prefixBytes, err := strconv.Atoi(prefixBytesStr)
Expand All @@ -72,6 +84,12 @@ func newStreamDialerFromPart(innerDialer transport.StreamDialer, oneDialerConfig
}
return split.NewStreamDialer(innerDialer, int64(prefixBytes))

case "ss":
return newShadowsocksStreamDialerFromURL(innerDialer, url)

case "tls":
return tls.NewStreamDialer(innerDialer), nil

default:
return nil, fmt.Errorf("config scheme '%v' is not supported", url.Scheme)
}
Expand Down Expand Up @@ -100,20 +118,24 @@ func newPacketDialerFromPart(innerDialer transport.PacketDialer, oneDialerConfig
return nil, errors.New("empty config part")
}

url, err := url.Parse(oneDialerConfig)
url, err := parseConfigPart(oneDialerConfig)
if err != nil {
return nil, fmt.Errorf("failed to parse config part: %w", err)
}

// Please keep scheme list sorted.
switch url.Scheme {
case "socks5":
return nil, errors.New("socks5 is not supported for PacketDialers")

case "split":
return nil, errors.New("split is not supported for PacketDialers")

case "ss":
return newShadowsocksPacketDialerFromURL(innerDialer, url)

case "split":
return nil, errors.New("split is not supported for PacketDialers")
case "tls":
return nil, errors.New("tls is not yet supported for PacketDialers")

default:
return nil, fmt.Errorf("config scheme '%v' is not supported", url.Scheme)
Expand Down

0 comments on commit 0e9afd8

Please sign in to comment.