mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-13 22:45:13 +00:00
socks5 server implementation
This commit is contained in:
1 parent
361f87df09
commit
e764275c58
5 files changed
+120
-30
No files matched your search
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user