-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change(ipv6): detect automatically and use only IPv6 if supported
- Keeps Go API to be up to the user with an `IPVersion` setting field - `DOT_IP_VERSION`, `DOH_IP_VERSION` removed
- Loading branch information
Showing
12 changed files
with
121 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package support | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net" | ||
"net/netip" | ||
"strings" | ||
"time" | ||
) | ||
|
||
func IPv6(ctx context.Context, ipv6AddrPort netip.AddrPort) ( | ||
ipv6Supported bool, err error) { | ||
if !ipv6AddrPort.IsValid() { | ||
const cloudflareIPv6AddrPort = "[2606:4700:4700::1111]:443" | ||
ipv6AddrPort = netip.MustParseAddrPort(cloudflareIPv6AddrPort) | ||
} | ||
|
||
dialer := net.Dialer{ | ||
Timeout: time.Second, | ||
} | ||
conn, err := dialer.DialContext(ctx, "tcp", ipv6AddrPort.String()) | ||
if err != nil { | ||
if ctxErr := ctx.Err(); ctxErr != nil { | ||
return false, ctxErr | ||
} | ||
if strings.HasSuffix(err.Error(), "cannot assign requested address") { | ||
return false, nil | ||
} | ||
return false, fmt.Errorf("unknown error: %w", err) | ||
} | ||
|
||
err = conn.Close() | ||
if err != nil { | ||
return false, fmt.Errorf("closing connection: %w", err) | ||
} | ||
|
||
return true, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//go:build integration | ||
// +build integration | ||
|
||
package support | ||
|
||
import ( | ||
"context" | ||
"net/netip" | ||
"testing" | ||
) | ||
|
||
func Test_IPv6(t *testing.T) { | ||
t.Parallel() | ||
|
||
ctx := context.Background() | ||
|
||
cloudflareIPv6AddrPort := netip.MustParseAddrPort("[2606:4700:4700::1111]:443") | ||
|
||
ipv6Supported, err := IPv6(ctx, cloudflareIPv6AddrPort) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
t.Log("IPv6 supported:", ipv6Supported) | ||
} |