general: minor changes in github actions and codes

This commit is contained in:
nadoo 2020-04-06 23:33:23 +08:00
parent 855907c46b
commit a4346d2b03
9 changed files with 58 additions and 54 deletions

View File

@ -11,6 +11,8 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Unshallow
run: git fetch --prune --unshallow
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v1 uses: actions/setup-go@v1
with: with:

2
go.mod
View File

@ -13,7 +13,7 @@ require (
github.com/xtaci/kcp-go v5.4.20+incompatible github.com/xtaci/kcp-go v5.4.20+incompatible
golang.org/x/crypto v0.0.0-20200403201458-baeed622b8d8 golang.org/x/crypto v0.0.0-20200403201458-baeed622b8d8
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect
golang.org/x/sys v0.0.0-20200331124033-c3d80250170d // indirect golang.org/x/sys v0.0.0-20200406113430-c6e801f48ba2 // indirect
) )
// Replace dependency modules with local developing copy // Replace dependency modules with local developing copy

4
go.sum
View File

@ -73,8 +73,8 @@ golang.org/x/sys v0.0.0-20191010194322-b09406accb47 h1:/XfQ9z7ib8eEJX2hdgFTZJ/nt
golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191020212454-3e7259c5e7c2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191020212454-3e7259c5e7c2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200331124033-c3d80250170d h1:nc5K6ox/4lTFbMVSL9WRR81ixkcwXThoiF6yf+R9scA= golang.org/x/sys v0.0.0-20200406113430-c6e801f48ba2 h1:Z9pPywZscwuw0ijrLEbTzW9lppFgBY4HDgbvoDnreQs=
golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200406113430-c6e801f48ba2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

View File

@ -89,7 +89,8 @@ func NewManager(rules []*rule.Config) (*Manager, error) {
Family: syscall.AF_NETLINK, Family: syscall.AF_NETLINK,
} }
if err = syscall.Bind(fd, &lsa); err != nil { err = syscall.Bind(fd, &lsa)
if err != nil {
log.F("%s", err) log.F("%s", err)
return nil, err return nil, err
} }
@ -123,7 +124,10 @@ func NewManager(rules []*rule.Config) (*Manager, error) {
// AddDomainIP implements the DNSAnswerHandler function, used to update ipset according to domainSet rule // AddDomainIP implements the DNSAnswerHandler function, used to update ipset according to domainSet rule
func (m *Manager) AddDomainIP(domain, ip string) error { func (m *Manager) AddDomainIP(domain, ip string) error {
if ip != "" { if domain == "" || ip == "" {
return errors.New("please specify the domain and ip address")
}
domainParts := strings.Split(domain, ".") domainParts := strings.Split(domain, ".")
length := len(domainParts) length := len(domainParts)
for i := length - 1; i >= 0; i-- { for i := length - 1; i >= 0; i-- {
@ -134,7 +138,6 @@ func (m *Manager) AddDomainIP(domain, ip string) error {
AddToSet(m.fd, m.lsa, ipset.(string), ip) AddToSet(m.fd, m.lsa, ipset.(string), ip)
} }
} }
}
return nil return nil
} }

View File

@ -42,7 +42,7 @@ func (p *HTTPObfs) NewConn(c net.Conn) (net.Conn, error) {
} }
func (c *HTTPObfsConn) writeHeader() (int, error) { func (c *HTTPObfsConn) writeHeader() (int, error) {
buf := new(bytes.Buffer) var buf bytes.Buffer
buf.WriteString("GET " + c.obfsURI + " HTTP/1.1\r\n") buf.WriteString("GET " + c.obfsURI + " HTTP/1.1\r\n")
buf.WriteString("Host: " + c.obfsHost + "\r\n") buf.WriteString("Host: " + c.obfsHost + "\r\n")
buf.WriteString("User-Agent: " + c.obfsUA + "\r\n") buf.WriteString("User-Agent: " + c.obfsUA + "\r\n")

View File

@ -69,9 +69,9 @@ func (c *TLSObfsConn) Write(b []byte) (int, error) {
end = n end = n
} }
buf := new(bytes.Buffer) var buf bytes.Buffer
buf.Write([]byte{0x17, 0x03, 0x03}) buf.Write([]byte{0x17, 0x03, 0x03})
binary.Write(buf, binary.BigEndian, uint16(len(b[i:end]))) binary.Write(&buf, binary.BigEndian, uint16(len(b[i:end])))
buf.Write(b[i:end]) buf.Write(b[i:end])
_, err := c.Conn.Write(buf.Bytes()) _, err := c.Conn.Write(buf.Bytes())
@ -124,7 +124,7 @@ func (c *TLSObfsConn) Read(b []byte) (int, error) {
} }
func (c *TLSObfsConn) handshake(b []byte) (int, error) { func (c *TLSObfsConn) handshake(b []byte) (int, error) {
buf := new(bytes.Buffer) var buf bytes.Buffer
// prepare extension & clientHello content // prepare extension & clientHello content
bufExt, bufHello := extension(b, c.obfsHost), clientHello() bufExt, bufHello := extension(b, c.obfsHost), clientHello()
@ -142,7 +142,7 @@ func (c *TLSObfsConn) handshake(b []byte) (int, error) {
buf.Write([]byte{0x03, 0x01}) buf.Write([]byte{0x03, 0x01})
// length // length
binary.Write(buf, binary.BigEndian, uint16(handshakeLen)) binary.Write(&buf, binary.BigEndian, uint16(handshakeLen))
// Handshake Begin // Handshake Begin
// Handshake Type: Client Hello (1) // Handshake Type: Client Hello (1)
@ -156,7 +156,7 @@ func (c *TLSObfsConn) handshake(b []byte) (int, error) {
// Extension Begin // Extension Begin
// ext content length // ext content length
binary.Write(buf, binary.BigEndian, uint16(extLen)) binary.Write(&buf, binary.BigEndian, uint16(extLen))
// ext content // ext content
buf.Write(bufExt.Bytes()) buf.Write(bufExt.Bytes())
@ -170,7 +170,7 @@ func (c *TLSObfsConn) handshake(b []byte) (int, error) {
} }
func clientHello() *bytes.Buffer { func clientHello() *bytes.Buffer {
buf := new(bytes.Buffer) var buf bytes.Buffer
// Version: TLS 1.2 (0x0303) // Version: TLS 1.2 (0x0303)
buf.Write([]byte{0x03, 0x03}) buf.Write([]byte{0x03, 0x03})
@ -182,7 +182,7 @@ func clientHello() *bytes.Buffer {
// clients do not send current time, and server do not check it, // clients do not send current time, and server do not check it,
// golang tls client and chrome browser send random bytes instead. // golang tls client and chrome browser send random bytes instead.
// //
binary.Write(buf, binary.BigEndian, uint32(time.Now().Unix())) binary.Write(&buf, binary.BigEndian, uint32(time.Now().Unix()))
random := make([]byte, 28) random := make([]byte, 28)
// The above 2 lines of codes was added to make it compatible with some server implementation, // The above 2 lines of codes was added to make it compatible with some server implementation,
// if we don't need the compatibility, just use the following code instead. // if we don't need the compatibility, just use the following code instead.
@ -200,7 +200,7 @@ func clientHello() *bytes.Buffer {
// https://github.com/shadowsocks/simple-obfs/blob/7659eeccf473aa41eb294e92c32f8f60a8747325/src/obfs_tls.c#L57 // https://github.com/shadowsocks/simple-obfs/blob/7659eeccf473aa41eb294e92c32f8f60a8747325/src/obfs_tls.c#L57
// Cipher Suites Length: 56 // Cipher Suites Length: 56
binary.Write(buf, binary.BigEndian, uint16(56)) binary.Write(&buf, binary.BigEndian, uint16(56))
// Cipher Suites (28 suites) // Cipher Suites (28 suites)
buf.Write([]byte{ buf.Write([]byte{
0xc0, 0x2c, 0xc0, 0x30, 0x00, 0x9f, 0xcc, 0xa9, 0xcc, 0xa8, 0xcc, 0xaa, 0xc0, 0x2b, 0xc0, 0x2f, 0xc0, 0x2c, 0xc0, 0x30, 0x00, 0x9f, 0xcc, 0xa9, 0xcc, 0xa8, 0xcc, 0xaa, 0xc0, 0x2b, 0xc0, 0x2f,
@ -214,43 +214,43 @@ func clientHello() *bytes.Buffer {
// Compression Methods (1 method) // Compression Methods (1 method)
buf.WriteByte(0x00) buf.WriteByte(0x00)
return buf return &buf
} }
func extension(b []byte, server string) *bytes.Buffer { func extension(b []byte, server string) *bytes.Buffer {
buf := new(bytes.Buffer) var buf bytes.Buffer
// Extension: SessionTicket TLS // Extension: SessionTicket TLS
buf.Write([]byte{0x00, 0x23}) // type buf.Write([]byte{0x00, 0x23}) // type
// NOTE: send some data in sessionticket, the server will treat it as data too // NOTE: send some data in sessionticket, the server will treat it as data too
binary.Write(buf, binary.BigEndian, uint16(len(b))) // length binary.Write(&buf, binary.BigEndian, uint16(len(b))) // length
buf.Write(b) buf.Write(b)
// Extension: server_name // Extension: server_name
buf.Write([]byte{0x00, 0x00}) // type buf.Write([]byte{0x00, 0x00}) // type
binary.Write(buf, binary.BigEndian, uint16(len(server)+5)) // length binary.Write(&buf, binary.BigEndian, uint16(len(server)+5)) // length
binary.Write(buf, binary.BigEndian, uint16(len(server)+3)) // Server Name list length binary.Write(&buf, binary.BigEndian, uint16(len(server)+3)) // Server Name list length
buf.WriteByte(0x00) // Server Name Type: host_name (0) buf.WriteByte(0x00) // Server Name Type: host_name (0)
binary.Write(buf, binary.BigEndian, uint16(len(server))) // Server Name length binary.Write(&buf, binary.BigEndian, uint16(len(server))) // Server Name length
buf.Write([]byte(server)) buf.Write([]byte(server))
// https://github.com/shadowsocks/simple-obfs/blob/7659eeccf473aa41eb294e92c32f8f60a8747325/src/obfs_tls.c#L88 // https://github.com/shadowsocks/simple-obfs/blob/7659eeccf473aa41eb294e92c32f8f60a8747325/src/obfs_tls.c#L88
// Extension: ec_point_formats (len=4) // Extension: ec_point_formats (len=4)
buf.Write([]byte{0x00, 0x0b}) // type buf.Write([]byte{0x00, 0x0b}) // type
binary.Write(buf, binary.BigEndian, uint16(4)) // length binary.Write(&buf, binary.BigEndian, uint16(4)) // length
buf.WriteByte(0x03) // format length buf.WriteByte(0x03) // format length
buf.Write([]byte{0x01, 0x00, 0x02}) buf.Write([]byte{0x01, 0x00, 0x02})
// Extension: supported_groups (len=10) // Extension: supported_groups (len=10)
buf.Write([]byte{0x00, 0x0a}) // type buf.Write([]byte{0x00, 0x0a}) // type
binary.Write(buf, binary.BigEndian, uint16(10)) // length binary.Write(&buf, binary.BigEndian, uint16(10)) // length
binary.Write(buf, binary.BigEndian, uint16(8)) // Supported Groups List Length: 8 binary.Write(&buf, binary.BigEndian, uint16(8)) // Supported Groups List Length: 8
buf.Write([]byte{0x00, 0x1d, 0x00, 0x17, 0x00, 0x19, 0x00, 0x18}) buf.Write([]byte{0x00, 0x1d, 0x00, 0x17, 0x00, 0x19, 0x00, 0x18})
// Extension: signature_algorithms (len=32) // Extension: signature_algorithms (len=32)
buf.Write([]byte{0x00, 0x0d}) // type buf.Write([]byte{0x00, 0x0d}) // type
binary.Write(buf, binary.BigEndian, uint16(32)) // length binary.Write(&buf, binary.BigEndian, uint16(32)) // length
binary.Write(buf, binary.BigEndian, uint16(30)) // Signature Hash Algorithms Length: 30 binary.Write(&buf, binary.BigEndian, uint16(30)) // Signature Hash Algorithms Length: 30
buf.Write([]byte{ buf.Write([]byte{
0x06, 0x01, 0x06, 0x02, 0x06, 0x03, 0x05, 0x01, 0x05, 0x02, 0x05, 0x03, 0x04, 0x01, 0x04, 0x02, 0x06, 0x01, 0x06, 0x02, 0x06, 0x03, 0x05, 0x01, 0x05, 0x02, 0x05, 0x03, 0x04, 0x01, 0x04, 0x02,
0x04, 0x03, 0x03, 0x01, 0x03, 0x02, 0x03, 0x03, 0x02, 0x01, 0x02, 0x02, 0x02, 0x03, 0x04, 0x03, 0x03, 0x01, 0x03, 0x02, 0x03, 0x03, 0x02, 0x01, 0x02, 0x02, 0x02, 0x03,
@ -258,11 +258,11 @@ func extension(b []byte, server string) *bytes.Buffer {
// Extension: encrypt_then_mac (len=0) // Extension: encrypt_then_mac (len=0)
buf.Write([]byte{0x00, 0x16}) // type buf.Write([]byte{0x00, 0x16}) // type
binary.Write(buf, binary.BigEndian, uint16(0)) // length binary.Write(&buf, binary.BigEndian, uint16(0)) // length
// Extension: extended_master_secret (len=0) // Extension: extended_master_secret (len=0)
buf.Write([]byte{0x00, 0x17}) // type buf.Write([]byte{0x00, 0x17}) // type
binary.Write(buf, binary.BigEndian, uint16(0)) // length binary.Write(&buf, binary.BigEndian, uint16(0)) // length
return buf return &buf
} }

View File

@ -39,7 +39,7 @@ const (
CmdUDP byte = 2 CmdUDP byte = 2
) )
// Client vmess client // Client is a vmess client
type Client struct { type Client struct {
users []*User users []*User
count int count int
@ -68,7 +68,7 @@ type Conn struct {
dataWriter io.Writer dataWriter io.Writer
} }
// NewClient . // NewClient returns a new vmess client.
func NewClient(uuidStr, security string, alterID int) (*Client, error) { func NewClient(uuidStr, security string, alterID int) (*Client, error) {
uuid, err := StrToUUID(uuidStr) uuid, err := StrToUUID(uuidStr)
if err != nil { if err != nil {
@ -105,7 +105,7 @@ func NewClient(uuidStr, security string, alterID int) (*Client, error) {
return c, nil return c, nil
} }
// NewConn . // NewConn returns a new vmess conn.
func (c *Client) NewConn(rc net.Conn, target string) (*Conn, error) { func (c *Client) NewConn(rc net.Conn, target string) (*Conn, error) {
r := rand.Intn(c.count) r := rand.Intn(c.count)
conn := &Conn{user: c.users[r], opt: c.opt, security: c.security} conn := &Conn{user: c.users[r], opt: c.opt, security: c.security}
@ -158,9 +158,9 @@ func (c *Conn) EncodeAuthInfo() []byte {
return h.Sum(nil) return h.Sum(nil)
} }
// EncodeRequest encodes requests to network bytes // EncodeRequest encodes requests to network bytes.
func (c *Conn) EncodeRequest() ([]byte, error) { func (c *Conn) EncodeRequest() ([]byte, error) {
buf := new(bytes.Buffer) var buf bytes.Buffer
// Request // Request
buf.WriteByte(1) // Ver buf.WriteByte(1) // Ver
@ -178,7 +178,7 @@ func (c *Conn) EncodeRequest() ([]byte, error) {
buf.WriteByte(CmdTCP) // cmd buf.WriteByte(CmdTCP) // cmd
// target // target
err := binary.Write(buf, binary.BigEndian, uint16(c.port)) // port err := binary.Write(&buf, binary.BigEndian, uint16(c.port)) // port
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -212,7 +212,7 @@ func (c *Conn) EncodeRequest() ([]byte, error) {
return buf.Bytes(), nil return buf.Bytes(), nil
} }
// DecodeRespHeader . // DecodeRespHeader decodes response header.
func (c *Conn) DecodeRespHeader() error { func (c *Conn) DecodeRespHeader() error {
block, err := aes.NewCipher(c.respBodyKey[:]) block, err := aes.NewCipher(c.respBodyKey[:])
if err != nil { if err != nil {

View File

@ -39,8 +39,7 @@ func NewWS(s string, d proxy.Dialer) (*WS, error) {
addr = d.Addr() addr = d.Addr()
} }
query := u.Query() host := u.Query().Get("host")
host := query.Get("host")
if host == "" { if host == "" {
colonPos := strings.LastIndex(addr, ":") colonPos := strings.LastIndex(addr, ":")
if colonPos == -1 { if colonPos == -1 {