Browse Source

Fix according to staticcheck result

staticcheck repo: https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck
loyalsoldier 5 years ago
parent
commit
f12f76582f

+ 3 - 4
app/dns/dnscommon_test.go

@@ -12,7 +12,6 @@ import (
 	"golang.org/x/net/dns/dnsmessage"
 	"v2ray.com/core/common"
 	"v2ray.com/core/common/net"
-	v2net "v2ray.com/core/common/net"
 )
 
 func Test_parseResponse(t *testing.T) {
@@ -52,7 +51,7 @@ func Test_parseResponse(t *testing.T) {
 		wantErr bool
 	}{
 		{"empty",
-			&IPRecord{0, []v2net.Address(nil), time.Time{}, dnsmessage.RCodeSuccess},
+			&IPRecord{0, []net.Address(nil), time.Time{}, dnsmessage.RCodeSuccess},
 			false,
 		},
 		{"error",
@@ -60,12 +59,12 @@ func Test_parseResponse(t *testing.T) {
 			true,
 		},
 		{"a record",
-			&IPRecord{1, []v2net.Address{v2net.ParseAddress("8.8.8.8"), v2net.ParseAddress("8.8.4.4")},
+			&IPRecord{1, []net.Address{net.ParseAddress("8.8.8.8"), net.ParseAddress("8.8.4.4")},
 				time.Time{}, dnsmessage.RCodeSuccess},
 			false,
 		},
 		{"aaaa record",
-			&IPRecord{2, []v2net.Address{v2net.ParseAddress("2001::123:8888"), v2net.ParseAddress("2001::123:8844")}, time.Time{}, dnsmessage.RCodeSuccess},
+			&IPRecord{2, []net.Address{net.ParseAddress("2001::123:8888"), net.ParseAddress("2001::123:8844")}, time.Time{}, dnsmessage.RCodeSuccess},
 			false,
 		},
 	}

+ 5 - 5
common/mux/client.go

@@ -83,7 +83,7 @@ func (p *IncrementalWorkerPicker) findAvailable() int {
 	return -1
 }
 
-func (p *IncrementalWorkerPicker) pickInternal() (*ClientWorker, error, bool) {
+func (p *IncrementalWorkerPicker) pickInternal() (*ClientWorker, bool, error) {
 	p.access.Lock()
 	defer p.access.Unlock()
 
@@ -93,14 +93,14 @@ func (p *IncrementalWorkerPicker) pickInternal() (*ClientWorker, error, bool) {
 		if n > 1 && idx != n-1 {
 			p.workers[n-1], p.workers[idx] = p.workers[idx], p.workers[n-1]
 		}
-		return p.workers[idx], nil, false
+		return p.workers[idx], false, nil
 	}
 
 	p.cleanup()
 
 	worker, err := p.Factory.Create()
 	if err != nil {
-		return nil, err, false
+		return nil, false, err
 	}
 	p.workers = append(p.workers, worker)
 
@@ -111,11 +111,11 @@ func (p *IncrementalWorkerPicker) pickInternal() (*ClientWorker, error, bool) {
 		}
 	}
 
-	return worker, nil, true
+	return worker, true, nil
 }
 
 func (p *IncrementalWorkerPicker) PickAvailable() (*ClientWorker, error) {
-	worker, err, start := p.pickInternal()
+	worker, start, err := p.pickInternal()
 	if start {
 		common.Must(p.cleanupTask.Start())
 	}

+ 1 - 1
proxy/mtproto/auth.go

@@ -83,7 +83,7 @@ func generateRandomBytes(random []byte, connType [4]byte) {
 			continue
 		}
 
-		if 0x00000000 == (uint32(random[7])<<24)|(uint32(random[6])<<16)|(uint32(random[5])<<8)|uint32(random[4]) {
+		if (uint32(random[7])<<24)|(uint32(random[6])<<16)|(uint32(random[5])<<8)|uint32(random[4]) == 0x00000000 {
 			continue
 		}
 

+ 2 - 2
proxy/vmess/aead/encrypt.go

@@ -8,6 +8,7 @@ import (
 	"encoding/binary"
 	"io"
 	"time"
+
 	"v2ray.com/core/common"
 )
 
@@ -21,8 +22,7 @@ func SealVMessAEADHeader(key [16]byte, data []byte) []byte {
 
 	aeadPayloadLengthSerializeBuffer := bytes.NewBuffer(nil)
 
-	var headerPayloadDataLen uint16
-	headerPayloadDataLen = uint16(len(data))
+	headerPayloadDataLen := uint16(len(data))
 
 	common.Must(binary.Write(aeadPayloadLengthSerializeBuffer, binary.BigEndian, headerPayloadDataLen))
 

+ 2 - 1
proxy/vmess/aead/encrypt_test.go

@@ -3,9 +3,10 @@ package aead
 import (
 	"bytes"
 	"fmt"
-	"github.com/stretchr/testify/assert"
 	"io"
 	"testing"
+
+	"github.com/stretchr/testify/assert"
 )
 
 func TestOpenVMessAEADHeader(t *testing.T) {

+ 4 - 6
proxy/vmess/encoding/server.go

@@ -12,19 +12,18 @@ import (
 	"io/ioutil"
 	"sync"
 	"time"
-	"v2ray.com/core/common/dice"
-	vmessaead "v2ray.com/core/proxy/vmess/aead"
 
 	"golang.org/x/crypto/chacha20poly1305"
-
 	"v2ray.com/core/common"
 	"v2ray.com/core/common/bitmask"
 	"v2ray.com/core/common/buf"
 	"v2ray.com/core/common/crypto"
+	"v2ray.com/core/common/dice"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/protocol"
 	"v2ray.com/core/common/task"
 	"v2ray.com/core/proxy/vmess"
+	vmessaead "v2ray.com/core/proxy/vmess/aead"
 )
 
 type sessionId struct {
@@ -170,7 +169,7 @@ func (s *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
 	var fixedSizeAuthID [16]byte
 	copy(fixedSizeAuthID[:], buffer.Bytes())
 
-	if foundAEAD == true {
+	if foundAEAD {
 		vmessAccount = user.Account.(*vmess.MemoryAccount)
 		var fixedSizeCmdKey [16]byte
 		copy(fixedSizeCmdKey[:], vmessAccount.ID.CmdKey())
@@ -405,8 +404,7 @@ func (s *ServerSession) EncodeResponseHeader(header *protocol.ResponseHeader, wr
 
 		aeadResponseHeaderLengthEncryptionBuffer := bytes.NewBuffer(nil)
 
-		var decryptedResponseHeaderLengthBinaryDeserializeBuffer uint16
-		decryptedResponseHeaderLengthBinaryDeserializeBuffer = uint16(aeadEncryptedHeaderBuffer.Len())
+		decryptedResponseHeaderLengthBinaryDeserializeBuffer := uint16(aeadEncryptedHeaderBuffer.Len())
 
 		common.Must(binary.Write(aeadResponseHeaderLengthEncryptionBuffer, binary.BigEndian, decryptedResponseHeaderLengthBinaryDeserializeBuffer))
 

+ 3 - 3
proxy/vmess/validator.go

@@ -11,13 +11,13 @@ import (
 	"sync"
 	"sync/atomic"
 	"time"
-	"v2ray.com/core/common/dice"
-	"v2ray.com/core/proxy/vmess/aead"
 
 	"v2ray.com/core/common"
+	"v2ray.com/core/common/dice"
 	"v2ray.com/core/common/protocol"
 	"v2ray.com/core/common/serial"
 	"v2ray.com/core/common/task"
+	"v2ray.com/core/proxy/vmess/aead"
 )
 
 const (
@@ -141,7 +141,7 @@ func (v *TimedUserValidator) Add(u *protocol.MemoryUser) error {
 	v.generateNewHashes(protocol.Timestamp(nowSec), uu)
 
 	account := uu.user.Account.(*MemoryAccount)
-	if v.behaviorFused == false {
+	if !v.behaviorFused {
 		hashkdf := hmac.New(func() hash.Hash { return sha256.New() }, []byte("VMESSBSKDF"))
 		hashkdf.Write(account.ID.Bytes())
 		v.behaviorSeed = crc64.Update(v.behaviorSeed, crc64.MakeTable(crc64.ECMA), hashkdf.Sum(nil))

+ 1 - 1
transport/internet/headers/http/http.go

@@ -126,7 +126,7 @@ func (h *HeaderReader) Read(reader io.Reader) (*buf.Buffer, error) {
 		}
 	}
 
-	if hasThisUri == false {
+	if !hasThisUri {
 		return nil, ErrHeaderMisMatch
 	}
 

+ 0 - 3
transport/internet/headers/http/http_test.go

@@ -34,7 +34,6 @@ func TestReaderWriter(t *testing.T) {
 		t.Error("unknown error ", err)
 	}
 	_ = buffer
-	return
 	/*
 		if buffer.String() != "efg" {
 			t.Error("buffer: ", buffer.String())
@@ -256,7 +255,6 @@ func TestConnectionInvPath(t *testing.T) {
 			break
 		}
 	}
-	return
 }
 
 func TestConnectionInvReq(t *testing.T) {
@@ -315,5 +313,4 @@ func TestConnectionInvReq(t *testing.T) {
 	if !strings.HasPrefix(string(l), "HTTP/1.1 400 Bad Request") {
 		t.Error("Resp to non http conn", string(l))
 	}
-	return
 }

+ 1 - 4
transport/internet/kcp/sending.go

@@ -121,10 +121,7 @@ func (sw *SendingWindow) Flush(current uint32, rto uint32, maxInFlightSize uint3
 		segment.transmit++
 		sw.writer.Write(segment)
 		inFlightSize++
-		if inFlightSize >= maxInFlightSize {
-			return false
-		}
-		return true
+		return inFlightSize < maxInFlightSize
 	})
 
 	if sw.onPacketLoss != nil && inFlightSize > 0 && sw.totalInFlightSize != 0 {