@@ -31,7 +31,6 @@ import (
31
31
"github.com/Jigsaw-Code/outline-go-tun2socks/outline/neterrors"
32
32
"github.com/Jigsaw-Code/outline-internal-sdk/transport"
33
33
"github.com/Jigsaw-Code/outline-internal-sdk/transport/shadowsocks"
34
- "github.com/Jigsaw-Code/outline-internal-sdk/transport/shadowsocks/client"
35
34
"github.com/eycorsican/go-tun2socks/common/log"
36
35
)
37
36
@@ -43,7 +42,7 @@ type Client = outline.Client
43
42
// Deprecated: Please use NewClientFromJSON.
44
43
func NewClient (config * Config ) (* Client , error ) {
45
44
if config == nil {
46
- return nil , fmt .Errorf ("Shadowsocks configuration is required" )
45
+ return nil , fmt .Errorf ("shadowsocks configuration is required" )
47
46
}
48
47
return newShadowsocksClient (config .Host , config .Port , config .CipherName , config .Password , config .Prefix )
49
48
}
@@ -53,12 +52,12 @@ func NewClient(config *Config) (*Client, error) {
53
52
func NewClientFromJSON (configJSON string ) (* Client , error ) {
54
53
config , err := parseConfigFromJSON (configJSON )
55
54
if err != nil {
56
- return nil , fmt .Errorf ("Failed to parse Shadowsocks configuration JSON: %w" , err )
55
+ return nil , fmt .Errorf ("failed to parse Shadowsocks configuration JSON: %w" , err )
57
56
}
58
57
var prefixBytes []byte = nil
59
58
if len (config .Prefix ) > 0 {
60
59
if p , err := utf8 .DecodeUTF8CodepointsToRawBytes (config .Prefix ); err != nil {
61
- return nil , fmt .Errorf ("Failed to parse prefix string: %w" , err )
60
+ return nil , fmt .Errorf ("failed to parse prefix string: %w" , err )
62
61
} else {
63
62
prefixBytes = p
64
63
}
@@ -68,34 +67,33 @@ func NewClientFromJSON(configJSON string) (*Client, error) {
68
67
69
68
func newShadowsocksClient (host string , port int , cipherName , password string , prefix []byte ) (* Client , error ) {
70
69
if err := validateConfig (host , port , cipherName , password ); err != nil {
71
- return nil , fmt .Errorf ("Invalid Shadowsocks configuration: %w" , err )
70
+ return nil , fmt .Errorf ("invalid Shadowsocks configuration: %w" , err )
72
71
}
73
72
74
73
// TODO: consider using net.LookupIP to get a list of IPs, and add logic for optimal selection.
75
74
proxyIP , err := net .ResolveIPAddr ("ip" , host )
76
75
if err != nil {
77
- return nil , fmt .Errorf ("Failed to resolve proxy address: %w" , err )
76
+ return nil , fmt .Errorf ("failed to resolve proxy address: %w" , err )
78
77
}
79
- proxyTCPEndpoint := transport.TCPEndpoint {RemoteAddr : net.TCPAddr {IP : proxyIP .IP , Port : port }}
80
- proxyUDPEndpoint := transport.UDPEndpoint {RemoteAddr : net.UDPAddr {IP : proxyIP .IP , Port : port }}
78
+ proxyAddress := net .JoinHostPort (proxyIP .String (), fmt .Sprint (port ))
81
79
82
- cipher , err := shadowsocks .NewCipher (cipherName , password )
80
+ cryptoKey , err := shadowsocks .NewEncryptionKey (cipherName , password )
83
81
if err != nil {
84
- return nil , fmt .Errorf ("Failed to create Shadowsocks cipher: %w" , err )
82
+ return nil , fmt .Errorf ("failed to create Shadowsocks cipher: %w" , err )
85
83
}
86
84
87
- streamDialer , err := client . NewShadowsocksStreamDialer ( proxyTCPEndpoint , cipher )
85
+ streamDialer , err := shadowsocks . NewStreamDialer ( & transport. TCPEndpoint { Address : proxyAddress }, cryptoKey )
88
86
if err != nil {
89
- return nil , fmt .Errorf ("Failed to create StreamDialer: %w" , err )
87
+ return nil , fmt .Errorf ("failed to create StreamDialer: %w" , err )
90
88
}
91
89
if len (prefix ) > 0 {
92
90
log .Debugf ("Using salt prefix: %s" , string (prefix ))
93
- streamDialer .SetTCPSaltGenerator ( client .NewPrefixSaltGenerator (prefix ) )
91
+ streamDialer .SaltGenerator = shadowsocks .NewPrefixSaltGenerator (prefix )
94
92
}
95
93
96
- packetListener , err := client . NewShadowsocksPacketListener ( proxyUDPEndpoint , cipher )
94
+ packetListener , err := shadowsocks . NewPacketListener ( & transport. UDPEndpoint { Address : proxyAddress }, cryptoKey )
97
95
if err != nil {
98
- return nil , fmt .Errorf ("Failed to create PacketListener: %w" , err )
96
+ return nil , fmt .Errorf ("failed to create PacketListener: %w" , err )
99
97
}
100
98
101
99
return & outline.Client {StreamDialer : streamDialer , PacketListener : packetListener }, nil
0 commit comments