Skip to content

Commit 40cbf8b

Browse files
committed
create custom resolvers from config
1 parent 7d23b5c commit 40cbf8b

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

core/node/dns.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
package node
22

33
import (
4+
"fmt"
5+
"strings"
6+
47
config "github.com/ipfs/go-ipfs-config"
8+
doh "github.com/libp2p/go-doh-resolver"
59
madns "github.com/multiformats/go-multiaddr-dns"
610
)
711

812
func DNSResolver(cfg *config.Config) (*madns.Resolver, error) {
9-
// TODO custom resolvers from config
10-
return madns.DefaultResolver, nil
13+
var opts []madns.Option
14+
if url := cfg.DNS.DefaultResolver; url != "" {
15+
if !strings.HasPrefix(url, "https://") {
16+
return nil, fmt.Errorf("invalid default resolver url: %s", url)
17+
}
18+
opts = append(opts, madns.WithDefaultResolver(doh.NewResolver(url)))
19+
}
20+
for domain, url := range cfg.DNS.CustomResolvers {
21+
if !strings.HasPrefix(url, "https://") {
22+
return nil, fmt.Errorf("invalid domain resolver url for %s: %s", domain, url)
23+
}
24+
opts = append(opts, madns.WithDomainResolver(domain, doh.NewResolver(url)))
25+
}
26+
return madns.NewResolver(opts...)
1127
}

0 commit comments

Comments
 (0)