From 9f198d7e3d40337cea6b814d090a71f65f119c2a Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Wed, 4 Apr 2018 00:29:30 +0200 Subject: [PATCH] fix lint errors --- app/commander/commander.go | 3 +++ app/dispatcher/default.go | 4 ---- app/dns/nameserver.go | 3 ++- app/stats/stats.go | 5 +++++ common/crypto/auth.go | 2 +- common/protocol/address.go | 2 +- common/uuid/uuid.go | 6 +++--- proxy/dokodemo/dokodemo.go | 1 - proxy/shadowsocks/protocol.go | 6 +++--- transport/config.go | 5 +---- 10 files changed, 19 insertions(+), 18 deletions(-) diff --git a/app/commander/commander.go b/app/commander/commander.go index 19991fce..072d38cd 100644 --- a/app/commander/commander.go +++ b/app/commander/commander.go @@ -34,10 +34,12 @@ func NewCommander(ctx context.Context, config *Config) (*Commander, error) { return c, nil } +// Type implements common.HasType. func (c *Commander) Type() interface{} { return (*Commander)(nil) } +// Start implements common.Runnable. func (c *Commander) Start() error { c.Lock() c.server = grpc.NewServer() @@ -77,6 +79,7 @@ func (c *Commander) Start() error { return nil } +// Close implements common.Closable. func (c *Commander) Close() error { c.Lock() defer c.Unlock() diff --git a/app/dispatcher/default.go b/app/dispatcher/default.go index 6354ce3f..3a9fb82d 100644 --- a/app/dispatcher/default.go +++ b/app/dispatcher/default.go @@ -52,10 +52,6 @@ func (*DefaultDispatcher) Start() error { // Close implements common.Closable. 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 { c := d.stats.GetCounter(name) if c != nil { diff --git a/app/dns/nameserver.go b/app/dns/nameserver.go index 88e9c26a..1d766712 100644 --- a/app/dns/nameserver.go +++ b/app/dns/nameserver.go @@ -7,6 +7,7 @@ import ( "github.com/miekg/dns" "v2ray.com/core" + "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/dice" "v2ray.com/core/common/net" @@ -54,7 +55,7 @@ func NewUDPNameServer(address net.Destination, dispatcher core.Dispatcher) *UDPN Interval: time.Minute, Execute: s.Cleanup, } - s.cleanup.Start() + common.Must(s.cleanup.Start()) return s } diff --git a/app/stats/stats.go b/app/stats/stats.go index 27fffc1b..03ee2982 100644 --- a/app/stats/stats.go +++ b/app/stats/stats.go @@ -10,22 +10,27 @@ import ( "v2ray.com/core" ) +// Counter is an implementation of core.StatCounter. type Counter struct { value int64 } +// Value implements core.StatCounter. func (c *Counter) Value() int64 { return atomic.LoadInt64(&c.value) } +// Set implements core.StatCounter. func (c *Counter) Set(newValue int64) int64 { return atomic.SwapInt64(&c.value, newValue) } +// Add implements core.StatCounter. func (c *Counter) Add(delta int64) int64 { return atomic.AddInt64(&c.value, delta) } +// Manager is an implementation of core.StatManager. type Manager struct { access sync.RWMutex counters map[string]*Counter diff --git a/common/crypto/auth.go b/common/crypto/auth.go index 85a84a19..2cf0eb15 100644 --- a/common/crypto/auth.go +++ b/common/crypto/auth.go @@ -124,7 +124,7 @@ func (r *AuthenticationReader) readSize() (int32, error) { var errSoft = newError("waiting for more data") 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 } diff --git a/common/protocol/address.go b/common/protocol/address.go index 48daf761..83437e0c 100644 --- a/common/protocol/address.go +++ b/common/protocol/address.go @@ -99,7 +99,7 @@ func (p *AddressParser) readAddress(b *buf.Buffer, reader io.Reader) (net.Addres return nil, err } 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 } domain := string(b.BytesFrom(-domainLength)) diff --git a/common/uuid/uuid.go b/common/uuid/uuid.go index fa90f915..1f3a8342 100755 --- a/common/uuid/uuid.go +++ b/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. func (u *UUID) Next() UUID { 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 for { md5hash.Sum(newid[:0]) if !newid.Equals(u) { return newid } - md5hash.Write([]byte("533eff8a-4113-4b10-b5ce-0f5d76b98cd2")) + common.Must2(md5hash.Write([]byte("533eff8a-4113-4b10-b5ce-0f5d76b98cd2"))) } } diff --git a/proxy/dokodemo/dokodemo.go b/proxy/dokodemo/dokodemo.go index 1445f864..7626911d 100644 --- a/proxy/dokodemo/dokodemo.go +++ b/proxy/dokodemo/dokodemo.go @@ -21,7 +21,6 @@ type DokodemoDoor struct { config *Config address net.Address port net.Port - v *core.Instance } func New(ctx context.Context, config *Config) (*DokodemoDoor, error) { diff --git a/proxy/shadowsocks/protocol.go b/proxy/shadowsocks/protocol.go index d6cfd31c..9a86c958 100644 --- a/proxy/shadowsocks/protocol.go +++ b/proxy/shadowsocks/protocol.go @@ -41,7 +41,7 @@ func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHea ivLen := account.Cipher.IVSize() var iv []byte 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) } @@ -227,7 +227,7 @@ func EncodeUDPPacket(request *protocol.RequestHeader, payload []byte) (*buf.Buff buffer := buf.New() ivLen := account.Cipher.IVSize() 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() @@ -293,7 +293,7 @@ func DecodeUDPPacket(user *protocol.User, payload *buf.Buffer) (*protocol.Reques authenticator := NewAuthenticator(HeaderKeyGenerator(account.Key, iv)) actualAuth := make([]byte, AuthSize) - authenticator.Authenticate(payload.BytesTo(payloadLen))(actualAuth) + common.Must2(authenticator.Authenticate(payload.BytesTo(payloadLen))(actualAuth)) if !bytes.Equal(actualAuth, authBytes) { return nil, nil, newError("invalid OTA") } diff --git a/transport/config.go b/transport/config.go index de51c0e3..486ea45a 100644 --- a/transport/config.go +++ b/transport/config.go @@ -9,8 +9,5 @@ func (c *Config) Apply() error { if c == nil { return nil } - if err := internet.ApplyGlobalTransportSettings(c.TransportSettings); err != nil { - return err - } - return nil + return internet.ApplyGlobalTransportSettings(c.TransportSettings) }