mirror of https://github.com/v2ray/v2ray-core
Customize UDP server address
parent
3c259b7069
commit
99671a173f
|
@ -1,6 +1,8 @@
|
||||||
package json
|
package json
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net"
|
||||||
|
|
||||||
"github.com/v2ray/v2ray-core/config"
|
"github.com/v2ray/v2ray-core/config"
|
||||||
"github.com/v2ray/v2ray-core/config/json"
|
"github.com/v2ray/v2ray-core/config/json"
|
||||||
)
|
)
|
||||||
|
@ -19,32 +21,45 @@ type SocksConfig struct {
|
||||||
AuthMethod string `json:"auth"`
|
AuthMethod string `json:"auth"`
|
||||||
Accounts []SocksAccount `json:"accounts"`
|
Accounts []SocksAccount `json:"accounts"`
|
||||||
UDPEnabled bool `json:"udp"`
|
UDPEnabled bool `json:"udp"`
|
||||||
|
HostIP string `json:"ip"`
|
||||||
|
|
||||||
accountMap map[string]string
|
accountMap map[string]string
|
||||||
|
ip net.IP
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *SocksConfig) Initialize() {
|
func (sc *SocksConfig) Initialize() {
|
||||||
config.accountMap = make(map[string]string)
|
sc.accountMap = make(map[string]string)
|
||||||
for _, account := range config.Accounts {
|
for _, account := range sc.Accounts {
|
||||||
config.accountMap[account.Username] = account.Password
|
sc.accountMap[account.Username] = account.Password
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(sc.HostIP) > 0 {
|
||||||
|
sc.ip = net.ParseIP(sc.HostIP)
|
||||||
|
if sc.ip == nil {
|
||||||
|
sc.ip = net.IPv4(127, 0, 0, 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *SocksConfig) IsNoAuth() bool {
|
func (sc *SocksConfig) IsNoAuth() bool {
|
||||||
return config.AuthMethod == AuthMethodNoAuth
|
return sc.AuthMethod == AuthMethodNoAuth
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *SocksConfig) IsPassword() bool {
|
func (sc *SocksConfig) IsPassword() bool {
|
||||||
return config.AuthMethod == AuthMethodUserPass
|
return sc.AuthMethod == AuthMethodUserPass
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *SocksConfig) HasAccount(user, pass string) bool {
|
func (sc *SocksConfig) HasAccount(user, pass string) bool {
|
||||||
if actualPass, found := config.accountMap[user]; found {
|
if actualPass, found := sc.accountMap[user]; found {
|
||||||
return actualPass == pass
|
return actualPass == pass
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sc *SocksConfig) IP() net.IP {
|
||||||
|
return sc.ip
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
json.RegisterConfigType("socks", config.TypeInbound, func() interface{} {
|
json.RegisterConfigType("socks", config.TypeInbound, func() interface{} {
|
||||||
return new(SocksConfig)
|
return new(SocksConfig)
|
||||||
|
|
|
@ -22,8 +22,7 @@ func (server *SocksServer) ListenUDP(port uint16) error {
|
||||||
log.Error("Socks failed to listen UDP on port %d: %v", port, err)
|
log.Error("Socks failed to listen UDP on port %d: %v", port, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// TODO: make this configurable
|
udpAddress = v2net.IPAddress(server.config.IP(), port)
|
||||||
udpAddress = v2net.IPAddress([]byte{127, 0, 0, 1}, port)
|
|
||||||
|
|
||||||
go server.AcceptPackets(conn)
|
go server.AcceptPackets(conn)
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
"protocol": "socks",
|
"protocol": "socks",
|
||||||
"settings": {
|
"settings": {
|
||||||
"auth": "noauth",
|
"auth": "noauth",
|
||||||
"udp": false
|
"udp": false,
|
||||||
|
"ip": "127.0.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outbound": {
|
"outbound": {
|
||||||
|
|
Loading…
Reference in New Issue