mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-29 16:58:34 +00:00
Add socks4/4a support
This commit is contained in:
parent
238bd5d050
commit
77d0419aca
4 changed files with 154 additions and 33 deletions
|
@ -2,6 +2,7 @@ package conf
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
|
||||
|
@ -73,11 +74,22 @@ type SocksRemoteConfig struct {
|
|||
|
||||
type SocksClientConfig struct {
|
||||
Servers []*SocksRemoteConfig `json:"servers"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
func (v *SocksClientConfig) Build() (proto.Message, error) {
|
||||
config := new(socks.ClientConfig)
|
||||
config.Server = make([]*protocol.ServerEndpoint, len(v.Servers))
|
||||
switch strings.ToLower(v.Version) {
|
||||
case "4":
|
||||
config.Version = socks.Version_SOCKS4
|
||||
case "4a":
|
||||
config.Version = socks.Version_SOCKS4A
|
||||
case "", "5":
|
||||
config.Version = socks.Version_SOCKS5
|
||||
default:
|
||||
return nil, newError("failed to parse socks server version: ", v.Version).AtError()
|
||||
}
|
||||
for idx, serverConfig := range v.Servers {
|
||||
server := &protocol.ServerEndpoint{
|
||||
Address: serverConfig.Address.Build(),
|
||||
|
@ -92,6 +104,9 @@ func (v *SocksClientConfig) Build() (proto.Message, error) {
|
|||
if err := json.Unmarshal(rawUser, account); err != nil {
|
||||
return nil, newError("failed to parse socks account").Base(err).AtError()
|
||||
}
|
||||
if config.Version != socks.Version_SOCKS5 && account.Password != "" {
|
||||
return nil, newError("password is only supported in socks5").AtError()
|
||||
}
|
||||
user.Account = serial.ToTypedMessage(account.Build())
|
||||
server.User = append(server.User, user)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue