Feature: sync missing resolver logic from premium, but still net.IP on opensource

This commit is contained in:
Dreamacro
2022-08-13 13:07:35 +08:00
parent 5940f62794
commit 3946d771e5
5 changed files with 129 additions and 43 deletions

View File

@ -4,7 +4,9 @@ import (
"bytes"
"context"
"crypto/tls"
"fmt"
"io"
"math/rand"
"net"
"net/http"
@ -91,10 +93,13 @@ func newDoHClient(url, iface string, r *Resolver) *dohClient {
return nil, err
}
ip, err := resolver.ResolveIPWithResolver(host, r)
ips, err := resolver.LookupIPWithResolver(ctx, host, r)
if err != nil {
return nil, err
} else if len(ips) == 0 {
return nil, fmt.Errorf("%w: %s", resolver.ErrIPNotFound, host)
}
ip := ips[rand.Intn(len(ips))]
options := []dialer.Option{}
if iface != "" {