From 991cea01ab582810ebd539d3bc3d1993d2f0c1ac Mon Sep 17 00:00:00 2001 From: v2ray Date: Tue, 26 Apr 2016 00:33:16 +0200 Subject: [PATCH] rename SocksServer to Server --- proxy/socks/{socks.go => server.go} | 26 +++++++++---------- proxy/socks/{socks_test.go => server_test.go} | 0 proxy/socks/socksfactory.go | 2 +- proxy/socks/udp.go | 4 +-- 4 files changed, 16 insertions(+), 16 deletions(-) rename proxy/socks/{socks.go => server.go} (88%) rename proxy/socks/{socks_test.go => server_test.go} (100%) diff --git a/proxy/socks/socks.go b/proxy/socks/server.go similarity index 88% rename from proxy/socks/socks.go rename to proxy/socks/server.go index b9b949cd..2fa38e95 100644 --- a/proxy/socks/socks.go +++ b/proxy/socks/server.go @@ -20,8 +20,8 @@ var ( ErrorUnsupportedAuthMethod = errors.New("Unsupported auth method.") ) -// SocksServer is a SOCKS 5 proxy server -type SocksServer struct { +// Server is a SOCKS 5 proxy server +type Server struct { tcpMutex sync.RWMutex udpMutex sync.RWMutex accepting bool @@ -34,21 +34,21 @@ type SocksServer struct { listeningPort v2net.Port } -// NewSocksSocks creates a new SocksServer object. -func NewSocksServer(config *Config, packetDispatcher dispatcher.PacketDispatcher) *SocksServer { - return &SocksServer{ +// NewServer creates a new Server object. +func NewServer(config *Config, packetDispatcher dispatcher.PacketDispatcher) *Server { + return &Server{ config: config, packetDispatcher: packetDispatcher, } } // Port implements InboundHandler.Port(). -func (this *SocksServer) Port() v2net.Port { +func (this *Server) Port() v2net.Port { return this.listeningPort } // Close implements InboundHandler.Close(). -func (this *SocksServer) Close() { +func (this *Server) Close() { this.accepting = false if this.tcpListener != nil { this.tcpMutex.Lock() @@ -65,7 +65,7 @@ func (this *SocksServer) Close() { } // Listen implements InboundHandler.Listen(). -func (this *SocksServer) Listen(port v2net.Port) error { +func (this *Server) Listen(port v2net.Port) error { if this.accepting { if this.listeningPort == port { return nil @@ -90,7 +90,7 @@ func (this *SocksServer) Listen(port v2net.Port) error { return nil } -func (this *SocksServer) handleConnection(connection *hub.TCPConn) { +func (this *Server) handleConnection(connection *hub.TCPConn) { defer connection.Close() timedReader := v2net.NewTimeOutReader(120, connection) @@ -113,7 +113,7 @@ func (this *SocksServer) handleConnection(connection *hub.TCPConn) { } } -func (this *SocksServer) handleSocks5(reader *v2io.BufferedReader, writer *v2io.BufferedWriter, auth protocol.Socks5AuthenticationRequest) error { +func (this *Server) handleSocks5(reader *v2io.BufferedReader, writer *v2io.BufferedWriter, auth protocol.Socks5AuthenticationRequest) error { expectedAuthMethod := protocol.AuthNotRequired if this.config.AuthType == AuthTypePassword { expectedAuthMethod = protocol.AuthUserPass @@ -210,7 +210,7 @@ func (this *SocksServer) handleSocks5(reader *v2io.BufferedReader, writer *v2io. return nil } -func (this *SocksServer) handleUDP(reader io.Reader, writer *v2io.BufferedWriter) error { +func (this *Server) handleUDP(reader io.Reader, writer *v2io.BufferedWriter) error { response := protocol.NewSocks5Response() response.Error = protocol.ErrorSuccess @@ -242,7 +242,7 @@ func (this *SocksServer) handleUDP(reader io.Reader, writer *v2io.BufferedWriter return nil } -func (this *SocksServer) handleSocks4(reader *v2io.BufferedReader, writer *v2io.BufferedWriter, auth protocol.Socks4AuthenticationRequest) error { +func (this *Server) handleSocks4(reader *v2io.BufferedReader, writer *v2io.BufferedWriter, auth protocol.Socks4AuthenticationRequest) error { result := protocol.Socks4RequestGranted if auth.Command == protocol.CmdBind { result = protocol.Socks4RequestRejected @@ -264,7 +264,7 @@ func (this *SocksServer) handleSocks4(reader *v2io.BufferedReader, writer *v2io. return nil } -func (this *SocksServer) transport(reader io.Reader, writer io.Writer, destination v2net.Destination) { +func (this *Server) transport(reader io.Reader, writer io.Writer, destination v2net.Destination) { ray := this.packetDispatcher.DispatchToOutbound(destination) input := ray.InboundInput() output := ray.InboundOutput() diff --git a/proxy/socks/socks_test.go b/proxy/socks/server_test.go similarity index 100% rename from proxy/socks/socks_test.go rename to proxy/socks/server_test.go diff --git a/proxy/socks/socksfactory.go b/proxy/socks/socksfactory.go index b1b779bf..8aab8415 100644 --- a/proxy/socks/socksfactory.go +++ b/proxy/socks/socksfactory.go @@ -13,7 +13,7 @@ func init() { if !space.HasApp(dispatcher.APP_ID) { return nil, internal.ErrorBadConfiguration } - return NewSocksServer( + return NewServer( rawConfig.(*Config), space.GetApp(dispatcher.APP_ID).(dispatcher.PacketDispatcher)), nil }) diff --git a/proxy/socks/udp.go b/proxy/socks/udp.go index 51aa6ca5..245dff96 100644 --- a/proxy/socks/udp.go +++ b/proxy/socks/udp.go @@ -8,7 +8,7 @@ import ( "github.com/v2ray/v2ray-core/transport/hub" ) -func (this *SocksServer) listenUDP(port v2net.Port) error { +func (this *Server) listenUDP(port v2net.Port) error { this.udpServer = hub.NewUDPServer(this.packetDispatcher) udpHub, err := hub.ListenUDP(port, this.handleUDPPayload) if err != nil { @@ -22,7 +22,7 @@ func (this *SocksServer) listenUDP(port v2net.Port) error { return nil } -func (this *SocksServer) handleUDPPayload(payload *alloc.Buffer, source v2net.Destination) { +func (this *Server) handleUDPPayload(payload *alloc.Buffer, source v2net.Destination) { log.Info("Socks: Client UDP connection from ", source) request, err := protocol.ReadUDPRequest(payload.Value) payload.Release()