Skip to content

Commit

Permalink
fix lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
DarienRaymond committed Dec 21, 2016
1 parent 99c8979 commit ceaf5d1
Show file tree
Hide file tree
Showing 31 changed files with 96 additions and 85 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"editor.tabSize": 2,

"go.buildTags": "json",
"go.lintTool": "gometalinter",

"protoc": {
"options": [
Expand Down
2 changes: 0 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,4 @@
"isBuildCommand": false
}
]


}
4 changes: 2 additions & 2 deletions app/dns/server/nameserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ type UDPNameServer struct {
sync.Mutex
address v2net.Destination
requests map[uint16]*PendingRequest
udpServer *udp.UDPServer
udpServer *udp.Server
nextCleanup time.Time
}

func NewUDPNameServer(address v2net.Destination, dispatcher dispatcher.PacketDispatcher) *UDPNameServer {
s := &UDPNameServer{
address: address,
requests: make(map[uint16]*PendingRequest),
udpServer: udp.NewUDPServer(dispatcher),
udpServer: udp.NewServer(dispatcher),
}
return s
}
Expand Down
2 changes: 1 addition & 1 deletion common/buf/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (b *Buffer) BytesFrom(from int) []byte {
return b.v[b.start+from : b.end]
}

// BytesFrom returns a slice of this Buffer from start to the given position.
// BytesTo returns a slice of this Buffer from start to the given position.
func (b *Buffer) BytesTo(to int) []byte {
if to < 0 {
to += b.Len()
Expand Down
6 changes: 3 additions & 3 deletions common/buf/buffer_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ func (p *BufferPool) Free(buffer *Buffer) {
const (
// Size of a regular buffer.
Size = 8 * 1024
// Size of a small buffer.
// SizeSmall is the size of a small buffer.
SizeSmall = 2 * 1024

PoolSizeEnvKey = "v2ray.buffer.size"
poolSizeEnvKey = "v2ray.buffer.size"
)

var (
Expand All @@ -109,7 +109,7 @@ var (

func init() {
var size uint32 = 20
sizeStr := os.Getenv(PoolSizeEnvKey)
sizeStr := os.Getenv(poolSizeEnvKey)
if len(sizeStr) > 0 {
customSize, err := strconv.ParseUint(sizeStr, 10, 32)
if err == nil {
Expand Down
2 changes: 1 addition & 1 deletion common/buf/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestBufferString(t *testing.T) {
buffer := New()
defer buffer.Release()

buffer.AppendSupplier(serial.WriteString("Test String"))
assert.Error(buffer.AppendSupplier(serial.WriteString("Test String"))).IsNil()
assert.String(buffer.String()).Equals("Test String")
}

Expand Down
6 changes: 4 additions & 2 deletions common/buf/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func (v *BytesToBufferReader) Read() (*Buffer, error) {

buffer := New()
if !v.largeBuffer.IsEmpty() {
buffer.AppendSupplier(ReadFrom(v.largeBuffer))
return buffer, nil
err := buffer.AppendSupplier(ReadFrom(v.largeBuffer))
return buffer, err
}

err := buffer.AppendSupplier(ReadFrom(v.reader))
Expand Down Expand Up @@ -58,6 +58,7 @@ type BufferToBytesReader struct {
eof bool
}

// Fill fills in the internal buffer.
// Private: Visible for testing.
func (v *BufferToBytesReader) Fill() {
b, err := v.stream.Read()
Expand Down Expand Up @@ -89,6 +90,7 @@ func (v *BufferToBytesReader) Read(b []byte) (int, error) {
return nBytes, err
}

// Release implements Releasable.Release().
func (v *BufferToBytesReader) Release() {
v.Lock()
defer v.Unlock()
Expand Down
1 change: 1 addition & 0 deletions common/buf/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (v *BytesToBufferWriter) Write(payload []byte) (int, error) {
return bytesWritten, nil
}

// Release implements Releasable.Release()
func (v *BytesToBufferWriter) Release() {
v.Lock()
v.writer.Release()
Expand Down
2 changes: 1 addition & 1 deletion common/buf/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestWriter(t *testing.T) {
assert := assert.On(t)

lb := New()
lb.AppendSupplier(ReadFrom(rand.Reader))
assert.Error(lb.AppendSupplier(ReadFrom(rand.Reader))).IsNil()

expectedBytes := append([]byte(nil), lb.Bytes()...)

Expand Down
2 changes: 1 addition & 1 deletion common/bufio/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestBufferedReader(t *testing.T) {
assert := assert.On(t)

content := buf.New()
content.AppendSupplier(buf.ReadFrom(rand.Reader))
assert.Error(content.AppendSupplier(buf.ReadFrom(rand.Reader))).IsNil()

len := content.Len()

Expand Down
10 changes: 8 additions & 2 deletions common/crypto/aes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ import (
// NewAesDecryptionStream creates a new AES encryption stream based on given key and IV.
// Caller must ensure the length of key and IV is either 16, 24 or 32 bytes.
func NewAesDecryptionStream(key []byte, iv []byte) cipher.Stream {
aesBlock, _ := aes.NewCipher(key)
aesBlock, err := aes.NewCipher(key)
if err != nil {
panic(err)
}
return cipher.NewCFBDecrypter(aesBlock, iv)
}

// NewAesEncryptionStream creates a new AES description stream based on given key and IV.
// Caller must ensure the length of key and IV is either 16, 24 or 32 bytes.
func NewAesEncryptionStream(key []byte, iv []byte) cipher.Stream {
aesBlock, _ := aes.NewCipher(key)
aesBlock, err := aes.NewCipher(key)
if err != nil {
panic(err)
}
return cipher.NewCFBEncrypter(aesBlock, iv)
}
8 changes: 3 additions & 5 deletions common/crypto/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,9 @@ func (v *AuthenticationReader) Read(b []byte) (int, error) {
}

type AuthenticationWriter struct {
auth Authenticator
buffer []byte
writer io.Writer
ivGen BytesGenerator
extraGen BytesGenerator
auth Authenticator
buffer []byte
writer io.Writer
}

func NewAuthenticationWriter(auth Authenticator, writer io.Writer) *AuthenticationWriter {
Expand Down
36 changes: 20 additions & 16 deletions common/net/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ import (
)

var (
LocalHostIP = IPAddress([]byte{127, 0, 0, 1})
AnyIP = IPAddress([]byte{0, 0, 0, 0})
// LocalHostIP is a constant value for localhost IP in IPv4.
LocalHostIP = IPAddress([]byte{127, 0, 0, 1})

// AnyIP is a constant value for any IP in IPv4.
AnyIP = IPAddress([]byte{0, 0, 0, 0})

// LocalHostDomain is a constant value for localhost domain.
LocalHostDomain = DomainAddress("localhost")
)

Expand Down Expand Up @@ -87,21 +92,20 @@ func IPAddress(ip []byte) Address {

// DomainAddress creates an Address with given domain.
func DomainAddress(domain string) Address {
var addr domainAddress = domainAddress(domain)
return addr
return domainAddress(domain)
}

type ipv4Address [4]byte

func (addr ipv4Address) IP() net.IP {
return net.IP(addr[:])
func (v ipv4Address) IP() net.IP {
return net.IP(v[:])
}

func (addr ipv4Address) Domain() string {
func (ipv4Address) Domain() string {
panic("Calling Domain() on an IPv4Address.")
}

func (addr ipv4Address) Family() AddressFamily {
func (ipv4Address) Family() AddressFamily {
return AddressFamilyIPv4
}

Expand All @@ -111,15 +115,15 @@ func (v ipv4Address) String() string {

type ipv6Address [16]byte

func (addr ipv6Address) IP() net.IP {
return net.IP(addr[:])
func (v ipv6Address) IP() net.IP {
return net.IP(v[:])
}

func (addr ipv6Address) Domain() string {
func (ipv6Address) Domain() string {
panic("Calling Domain() on an IPv6Address.")
}

func (v ipv6Address) Family() AddressFamily {
func (ipv6Address) Family() AddressFamily {
return AddressFamilyIPv6
}

Expand All @@ -129,15 +133,15 @@ func (v ipv6Address) String() string {

type domainAddress string

func (addr domainAddress) IP() net.IP {
func (domainAddress) IP() net.IP {
panic("Calling IP() on a DomainAddress.")
}

func (addr domainAddress) Domain() string {
return string(addr)
func (v domainAddress) Domain() string {
return string(v)
}

func (addr domainAddress) Family() AddressFamily {
func (domainAddress) Family() AddressFamily {
return AddressFamilyDomain
}

Expand Down
4 changes: 2 additions & 2 deletions common/net/destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
// Destination represents a network destination including address and protocol (tcp / udp).
type Destination struct {
Network Network
Address Address
Port Port
Address Address
}

func DestinationFromAddr(addr net.Addr) Destination {
Expand Down Expand Up @@ -45,7 +45,7 @@ func (v Destination) NetAddr() string {
}

func (v Destination) String() string {
return v.Network.UrlPrefix() + ":" + v.NetAddr()
return v.Network.URLPrefix() + ":" + v.NetAddr()
}

func (v *Endpoint) AsDestination() Destination {
Expand Down
2 changes: 1 addition & 1 deletion common/net/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (v Network) SystemString() string {
}
}

func (v Network) UrlPrefix() string {
func (v Network) URLPrefix() string {
switch v {
case Network_TCP, Network_RawTCP:
return "tcp"
Expand Down
4 changes: 2 additions & 2 deletions common/protocol/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ func NormSecurity(s Security) Security {

type RequestHeader struct {
Version byte
User *User
Command RequestCommand
Option RequestOption
Security Security
Address v2net.Address
Port v2net.Port
Address v2net.Address
User *User
}

func (v *RequestHeader) Destination() v2net.Destination {
Expand Down
4 changes: 2 additions & 2 deletions inbound_detour_always.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"v2ray.com/core/proxy"
)

// Handler for inbound detour connections.
// InboundDetourHandlerAlways is a handler for inbound detour connections.
type InboundDetourHandlerAlways struct {
space app.Space
config *InboundConnectionConfig
Expand Down Expand Up @@ -54,7 +54,7 @@ func (v *InboundDetourHandlerAlways) Close() {
}
}

// Starts the inbound connection handler.
// Start starts the inbound connection handler.
func (v *InboundDetourHandlerAlways) Start() error {
for _, ich := range v.ich {
err := retry.ExponentialBackoff(10 /* times */, 200 /* ms */).On(func() error {
Expand Down
4 changes: 2 additions & 2 deletions proxy/dokodemo/dokodemo.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type DokodemoDoor struct {
packetDispatcher dispatcher.PacketDispatcher
tcpListener *internet.TCPHub
udpHub *udp.UDPHub
udpServer *udp.UDPServer
udpServer *udp.Server
meta *proxy.InboundHandlerMeta
}

Expand Down Expand Up @@ -88,7 +88,7 @@ func (v *DokodemoDoor) Start() error {
}

func (v *DokodemoDoor) ListenUDP() error {
v.udpServer = udp.NewUDPServer(v.packetDispatcher)
v.udpServer = udp.NewServer(v.packetDispatcher)
udpHub, err := udp.ListenUDP(
v.meta.Address, v.meta.Port, udp.ListenOption{
Callback: v.handleUDPPackets,
Expand Down
4 changes: 2 additions & 2 deletions proxy/shadowsocks/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Server struct {
accepting bool
tcpHub *internet.TCPHub
udpHub *udp.UDPHub
udpServer *udp.UDPServer
udpServer *udp.Server
}

func NewServer(config *ServerConfig, space app.Space, meta *proxy.InboundHandlerMeta) (*Server, error) {
Expand Down Expand Up @@ -90,7 +90,7 @@ func (v *Server) Start() error {
v.tcpHub = tcpHub

if v.config.UdpEnabled {
v.udpServer = udp.NewUDPServer(v.packetDispatcher)
v.udpServer = udp.NewServer(v.packetDispatcher)
udpHub, err := udp.ListenUDP(v.meta.Address, v.meta.Port, udp.ListenOption{Callback: v.handlerUDPPayload})
if err != nil {
log.Error("Shadowsocks: Failed to listen UDP on ", v.meta.Address, ":", v.meta.Port, ": ", err)
Expand Down
2 changes: 1 addition & 1 deletion proxy/socks/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Server struct {
tcpListener *internet.TCPHub
udpHub *udp.UDPHub
udpAddress v2net.Destination
udpServer *udp.UDPServer
udpServer *udp.Server
meta *proxy.InboundHandlerMeta
}

Expand Down
2 changes: 1 addition & 1 deletion proxy/socks/server_udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func (v *Server) listenUDP() error {
v.udpServer = udp.NewUDPServer(v.packetDispatcher)
v.udpServer = udp.NewServer(v.packetDispatcher)
udpHub, err := udp.ListenUDP(v.meta.Address, v.meta.Port, udp.ListenOption{Callback: v.handleUDPPayload})
if err != nil {
log.Error("Socks: Failed to listen on udp (", v.meta.Address, ":", v.meta.Port, "): ", err)
Expand Down
2 changes: 1 addition & 1 deletion transport/internet/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package internet

import (
"v2ray.com/core/common/errors"
"v2ray.com/core/common/serial"
"v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/common/serial"
)

type ConfigCreator func() interface{}
Expand Down
1 change: 1 addition & 0 deletions transport/internet/internal/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net"
"sync"
"time"

v2net "v2ray.com/core/common/net"
"v2ray.com/core/common/signal"
)
Expand Down
Loading

0 comments on commit ceaf5d1

Please sign in to comment.