diff --git a/.vscode/settings.json b/.vscode/settings.json index 2dc556c5b..0596f0284 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,7 @@ "editor.tabSize": 2, "go.buildTags": "json", + "go.lintTool": "gometalinter", "protoc": { "options": [ diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 9eaf9e815..769b0b3d3 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -25,6 +25,4 @@ "isBuildCommand": false } ] - - } \ No newline at end of file diff --git a/app/dns/server/nameserver.go b/app/dns/server/nameserver.go index f381447b9..fe6517d30 100644 --- a/app/dns/server/nameserver.go +++ b/app/dns/server/nameserver.go @@ -44,7 +44,7 @@ type UDPNameServer struct { sync.Mutex address v2net.Destination requests map[uint16]*PendingRequest - udpServer *udp.UDPServer + udpServer *udp.Server nextCleanup time.Time } @@ -52,7 +52,7 @@ func NewUDPNameServer(address v2net.Destination, dispatcher dispatcher.PacketDis s := &UDPNameServer{ address: address, requests: make(map[uint16]*PendingRequest), - udpServer: udp.NewUDPServer(dispatcher), + udpServer: udp.NewServer(dispatcher), } return s } diff --git a/common/buf/buffer.go b/common/buf/buffer.go index 48c8ff6a5..144cd3fe6 100644 --- a/common/buf/buffer.go +++ b/common/buf/buffer.go @@ -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() diff --git a/common/buf/buffer_pool.go b/common/buf/buffer_pool.go index f689bc8e2..d64fe54bd 100644 --- a/common/buf/buffer_pool.go +++ b/common/buf/buffer_pool.go @@ -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 ( @@ -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 { diff --git a/common/buf/buffer_test.go b/common/buf/buffer_test.go index fac397b4b..8c1a94f97 100644 --- a/common/buf/buffer_test.go +++ b/common/buf/buffer_test.go @@ -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") } diff --git a/common/buf/reader.go b/common/buf/reader.go index 05cf0f2dd..c528013f9 100644 --- a/common/buf/reader.go +++ b/common/buf/reader.go @@ -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)) @@ -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() @@ -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() diff --git a/common/buf/writer.go b/common/buf/writer.go index acf943ba2..e4828880c 100644 --- a/common/buf/writer.go +++ b/common/buf/writer.go @@ -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() diff --git a/common/buf/writer_test.go b/common/buf/writer_test.go index 3f82e7a17..2b8b1b441 100644 --- a/common/buf/writer_test.go +++ b/common/buf/writer_test.go @@ -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()...) diff --git a/common/bufio/reader_test.go b/common/bufio/reader_test.go index 0bf0bf50e..55c3e9405 100644 --- a/common/bufio/reader_test.go +++ b/common/bufio/reader_test.go @@ -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() diff --git a/common/crypto/aes.go b/common/crypto/aes.go index 64967a339..2c1a1bd3d 100644 --- a/common/crypto/aes.go +++ b/common/crypto/aes.go @@ -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) } diff --git a/common/crypto/auth.go b/common/crypto/auth.go index fd8a9df06..64d9465e4 100644 --- a/common/crypto/auth.go +++ b/common/crypto/auth.go @@ -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 { diff --git a/common/net/address.go b/common/net/address.go index 1a1633199..24953a344 100644 --- a/common/net/address.go +++ b/common/net/address.go @@ -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") ) @@ -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 } @@ -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 } @@ -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 } diff --git a/common/net/destination.go b/common/net/destination.go index 4be6aaa6b..11426e8b1 100644 --- a/common/net/destination.go +++ b/common/net/destination.go @@ -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 { @@ -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 { diff --git a/common/net/network.go b/common/net/network.go index 3c8bcd20d..f2f65b368 100644 --- a/common/net/network.go +++ b/common/net/network.go @@ -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" diff --git a/common/protocol/headers.go b/common/protocol/headers.go index 7050ac5d4..8fd667934 100644 --- a/common/protocol/headers.go +++ b/common/protocol/headers.go @@ -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 { diff --git a/inbound_detour_always.go b/inbound_detour_always.go index 9c1dc6e5d..5f3a6060e 100644 --- a/inbound_detour_always.go +++ b/inbound_detour_always.go @@ -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 @@ -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 { diff --git a/proxy/dokodemo/dokodemo.go b/proxy/dokodemo/dokodemo.go index 023d6a522..b32006bd6 100644 --- a/proxy/dokodemo/dokodemo.go +++ b/proxy/dokodemo/dokodemo.go @@ -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 } @@ -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, diff --git a/proxy/shadowsocks/server.go b/proxy/shadowsocks/server.go index 52be34d39..19d2e6546 100644 --- a/proxy/shadowsocks/server.go +++ b/proxy/shadowsocks/server.go @@ -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) { @@ -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) diff --git a/proxy/socks/server.go b/proxy/socks/server.go index b9d7e5f98..6042fc722 100644 --- a/proxy/socks/server.go +++ b/proxy/socks/server.go @@ -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 } diff --git a/proxy/socks/server_udp.go b/proxy/socks/server_udp.go index d19ca08f4..b05e2b724 100644 --- a/proxy/socks/server_udp.go +++ b/proxy/socks/server_udp.go @@ -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) diff --git a/transport/internet/config.go b/transport/internet/config.go index e013d4142..1476faf82 100644 --- a/transport/internet/config.go +++ b/transport/internet/config.go @@ -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{} diff --git a/transport/internet/internal/pool.go b/transport/internet/internal/pool.go index 470caebfb..07af634a9 100644 --- a/transport/internet/internal/pool.go +++ b/transport/internet/internal/pool.go @@ -4,6 +4,7 @@ import ( "net" "sync" "time" + v2net "v2ray.com/core/common/net" "v2ray.com/core/common/signal" ) diff --git a/transport/internet/kcp/listener.go b/transport/internet/kcp/listener.go index fb737fe9b..294678c06 100644 --- a/transport/internet/kcp/listener.go +++ b/transport/internet/kcp/listener.go @@ -20,7 +20,7 @@ import ( "v2ray.com/core/transport/internet/udp" ) -type ConnectionId struct { +type ConnectionID struct { Remote v2net.Address Port v2net.Port Conv uint16 @@ -81,7 +81,7 @@ func (o *ServerConnection) Id() internal.ConnectionId { type Listener struct { sync.Mutex running bool - sessions map[ConnectionId]*Connection + sessions map[ConnectionID]*Connection awaitingConns chan *Connection hub *udp.UDPHub tlsConfig *tls.Config @@ -115,7 +115,7 @@ func NewListener(address v2net.Address, port v2net.Port, options internet.Listen Header: header, Security: security, }, - sessions: make(map[ConnectionId]*Connection), + sessions: make(map[ConnectionID]*Connection), awaitingConns: make(chan *Connection, 64), running: true, config: kcpSettings, @@ -165,7 +165,7 @@ func (v *Listener) OnReceive(payload *buf.Buffer, session *proxy.SessionInfo) { conv := segments[0].Conversation() cmd := segments[0].Command() - id := ConnectionId{ + id := ConnectionID{ Remote: src.Address, Port: src.Port, Conv: conv, @@ -210,7 +210,7 @@ func (v *Listener) OnReceive(payload *buf.Buffer, session *proxy.SessionInfo) { conn.Input(segments) } -func (v *Listener) Remove(id ConnectionId) { +func (v *Listener) Remove(id ConnectionID) { if !v.running { return } @@ -277,7 +277,7 @@ func (v *Listener) Addr() net.Addr { func (v *Listener) Put(internal.ConnectionId, net.Conn) {} type Writer struct { - id ConnectionId + id ConnectionID dest v2net.Destination hub *udp.UDPHub listener *Listener diff --git a/transport/internet/kcp/receiving.go b/transport/internet/kcp/receiving.go index 708388079..b85ccd9fd 100644 --- a/transport/internet/kcp/receiving.go +++ b/transport/internet/kcp/receiving.go @@ -129,7 +129,7 @@ func (v *AckList) Flush(current uint32, rto uint32) { v.dirty = false } } - if v.dirty || seg.Count > 0 { + if v.dirty || !seg.IsEmpty() { for _, number := range v.flushCandidates { if seg.IsFull() { break diff --git a/transport/internet/kcp/segment.go b/transport/internet/kcp/segment.go index 9b3ed26a4..2b1bda09c 100644 --- a/transport/internet/kcp/segment.go +++ b/transport/internet/kcp/segment.go @@ -79,7 +79,7 @@ func (v *DataSegment) Bytes() buf.Supplier { b = serial.Uint32ToBytes(v.SendingNext, b) b = serial.Uint16ToBytes(uint16(v.Data.Len()), b) b = append(b, v.Data.Bytes()...) - return v.ByteSize(), nil + return len(b), nil } } @@ -98,7 +98,6 @@ type AckSegment struct { ReceivingWindow uint32 ReceivingNext uint32 Timestamp uint32 - Count byte NumberList []uint32 } @@ -125,16 +124,19 @@ func (v *AckSegment) PutTimestamp(timestamp uint32) { } func (v *AckSegment) PutNumber(number uint32) { - v.Count++ v.NumberList = append(v.NumberList, number) } func (v *AckSegment) IsFull() bool { - return v.Count == ackNumberLimit + return len(v.NumberList) == ackNumberLimit +} + +func (v *AckSegment) IsEmpty() bool { + return len(v.NumberList) == 0 } func (v *AckSegment) ByteSize() int { - return 2 + 1 + 1 + 4 + 4 + 4 + 1 + int(v.Count)*4 + return 2 + 1 + 1 + 4 + 4 + 4 + 1 + len(v.NumberList)*4 } func (v *AckSegment) Bytes() buf.Supplier { @@ -144,9 +146,10 @@ func (v *AckSegment) Bytes() buf.Supplier { b = serial.Uint32ToBytes(v.ReceivingWindow, b) b = serial.Uint32ToBytes(v.ReceivingNext, b) b = serial.Uint32ToBytes(v.Timestamp, b) - b = append(b, v.Count) - for i := byte(0); i < v.Count; i++ { - b = serial.Uint32ToBytes(v.NumberList[i], b) + count := byte(len(v.NumberList)) + b = append(b, count) + for _, number := range v.NumberList { + b = serial.Uint32ToBytes(number, b) } return v.ByteSize(), nil } @@ -188,7 +191,7 @@ func (v *CmdOnlySegment) Bytes() buf.Supplier { b = serial.Uint32ToBytes(v.SendingNext, b) b = serial.Uint32ToBytes(v.ReceivinNext, b) b = serial.Uint32ToBytes(v.PeerRTO, b) - return v.ByteSize(), nil + return len(b), nil } } diff --git a/transport/internet/kcp/segment_test.go b/transport/internet/kcp/segment_test.go index 571a6defb..5be254950 100644 --- a/transport/internet/kcp/segment_test.go +++ b/transport/internet/kcp/segment_test.go @@ -52,7 +52,6 @@ func TestACKSegment(t *testing.T) { ReceivingWindow: 2, ReceivingNext: 3, Timestamp: 10, - Count: 5, NumberList: []uint32{1, 3, 5, 7, 9}, } @@ -67,10 +66,10 @@ func TestACKSegment(t *testing.T) { assert.Uint16(seg2.Conv).Equals(seg.Conv) assert.Uint32(seg2.ReceivingWindow).Equals(seg.ReceivingWindow) assert.Uint32(seg2.ReceivingNext).Equals(seg.ReceivingNext) - assert.Byte(seg2.Count).Equals(seg.Count) + assert.Int(len(seg2.NumberList)).Equals(len(seg.NumberList)) assert.Uint32(seg2.Timestamp).Equals(seg.Timestamp) - for i := byte(0); i < seg2.Count; i++ { - assert.Uint32(seg2.NumberList[i]).Equals(seg.NumberList[i]) + for i, number := range seg2.NumberList { + assert.Uint32(number).Equals(seg.NumberList[i]) } } diff --git a/transport/internet/kcp/sending.go b/transport/internet/kcp/sending.go index 8336f7a54..460d51a52 100644 --- a/transport/internet/kcp/sending.go +++ b/transport/internet/kcp/sending.go @@ -260,15 +260,13 @@ func (v *SendingWorker) ProcessSegment(current uint32, seg *AckSegment, rto uint } v.ProcessReceivingNextWithoutLock(seg.ReceivingNext) - if seg.Count == 0 { + if seg.IsEmpty() { return } var maxack uint32 var maxackRemoved bool - for i := 0; i < int(seg.Count); i++ { - number := seg.NumberList[i] - + for _, number := range seg.NumberList { removed := v.ProcessAck(number) if maxack < number { maxack = number diff --git a/transport/internet/udp/connection.go b/transport/internet/udp/connection.go index 2a25fae1a..fcd1a9664 100644 --- a/transport/internet/udp/connection.go +++ b/transport/internet/udp/connection.go @@ -2,6 +2,7 @@ package udp import ( "net" + v2net "v2ray.com/core/common/net" "v2ray.com/core/transport/internet" ) diff --git a/transport/internet/udp/udp_server.go b/transport/internet/udp/udp_server.go index 200f1af29..27fa2d978 100644 --- a/transport/internet/udp/udp_server.go +++ b/transport/internet/udp/udp_server.go @@ -12,17 +12,17 @@ import ( "v2ray.com/core/transport/ray" ) -type UDPResponseCallback func(destination v2net.Destination, payload *buf.Buffer) +type ResponseCallback func(destination v2net.Destination, payload *buf.Buffer) type TimedInboundRay struct { name string inboundRay ray.InboundRay accessed chan bool - server *UDPServer + server *Server sync.RWMutex } -func NewTimedInboundRay(name string, inboundRay ray.InboundRay, server *UDPServer) *TimedInboundRay { +func NewTimedInboundRay(name string, inboundRay ray.InboundRay, server *Server) *TimedInboundRay { r := &TimedInboundRay{ name: name, inboundRay: inboundRay, @@ -92,26 +92,26 @@ func (v *TimedInboundRay) Release() { v.inboundRay = nil } -type UDPServer struct { +type Server struct { sync.RWMutex conns map[string]*TimedInboundRay packetDispatcher dispatcher.PacketDispatcher } -func NewUDPServer(packetDispatcher dispatcher.PacketDispatcher) *UDPServer { - return &UDPServer{ +func NewServer(packetDispatcher dispatcher.PacketDispatcher) *Server { + return &Server{ conns: make(map[string]*TimedInboundRay), packetDispatcher: packetDispatcher, } } -func (v *UDPServer) RemoveRay(name string) { +func (v *Server) RemoveRay(name string) { v.Lock() defer v.Unlock() delete(v.conns, name) } -func (v *UDPServer) locateExistingAndDispatch(name string, payload *buf.Buffer) bool { +func (v *Server) locateExistingAndDispatch(name string, payload *buf.Buffer) bool { log.Debug("UDP Server: Locating existing connection for ", name) v.RLock() defer v.RUnlock() @@ -130,7 +130,7 @@ func (v *UDPServer) locateExistingAndDispatch(name string, payload *buf.Buffer) return false } -func (v *UDPServer) Dispatch(session *proxy.SessionInfo, payload *buf.Buffer, callback UDPResponseCallback) { +func (v *Server) Dispatch(session *proxy.SessionInfo, payload *buf.Buffer, callback ResponseCallback) { source := session.Source destination := session.Destination @@ -155,7 +155,7 @@ func (v *UDPServer) Dispatch(session *proxy.SessionInfo, payload *buf.Buffer, ca go v.handleConnection(timedInboundRay, source, callback) } -func (v *UDPServer) handleConnection(inboundRay *TimedInboundRay, source v2net.Destination, callback UDPResponseCallback) { +func (v *Server) handleConnection(inboundRay *TimedInboundRay, source v2net.Destination, callback ResponseCallback) { for { inputStream := inboundRay.InboundOutput() if inputStream == nil { diff --git a/transport/internet/ws/wsconn.go b/transport/internet/ws/wsconn.go index 255e74396..db86fd237 100644 --- a/transport/internet/ws/wsconn.go +++ b/transport/internet/ws/wsconn.go @@ -185,7 +185,6 @@ func (ws *wsconn) pingPong() { select { case <-pongRcv: - break case <-tick: if !ws.connClosing { log.Debug("WS:Closing as ping is not responded~" + ws.wsc.UnderlyingConn().LocalAddr().String() + "-" + ws.wsc.UnderlyingConn().RemoteAddr().String())