Compare commits

...

2 Commits

Author SHA1 Message Date
3e68faecb2 Improve: add rc4-md5 and chacha20 supported with the fork 2018-09-21 15:27:51 +08:00
eb778ad6e2 Improve: cleanup code 2018-09-21 11:33:29 +08:00
12 changed files with 47 additions and 40 deletions

36
Gopkg.lock generated
View File

@ -1,6 +1,19 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
digest = "1:d21e998147c1c8cd727bd34148f373d3faa46fd8669c389b53c4eaabbe4eb2b3"
name = "github.com/Dreamacro/go-shadowsocks2"
packages = [
"core",
"shadowaead",
"shadowstream",
"socks",
]
pruneopts = "UT"
revision = "1c1fd6c192eb76261ea3ccd80e3b141b25f20db4"
version = "v0.1.1"
[[projects]]
branch = "master"
digest = "1:8fa55a6e302771a90a86ceae1ca3c0df4ef15d21092198e8313f61dde9eea963"
@ -65,19 +78,6 @@
revision = "c5bec84d1963260297932a1b7a1753c8420717a7"
version = "v1.3.0"
[[projects]]
digest = "1:2bfa1a73654feb90893014b04779ce5205f3e19e843c0e32a89ea051d31f12d5"
name = "github.com/riobard/go-shadowsocks2"
packages = [
"core",
"shadowaead",
"shadowstream",
"socks",
]
pruneopts = "UT"
revision = "8346403248229fc7e10d7a259de8e9352a9d8830"
version = "v0.1.0"
[[projects]]
digest = "1:d867dfa6751c8d7a435821ad3b736310c2ed68945d05b50fb9d23aee0540c8cc"
name = "github.com/sirupsen/logrus"
@ -99,11 +99,11 @@
"ssh/terminal",
]
pruneopts = "UT"
revision = "0709b304e793a5edb4a2c0145f281ecdc20838a4"
revision = "0e37d006457bf46f9e6692014ba72ef82c33022c"
[[projects]]
branch = "master"
digest = "1:576f8d82185dc836ec6d10c0e5568dc4ff94e4d9f101d33ed5d6bae0cbba65b2"
digest = "1:ddbafa32d1899456edbf7a64aec7afe5aa287b840e6a12b996f8a8425c1d9a6a"
name = "golang.org/x/sys"
packages = [
"cpu",
@ -111,7 +111,7 @@
"windows",
]
pruneopts = "UT"
revision = "ebe1bf3edb3325c393447059974de898d5133eb8"
revision = "d641721ec2dead6fe5ca284096fe4b1fcd49e427"
[[projects]]
digest = "1:975a4480c40f2d0b95e1f83d3ec1aa29a2774e80179e08a9a4ba2aab86721b23"
@ -133,13 +133,13 @@
analyzer-name = "dep"
analyzer-version = 1
input-imports = [
"github.com/Dreamacro/go-shadowsocks2/core",
"github.com/Dreamacro/go-shadowsocks2/socks",
"github.com/go-chi/chi",
"github.com/go-chi/cors",
"github.com/go-chi/render",
"github.com/gofrs/uuid",
"github.com/oschwald/geoip2-golang",
"github.com/riobard/go-shadowsocks2/core",
"github.com/riobard/go-shadowsocks2/socks",
"github.com/sirupsen/logrus",
"golang.org/x/crypto/chacha20poly1305",
"gopkg.in/eapache/channels.v1",

View File

@ -25,6 +25,10 @@
# unused-packages = true
[[constraint]]
name = "github.com/Dreamacro/go-shadowsocks2"
version = "0.1.1"
[[constraint]]
name = "github.com/go-chi/chi"
version = "3.3.3"
@ -45,10 +49,6 @@
name = "github.com/oschwald/geoip2-golang"
version = "1.2.1"
[[constraint]]
name = "github.com/riobard/go-shadowsocks2"
version = "0.1.0"
[[constraint]]
name = "github.com/sirupsen/logrus"
version = "1.0.6"

View File

@ -4,7 +4,7 @@ import (
"net"
C "github.com/Dreamacro/clash/constant"
"github.com/riobard/go-shadowsocks2/socks"
"github.com/Dreamacro/go-shadowsocks2/socks"
)
// SocketAdapter is a adapter for socks and redir connection

View File

@ -6,7 +6,7 @@ import (
"strconv"
C "github.com/Dreamacro/clash/constant"
"github.com/riobard/go-shadowsocks2/socks"
"github.com/Dreamacro/go-shadowsocks2/socks"
)
func parseSocksAddr(target socks.Addr) *C.Addr {

View File

@ -7,11 +7,11 @@ 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"
"github.com/Dreamacro/go-shadowsocks2/core"
"github.com/Dreamacro/go-shadowsocks2/socks"
)
// ShadowsocksAdapter is a shadowsocks adapter
@ -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)
}

View File

@ -9,7 +9,7 @@ import (
C "github.com/Dreamacro/clash/constant"
"github.com/riobard/go-shadowsocks2/socks"
"github.com/Dreamacro/go-shadowsocks2/socks"
)
// Socks5Adapter is a shadowsocks adapter
@ -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
}

View File

@ -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
}

View File

@ -5,7 +5,7 @@ import (
"syscall"
"unsafe"
"github.com/riobard/go-shadowsocks2/socks"
"github.com/Dreamacro/go-shadowsocks2/socks"
)
func parserPacket(c net.Conn) (socks.Addr, error) {

View File

@ -6,7 +6,7 @@ import (
"syscall"
"unsafe"
"github.com/riobard/go-shadowsocks2/socks"
"github.com/Dreamacro/go-shadowsocks2/socks"
)
const (

View File

@ -4,7 +4,7 @@ import (
"errors"
"net"
"github.com/riobard/go-shadowsocks2/socks"
"github.com/Dreamacro/go-shadowsocks2/socks"
)
func parserPacket(conn net.Conn) (socks.Addr, error) {

View File

@ -7,7 +7,7 @@ import (
C "github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/tunnel"
"github.com/riobard/go-shadowsocks2/socks"
"github.com/Dreamacro/go-shadowsocks2/socks"
log "github.com/sirupsen/logrus"
)

View File

@ -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
}