Skip to content

Commit

Permalink
默认使用 passthrough resolver close #75
Browse files Browse the repository at this point in the history
Co-authored-by: NewbieOrange <[email protected]>
  • Loading branch information
naiba and NewbieOrange committed Oct 19, 2024
1 parent 4042601 commit 765f7d9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/resolver"

"github.com/nezhahq/agent/model"
fm "github.com/nezhahq/agent/pkg/fm"
Expand Down Expand Up @@ -63,7 +64,7 @@ var (
arch string
client pb.NezhaServiceClient
initialized bool
resolver = &net.Resolver{PreferGo: true}
dnsResolver = &net.Resolver{PreferGo: true}
)

var agentCmd = &cobra.Command{
Expand Down Expand Up @@ -99,6 +100,7 @@ const (
)

func init() {
resolver.SetDefaultScheme("passthrough")
net.DefaultResolver.PreferGo = true // 使用 Go 内置的 DNS 解析器解析域名
net.DefaultResolver.Dial = func(ctx context.Context, network, address string) (net.Conn, error) {
d := net.Dialer{
Expand Down Expand Up @@ -862,7 +864,7 @@ func generateQueue(start int, size int) []int {

func lookupIP(hostOrIp string) (string, error) {
if net.ParseIP(hostOrIp) == nil {
ips, err := resolver.LookupIPAddr(context.Background(), hostOrIp)
ips, err := dnsResolver.LookupIPAddr(context.Background(), hostOrIp)
if err != nil {
return "", err
}
Expand Down

0 comments on commit 765f7d9

Please sign in to comment.