1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-04 17:27:23 -05:00

Actually use UDP relay

This commit is contained in:
V2Ray 2015-10-06 16:43:50 +02:00
parent af8baa144d
commit be59463fd0
2 changed files with 11 additions and 8 deletions

View File

@ -46,7 +46,7 @@ func (config VNextConfig) HasNetwork(network string) bool {
return strings.Contains(config.Network, network) return strings.Contains(config.Network, network)
} }
func (config VNextConfig) ToVNextServer() VNextServer { func (config VNextConfig) ToVNextServer(network string) VNextServer {
users := make([]user.User, 0, len(config.Users)) users := make([]user.User, 0, len(config.Users))
for _, user := range config.Users { for _, user := range config.Users {
vuser, err := user.ToUser() vuser, err := user.ToUser()
@ -60,10 +60,12 @@ func (config VNextConfig) ToVNextServer() VNextServer {
panic(log.Error("Unable to parse VNext IP: %s", config.Address)) panic(log.Error("Unable to parse VNext IP: %s", config.Address))
} }
address := v2net.IPAddress(ip, config.Port) address := v2net.IPAddress(ip, config.Port)
dest := v2net.NewTCPDestination(address) var dest v2net.Destination
if config.Network == "udp" { if network == "tcp" {
dest = v2net.NewUDPDestination(address) dest = v2net.NewTCPDestination(address)
} } else {
dest = v2net.NewUDPDestination(address)
}
return VNextServer{ return VNextServer{
Destination: dest, Destination: dest,
Users: users, Users: users,

View File

@ -99,7 +99,7 @@ func startCommunicate(request *protocol.VMessRequest, dest v2net.Destination, ra
} }
return err return err
} }
log.Info("VMessOut: Tunneling request for %s", request.Address.String()) log.Info("VMessOut: Tunneling request to %s via %s", request.Address.String(), dest.String())
defer conn.Close() defer conn.Close()
@ -181,6 +181,7 @@ func handleResponse(conn net.Conn, request *protocol.VMessRequest, output chan<-
log.Warning("VMessOut: unexepcted response header. The connection is probably hijacked.") log.Warning("VMessOut: unexepcted response header. The connection is probably hijacked.")
return return
} }
log.Info("VMessOut received %d bytes from %s", len(buffer) - 4, conn.RemoteAddr().String())
output <- buffer[4:] output <- buffer[4:]
@ -206,10 +207,10 @@ func (factory *VMessOutboundHandlerFactory) Initialize(rawConfig []byte) error {
udpServers := make([]VNextServer, 0, len(config.VNextList)) udpServers := make([]VNextServer, 0, len(config.VNextList))
for _, server := range config.VNextList { for _, server := range config.VNextList {
if server.HasNetwork("tcp") { if server.HasNetwork("tcp") {
servers = append(servers, server.ToVNextServer()) servers = append(servers, server.ToVNextServer("tcp"))
} }
if server.HasNetwork("udp") { if server.HasNetwork("udp") {
udpServers = append(udpServers, server.ToVNextServer()) udpServers = append(udpServers, server.ToVNextServer("udp"))
} }
} }
factory.servers = servers factory.servers = servers