Browse Source

fix lint errors

Darien Raymond 7 years ago
parent
commit
9f198d7e3d

+ 3 - 0
app/commander/commander.go

@@ -34,10 +34,12 @@ func NewCommander(ctx context.Context, config *Config) (*Commander, error) {
 	return c, nil
 	return c, nil
 }
 }
 
 
+// Type implements common.HasType.
 func (c *Commander) Type() interface{} {
 func (c *Commander) Type() interface{} {
 	return (*Commander)(nil)
 	return (*Commander)(nil)
 }
 }
 
 
+// Start implements common.Runnable.
 func (c *Commander) Start() error {
 func (c *Commander) Start() error {
 	c.Lock()
 	c.Lock()
 	c.server = grpc.NewServer()
 	c.server = grpc.NewServer()
@@ -77,6 +79,7 @@ func (c *Commander) Start() error {
 	return nil
 	return nil
 }
 }
 
 
+// Close implements common.Closable.
 func (c *Commander) Close() error {
 func (c *Commander) Close() error {
 	c.Lock()
 	c.Lock()
 	defer c.Unlock()
 	defer c.Unlock()

+ 0 - 4
app/dispatcher/default.go

@@ -52,10 +52,6 @@ func (*DefaultDispatcher) Start() error {
 // Close implements common.Closable.
 // Close implements common.Closable.
 func (*DefaultDispatcher) Close() error { return nil }
 func (*DefaultDispatcher) Close() error { return nil }
 
 
-func getStatsName(u *protocol.User) string {
-	return "user>traffic>" + u.Email
-}
-
 func (d *DefaultDispatcher) getStatCounter(name string) core.StatCounter {
 func (d *DefaultDispatcher) getStatCounter(name string) core.StatCounter {
 	c := d.stats.GetCounter(name)
 	c := d.stats.GetCounter(name)
 	if c != nil {
 	if c != nil {

+ 2 - 1
app/dns/nameserver.go

@@ -7,6 +7,7 @@ import (
 
 
 	"github.com/miekg/dns"
 	"github.com/miekg/dns"
 	"v2ray.com/core"
 	"v2ray.com/core"
+	"v2ray.com/core/common"
 	"v2ray.com/core/common/buf"
 	"v2ray.com/core/common/buf"
 	"v2ray.com/core/common/dice"
 	"v2ray.com/core/common/dice"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/net"
@@ -54,7 +55,7 @@ func NewUDPNameServer(address net.Destination, dispatcher core.Dispatcher) *UDPN
 		Interval: time.Minute,
 		Interval: time.Minute,
 		Execute:  s.Cleanup,
 		Execute:  s.Cleanup,
 	}
 	}
-	s.cleanup.Start()
+	common.Must(s.cleanup.Start())
 	return s
 	return s
 }
 }
 
 

+ 5 - 0
app/stats/stats.go

@@ -10,22 +10,27 @@ import (
 	"v2ray.com/core"
 	"v2ray.com/core"
 )
 )
 
 
+// Counter is an implementation of core.StatCounter.
 type Counter struct {
 type Counter struct {
 	value int64
 	value int64
 }
 }
 
 
+// Value implements core.StatCounter.
 func (c *Counter) Value() int64 {
 func (c *Counter) Value() int64 {
 	return atomic.LoadInt64(&c.value)
 	return atomic.LoadInt64(&c.value)
 }
 }
 
 
+// Set implements core.StatCounter.
 func (c *Counter) Set(newValue int64) int64 {
 func (c *Counter) Set(newValue int64) int64 {
 	return atomic.SwapInt64(&c.value, newValue)
 	return atomic.SwapInt64(&c.value, newValue)
 }
 }
 
 
+// Add implements core.StatCounter.
 func (c *Counter) Add(delta int64) int64 {
 func (c *Counter) Add(delta int64) int64 {
 	return atomic.AddInt64(&c.value, delta)
 	return atomic.AddInt64(&c.value, delta)
 }
 }
 
 
+// Manager is an implementation of core.StatManager.
 type Manager struct {
 type Manager struct {
 	access   sync.RWMutex
 	access   sync.RWMutex
 	counters map[string]*Counter
 	counters map[string]*Counter

+ 1 - 1
common/crypto/auth.go

@@ -124,7 +124,7 @@ func (r *AuthenticationReader) readSize() (int32, error) {
 var errSoft = newError("waiting for more data")
 var errSoft = newError("waiting for more data")
 
 
 func (r *AuthenticationReader) readInternal(soft bool) (*buf.Buffer, error) {
 func (r *AuthenticationReader) readInternal(soft bool) (*buf.Buffer, error) {
-	if soft && r.reader.BufferedBytes() < int32(r.sizeParser.SizeBytes()) {
+	if soft && r.reader.BufferedBytes() < r.sizeParser.SizeBytes() {
 		return nil, errSoft
 		return nil, errSoft
 	}
 	}
 
 

+ 1 - 1
common/protocol/address.go

@@ -99,7 +99,7 @@ func (p *AddressParser) readAddress(b *buf.Buffer, reader io.Reader) (net.Addres
 			return nil, err
 			return nil, err
 		}
 		}
 		domainLength := int32(b.Byte(b.Len() - 1))
 		domainLength := int32(b.Byte(b.Len() - 1))
-		if err := b.AppendSupplier(buf.ReadFullFrom(reader, int32(domainLength))); err != nil {
+		if err := b.AppendSupplier(buf.ReadFullFrom(reader, domainLength)); err != nil {
 			return nil, err
 			return nil, err
 		}
 		}
 		domain := string(b.BytesFrom(-domainLength))
 		domain := string(b.BytesFrom(-domainLength))

+ 3 - 3
common/uuid/uuid.go

@@ -49,15 +49,15 @@ func (u *UUID) Equals(another *UUID) bool {
 // Next generates a deterministic random UUID based on this UUID.
 // Next generates a deterministic random UUID based on this UUID.
 func (u *UUID) Next() UUID {
 func (u *UUID) Next() UUID {
 	md5hash := md5.New()
 	md5hash := md5.New()
-	md5hash.Write(u.Bytes())
-	md5hash.Write([]byte("16167dc8-16b6-4e6d-b8bb-65dd68113a81"))
+	common.Must2(md5hash.Write(u.Bytes()))
+	common.Must2(md5hash.Write([]byte("16167dc8-16b6-4e6d-b8bb-65dd68113a81")))
 	var newid UUID
 	var newid UUID
 	for {
 	for {
 		md5hash.Sum(newid[:0])
 		md5hash.Sum(newid[:0])
 		if !newid.Equals(u) {
 		if !newid.Equals(u) {
 			return newid
 			return newid
 		}
 		}
-		md5hash.Write([]byte("533eff8a-4113-4b10-b5ce-0f5d76b98cd2"))
+		common.Must2(md5hash.Write([]byte("533eff8a-4113-4b10-b5ce-0f5d76b98cd2")))
 	}
 	}
 }
 }
 
 

+ 0 - 1
proxy/dokodemo/dokodemo.go

@@ -21,7 +21,6 @@ type DokodemoDoor struct {
 	config        *Config
 	config        *Config
 	address       net.Address
 	address       net.Address
 	port          net.Port
 	port          net.Port
-	v             *core.Instance
 }
 }
 
 
 func New(ctx context.Context, config *Config) (*DokodemoDoor, error) {
 func New(ctx context.Context, config *Config) (*DokodemoDoor, error) {

+ 3 - 3
proxy/shadowsocks/protocol.go

@@ -41,7 +41,7 @@ func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHea
 	ivLen := account.Cipher.IVSize()
 	ivLen := account.Cipher.IVSize()
 	var iv []byte
 	var iv []byte
 	if ivLen > 0 {
 	if ivLen > 0 {
-		if err := buffer.AppendSupplier(buf.ReadFullFrom(reader, int32(ivLen))); err != nil {
+		if err := buffer.AppendSupplier(buf.ReadFullFrom(reader, ivLen)); err != nil {
 			return nil, nil, newError("failed to read IV").Base(err)
 			return nil, nil, newError("failed to read IV").Base(err)
 		}
 		}
 
 
@@ -227,7 +227,7 @@ func EncodeUDPPacket(request *protocol.RequestHeader, payload []byte) (*buf.Buff
 	buffer := buf.New()
 	buffer := buf.New()
 	ivLen := account.Cipher.IVSize()
 	ivLen := account.Cipher.IVSize()
 	if ivLen > 0 {
 	if ivLen > 0 {
-		common.Must(buffer.Reset(buf.ReadFullFrom(rand.Reader, int32(ivLen))))
+		common.Must(buffer.Reset(buf.ReadFullFrom(rand.Reader, ivLen)))
 	}
 	}
 	iv := buffer.Bytes()
 	iv := buffer.Bytes()
 
 
@@ -293,7 +293,7 @@ func DecodeUDPPacket(user *protocol.User, payload *buf.Buffer) (*protocol.Reques
 
 
 			authenticator := NewAuthenticator(HeaderKeyGenerator(account.Key, iv))
 			authenticator := NewAuthenticator(HeaderKeyGenerator(account.Key, iv))
 			actualAuth := make([]byte, AuthSize)
 			actualAuth := make([]byte, AuthSize)
-			authenticator.Authenticate(payload.BytesTo(payloadLen))(actualAuth)
+			common.Must2(authenticator.Authenticate(payload.BytesTo(payloadLen))(actualAuth))
 			if !bytes.Equal(actualAuth, authBytes) {
 			if !bytes.Equal(actualAuth, authBytes) {
 				return nil, nil, newError("invalid OTA")
 				return nil, nil, newError("invalid OTA")
 			}
 			}

+ 1 - 4
transport/config.go

@@ -9,8 +9,5 @@ func (c *Config) Apply() error {
 	if c == nil {
 	if c == nil {
 		return nil
 		return nil
 	}
 	}
-	if err := internet.ApplyGlobalTransportSettings(c.TransportSettings); err != nil {
-		return err
-	}
-	return nil
+	return internet.ApplyGlobalTransportSettings(c.TransportSettings)
 }
 }