mirror of
https://github.com/golang/go
synced 2024-11-08 11:16:19 -07:00
net: enable RFC 6555 Fast Fallback by default
The Dialer.DualStack field is now meaningless and documented as deprecated. To disable fallback, set FallbackDelay to a negative value. Fixes #22225 Change-Id: Icc212fe07bb69d7651ab81e539b8b3e3d3372fa9 Reviewed-on: https://go-review.googlesource.com/c/146659 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
0ff6e5f1b4
commit
efc185029b
@ -44,16 +44,23 @@ type Dialer struct {
|
|||||||
// If nil, a local address is automatically chosen.
|
// If nil, a local address is automatically chosen.
|
||||||
LocalAddr Addr
|
LocalAddr Addr
|
||||||
|
|
||||||
// DualStack enables RFC 6555-compliant "Happy Eyeballs"
|
// DualStack previously enabled RFC 6555 Fast Fallback
|
||||||
// dialing when the network is "tcp" and the host in the
|
// support, also known as "Happy Eyeballs", in which IPv4 is
|
||||||
// address parameter resolves to both IPv4 and IPv6 addresses.
|
// tried soon if IPv6 appears to be misconfigured and
|
||||||
// This allows a client to tolerate networks where one address
|
// hanging.
|
||||||
// family is silently broken.
|
//
|
||||||
|
// Deprecated: Fast Fallback is enabled by default. To
|
||||||
|
// disable, set FallbackDelay to a negative value.
|
||||||
DualStack bool
|
DualStack bool
|
||||||
|
|
||||||
// FallbackDelay specifies the length of time to wait before
|
// FallbackDelay specifies the length of time to wait before
|
||||||
// spawning a fallback connection, when DualStack is enabled.
|
// spawning a RFC 6555 Fast Fallback connection. That is, this
|
||||||
|
// is the amount of time to wait for IPv6 to succeed before
|
||||||
|
// assuming that IPv6 is misconfigured and falling back to
|
||||||
|
// IPv4.
|
||||||
|
//
|
||||||
// If zero, a default delay of 300ms is used.
|
// If zero, a default delay of 300ms is used.
|
||||||
|
// A negative value disables Fast Fallback support.
|
||||||
FallbackDelay time.Duration
|
FallbackDelay time.Duration
|
||||||
|
|
||||||
// KeepAlive specifies the keep-alive period for an active
|
// KeepAlive specifies the keep-alive period for an active
|
||||||
@ -81,6 +88,8 @@ type Dialer struct {
|
|||||||
Control func(network, address string, c syscall.RawConn) error
|
Control func(network, address string, c syscall.RawConn) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Dialer) dualStack() bool { return d.FallbackDelay >= 0 }
|
||||||
|
|
||||||
func minNonzeroTime(a, b time.Time) time.Time {
|
func minNonzeroTime(a, b time.Time) time.Time {
|
||||||
if a.IsZero() {
|
if a.IsZero() {
|
||||||
return b
|
return b
|
||||||
@ -393,7 +402,7 @@ func (d *Dialer) DialContext(ctx context.Context, network, address string) (Conn
|
|||||||
}
|
}
|
||||||
|
|
||||||
var primaries, fallbacks addrList
|
var primaries, fallbacks addrList
|
||||||
if d.DualStack && network == "tcp" {
|
if d.dualStack() && network == "tcp" {
|
||||||
primaries, fallbacks = addrs.partition(isIPv4)
|
primaries, fallbacks = addrs.partition(isIPv4)
|
||||||
} else {
|
} else {
|
||||||
primaries = addrs
|
primaries = addrs
|
||||||
|
Loading…
Reference in New Issue
Block a user