From e6a35199e0d397d68994d4b6a9e8312073596260 Mon Sep 17 00:00:00 2001 From: Skyxim Date: Sun, 26 Feb 2023 20:15:28 +0800 Subject: [PATCH] fix: dual stack serial dial --- component/dialer/dialer.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/component/dialer/dialer.go b/component/dialer/dialer.go index 3d1be1d6..d4c937e7 100644 --- a/component/dialer/dialer.go +++ b/component/dialer/dialer.go @@ -133,15 +133,12 @@ func serialDualStackDialContext(ctx context.Context, network, address string, op if err != nil { return nil, err } - if opt.prefer != 4 && opt.prefer != 6 { - return serialDialContext(ctx, network, ips, port, opt) - } ipv4s, ipv6s := sortationAddr(ips) return dualStackDialContext( ctx, func(ctx context.Context) (net.Conn, error) { return serialDialContext(ctx, network, ipv4s, port, opt) }, func(ctx context.Context) (net.Conn, error) { return serialDialContext(ctx, network, ipv6s, port, opt) }, - opt.prefer == 4) + opt.prefer) } func concurrentSingleStackDialContext(ctx context.Context, network string, address string, opt *option) (net.Conn, error) { @@ -174,14 +171,14 @@ func concurrentDualStackDialContext(ctx context.Context, network, address string func(ctx context.Context) (net.Conn, error) { return parallelDialContext(ctx, network, ipv6s, port, opt) }, - opt.prefer == 4) + opt.prefer) } func dualStackDialContext( ctx context.Context, ipv4DialFn func(ctx context.Context) (net.Conn, error), ipv6DialFn func(ctx context.Context) (net.Conn, error), - preferIPv4 bool) (net.Conn, error) { + preferIPVersion int) (net.Conn, error) { fallbackTicker := time.NewTicker(fallbackTimeout) defer fallbackTicker.Stop() results := make(chan dialResult) @@ -200,8 +197,8 @@ func dualStackDialContext( }() result.Conn, result.error = dial(ctx) } - go racer(ipv4DialFn, preferIPv4) - go racer(ipv6DialFn, !preferIPv4) + go racer(ipv4DialFn, preferIPVersion != 6) + go racer(ipv6DialFn, preferIPVersion != 4) var fallback dialResult var err error for {