Chore: add some linters and clean up the code
This commit is contained in:
parent
a7252a1576
commit
5045ca4574
@ -1,10 +1,16 @@
|
|||||||
linters:
|
linters:
|
||||||
disable-all: true
|
disable-all: true
|
||||||
enable:
|
enable:
|
||||||
- gofumpt
|
|
||||||
- staticcheck
|
|
||||||
- govet
|
|
||||||
- gci
|
- gci
|
||||||
|
- gofumpt
|
||||||
|
- gosimple
|
||||||
|
- govet
|
||||||
|
- ineffassign
|
||||||
|
- misspell
|
||||||
|
- staticcheck
|
||||||
|
- unconvert
|
||||||
|
- unused
|
||||||
|
- usestdlibvars
|
||||||
|
|
||||||
linters-settings:
|
linters-settings:
|
||||||
gci:
|
gci:
|
||||||
|
@ -340,15 +340,15 @@ func parseVmessAddr(metadata *C.Metadata) *vmess.DstAddr {
|
|||||||
var addr []byte
|
var addr []byte
|
||||||
switch metadata.AddrType() {
|
switch metadata.AddrType() {
|
||||||
case socks5.AtypIPv4:
|
case socks5.AtypIPv4:
|
||||||
addrType = byte(vmess.AtypIPv4)
|
addrType = vmess.AtypIPv4
|
||||||
addr = make([]byte, net.IPv4len)
|
addr = make([]byte, net.IPv4len)
|
||||||
copy(addr[:], metadata.DstIP.To4())
|
copy(addr[:], metadata.DstIP.To4())
|
||||||
case socks5.AtypIPv6:
|
case socks5.AtypIPv6:
|
||||||
addrType = byte(vmess.AtypIPv6)
|
addrType = vmess.AtypIPv6
|
||||||
addr = make([]byte, net.IPv6len)
|
addr = make([]byte, net.IPv6len)
|
||||||
copy(addr[:], metadata.DstIP.To16())
|
copy(addr[:], metadata.DstIP.To16())
|
||||||
case socks5.AtypDomainName:
|
case socks5.AtypDomainName:
|
||||||
addrType = byte(vmess.AtypDomainName)
|
addrType = vmess.AtypDomainName
|
||||||
addr = make([]byte, len(metadata.Host)+1)
|
addr = make([]byte, len(metadata.Host)+1)
|
||||||
addr[0] = byte(len(metadata.Host))
|
addr[0] = byte(len(metadata.Host))
|
||||||
copy(addr[1:], []byte(metadata.Host))
|
copy(addr[1:], []byte(metadata.Host))
|
||||||
|
@ -62,7 +62,7 @@ func findProcessName(network string, ip net.IP, srcPort int) (string, error) {
|
|||||||
err := initWin32API()
|
err := initWin32API()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorln("Initialize PROCESS-NAME failed: %s", err.Error())
|
log.Errorln("Initialize PROCESS-NAME failed: %s", err.Error())
|
||||||
log.Warnln("All PROCESS-NAMES rules will be skiped")
|
log.Warnln("All PROCESS-NAMES rules will be skipped")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -65,7 +65,7 @@ func (ho *HTTPObfs) Write(b []byte) (int, error) {
|
|||||||
if ho.firstRequest {
|
if ho.firstRequest {
|
||||||
randBytes := make([]byte, 16)
|
randBytes := make([]byte, 16)
|
||||||
rand.Read(randBytes)
|
rand.Read(randBytes)
|
||||||
req, _ := http.NewRequest("GET", fmt.Sprintf("http://%s/", ho.host), bytes.NewBuffer(b[:]))
|
req, _ := http.NewRequest(http.MethodGet, fmt.Sprintf("http://%s/", ho.host), bytes.NewBuffer(b[:]))
|
||||||
req.Header.Set("User-Agent", fmt.Sprintf("curl/7.%d.%d", mathRand.Int()%54, mathRand.Int()%2))
|
req.Header.Set("User-Agent", fmt.Sprintf("curl/7.%d.%d", mathRand.Int()%54, mathRand.Int()%2))
|
||||||
req.Header.Set("Upgrade", "websocket")
|
req.Header.Set("Upgrade", "websocket")
|
||||||
req.Header.Set("Connection", "Upgrade")
|
req.Header.Set("Connection", "Upgrade")
|
||||||
|
@ -159,7 +159,7 @@ func ServerHandshake(rw net.Conn, authenticator auth.Authenticator) (addr Addr,
|
|||||||
pass := string(authBuf[:passLen])
|
pass := string(authBuf[:passLen])
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
if ok := authenticator.Verify(string(user), string(pass)); !ok {
|
if ok := authenticator.Verify(user, pass); !ok {
|
||||||
rw.Write([]byte{1, 1})
|
rw.Write([]byte{1, 1})
|
||||||
err = ErrAuth
|
err = ErrAuth
|
||||||
return
|
return
|
||||||
|
@ -76,7 +76,7 @@ func (vc *Conn) sendRequest() error {
|
|||||||
|
|
||||||
p := mathRand.Intn(16)
|
p := mathRand.Intn(16)
|
||||||
// P Sec Reserve Cmd
|
// P Sec Reserve Cmd
|
||||||
buf.WriteByte(byte(p<<4) | byte(vc.security))
|
buf.WriteByte(byte(p<<4) | vc.security)
|
||||||
buf.WriteByte(0)
|
buf.WriteByte(0)
|
||||||
if vc.dst.UDP {
|
if vc.dst.UDP {
|
||||||
buf.WriteByte(CommandUDP)
|
buf.WriteByte(CommandUDP)
|
||||||
|
@ -30,7 +30,7 @@ func (hc *h2Conn) establishConn() error {
|
|||||||
path := hc.cfg.Path
|
path := hc.cfg.Path
|
||||||
// TODO: connect use VMess Host instead of H2 Host
|
// TODO: connect use VMess Host instead of H2 Host
|
||||||
req := http.Request{
|
req := http.Request{
|
||||||
Method: "PUT",
|
Method: http.MethodPut,
|
||||||
Host: host,
|
Host: host,
|
||||||
URL: &url.URL{
|
URL: &url.URL{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
|
@ -58,7 +58,7 @@ func (hc *httpConn) Write(b []byte) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
u := fmt.Sprintf("http://%s%s", host, path)
|
u := fmt.Sprintf("http://%s%s", host, path)
|
||||||
req, _ := http.NewRequest("GET", u, bytes.NewBuffer(b))
|
req, _ := http.NewRequest(http.MethodGet, u, bytes.NewBuffer(b))
|
||||||
for key, list := range hc.cfg.Headers {
|
for key, list := range hc.cfg.Headers {
|
||||||
req.Header.Set(key, list[rand.Intn(len(list))])
|
req.Header.Set(key, list[rand.Intn(len(list))])
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user