Actually use UDP relay

pull/40/head
V2Ray 9 years ago
parent af8baa144d
commit be59463fd0

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

@ -99,7 +99,7 @@ func startCommunicate(request *protocol.VMessRequest, dest v2net.Destination, ra
}
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()
@ -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.")
return
}
log.Info("VMessOut received %d bytes from %s", len(buffer) - 4, conn.RemoteAddr().String())
output <- buffer[4:]
@ -206,10 +207,10 @@ func (factory *VMessOutboundHandlerFactory) Initialize(rawConfig []byte) error {
udpServers := make([]VNextServer, 0, len(config.VNextList))
for _, server := range config.VNextList {
if server.HasNetwork("tcp") {
servers = append(servers, server.ToVNextServer())
servers = append(servers, server.ToVNextServer("tcp"))
}
if server.HasNetwork("udp") {
udpServers = append(udpServers, server.ToVNextServer())
udpServers = append(udpServers, server.ToVNextServer("udp"))
}
}
factory.servers = servers

Loading…
Cancel
Save