mirror of https://github.com/v2ray/v2ray-core
use golang's default dual stack algo when dialling to a domain
parent
d2c5771fae
commit
00fd6861a6
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue