diff --git a/adapters/remote/shadowsocks.go b/adapters/remote/shadowsocks.go index 47035c60..919a9393 100644 --- a/adapters/remote/shadowsocks.go +++ b/adapters/remote/shadowsocks.go @@ -7,9 +7,9 @@ import ( "net/url" "strconv" + "github.com/Dreamacro/clash/common/simple-obfs" C "github.com/Dreamacro/clash/constant" - "github.com/Dreamacro/clash/common/simple-obfs" "github.com/riobard/go-shadowsocks2/core" "github.com/riobard/go-shadowsocks2/socks" ) @@ -63,9 +63,8 @@ func (ss *ShadowSocks) Generator(addr *C.Addr) (adapter C.ProxyAdapter, err erro } func NewShadowSocks(name string, ssURL string, option map[string]string) (*ShadowSocks, error) { - var key []byte server, cipher, password, _ := parseURL(ssURL) - ciph, err := core.PickCipher(cipher, key, password) + ciph, err := core.PickCipher(cipher, nil, password) if err != nil { return nil, fmt.Errorf("ss %s initialize error: %s", server, err.Error()) } @@ -120,5 +119,5 @@ func serializesSocksAddr(addr *C.Addr) []byte { host := addr.IP.To16() buf = [][]byte{{aType}, host, port} } - return bytes.Join(buf, []byte("")) + return bytes.Join(buf, nil) } diff --git a/adapters/remote/socks5.go b/adapters/remote/socks5.go index 8d82f183..5be06387 100644 --- a/adapters/remote/socks5.go +++ b/adapters/remote/socks5.go @@ -45,13 +45,13 @@ func (ss *Socks5) Generator(addr *C.Addr) (adapter C.ProxyAdapter, err error) { return nil, fmt.Errorf("%s connect error", ss.addr) } tcpKeepAlive(c) - if err := ss.sharkHand(addr, c); err != nil { + if err := ss.shakeHand(addr, c); err != nil { return nil, err } return &Socks5Adapter{conn: c}, nil } -func (ss *Socks5) sharkHand(addr *C.Addr, rw io.ReadWriter) error { +func (ss *Socks5) shakeHand(addr *C.Addr, rw io.ReadWriter) error { buf := make([]byte, socks.MaxAddrLen) // VER, CMD, RSV @@ -71,7 +71,7 @@ func (ss *Socks5) sharkHand(addr *C.Addr, rw io.ReadWriter) error { } // VER, CMD, RSV, ADDR - if _, err := rw.Write(bytes.Join([][]byte{[]byte{5, 1, 0}, serializesSocksAddr(addr)}, []byte(""))); err != nil { + if _, err := rw.Write(bytes.Join([][]byte{{5, 1, 0}, serializesSocksAddr(addr)}, []byte(""))); err != nil { return err } diff --git a/config/config.go b/config/config.go index ea83c4d6..0fb589a2 100644 --- a/config/config.go +++ b/config/config.go @@ -3,6 +3,7 @@ package config import ( "bufio" "fmt" + "net/url" "os" "strconv" "strings" @@ -226,9 +227,13 @@ func (c *Config) parseProxies(cfg *ini.File) error { if len(proxy) < 5 { continue } - ssURL := fmt.Sprintf("ss://%s:%s@%s:%s", proxy[3], proxy[4], proxy[1], proxy[2]) + ssURL := url.URL{ + Scheme: "ss", + User: url.UserPassword(proxy[3], proxy[4]), + Host: fmt.Sprintf("%s:%s", proxy[1], proxy[2]), + } option := parseOptions(5, proxy...) - ss, err := adapters.NewShadowSocks(key.Name(), ssURL, option) + ss, err := adapters.NewShadowSocks(key.Name(), ssURL.String(), option) if err != nil { return err } diff --git a/tunnel/connection.go b/tunnel/connection.go index 87d85d3f..842927a1 100644 --- a/tunnel/connection.go +++ b/tunnel/connection.go @@ -5,6 +5,7 @@ import ( "io" "net" "net/http" + "time" "github.com/Dreamacro/clash/adapters/local" C "github.com/Dreamacro/clash/constant" @@ -66,9 +67,11 @@ func relay(leftConn, rightConn net.Conn) { go func() { _, err := io.Copy(leftConn, rightConn) + leftConn.SetReadDeadline(time.Now()) ch <- err }() io.Copy(rightConn, leftConn) + rightConn.SetReadDeadline(time.Now()) <-ch }