socks5 server implementation

This commit is contained in:
V2Ray committed 2015-09-09 12:13:52 +02:00
1 parent 361f87df09
commit e764275c58
5 files changed
+120 -30

No files matched your search

+36
View File
@@ -1,7 +1,15 @@
package socks
import (
"errors"
"net"
socksio "github.com/v2ray/v2ray-core/io/socks"
)
var (
ErrorAuthenticationFailed = errors.New("None of the authentication methods is allowed.")
ErrorCommandNotSupported = errors.New("Client requested an unsupported command.")
)
// SocksServer is a SOCKS 5 proxy server
@@ -31,5 +39,33 @@ func (server *SocksServer) AcceptConnections(listener net.Listener) error {
}
func (server *SocksServer) HandleConnection(connection net.Conn) error {
defer connection.Close()
auth, err := socksio.ReadAuthentication(connection)
if err != nil {
return err
}
if auth.HasAuthMethod(socksio.AuthNotRequired) {
return ErrorAuthenticationFailed
}
authResponse := socksio.NewAuthenticationResponse(socksio.AuthNotRequired)
socksio.WriteAuthentication(connection, authResponse)
request, err := socksio.ReadRequest(connection)
if err != nil {
return err
}
if request.Command == socksio.CmdBind || request.Command == socksio.CmdUdpAssociate {
response := socksio.NewSocks5Response()
response.Error = socksio.ErrorCommandNotSupported
socksio.WriteResponse(connection, response)
return ErrorCommandNotSupported
}
// TODO: establish connection with VNext
return nil
}
+1 -1
View File
@@ -1,4 +1,4 @@
package net
package vemss
import (
"net"