From 9e6b746e8628f64d00b48a7076de4cda35650951 Mon Sep 17 00:00:00 2001 From: V2Ray Date: Fri, 11 Sep 2015 14:12:26 +0200 Subject: [PATCH] format code --- io/socks/socks.go | 16 +++++----- net/freedom/freedom.go | 10 +++---- net/freedom/freedomfactory.go | 2 +- net/socks/socks.go | 55 +++++++++++++++++------------------ net/vdest.go | 10 +++---- release/server/socks/main.go | 42 +++++++++++++------------- vpoint.go | 6 ++-- 7 files changed, 70 insertions(+), 71 deletions(-) diff --git a/io/socks/socks.go b/io/socks/socks.go index bbbb7398..2e633ba4 100644 --- a/io/socks/socks.go +++ b/io/socks/socks.go @@ -5,7 +5,7 @@ import ( "encoding/binary" "fmt" "io" - _ "log" + _ "log" v2net "github.com/v2ray/v2ray-core/net" ) @@ -26,7 +26,7 @@ type Socks5AuthenticationRequest struct { } func (request *Socks5AuthenticationRequest) HasAuthMethod(method byte) bool { - for i := 0; i < int(request.nMethods); i++ { + for i := 0; i < int(request.nMethods); i++ { if request.authMethods[i] == method { return true } @@ -142,16 +142,16 @@ func ReadRequest(reader io.Reader) (request *Socks5Request, err error) { } case AddrTypeDomain: buffer = make([]byte, 256) - nBytes, err = reader.Read(buffer[0:1]) - if err != nil { - return - } - domainLength := buffer[0] + nBytes, err = reader.Read(buffer[0:1]) + if err != nil { + return + } + domainLength := buffer[0] nBytes, err = reader.Read(buffer[:domainLength]) if err != nil { return } - + if nBytes != int(domainLength) { err = fmt.Errorf("Unable to read domain with %d bytes, expecting %d bytes", nBytes, domainLength) return diff --git a/net/freedom/freedom.go b/net/freedom/freedom.go index 48ec23fd..7727c69a 100644 --- a/net/freedom/freedom.go +++ b/net/freedom/freedom.go @@ -2,8 +2,8 @@ package freedom import ( "io" + "log" "net" - "log" "github.com/v2ray/v2ray-core" v2net "github.com/v2ray/v2ray-core/net" @@ -26,10 +26,10 @@ func (vconn *VFreeConnection) Start(vRay core.OutboundVRay) error { output := vRay.OutboundOutput() conn, err := net.Dial("tcp", vconn.dest.String()) if err != nil { - log.Print(err) + log.Print(err) return err } - log.Print("Working on tcp:" + vconn.dest.String()) + log.Print("Working on tcp:" + vconn.dest.String()) finish := make(chan bool, 2) go vconn.DumpInput(conn, input, finish) @@ -54,11 +54,11 @@ func (vconn *VFreeConnection) DumpOutput(conn net.Conn, output chan<- []byte, fi buffer := make([]byte, 128) nBytes, err := conn.Read(buffer) if err == io.EOF { - close(output) + close(output) finish <- true break } - log.Print(buffer[:nBytes]) + log.Print(buffer[:nBytes]) output <- buffer[:nBytes] } } diff --git a/net/freedom/freedomfactory.go b/net/freedom/freedomfactory.go index fa4efe3a..b07367f9 100644 --- a/net/freedom/freedomfactory.go +++ b/net/freedom/freedomfactory.go @@ -2,7 +2,7 @@ package freedom import ( "github.com/v2ray/v2ray-core" - v2net "github.com/v2ray/v2ray-core/net" + v2net "github.com/v2ray/v2ray-core/net" ) type FreedomFactory struct { diff --git a/net/socks/socks.go b/net/socks/socks.go index 8ba6c4f8..7478cb7e 100644 --- a/net/socks/socks.go +++ b/net/socks/socks.go @@ -3,9 +3,9 @@ package socks import ( "errors" "io" - "log" + "log" "net" - "strconv" + "strconv" "github.com/v2ray/v2ray-core" socksio "github.com/v2ray/v2ray-core/io/socks" @@ -42,7 +42,7 @@ func (server *SocksServer) AcceptConnections(listener net.Listener) error { for server.accepting { connection, err := listener.Accept() if err != nil { - log.Print(err) + log.Print(err) return err } go server.HandleConnection(connection) @@ -55,14 +55,14 @@ func (server *SocksServer) HandleConnection(connection net.Conn) error { auth, err := socksio.ReadAuthentication(connection) if err != nil { - log.Print(err) + log.Print(err) return err } - log.Print(auth) + log.Print(auth) if !auth.HasAuthMethod(socksio.AuthNotRequired) { - // TODO send response with FF - log.Print(ErrorAuthenticationFailed) + // TODO send response with FF + log.Print(ErrorAuthenticationFailed) return ErrorAuthenticationFailed } @@ -71,33 +71,32 @@ func (server *SocksServer) HandleConnection(connection net.Conn) error { request, err := socksio.ReadRequest(connection) if err != nil { - log.Print(err) + log.Print(err) return err } - - response := socksio.NewSocks5Response() + + response := socksio.NewSocks5Response() if request.Command == socksio.CmdBind || request.Command == socksio.CmdUdpAssociate { response := socksio.NewSocks5Response() response.Error = socksio.ErrorCommandNotSupported socksio.WriteResponse(connection, response) - log.Print(ErrorCommandNotSupported) + log.Print(ErrorCommandNotSupported) return ErrorCommandNotSupported } - - response.Error = socksio.ErrorSuccess - response.Port = request.Port - response.AddrType = request.AddrType - switch response.AddrType { - case socksio.AddrTypeIPv4: - copy(response.IPv4[:], request.IPv4[:]) - case socksio.AddrTypeIPv6: - copy(response.IPv6[:], request.IPv6[:]) - case socksio.AddrTypeDomain: - response.Domain = request.Domain - } - socksio.WriteResponse(connection, response) - + + response.Error = socksio.ErrorSuccess + response.Port = request.Port + response.AddrType = request.AddrType + switch response.AddrType { + case socksio.AddrTypeIPv4: + copy(response.IPv4[:], request.IPv4[:]) + case socksio.AddrTypeIPv6: + copy(response.IPv6[:], request.IPv6[:]) + case socksio.AddrTypeDomain: + response.Domain = request.Domain + } + socksio.WriteResponse(connection, response) ray := server.vPoint.NewInboundConnectionAccepted(request.Destination()) input := ray.InboundInput() @@ -115,9 +114,9 @@ func (server *SocksServer) dumpInput(conn net.Conn, input chan<- []byte, finish for { buffer := make([]byte, 256) nBytes, err := conn.Read(buffer) - log.Printf("Reading %d bytes, with error %v", nBytes, err) + log.Printf("Reading %d bytes, with error %v", nBytes, err) if err == io.EOF { - close(input) + close(input) finish <- true break } @@ -133,7 +132,7 @@ func (server *SocksServer) dumpOutput(conn net.Conn, output <-chan []byte, finis break } nBytes, _ := conn.Write(buffer) - log.Printf("Writing %d bytes", nBytes) + log.Printf("Writing %d bytes", nBytes) } } diff --git a/net/vdest.go b/net/vdest.go index ea844928..769e23b5 100644 --- a/net/vdest.go +++ b/net/vdest.go @@ -50,11 +50,11 @@ func (addr VAddress) String() string { var host string switch addr.Type { case AddrTypeIP: - host = addr.IP.String() - if len(addr.IP) == net.IPv6len { - host = "[" + host + "]" - } - + host = addr.IP.String() + if len(addr.IP) == net.IPv6len { + host = "[" + host + "]" + } + case AddrTypeDomain: host = addr.Domain default: diff --git a/release/server/socks/main.go b/release/server/socks/main.go index e728748f..116f00fa 100644 --- a/release/server/socks/main.go +++ b/release/server/socks/main.go @@ -1,21 +1,21 @@ package main import ( - "log" - - "github.com/v2ray/v2ray-core" - "github.com/v2ray/v2ray-core/net/freedom" - "github.com/v2ray/v2ray-core/net/socks" + "log" + + "github.com/v2ray/v2ray-core" + "github.com/v2ray/v2ray-core/net/freedom" + "github.com/v2ray/v2ray-core/net/socks" ) func main() { - port := uint16(8888) - - uuid := "2418d087-648d-4990-86e8-19dca1d006d3" + port := uint16(8888) + + uuid := "2418d087-648d-4990-86e8-19dca1d006d3" vid, err := core.UUIDToVID(uuid) - if err != nil { - log.Fatal(err) - } + if err != nil { + log.Fatal(err) + } config := core.VConfig{ port, @@ -24,14 +24,14 @@ func main() { []core.VNext{}} vpoint, err := core.NewVPoint(&config, socks.SocksServerFactory{}, freedom.FreedomFactory{}) - if err != nil { - log.Fatal(err) - } - err = vpoint.Start() - if err != nil { - log.Fatal(err) - } - - finish := make(chan bool) - <-finish + if err != nil { + log.Fatal(err) + } + err = vpoint.Start() + if err != nil { + log.Fatal(err) + } + + finish := make(chan bool) + <-finish } diff --git a/vpoint.go b/vpoint.go index 34ac3495..b6f81855 100644 --- a/vpoint.go +++ b/vpoint.go @@ -24,9 +24,9 @@ func NewVPoint(config *VConfig, ichFactory InboundConnectionHandlerFactory, ochF for _, user := range vpoint.Config.AllowedClients { vpoint.UserSet.AddUser(user) } - - vpoint.ichFactory = ichFactory - vpoint.ochFactory = ochFactory + + vpoint.ichFactory = ichFactory + vpoint.ochFactory = ochFactory return vpoint, nil }