do prestart dns checkings 10 times faster in parallel
This commit is contained in:
@@ -2,6 +2,7 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
@@ -12,6 +13,7 @@ import (
|
|||||||
C "github.com/sagernet/sing-box/constant"
|
C "github.com/sagernet/sing-box/constant"
|
||||||
"github.com/sagernet/sing-box/option"
|
"github.com/sagernet/sing-box/option"
|
||||||
dns "github.com/sagernet/sing-dns"
|
dns "github.com/sagernet/sing-dns"
|
||||||
|
"github.com/sagernet/sing/common/batch"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -470,11 +472,19 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
|
|||||||
if len(directDNSDomains) > 0 {
|
if len(directDNSDomains) > 0 {
|
||||||
trickDnsDomains := []string{}
|
trickDnsDomains := []string{}
|
||||||
directDNSDomains = removeDuplicateStr(directDNSDomains)
|
directDNSDomains = removeDuplicateStr(directDNSDomains)
|
||||||
|
b, _ := batch.New(context.Background(), batch.WithConcurrencyNum[bool](10))
|
||||||
for _, d := range directDNSDomains {
|
for _, d := range directDNSDomains {
|
||||||
if isBlockedDomain(d) {
|
b.Go(d, func() (bool, error) {
|
||||||
trickDnsDomains = append(trickDnsDomains, d)
|
return isBlockedDomain(d), nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
b.Wait()
|
||||||
|
for domain, isBlock := range b.Result() {
|
||||||
|
if isBlock.Value {
|
||||||
|
trickDnsDomains = append(trickDnsDomains, domain)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trickDomains := strings.Join(trickDnsDomains, ",")
|
trickDomains := strings.Join(trickDnsDomains, ",")
|
||||||
trickRule := Rule{Domains: trickDomains, Outbound: OutboundBypassTag}
|
trickRule := Rule{Domains: trickDomains, Outbound: OutboundBypassTag}
|
||||||
trickDnsRule := trickRule.MakeDNSRule()
|
trickDnsRule := trickRule.MakeDNSRule()
|
||||||
|
|||||||
5
go.mod
5
go.mod
@@ -19,6 +19,7 @@ require (
|
|||||||
require (
|
require (
|
||||||
berty.tech/go-libtor v1.0.385 // indirect
|
berty.tech/go-libtor v1.0.385 // indirect
|
||||||
github.com/ajg/form v1.5.1 // 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/andybalholm/brotli v1.0.6 // indirect
|
||||||
github.com/caddyserver/certmagic v0.20.0 // indirect
|
github.com/caddyserver/certmagic v0.20.0 // indirect
|
||||||
github.com/cloudflare/circl v1.3.7 // indirect
|
github.com/cloudflare/circl v1.3.7 // indirect
|
||||||
@@ -103,8 +104,8 @@ require (
|
|||||||
lukechampine.com/blake3 v1.2.1 // indirect
|
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/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