mirror of
https://github.com/fumiama/terasu.git
synced 2026-06-05 01:00:23 +08:00
feat: drop ipv6 test due to server down
This commit is contained in:
@@ -16,7 +16,7 @@ func LookupHost(ctx context.Context, host string) (addrs []string, err error) {
|
|||||||
if len(addrs) == 0 {
|
if len(addrs) == 0 {
|
||||||
addrs, err = DefaultResolver.LookupHost(ctx, host)
|
addrs, err = DefaultResolver.LookupHost(ctx, host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if ip.IsIPv6Available.Get() {
|
if ip.IsIPv6Available {
|
||||||
addrs, err = IPv6Servers.lookupHostDoH(ctx, host)
|
addrs, err = IPv6Servers.lookupHostDoH(ctx, host)
|
||||||
} else {
|
} else {
|
||||||
addrs, err = IPv4Servers.lookupHostDoH(ctx, host)
|
addrs, err = IPv4Servers.lookupHostDoH(ctx, host)
|
||||||
|
|||||||
@@ -273,7 +273,7 @@ var IPv4Servers = DNSList{
|
|||||||
var DefaultResolver = &net.Resolver{
|
var DefaultResolver = &net.Resolver{
|
||||||
PreferGo: true,
|
PreferGo: true,
|
||||||
Dial: func(ctx context.Context, nw, _ string) (net.Conn, error) {
|
Dial: func(ctx context.Context, nw, _ string) (net.Conn, error) {
|
||||||
if ip.IsIPv6Available.Get() {
|
if ip.IsIPv6Available {
|
||||||
return IPv6Servers.DialContext(ctx, nil, terasu.DefaultFirstFragmentLen)
|
return IPv6Servers.DialContext(ctx, nil, terasu.DefaultFirstFragmentLen)
|
||||||
}
|
}
|
||||||
return IPv4Servers.DialContext(ctx, nil, terasu.DefaultFirstFragmentLen)
|
return IPv4Servers.DialContext(ctx, nil, terasu.DefaultFirstFragmentLen)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestResolver(t *testing.T) {
|
func TestResolver(t *testing.T) {
|
||||||
t.Log("IsIPv6Available:", ip.IsIPv6Available.Get())
|
t.Log("IsIPv6Available:", ip.IsIPv6Available)
|
||||||
addrs, err := DefaultResolver.LookupHost(context.TODO(), "huggingface.co")
|
addrs, err := DefaultResolver.LookupHost(context.TODO(), "huggingface.co")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -25,9 +25,9 @@ func TestResolver(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestResolverFallback(t *testing.T) {
|
func TestResolverFallback(t *testing.T) {
|
||||||
t.Log("IsIPv6Available:", ip.IsIPv6Available.Get())
|
t.Log("IsIPv6Available:", ip.IsIPv6Available)
|
||||||
|
|
||||||
if ip.IsIPv6Available.Get() {
|
if ip.IsIPv6Available {
|
||||||
addrs, err := IPv6Servers.lookupHostDoH(context.TODO(), "huggingface.co")
|
addrs, err := IPv6Servers.lookupHostDoH(context.TODO(), "huggingface.co")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -48,7 +48,7 @@ func TestResolverFallback(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDNS(t *testing.T) {
|
func TestDNS(t *testing.T) {
|
||||||
if ip.IsIPv6Available.Get() {
|
if ip.IsIPv6Available {
|
||||||
IPv6Servers.test()
|
IPv6Servers.test()
|
||||||
}
|
}
|
||||||
IPv4Servers.test()
|
IPv4Servers.test()
|
||||||
@@ -76,7 +76,7 @@ func TestBadDNS(t *testing.T) {
|
|||||||
IPv6Servers.m = dotv6serversbak
|
IPv6Servers.m = dotv6serversbak
|
||||||
IPv4Servers.m = dotv4serversbak
|
IPv4Servers.m = dotv4serversbak
|
||||||
}()
|
}()
|
||||||
if ip.IsIPv6Available.Get() {
|
if ip.IsIPv6Available {
|
||||||
IPv6Servers = DNSList{
|
IPv6Servers = DNSList{
|
||||||
m: map[string][]*dnsstat{},
|
m: map[string][]*dnsstat{},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ func lookupdoh(ctx context.Context, server, u string) (jr dohjsonresponse, err e
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ip.IsIPv6Available.Get() {
|
if ip.IsIPv6Available {
|
||||||
jr, err = lookupdohwithtype(ctx, server, u, recordTypeA)
|
jr, err = lookupdohwithtype(ctx, server, u, recordTypeA)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@@ -157,7 +157,7 @@ func lookupdohwithtype(ctx context.Context, server, u string, typ recordType) (j
|
|||||||
}
|
}
|
||||||
|
|
||||||
func preferreddohtype() recordType {
|
func preferreddohtype() recordType {
|
||||||
if ip.IsIPv6Available.Get() {
|
if ip.IsIPv6Available {
|
||||||
return recordTypeAAAA
|
return recordTypeAAAA
|
||||||
}
|
}
|
||||||
return recordTypeA
|
return recordTypeA
|
||||||
|
|||||||
1
go.mod
1
go.mod
@@ -4,7 +4,6 @@ go 1.20
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/FloatTech/ttl v0.0.0-20250224045156-012b1463287d
|
github.com/FloatTech/ttl v0.0.0-20250224045156-012b1463287d
|
||||||
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7
|
|
||||||
golang.org/x/net v0.24.0
|
golang.org/x/net v0.24.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -1,7 +1,5 @@
|
|||||||
github.com/FloatTech/ttl v0.0.0-20250224045156-012b1463287d h1:mUQ/c3wXKsUGa4Sg9DBy01APXKB68PmobhxOyaJI7lY=
|
github.com/FloatTech/ttl v0.0.0-20250224045156-012b1463287d h1:mUQ/c3wXKsUGa4Sg9DBy01APXKB68PmobhxOyaJI7lY=
|
||||||
github.com/FloatTech/ttl v0.0.0-20250224045156-012b1463287d/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
|
github.com/FloatTech/ttl v0.0.0-20250224045156-012b1463287d/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
|
||||||
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7 h1:S/ferNiehVjNaBMNNBxUjLtVmP/YWD6Yh79RfPv4ehU=
|
|
||||||
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7/go.mod h1:vD7Ra3Q9onRtojoY5sMCLQ7JBgjUsrXDnDKyFxqpf9w=
|
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
||||||
|
|||||||
27
ip/ipv6.go
27
ip/ipv6.go
@@ -1,28 +1,3 @@
|
|||||||
package ip
|
package ip
|
||||||
|
|
||||||
import (
|
var IsIPv6Available = true
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/RomiChan/syncx"
|
|
||||||
)
|
|
||||||
|
|
||||||
var IsIPv6Available = syncx.Lazy[bool]{Init: func() bool {
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
|
|
||||||
defer cancel()
|
|
||||||
req, err := http.NewRequestWithContext(ctx, "GET", "http://v6.ipv6-test.com/json/widgetdata.php?callback=?", nil)
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
resp, err := http.DefaultClient.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
_ = resp.Body.Close()
|
|
||||||
return true
|
|
||||||
}}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
go IsIPv6Available.Get()
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user