1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-28 14:56:33 -04:00

use golang's default dual stack algo when dialling to a domain

This commit is contained in:
v2ray 2016-02-18 12:28:45 +01:00
parent d2c5771fae
commit 00fd6861a6

View File

@ -3,8 +3,8 @@ package dialer
import (
"errors"
"net"
"time"
"github.com/v2ray/v2ray-core/common/dice"
v2net "github.com/v2ray/v2ray-core/common/net"
)
@ -13,19 +13,19 @@ var (
)
func Dial(dest v2net.Destination) (net.Conn, error) {
var ip net.IP
if dest.Address().IsIPv4() || dest.Address().IsIPv6() {
ip = dest.Address().IP()
} else {
ips, err := net.LookupIP(dest.Address().Domain())
if err != nil {
return nil, err
if dest.Address().IsDomain() {
dialer := &net.Dialer{
Timeout: time.Second * 60,
DualStack: true,
}
if len(ips) == 0 {
return nil, ErrorInvalidHost
network := "tcp"
if dest.IsUDP() {
network = "udp"
}
ip = ips[dice.Roll(len(ips))]
return dialer.Dial(network, dest.NetAddr())
}
ip := dest.Address().IP()
if dest.IsTCP() {
return net.DialTCP("tcp", nil, &net.TCPAddr{
IP: ip,