rename SocksServer to Server

pull/131/head
v2ray 9 years ago
parent 42907ff2e8
commit 991cea01ab

@ -20,8 +20,8 @@ var (
ErrorUnsupportedAuthMethod = errors.New("Unsupported auth method.") ErrorUnsupportedAuthMethod = errors.New("Unsupported auth method.")
) )
// SocksServer is a SOCKS 5 proxy server // Server is a SOCKS 5 proxy server
type SocksServer struct { type Server struct {
tcpMutex sync.RWMutex tcpMutex sync.RWMutex
udpMutex sync.RWMutex udpMutex sync.RWMutex
accepting bool accepting bool
@ -34,21 +34,21 @@ type SocksServer struct {
listeningPort v2net.Port listeningPort v2net.Port
} }
// NewSocksSocks creates a new SocksServer object. // NewServer creates a new Server object.
func NewSocksServer(config *Config, packetDispatcher dispatcher.PacketDispatcher) *SocksServer { func NewServer(config *Config, packetDispatcher dispatcher.PacketDispatcher) *Server {
return &SocksServer{ return &Server{
config: config, config: config,
packetDispatcher: packetDispatcher, packetDispatcher: packetDispatcher,
} }
} }
// Port implements InboundHandler.Port(). // Port implements InboundHandler.Port().
func (this *SocksServer) Port() v2net.Port { func (this *Server) Port() v2net.Port {
return this.listeningPort return this.listeningPort
} }
// Close implements InboundHandler.Close(). // Close implements InboundHandler.Close().
func (this *SocksServer) Close() { func (this *Server) Close() {
this.accepting = false this.accepting = false
if this.tcpListener != nil { if this.tcpListener != nil {
this.tcpMutex.Lock() this.tcpMutex.Lock()
@ -65,7 +65,7 @@ func (this *SocksServer) Close() {
} }
// Listen implements InboundHandler.Listen(). // 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.accepting {
if this.listeningPort == port { if this.listeningPort == port {
return nil return nil
@ -90,7 +90,7 @@ func (this *SocksServer) Listen(port v2net.Port) error {
return nil return nil
} }
func (this *SocksServer) handleConnection(connection *hub.TCPConn) { func (this *Server) handleConnection(connection *hub.TCPConn) {
defer connection.Close() defer connection.Close()
timedReader := v2net.NewTimeOutReader(120, connection) 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 expectedAuthMethod := protocol.AuthNotRequired
if this.config.AuthType == AuthTypePassword { if this.config.AuthType == AuthTypePassword {
expectedAuthMethod = protocol.AuthUserPass expectedAuthMethod = protocol.AuthUserPass
@ -210,7 +210,7 @@ func (this *SocksServer) handleSocks5(reader *v2io.BufferedReader, writer *v2io.
return nil 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 := protocol.NewSocks5Response()
response.Error = protocol.ErrorSuccess response.Error = protocol.ErrorSuccess
@ -242,7 +242,7 @@ func (this *SocksServer) handleUDP(reader io.Reader, writer *v2io.BufferedWriter
return nil 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 result := protocol.Socks4RequestGranted
if auth.Command == protocol.CmdBind { if auth.Command == protocol.CmdBind {
result = protocol.Socks4RequestRejected result = protocol.Socks4RequestRejected
@ -264,7 +264,7 @@ func (this *SocksServer) handleSocks4(reader *v2io.BufferedReader, writer *v2io.
return nil 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) ray := this.packetDispatcher.DispatchToOutbound(destination)
input := ray.InboundInput() input := ray.InboundInput()
output := ray.InboundOutput() output := ray.InboundOutput()

@ -13,7 +13,7 @@ func init() {
if !space.HasApp(dispatcher.APP_ID) { if !space.HasApp(dispatcher.APP_ID) {
return nil, internal.ErrorBadConfiguration return nil, internal.ErrorBadConfiguration
} }
return NewSocksServer( return NewServer(
rawConfig.(*Config), rawConfig.(*Config),
space.GetApp(dispatcher.APP_ID).(dispatcher.PacketDispatcher)), nil space.GetApp(dispatcher.APP_ID).(dispatcher.PacketDispatcher)), nil
}) })

@ -8,7 +8,7 @@ import (
"github.com/v2ray/v2ray-core/transport/hub" "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) this.udpServer = hub.NewUDPServer(this.packetDispatcher)
udpHub, err := hub.ListenUDP(port, this.handleUDPPayload) udpHub, err := hub.ListenUDP(port, this.handleUDPPayload)
if err != nil { if err != nil {
@ -22,7 +22,7 @@ func (this *SocksServer) listenUDP(port v2net.Port) error {
return nil 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) log.Info("Socks: Client UDP connection from ", source)
request, err := protocol.ReadUDPRequest(payload.Value) request, err := protocol.ReadUDPRequest(payload.Value)
payload.Release() payload.Release()

Loading…
Cancel
Save