1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-28 23:06:14 -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 ( import (
"errors" "errors"
"net" "net"
"time"
"github.com/v2ray/v2ray-core/common/dice"
v2net "github.com/v2ray/v2ray-core/common/net" v2net "github.com/v2ray/v2ray-core/common/net"
) )
@ -13,19 +13,19 @@ var (
) )
func Dial(dest v2net.Destination) (net.Conn, error) { func Dial(dest v2net.Destination) (net.Conn, error) {
var ip net.IP if dest.Address().IsDomain() {
if dest.Address().IsIPv4() || dest.Address().IsIPv6() { dialer := &net.Dialer{
ip = dest.Address().IP() Timeout: time.Second * 60,
} else { DualStack: true,
ips, err := net.LookupIP(dest.Address().Domain())
if err != nil {
return nil, err
} }
if len(ips) == 0 { network := "tcp"
return nil, ErrorInvalidHost if dest.IsUDP() {
network = "udp"
} }
ip = ips[dice.Roll(len(ips))] return dialer.Dial(network, dest.NetAddr())
} }
ip := dest.Address().IP()
if dest.IsTCP() { if dest.IsTCP() {
return net.DialTCP("tcp", nil, &net.TCPAddr{ return net.DialTCP("tcp", nil, &net.TCPAddr{
IP: ip, IP: ip,