diff --git a/proxy/shadowsocks/client.go b/proxy/shadowsocks/client.go index 96ce20c73..355874f5e 100644 --- a/proxy/shadowsocks/client.go +++ b/proxy/shadowsocks/client.go @@ -15,11 +15,13 @@ import ( "v2ray.com/core/transport/ray" ) +// Client is a inbound handler for Shadowsocks protocol type Client struct { serverPicker protocol.ServerPicker meta *proxy.OutboundHandlerMeta } +// NewClient create a new Shadowsocks client. func NewClient(config *ClientConfig, space app.Space, meta *proxy.OutboundHandlerMeta) (*Client, error) { serverList := protocol.NewServerList() for _, rec := range config.Server { @@ -33,6 +35,7 @@ func NewClient(config *ClientConfig, space app.Space, meta *proxy.OutboundHandle return client, nil } +// Dispatch implements OutboundHandler.Dispatch(). func (v *Client) Dispatch(destination v2net.Destination, payload *buf.Buffer, ray ray.OutboundRay) { defer payload.Release() defer ray.OutboundInput().Release() @@ -95,7 +98,7 @@ func (v *Client) Dispatch(destination v2net.Destination, payload *buf.Buffer, ra defer bodyWriter.Release() if err != nil { - log.Info("Shadowsock|Client: Failed to write request: ", err) + log.Info("Shadowsocks|Client: Failed to write request: ", err) return } @@ -167,14 +170,17 @@ func (v *Client) Dispatch(destination v2net.Destination, payload *buf.Buffer, ra } } +// ClientFactory is a OutboundHandlerFactory. type ClientFactory struct{} +// StreamCapability implements OutboundHandlerFactory.StreamCapability(). func (v *ClientFactory) StreamCapability() v2net.NetworkList { return v2net.NetworkList{ Network: []v2net.Network{v2net.Network_TCP, v2net.Network_RawTCP}, } } +// Create implements OutboundHandlerFactory.Create(). func (v *ClientFactory) Create(space app.Space, rawConfig interface{}, meta *proxy.OutboundHandlerMeta) (proxy.OutboundHandler, error) { return NewClient(rawConfig.(*ClientConfig), space, meta) } diff --git a/proxy/shadowsocks/ota.go b/proxy/shadowsocks/ota.go index fbacac299..6794cf218 100644 --- a/proxy/shadowsocks/ota.go +++ b/proxy/shadowsocks/ota.go @@ -12,6 +12,7 @@ import ( ) const ( + // AuthSize is the number of extra bytes for Shadowsocks OTA. AuthSize = 10 ) @@ -46,12 +47,12 @@ func HeaderKeyGenerator(key []byte, iv []byte) func() []byte { } func ChunkKeyGenerator(iv []byte) func() []byte { - chunkId := 0 + chunkID := 0 return func() []byte { newKey := make([]byte, 0, len(iv)+4) newKey = append(newKey, iv...) - newKey = serial.IntToBytes(chunkId, newKey) - chunkId++ + newKey = serial.IntToBytes(chunkID, newKey) + chunkID++ return newKey } } diff --git a/proxy/shadowsocks/server.go b/proxy/shadowsocks/server.go index 603f27358..7d90ba959 100644 --- a/proxy/shadowsocks/server.go +++ b/proxy/shadowsocks/server.go @@ -1,4 +1,3 @@ -// R.I.P Shadowsocks package shadowsocks import ( diff --git a/proxy/shadowsocks/shadowsocks.go b/proxy/shadowsocks/shadowsocks.go new file mode 100644 index 000000000..cac631e89 --- /dev/null +++ b/proxy/shadowsocks/shadowsocks.go @@ -0,0 +1,12 @@ +// Package shadowsocks provides compatible functionality to Shadowsocks. +// +// Shadowsocks client and server are implemented as outbound and inbound respectively in V2Ray's term. +// Shadowsocks OTA is fully supported. +// Supperted Ciphers: +// * AES-256-CFB +// * AES-128-CFB +// * Chacha20 +// * Chacha20-IEFT +// +// R.I.P Shadowsocks +package shadowsocks