From df750c3f9cea936efd868f45c5fe131e76eceb33 Mon Sep 17 00:00:00 2001 From: Hiddify Date: Mon, 12 Feb 2024 07:59:55 +0100 Subject: [PATCH] do prestart dns checkings 10 times faster in parallel --- config/config.go | 14 ++++++++++++-- go.mod | 5 +++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/config/config.go b/config/config.go index 1c7f593..e94a1a2 100644 --- a/config/config.go +++ b/config/config.go @@ -2,6 +2,7 @@ package config import ( "bytes" + "context" "encoding/json" "fmt" "net" @@ -12,6 +13,7 @@ import ( C "github.com/sagernet/sing-box/constant" "github.com/sagernet/sing-box/option" dns "github.com/sagernet/sing-dns" + "github.com/sagernet/sing/common/batch" ) const ( @@ -470,11 +472,19 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro if len(directDNSDomains) > 0 { trickDnsDomains := []string{} directDNSDomains = removeDuplicateStr(directDNSDomains) + b, _ := batch.New(context.Background(), batch.WithConcurrencyNum[bool](10)) for _, d := range directDNSDomains { - if isBlockedDomain(d) { - trickDnsDomains = append(trickDnsDomains, d) + b.Go(d, func() (bool, error) { + return isBlockedDomain(d), nil + }) + } + b.Wait() + for domain, isBlock := range b.Result() { + if isBlock.Value { + trickDnsDomains = append(trickDnsDomains, domain) } } + trickDomains := strings.Join(trickDnsDomains, ",") trickRule := Rule{Domains: trickDomains, Outbound: OutboundBypassTag} trickDnsRule := trickRule.MakeDNSRule() diff --git a/go.mod b/go.mod index 6a61990..1613ee4 100644 --- a/go.mod +++ b/go.mod @@ -19,6 +19,7 @@ require ( require ( berty.tech/go-libtor v1.0.385 // indirect github.com/ajg/form v1.5.1 // indirect + github.com/akavel/rsrc v0.10.2 // indirect github.com/andybalholm/brotli v1.0.6 // indirect github.com/caddyserver/certmagic v0.20.0 // indirect github.com/cloudflare/circl v1.3.7 // indirect @@ -103,8 +104,8 @@ require ( lukechampine.com/blake3 v1.2.1 // indirect ) -replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.7.9-0.20240210202736-e5b942dbf7d9 +replace github.com/sagernet/sing-box => github.com/hiddify/hiddify-sing-box v1.7.9-0.20240212055434-7c6e0e8e8af9 replace github.com/sagernet/wireguard-go => github.com/hiddify/wireguard-go v0.0.0-20240125143346-481d18d77fe1 -replace github.com/bepass-org/wireguard-go => github.com/hiddify-com/wireguard-go v0.0.2-alpha.0.20240206112722-83bfc813cc29 +replace github.com/bepass-org/wireguard-go => github.com/hiddify-com/wireguard-go v0.0.2-alpha.0.20240212065415-62301f758cb7