From 78daf8a879b31efa109577ae1f60e4ff3bac1aef Mon Sep 17 00:00:00 2001 From: V2Ray Date: Tue, 6 Oct 2015 17:24:57 +0200 Subject: [PATCH] format code --- common/net/transport.go | 6 +++--- proxy/freedom/freedom.go | 2 +- proxy/socks/socks.go | 10 +++++----- proxy/socks/udp.go | 18 +++++++++--------- proxy/vmess/config.go | 12 ++++++------ proxy/vmess/vmessin_udp.go | 2 +- proxy/vmess/vmessout.go | 2 +- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/common/net/transport.go b/common/net/transport.go index 01b8c754a..ae5d72954 100644 --- a/common/net/transport.go +++ b/common/net/transport.go @@ -11,9 +11,9 @@ const ( func ReadFrom(reader io.Reader) ([]byte, error) { buffer := make([]byte, bufferSize) nBytes, err := reader.Read(buffer) - if nBytes == 0 { - buffer = nil - } + if nBytes == 0 { + buffer = nil + } return buffer[:nBytes], err } diff --git a/proxy/freedom/freedom.go b/proxy/freedom/freedom.go index b9de87942..3d7cdacb2 100644 --- a/proxy/freedom/freedom.go +++ b/proxy/freedom/freedom.go @@ -69,7 +69,7 @@ func dumpOutput(conn net.Conn, output chan<- []byte, finish *sync.Mutex, udp boo defer close(output) response, err := v2net.ReadFrom(conn) - log.Info("Freedom receives %d bytes from %s", len(response), conn.RemoteAddr().String()) + log.Info("Freedom receives %d bytes from %s", len(response), conn.RemoteAddr().String()) if len(response) > 0 { output <- response } diff --git a/proxy/socks/socks.go b/proxy/socks/socks.go index e2cb4507a..20415b567 100644 --- a/proxy/socks/socks.go +++ b/proxy/socks/socks.go @@ -5,7 +5,7 @@ import ( "net" "strconv" "sync" - "time" + "time" "github.com/v2ray/v2ray-core" "github.com/v2ray/v2ray-core/common/errors" @@ -198,10 +198,10 @@ func (server *SocksServer) handleUDP(reader *v2net.TimeOutReader, writer io.Writ } reader.SetTimeOut(300) /* 5 minutes */ - v2net.ReadFrom(reader) // Just in case of anything left in the socket - // The TCP connection closes after this method returns. We need to wait until - // the client closes it. - // TODO: get notified from UDP part + v2net.ReadFrom(reader) // Just in case of anything left in the socket + // The TCP connection closes after this method returns. We need to wait until + // the client closes it. + // TODO: get notified from UDP part <-time.After(5 * time.Minute) return nil diff --git a/proxy/socks/udp.go b/proxy/socks/udp.go index 9d912ea10..408dea6c3 100644 --- a/proxy/socks/udp.go +++ b/proxy/socks/udp.go @@ -25,7 +25,7 @@ func (server *SocksServer) ListenUDP(port uint16) error { log.Error("Socks failed to listen UDP on port %d: %v", port, err) return err } - // TODO: make this configurable + // TODO: make this configurable udpAddress = v2net.IPAddress([]byte{127, 0, 0, 1}, port) go server.AcceptPackets(conn) @@ -44,7 +44,7 @@ func (server *SocksServer) AcceptPackets(conn *net.UDPConn) error { log.Error("Socks failed to read UDP packets: %v", err) continue } - log.Info("Client UDP connection from %v", addr) + log.Info("Client UDP connection from %v", addr) request, err := protocol.ReadUDPRequest(buffer[:nBytes]) if err != nil { log.Error("Socks failed to parse UDP request: %v", err) @@ -57,7 +57,7 @@ func (server *SocksServer) AcceptPackets(conn *net.UDPConn) error { } udpPacket := v2net.NewPacket(request.Destination(), request.Data, false) - log.Info("Send packet to %s with %d bytes", udpPacket.Destination().String(), len(request.Data)) + log.Info("Send packet to %s with %d bytes", udpPacket.Destination().String(), len(request.Data)) go server.handlePacket(conn, udpPacket, addr, request.Address) } } @@ -67,12 +67,12 @@ func (server *SocksServer) handlePacket(conn *net.UDPConn, packet v2net.Packet, close(ray.InboundInput()) if data, ok := <-ray.InboundOutput(); ok { - response := &protocol.Socks5UDPRequest { - Fragment: 0, - Address: targetAddr, - Data: data, - } - log.Info("Writing back UDP response with %d bytes from %s to %s", len(data), targetAddr.String(), clientAddr.String()) + response := &protocol.Socks5UDPRequest{ + Fragment: 0, + Address: targetAddr, + Data: data, + } + log.Info("Writing back UDP response with %d bytes from %s to %s", len(data), targetAddr.String(), clientAddr.String()) udpMessage := response.Bytes(nil) nBytes, err := conn.WriteToUDP(udpMessage, clientAddr) if err != nil { diff --git a/proxy/vmess/config.go b/proxy/vmess/config.go index 36b6577e5..fcc59f163 100644 --- a/proxy/vmess/config.go +++ b/proxy/vmess/config.go @@ -60,12 +60,12 @@ func (config VNextConfig) ToVNextServer(network string) VNextServer { panic(log.Error("Unable to parse VNext IP: %s", config.Address)) } address := v2net.IPAddress(ip, config.Port) - var dest v2net.Destination - if network == "tcp" { - dest = v2net.NewTCPDestination(address) - } else { - dest = v2net.NewUDPDestination(address) - } + var dest v2net.Destination + if network == "tcp" { + dest = v2net.NewTCPDestination(address) + } else { + dest = v2net.NewUDPDestination(address) + } return VNextServer{ Destination: dest, Users: users, diff --git a/proxy/vmess/vmessin_udp.go b/proxy/vmess/vmessin_udp.go index fc14db5ec..f6a91b83e 100644 --- a/proxy/vmess/vmessin_udp.go +++ b/proxy/vmess/vmessin_udp.go @@ -93,6 +93,6 @@ func (handler *VMessInboundHandler) handlePacket(conn *net.UDPConn, request *pro if hasData { conn.WriteToUDP(buffer.Bytes(), clientAddr) - log.Info("VMessIn sending %d bytes to %s", len(buffer.Bytes()), clientAddr.String()) + log.Info("VMessIn sending %d bytes to %s", len(buffer.Bytes()), clientAddr.String()) } } diff --git a/proxy/vmess/vmessout.go b/proxy/vmess/vmessout.go index c65a85e7c..f39b6714b 100644 --- a/proxy/vmess/vmessout.go +++ b/proxy/vmess/vmessout.go @@ -181,7 +181,7 @@ func handleResponse(conn net.Conn, request *protocol.VMessRequest, output chan<- log.Warning("VMessOut: unexepcted response header. The connection is probably hijacked.") return } - log.Info("VMessOut received %d bytes from %s", len(buffer) - 4, conn.RemoteAddr().String()) + log.Info("VMessOut received %d bytes from %s", len(buffer)-4, conn.RemoteAddr().String()) output <- buffer[4:]