do prestart dns checkings 10 times faster in parallel
This commit is contained in:
@@ -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()
|
||||
|
||||
5
go.mod
5
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
|
||||
|
||||
Reference in New Issue
Block a user